playnote uses volume from vm to set gain

This commit is contained in:
Eric Rosenbaum 2017-02-09 14:53:59 -05:00
parent 83c4072e59
commit b91226f9e8
2 changed files with 8 additions and 4 deletions

View file

@ -35,11 +35,15 @@ function InstrumentPlayer (outputNode) {
* @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)
*/ */
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
}
); );
}); });
}; };

View file

@ -97,9 +97,9 @@ AudioEngine.prototype.loadSounds = function (sounds) {
* @param {number} inst - an instrument number (0-indexed) * @param {number} inst - an instrument number (0-indexed)
* @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);
}; };