Clamp range for “play note” input

Clamp to 36-96, which is C2-C7.

This is a temporary fix to prevent errors, until we have a new instrument player implementation, which may have a different range.
This commit is contained in:
Eric Rosenbaum 2017-03-17 17:23:53 -04:00
parent b03768cad6
commit 1ba7ad0218

View file

@ -33,6 +33,12 @@ Scratch3SoundBlocks.DEFAULT_SOUND_STATE = {
}
};
/**
* The minimum and maximum MIDI note numbers, for clamping the input to play note.
* @type {{min: number, max: number}}
*/
Scratch3SoundBlocks.MIDI_NOTE_RANGE = {min: 36, max: 96}; // C2 to C7
/**
* @param {Target} target - collect sound state for this target.
* @returns {SoundState} the mutable sound state associated with that target. This will be created if necessary.
@ -132,6 +138,7 @@ Scratch3SoundBlocks.prototype.stopAllSounds = function (args, util) {
Scratch3SoundBlocks.prototype.playNoteForBeats = function (args, util) {
var note = Cast.toNumber(args.NOTE);
note = MathUtil.clamp(note, Scratch3SoundBlocks.MIDI_NOTE_RANGE.min, Scratch3SoundBlocks.MIDI_NOTE_RANGE.max);
var beats = Cast.toNumber(args.BEATS);
var soundState = this._getSoundState(util.target);
var inst = soundState.currentInstrument;