From c97c636cd14919028f75b179ca978511079acc07 Mon Sep 17 00:00:00 2001 From: Michael Deal Date: Fri, 25 Jan 2013 09:33:47 -0800 Subject: [PATCH] add @Miranet's fix for issue #11 https://github.com/mudcube/MIDI.js/issues/11 --- js/MIDI/Plugin.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/js/MIDI/Plugin.js b/js/MIDI/Plugin.js index 4526843..92b2c52 100644 --- a/js/MIDI/Plugin.js +++ b/js/MIDI/Plugin.js @@ -4,7 +4,10 @@ -------------------------------------------- https://github.com/mudcube/MIDI.js -------------------------------------------- - APIs: + Inspired by javax.sound.midi (albeit a super simple version): + http://docs.oracle.com/javase/6/docs/api/javax/sound/midi/package-summary.html + -------------------------------------------- + Technologies: MIDI.WebMIDIAPI MIDI.WebAudioAPI MIDI.Flash @@ -175,15 +178,16 @@ if (window.AudioContext || window.webkitAudioContext) (function () { return source; }; - // FIX: needs some way to fade out smoothly.. - // POSSIBLE FIX: fade out smoothly using gain and ramping to value root.noteOff = function (channel, note, delay) { delay = delay || 0; + if (delay < ctx.currentTime) delay += ctx.currentTime; var source = sources[channel + "" + note]; if (!source) return; + // @Miranet: "the values of 0.4 and 0.5 could ofcourse be used as + // a 'release' parameter for ADSR like time settings." source.gain.linearRampToValueAtTime(1, delay); - source.gain.linearRampToValueAtTime(0, delay + 0.75); - source.noteOff(delay + 0.75); + source.gain.linearRampToValueAtTime(0, delay + 0.4); + source.noteOff(delay + 0.5); return source; };