From b91226f9e8b0f80d2ee51e51b3eeb3bf58b2f7f9 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Thu, 9 Feb 2017 14:53:59 -0500 Subject: [PATCH] playnote uses volume from vm to set gain --- src/InstrumentPlayer.js | 8 ++++++-- src/index.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/InstrumentPlayer.js b/src/InstrumentPlayer.js index 81dbacb..d3cf1cd 100644 --- a/src/InstrumentPlayer.js +++ b/src/InstrumentPlayer.js @@ -35,11 +35,15 @@ function InstrumentPlayer (outputNode) { * @param {number} sec - a duration in seconds * @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) .then(() => { this.instruments[instrumentNum].play( - note, Tone.context.currentTime, {duration : sec} + note, Tone.context.currentTime, { + duration : sec, + gain : gain + } ); }); }; diff --git a/src/index.js b/src/index.js index bb6fa7c..2d1be57 100644 --- a/src/index.js +++ b/src/index.js @@ -97,9 +97,9 @@ AudioEngine.prototype.loadSounds = function (sounds) { * @param {number} inst - an instrument number (0-indexed) * @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); - this.instrumentPlayer.playNoteForSecWithInst(note, sec, inst); + this.instrumentPlayer.playNoteForSecWithInstAndVol(note, sec, inst, vol); return this.waitForBeats(beats); };