diff --git a/src/sfizz/PolyphonyGroup.h b/src/sfizz/PolyphonyGroup.h index 8f6a8c40..ed5d6159 100644 --- a/src/sfizz/PolyphonyGroup.h +++ b/src/sfizz/PolyphonyGroup.h @@ -1,6 +1,7 @@ #pragma once #include "Region.h" #include "Voice.h" +#include "SwapAndPop.h" #include "absl/algorithm/container.h" namespace sfz @@ -20,15 +21,7 @@ public: } void removeVoice(const Voice* voice) { - auto it = absl::c_find(voices, voice); - if (it == voices.end()) - return; - - auto last = voices.end() - 1; - if (it != last) - std::iter_swap(it, last); - - voices.pop_back(); + swapAndPopFirst(voices, [voice](const Voice* v) { return v == voice; }); } const std::vector& getActiveVoices() const { return voices; } std::vector& getActiveVoices() { return voices; } diff --git a/src/sfizz/RegionSet.h b/src/sfizz/RegionSet.h index 539e3eca..87f8490b 100644 --- a/src/sfizz/RegionSet.h +++ b/src/sfizz/RegionSet.h @@ -1,6 +1,7 @@ #pragma once #include "Region.h" #include "Voice.h" +#include "SwapAndPop.h" #include namespace sfz @@ -31,16 +32,7 @@ public: } void removeVoice(const Voice* voice) { - auto it = absl::c_find(voices, voice); - if (it == voices.end()) - return; - - auto last = voices.end() - 1; - if (it != last) - std::iter_swap(it, last); - - voices.pop_back(); - DBG("Active voices size " << voices.size()); + swapAndPopFirst(voices, [voice](const Voice* v) { return v == voice; }); } static void registerVoiceInHierarchy(const Region* region, Voice* voice) { diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 8d1d6222..0eec9944 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -53,7 +53,6 @@ void sfz::Synth::onVoiceStateChanged(NumericId id, Voice::State state) (void)state; if (state == Voice::State::idle) { auto voice = getVoiceById(id); - DBG("Removing voice " << id.number << " from hierarchies"); RegionSet::removeVoiceFromHierarchy(voice->getRegion(), voice); polyphonyGroups[voice->getRegion()->group].removeVoice(voice); }