@@ -202,8 +202,15 @@ MPESynthesiserVoice* MPESynthesiser::findVoiceToSteal (MPENote noteToStealVoiceF | |||||
jassert (voice->isActive()); // We wouldn't be here otherwise | jassert (voice->isActive()); // We wouldn't be here otherwise | ||||
usableVoices.add (voice); | usableVoices.add (voice); | ||||
std::sort (usableVoices.begin(), usableVoices.end(), | |||||
[] (const MPESynthesiserVoice* a, const MPESynthesiserVoice* b) { return a->wasStartedBefore (*b); }); | |||||
// NB: Using a functor rather than a lambda here due to scare-stories about | |||||
// compilers generating code containing heap allocations.. | |||||
struct Sorter | |||||
{ | |||||
bool operator() (const MPESynthesiserVoice* a, const MPESynthesiserVoice* b) const noexcept { return a->wasStartedBefore (*b); } | |||||
}; | |||||
std::sort (usableVoices.begin(), usableVoices.end(), Sorter()); | |||||
if (! voice->isPlayingButReleased()) // Don't protect released notes | if (! voice->isPlayingButReleased()) // Don't protect released notes | ||||
{ | { | ||||
@@ -514,8 +514,15 @@ SynthesiserVoice* Synthesiser::findVoiceToSteal (SynthesiserSound* soundToPlay, | |||||
jassert (voice->isVoiceActive()); // We wouldn't be here otherwise | jassert (voice->isVoiceActive()); // We wouldn't be here otherwise | ||||
usableVoices.add (voice); | usableVoices.add (voice); | ||||
std::sort (usableVoices.begin(), usableVoices.end(), | |||||
[] (const SynthesiserVoice* a, const SynthesiserVoice* b) { return a->wasStartedBefore (*b); }); | |||||
// NB: Using a functor rather than a lambda here due to scare-stories about | |||||
// compilers generating code containing heap allocations.. | |||||
struct Sorter | |||||
{ | |||||
bool operator() (const SynthesiserVoice* a, const SynthesiserVoice* b) const noexcept { return a->wasStartedBefore (*b); } | |||||
}; | |||||
std::sort (usableVoices.begin(), usableVoices.end(), Sorter()); | |||||
if (! voice->isPlayingButReleased()) // Don't protect released notes | if (! voice->isPlayingButReleased()) // Don't protect released notes | ||||
{ | { | ||||