From f7e36108f8a036963053d01d04024ba2f4b9dcda Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 16 Jan 2015 13:35:30 +0000 Subject: [PATCH] Fix for the Synthesiser voice-stealing algorithm --- .../synthesisers/juce_Synthesiser.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp index e817263a36..d9a4a64144 100644 --- a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp +++ b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp @@ -447,7 +447,7 @@ struct VoiceAgeSorter { static int compareElements (SynthesiserVoice* v1, SynthesiserVoice* v2) noexcept { - return v1->wasStartedBefore (*v2) ? 1 : (v2->wasStartedBefore (*v1) ? -1 : 0); + return v1->wasStartedBefore (*v2) ? -1 : (v2->wasStartedBefore (*v1) ? 1 : 0); } }; @@ -480,10 +480,10 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, } } - jassert (bottom != nullptr && top != nullptr); + const int stealableVoiceRange = usableVoices.size() - 6; // The oldest note that's playing with the target pitch playing is ideal.. - for (int i = 0; i < usableVoices.size(); ++i) + for (int i = 0; i < stealableVoiceRange; ++i) { SynthesiserVoice* const voice = usableVoices.getUnchecked (i); @@ -492,7 +492,7 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, } // ..otherwise, look for the oldest note that isn't the top or bottom note.. - for (int i = 0; i < usableVoices.size(); ++i) + for (int i = 0; i < stealableVoiceRange; ++i) { SynthesiserVoice* const voice = usableVoices.getUnchecked (i); @@ -500,6 +500,6 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, return voice; } - // ..otherwise, there's only one or two voices to choose from - we'll return the top one.. - return top; + // ..otherwise, there's only one or two voices to choose from - we'll return the oldest one.. + return usableVoices.getFirst(); }