diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 26315a952..a86c17130 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -68,6 +68,10 @@ const ArgumentTypeMap = (() => { shadowType: 'matrix', fieldType: 'MATRIX' }; + map[ArgumentType.NOTE] = { + shadowType: 'note', + fieldType: 'NOTE' + }; return map; })(); diff --git a/src/extension-support/argument-type.js b/src/extension-support/argument-type.js index 48f8c56fd..ddbc9463d 100644 --- a/src/extension-support/argument-type.js +++ b/src/extension-support/argument-type.js @@ -29,9 +29,14 @@ const ArgumentType = { STRING: 'string', /** - * String value with matirx field + * String value with matrix field */ - MATRIX: 'matrix' + MATRIX: 'matrix', + + /** + * MIDI note number with note picker (piano) field + */ + NOTE: 'note' }; module.exports = ArgumentType; diff --git a/src/extensions/scratch3_ev3/index.js b/src/extensions/scratch3_ev3/index.js index b24dac572..41d541d81 100644 --- a/src/extensions/scratch3_ev3/index.js +++ b/src/extensions/scratch3_ev3/index.js @@ -910,6 +910,9 @@ class Scratch3Ev3Blocks { // Create a new EV3 peripheral instance this._peripheral = new EV3(this.runtime, Scratch3Ev3Blocks.EXTENSION_ID); + + this._playNoteForPicker = this._playNoteForPicker.bind(this); + this.runtime.on('PLAY_NOTE', this._playNoteForPicker); } /** @@ -1089,7 +1092,7 @@ class Scratch3Ev3Blocks { blockType: BlockType.COMMAND, arguments: { NOTE: { - type: ArgumentType.NUMBER, + type: ArgumentType.NOTE, defaultValue: 60 }, TIME: { @@ -1212,6 +1215,14 @@ class Scratch3Ev3Blocks { return this._peripheral.brightness; } + _playNoteForPicker (note, category) { + if (category !== this.getInfo().name) return; + this.beep({ + NOTE: note, + TIME: 0.25 + }); + } + beep (args) { const note = MathUtil.clamp(Cast.toNumber(args.NOTE), 47, 99); // valid EV3 sounds let time = Cast.toNumber(args.TIME) * 1000; diff --git a/src/extensions/scratch3_music/index.js b/src/extensions/scratch3_music/index.js index 708c1154f..352257415 100644 --- a/src/extensions/scratch3_music/index.js +++ b/src/extensions/scratch3_music/index.js @@ -85,6 +85,9 @@ class Scratch3MusicBlocks { this._onTargetCreated = this._onTargetCreated.bind(this); this.runtime.on('targetWasCreated', this._onTargetCreated); + + this._playNoteForPicker = this._playNoteForPicker.bind(this); + this.runtime.on('PLAY_NOTE', this._playNoteForPicker); } /** @@ -747,7 +750,7 @@ class Scratch3MusicBlocks { }), arguments: { NOTE: { - type: ArgumentType.NUMBER, + type: ArgumentType.NOTE, defaultValue: 60 }, BEATS: { @@ -940,6 +943,15 @@ class Scratch3MusicBlocks { } } + _playNoteForPicker (noteNum, category) { + if (category !== this.getInfo().name) return; + const util = { + runtime: this.runtime, + target: this.runtime.getEditingTarget() + }; + this._playNote(util, noteNum, 0.25); + } + /** * Play a note using the current instrument for a duration in seconds. * This function actually plays the sound, and handles the timing of the sound, including the