From 15d4d0cb1e68d3e6e8f345e6dfec2c034ea54e7a Mon Sep 17 00:00:00 2001 From: Pete Otaqui Date: Wed, 21 Nov 2012 06:19:25 +0300 Subject: [PATCH] Enabled noteOff with a linear fade to 0 fade out smoothly using gain and ramping to value. I've chosen an arbitrary amount to fade by here, which I guess isn't great. --- js/MIDI/Plugin.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/js/MIDI/Plugin.js b/js/MIDI/Plugin.js index 935b318..41c62ba 100644 --- a/js/MIDI/Plugin.js +++ b/js/MIDI/Plugin.js @@ -102,11 +102,14 @@ if (window.AudioContext || window.webkitAudioContext) (function () { }; // 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) { -// var source = sources[channel+""+note]; -// if (!source) return; -// source.noteOff(delay || 0); -// return source; + var source = sources[channel+""+note]; + if (!source) return; + source.gain.linearRampToValueAtTime(1, delay); + source.gain.linearRampToValueAtTime(0, delay + 0.1); + source.noteOff(delay || 0); + return source; }; root.chordOff = function (channel, chord, delay) {