Rebase and use the swap and pop helper
This commit is contained in:
parent
5ef921485b
commit
2195466055
3 changed files with 4 additions and 20 deletions
|
|
@ -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<Voice*>& getActiveVoices() const { return voices; }
|
||||
std::vector<Voice*>& getActiveVoices() { return voices; }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "Region.h"
|
||||
#include "Voice.h"
|
||||
#include "SwapAndPop.h"
|
||||
#include <vector>
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ void sfz::Synth::onVoiceStateChanged(NumericId<Voice> 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue