1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Improvement to the Synthesiser voice-stealing algorithm

This commit is contained in:
jules 2015-05-12 13:07:28 +01:00
parent 1c19301b1f
commit c1df93cf67

View file

@ -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);
}