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
|
#pragma once
|
||||||
#include "Region.h"
|
#include "Region.h"
|
||||||
#include "Voice.h"
|
#include "Voice.h"
|
||||||
|
#include "SwapAndPop.h"
|
||||||
#include "absl/algorithm/container.h"
|
#include "absl/algorithm/container.h"
|
||||||
|
|
||||||
namespace sfz
|
namespace sfz
|
||||||
|
|
@ -20,15 +21,7 @@ public:
|
||||||
}
|
}
|
||||||
void removeVoice(const Voice* voice)
|
void removeVoice(const Voice* voice)
|
||||||
{
|
{
|
||||||
auto it = absl::c_find(voices, voice);
|
swapAndPopFirst(voices, [voice](const Voice* v) { return v == voice; });
|
||||||
if (it == voices.end())
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto last = voices.end() - 1;
|
|
||||||
if (it != last)
|
|
||||||
std::iter_swap(it, last);
|
|
||||||
|
|
||||||
voices.pop_back();
|
|
||||||
}
|
}
|
||||||
const std::vector<Voice*>& getActiveVoices() const { return voices; }
|
const std::vector<Voice*>& getActiveVoices() const { return voices; }
|
||||||
std::vector<Voice*>& getActiveVoices() { return voices; }
|
std::vector<Voice*>& getActiveVoices() { return voices; }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Region.h"
|
#include "Region.h"
|
||||||
#include "Voice.h"
|
#include "Voice.h"
|
||||||
|
#include "SwapAndPop.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace sfz
|
namespace sfz
|
||||||
|
|
@ -31,16 +32,7 @@ public:
|
||||||
}
|
}
|
||||||
void removeVoice(const Voice* voice)
|
void removeVoice(const Voice* voice)
|
||||||
{
|
{
|
||||||
auto it = absl::c_find(voices, voice);
|
swapAndPopFirst(voices, [voice](const Voice* v) { return v == 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());
|
|
||||||
}
|
}
|
||||||
static void registerVoiceInHierarchy(const Region* region, Voice* 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;
|
(void)state;
|
||||||
if (state == Voice::State::idle) {
|
if (state == Voice::State::idle) {
|
||||||
auto voice = getVoiceById(id);
|
auto voice = getVoiceById(id);
|
||||||
DBG("Removing voice " << id.number << " from hierarchies");
|
|
||||||
RegionSet::removeVoiceFromHierarchy(voice->getRegion(), voice);
|
RegionSet::removeVoiceFromHierarchy(voice->getRegion(), voice);
|
||||||
polyphonyGroups[voice->getRegion()->group].removeVoice(voice);
|
polyphonyGroups[voice->getRegion()->group].removeVoice(voice);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue