-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link the voice lifecycle into region sets and polyphony groups Respect crudely the polyphony limits without stealing for now
- Loading branch information
Showing
8 changed files
with
528 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
#include "Region.h" | ||
#include "Voice.h" | ||
#include "absl/algorithm/container.h" | ||
|
||
namespace sfz | ||
{ | ||
class PolyphonyGroup { | ||
public: | ||
void setPolyphonyLimit(unsigned limit) | ||
{ | ||
polyphonyLimit = limit; | ||
voices.reserve(limit); | ||
} | ||
unsigned getPolyphonyLimit() const { return polyphonyLimit; } | ||
void registerVoice(Voice* voice) | ||
{ | ||
if (absl::c_find(voices, voice) == voices.end()) | ||
voices.push_back(voice); | ||
} | ||
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(); | ||
} | ||
const std::vector<Voice*>& getActiveVoices() const { return voices; } | ||
std::vector<Voice*>& getActiveVoices() { return voices; } | ||
private: | ||
unsigned polyphonyLimit { config::maxVoices }; | ||
std::vector<Voice*> voices; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#pragma once | ||
#include "Region.h" | ||
#include "Voice.h" | ||
#include <vector> | ||
|
||
namespace sfz | ||
{ | ||
|
||
class RegionSet { | ||
public: | ||
void setPolyphonyLimit(unsigned limit) | ||
{ | ||
polyphonyLimit = limit; | ||
voices.reserve(limit); | ||
} | ||
unsigned getPolyphonyLimit() const { return polyphonyLimit; } | ||
void addRegion(Region* region) | ||
{ | ||
if (absl::c_find(regions, region) == regions.end()) | ||
regions.push_back(region); | ||
} | ||
void addSubset(RegionSet* group) | ||
{ | ||
if (absl::c_find(subsets, group) == subsets.end()) | ||
subsets.push_back(group); | ||
} | ||
void registerVoice(Voice* voice) | ||
{ | ||
if (absl::c_find(voices, voice) == voices.end()) | ||
voices.push_back(voice); | ||
} | ||
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()); | ||
} | ||
static void registerVoiceInHierarchy(const Region* region, Voice* voice) | ||
{ | ||
auto parent = region->parent; | ||
while (parent != nullptr) { | ||
parent->registerVoice(voice); | ||
parent = parent->getParent(); | ||
} | ||
} | ||
static void removeVoiceFromHierarchy(const Region* region, const Voice* voice) | ||
{ | ||
auto parent = region->parent; | ||
while (parent != nullptr) { | ||
parent->removeVoice(voice); | ||
parent = parent->getParent(); | ||
} | ||
} | ||
RegionSet* getParent() const { return parent; } | ||
void setParent(RegionSet* parent) { this->parent = parent; } | ||
const std::vector<Voice*>& getActiveVoices() const { return voices; } | ||
const std::vector<Region*>& getRegions() const { return regions; } | ||
const std::vector<RegionSet*>& getSubsets() const { return subsets; } | ||
private: | ||
RegionSet* parent { nullptr }; | ||
std::vector<Region*> regions; | ||
std::vector<RegionSet*> subsets; | ||
std::vector<Voice*> voices; | ||
unsigned polyphonyLimit { config::maxVoices }; | ||
}; | ||
|
||
} |
Oops, something went wrong.