Skip to content

Commit

Permalink
Rebase and use the swap and pop helper
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfd committed Jun 15, 2020
1 parent 605f08f commit cd0b715
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
11 changes: 2 additions & 9 deletions src/sfizz/PolyphonyGroup.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "Region.h"
#include "Voice.h"
#include "SwapAndPop.h"
#include "absl/algorithm/container.h"

namespace sfz
Expand All @@ -20,15 +21,7 @@ class PolyphonyGroup {
}
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; }
Expand Down
12 changes: 2 additions & 10 deletions src/sfizz/RegionSet.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "Region.h"
#include "Voice.h"
#include "SwapAndPop.h"
#include <vector>

namespace sfz
Expand Down Expand Up @@ -31,16 +32,7 @@ class RegionSet {
}
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)
{
Expand Down
1 change: 0 additions & 1 deletion src/sfizz/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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);
}
Expand Down

0 comments on commit cd0b715

Please sign in to comment.