From 16396ad20a55d40b79f61362089ff21b20ee8b2d Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Fri, 18 Oct 2013 18:52:59 -0700 Subject: [PATCH] Fixed MIDI fading and stopping at the end --- Plugins/MIDI/MIDI/MIDIDecoder.mm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.mm b/Plugins/MIDI/MIDI/MIDIDecoder.mm index 45a7e3e42..c38341184 100755 --- a/Plugins/MIDI/MIDI/MIDIDecoder.mm +++ b/Plugins/MIDI/MIDI/MIDIDecoder.mm @@ -127,17 +127,19 @@ float * buff = ( float * ) buf; float fadeScale = (float)(framesFade - (fadeStart - framesLength)) / framesFade; - float fadeStep = 1 / framesFade; + float fadeStep = 1.0 / (float)framesFade; for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) { buff[ 0 ] *= fadeScale; buff[ 1 ] *= fadeScale; buff += 2; fadeScale -= fadeStep; - if (fadeScale < 0) break; + if (fadeScale < 0) { + fadeScale = 0; + fadeStep = 0; + } } - - if (fadePos < totalFrames) - frames = (int)(fadePos - framesRead); + + frames = (int)(fadeEnd - framesRead); } else { frames = (int)(totalFrames - framesRead);