Use the back inserter idiom in all stealing methods

This commit is contained in:
Paul Ferrand 2020-10-06 23:03:25 +02:00
parent 480a7d4628
commit 02a1615e2d

View file

@ -1024,12 +1024,9 @@ void sfz::Synth::noteOffDispatch(int delay, int noteNumber, float velocity) noex
void sfz::Synth::checkRegionPolyphony(const Region* region, int delay) noexcept void sfz::Synth::checkRegionPolyphony(const Region* region, int delay) noexcept
{ {
tempPolyphonyArray.clear(); tempPolyphonyArray.clear();
absl::c_copy_if(voiceViewArray,
for (Voice* voice : voiceViewArray) { std::back_inserter(tempPolyphonyArray),
if (voice->getRegion() == region && !voice->releasedOrFree()) { [region](Voice* v) { return v->getRegion() == region && !v->releasedOrFree(); });
tempPolyphonyArray.push_back(voice);
}
}
if (tempPolyphonyArray.size() >= region->polyphony) { if (tempPolyphonyArray.size() >= region->polyphony) {
const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray)); const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray));
@ -1078,11 +1075,8 @@ void sfz::Synth::checkGroupPolyphony(const Region* region, int delay) noexcept
{ {
const auto& activeVoices = polyphonyGroups[region->group].getActiveVoices(); const auto& activeVoices = polyphonyGroups[region->group].getActiveVoices();
tempPolyphonyArray.clear(); tempPolyphonyArray.clear();
for (Voice* voice : activeVoices) { absl::c_copy_if(activeVoices,
if (!voice->releasedOrFree()) { std::back_inserter(tempPolyphonyArray), [](Voice* v) { return !v->releasedOrFree(); });
tempPolyphonyArray.push_back(voice);
}
}
if (tempPolyphonyArray.size() >= polyphonyGroups[region->group].getPolyphonyLimit()) { if (tempPolyphonyArray.size() >= polyphonyGroups[region->group].getPolyphonyLimit()) {
const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray)); const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray));
@ -1096,11 +1090,8 @@ void sfz::Synth::checkSetPolyphony(const Region* region, int delay) noexcept
while (parent != nullptr) { while (parent != nullptr) {
const auto& activeVoices = parent->getActiveVoices(); const auto& activeVoices = parent->getActiveVoices();
tempPolyphonyArray.clear(); tempPolyphonyArray.clear();
for (Voice* voice : activeVoices) { absl::c_copy_if(activeVoices,
if (!voice->releasedOrFree()) { std::back_inserter(tempPolyphonyArray), [](Voice* v) { return !v->releasedOrFree(); });
tempPolyphonyArray.push_back(voice);
}
}
if (tempPolyphonyArray.size() >= parent->getPolyphonyLimit()) { if (tempPolyphonyArray.size() >= parent->getPolyphonyLimit()) {
const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray)); const auto voiceToSteal = stealer.steal(absl::MakeSpan(tempPolyphonyArray));