From c1df93cf67efd55954928da2c4f3b79f58e325c8 Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 12 May 2015 13:07:28 +0100 Subject: [PATCH] Improvement to the Synthesiser voice-stealing algorithm --- .../synthesisers/juce_Synthesiser.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp index 8c81f8c37c..2fa2c540ea 100644 --- a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp +++ b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp @@ -542,23 +542,21 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, return voice; } - // Oldest voice that's isn't being held: - // (this could be the top or bottom note if it had just been released.) + // Oldest voice that has been released (no finger on it and not held by sustain pedal) for (int i = 0; i < numUsableVoices; ++i) { SynthesiserVoice* const voice = usableVoices.getUnchecked (i); - if (! (voice->isKeyDown() || voice->isSostenutoPedalDown())) + if (voice != bottom && voice != top && ! voice->isKeyDown() && ! voice->isSostenutoPedalDown()) return voice; } // Oldest voice that doesn't have a finger on it: - // (this could be the top or bottom note if it had just been released.) for (int i = 0; i < numUsableVoices; ++i) { SynthesiserVoice* const voice = usableVoices.getUnchecked (i); - if (! voice->isKeyDown()) + if (voice != bottom && voice != top && ! voice->isKeyDown()) return voice; } @@ -574,5 +572,5 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, // ..otherwise, there's only one or two voices to choose from - prefer to steal the highest one: jassert (top != nullptr || bottom != nullptr); - return top != nullptr ? top : bottom; + return (top == nullptr ? bottom : top); }