mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2025-03-23 05:05:48 -04:00
Merge pull request #26 from LLK/bugfix/playnote-volume
Playnote uses volume from vm to set gain
This commit is contained in:
commit
4eb12ea075
2 changed files with 11 additions and 5 deletions
|
@ -34,12 +34,17 @@ function InstrumentPlayer (outputNode) {
|
||||||
* @param {number} note - a MIDI note number
|
* @param {number} note - a MIDI note number
|
||||||
* @param {number} sec - a duration in seconds
|
* @param {number} sec - a duration in seconds
|
||||||
* @param {number} instrumentNum - an instrument number (0-indexed)
|
* @param {number} instrumentNum - an instrument number (0-indexed)
|
||||||
|
* @param {number} vol - a volume level (0-100%)
|
||||||
*/
|
*/
|
||||||
InstrumentPlayer.prototype.playNoteForSecWithInst = function (note, sec, instrumentNum) {
|
InstrumentPlayer.prototype.playNoteForSecWithInstAndVol = function (note, sec, instrumentNum, vol) {
|
||||||
|
var gain = vol / 100;
|
||||||
this.loadInstrument(instrumentNum)
|
this.loadInstrument(instrumentNum)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.instruments[instrumentNum].play(
|
this.instruments[instrumentNum].play(
|
||||||
note, Tone.context.currentTime, {duration : sec}
|
note, Tone.context.currentTime, {
|
||||||
|
duration : sec,
|
||||||
|
gain : gain
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -91,15 +91,16 @@ AudioEngine.prototype.loadSounds = function (sounds) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play a note for a duration on an instrument
|
* Play a note for a duration on an instrument with a volume
|
||||||
* @param {number} note - a MIDI note number
|
* @param {number} note - a MIDI note number
|
||||||
* @param {number} beats - a duration in beats
|
* @param {number} beats - a duration in beats
|
||||||
* @param {number} inst - an instrument number (0-indexed)
|
* @param {number} inst - an instrument number (0-indexed)
|
||||||
|
* @param {number} vol - a volume level (0-100%)
|
||||||
* @return {Promise} a Promise that resolves after the duration has elapsed
|
* @return {Promise} a Promise that resolves after the duration has elapsed
|
||||||
*/
|
*/
|
||||||
AudioEngine.prototype.playNoteForBeatsWithInst = function (note, beats, inst) {
|
AudioEngine.prototype.playNoteForBeatsWithInstAndVol = function (note, beats, inst, vol) {
|
||||||
var sec = this.beatsToSec(beats);
|
var sec = this.beatsToSec(beats);
|
||||||
this.instrumentPlayer.playNoteForSecWithInst(note, sec, inst);
|
this.instrumentPlayer.playNoteForSecWithInstAndVol(note, sec, inst, vol);
|
||||||
return this.waitForBeats(beats);
|
return this.waitForBeats(beats);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue