Don't assume a single <global> for region sets
This commit is contained in:
parent
7933bcec8d
commit
0b502b44f1
5 changed files with 39 additions and 32 deletions
|
|
@ -43,7 +43,7 @@ enum OpcodeCategory {
|
||||||
*/
|
*/
|
||||||
enum OpcodeScope {
|
enum OpcodeScope {
|
||||||
//! unknown scope or other
|
//! unknown scope or other
|
||||||
kOpcodeScopeGeneric,
|
kOpcodeScopeGeneric = 0,
|
||||||
//! global scope
|
//! global scope
|
||||||
kOpcodeScopeGlobal,
|
kOpcodeScopeGlobal,
|
||||||
//! control scope
|
//! control scope
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "Region.h"
|
#include "Region.h"
|
||||||
#include "Voice.h"
|
#include "Voice.h"
|
||||||
|
#include "Opcode.h"
|
||||||
#include "SwapAndPop.h"
|
#include "SwapAndPop.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -16,6 +17,13 @@ namespace sfz
|
||||||
|
|
||||||
class RegionSet {
|
class RegionSet {
|
||||||
public:
|
public:
|
||||||
|
RegionSet() = delete;
|
||||||
|
RegionSet(RegionSet* parentSet, OpcodeScope level)
|
||||||
|
: parent(parentSet), level(level)
|
||||||
|
{
|
||||||
|
if (parentSet != nullptr)
|
||||||
|
parentSet->addSubset(this);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Set the polyphony limit for the set
|
* @brief Set the polyphony limit for the set
|
||||||
*
|
*
|
||||||
|
|
@ -73,6 +81,13 @@ public:
|
||||||
* @return RegionSet*
|
* @return RegionSet*
|
||||||
*/
|
*/
|
||||||
RegionSet* getParent() const noexcept { return parent; }
|
RegionSet* getParent() const noexcept { return parent; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the set level
|
||||||
|
*
|
||||||
|
* @return OpcodeScope
|
||||||
|
*/
|
||||||
|
OpcodeScope getLevel() const noexcept { return level; }
|
||||||
/**
|
/**
|
||||||
* @brief Set the parent set
|
* @brief Set the parent set
|
||||||
*
|
*
|
||||||
|
|
@ -109,6 +124,7 @@ public:
|
||||||
const std::vector<RegionSet*>& getSubsets() const noexcept { return subsets; }
|
const std::vector<RegionSet*>& getSubsets() const noexcept { return subsets; }
|
||||||
private:
|
private:
|
||||||
RegionSet* parent { nullptr };
|
RegionSet* parent { nullptr };
|
||||||
|
OpcodeScope level { kOpcodeScopeGeneric };
|
||||||
std::vector<Region*> regions;
|
std::vector<Region*> regions;
|
||||||
std::vector<RegionSet*> subsets;
|
std::vector<RegionSet*> subsets;
|
||||||
std::vector<Voice*> voices;
|
std::vector<Voice*> voices;
|
||||||
|
|
|
||||||
|
|
@ -77,20 +77,19 @@ void sfz::Synth::onVoiceStateChanged(NumericId<Voice> id, Voice::State state)
|
||||||
|
|
||||||
void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector<Opcode>& members)
|
void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector<Opcode>& members)
|
||||||
{
|
{
|
||||||
const auto newRegionSet = [&](RegionSet* parentSet) {
|
const auto newRegionSet = [&](OpcodeScope level) {
|
||||||
ASSERT(parentSet != nullptr);
|
auto parent = currentSet;
|
||||||
sets.emplace_back(new RegionSet);
|
while (parent && parent->getLevel() >= level)
|
||||||
auto newSet = sets.back().get();
|
parent = parent->getParent();
|
||||||
parentSet->addSubset(newSet);
|
|
||||||
newSet->setParent(parentSet);
|
sets.emplace_back(new RegionSet(parent, level));
|
||||||
currentSet = newSet;
|
currentSet = sets.back().get();
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (hash(header)) {
|
switch (hash(header)) {
|
||||||
case hash("global"):
|
case hash("global"):
|
||||||
globalOpcodes = members;
|
globalOpcodes = members;
|
||||||
currentSet = sets.front().get();
|
newRegionSet(OpcodeScope::kOpcodeScopeGlobal);
|
||||||
lastHeader = OpcodeScope::kOpcodeScopeGlobal;
|
|
||||||
groupOpcodes.clear();
|
groupOpcodes.clear();
|
||||||
masterOpcodes.clear();
|
masterOpcodes.clear();
|
||||||
handleGlobalOpcodes(members);
|
handleGlobalOpcodes(members);
|
||||||
|
|
@ -101,19 +100,14 @@ void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector<O
|
||||||
break;
|
break;
|
||||||
case hash("master"):
|
case hash("master"):
|
||||||
masterOpcodes = members;
|
masterOpcodes = members;
|
||||||
newRegionSet(sets.front().get());
|
newRegionSet(OpcodeScope::kOpcodeScopeMaster);
|
||||||
groupOpcodes.clear();
|
groupOpcodes.clear();
|
||||||
lastHeader = OpcodeScope::kOpcodeScopeMaster;
|
|
||||||
handleMasterOpcodes(members);
|
handleMasterOpcodes(members);
|
||||||
numMasters++;
|
numMasters++;
|
||||||
break;
|
break;
|
||||||
case hash("group"):
|
case hash("group"):
|
||||||
groupOpcodes = members;
|
groupOpcodes = members;
|
||||||
if (lastHeader == OpcodeScope::kOpcodeScopeGroup)
|
newRegionSet(OpcodeScope::kOpcodeScopeGroup);
|
||||||
newRegionSet(currentSet->getParent());
|
|
||||||
else
|
|
||||||
newRegionSet(currentSet);
|
|
||||||
lastHeader = OpcodeScope::kOpcodeScopeGroup;
|
|
||||||
handleGroupOpcodes(members, masterOpcodes);
|
handleGroupOpcodes(members, masterOpcodes);
|
||||||
numGroups++;
|
numGroups++;
|
||||||
break;
|
break;
|
||||||
|
|
@ -145,8 +139,6 @@ void sfz::Synth::onParseWarning(const SourceRange& range, const std::string& mes
|
||||||
|
|
||||||
void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
|
void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
|
||||||
{
|
{
|
||||||
ASSERT(currentSet != nullptr);
|
|
||||||
|
|
||||||
int regionNumber = static_cast<int>(regions.size());
|
int regionNumber = static_cast<int>(regions.size());
|
||||||
auto lastRegion = absl::make_unique<Region>(regionNumber, resources.midiState, defaultPath);
|
auto lastRegion = absl::make_unique<Region>(regionNumber, resources.midiState, defaultPath);
|
||||||
|
|
||||||
|
|
@ -184,8 +176,10 @@ void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
|
||||||
if (lastRegion->group != Default::group && lastRegion->polyphony != config::maxVoices)
|
if (lastRegion->group != Default::group && lastRegion->polyphony != config::maxVoices)
|
||||||
setGroupPolyphony(lastRegion->group, lastRegion->polyphony);
|
setGroupPolyphony(lastRegion->group, lastRegion->polyphony);
|
||||||
|
|
||||||
lastRegion->parent = currentSet;
|
if (currentSet != nullptr) {
|
||||||
currentSet->addRegion(lastRegion.get());
|
lastRegion->parent = currentSet;
|
||||||
|
currentSet->addRegion(lastRegion.get());
|
||||||
|
}
|
||||||
|
|
||||||
// Adapt the size of the delayed releases to avoid allocating later on
|
// Adapt the size of the delayed releases to avoid allocating later on
|
||||||
lastRegion->delayedReleases.reserve(lastRegion->keyRange.length());
|
lastRegion->delayedReleases.reserve(lastRegion->keyRange.length());
|
||||||
|
|
@ -204,10 +198,8 @@ void sfz::Synth::clear()
|
||||||
for (auto& list : ccActivationLists)
|
for (auto& list : ccActivationLists)
|
||||||
list.clear();
|
list.clear();
|
||||||
|
|
||||||
lastHeader = OpcodeScope::kOpcodeScopeGlobal;
|
currentSet = nullptr;
|
||||||
sets.clear();
|
sets.clear();
|
||||||
sets.emplace_back(new RegionSet);
|
|
||||||
currentSet = sets.front().get();
|
|
||||||
regions.clear();
|
regions.clear();
|
||||||
effectBuses.clear();
|
effectBuses.clear();
|
||||||
effectBuses.emplace_back(new EffectBus);
|
effectBuses.emplace_back(new EffectBus);
|
||||||
|
|
|
||||||
|
|
@ -817,8 +817,7 @@ private:
|
||||||
std::vector<VoicePtr> voices;
|
std::vector<VoicePtr> voices;
|
||||||
|
|
||||||
// These are more general "groups" than sfz and encapsulates the full hierarchy
|
// These are more general "groups" than sfz and encapsulates the full hierarchy
|
||||||
RegionSet* currentSet;
|
RegionSet* currentSet { nullptr };
|
||||||
OpcodeScope lastHeader { OpcodeScope::kOpcodeScopeGlobal };
|
|
||||||
std::vector<RegionSetPtr> sets;
|
std::vector<RegionSetPtr> sets;
|
||||||
|
|
||||||
// These are the `group=` groups where you can off voices
|
// These are the `group=` groups where you can off voices
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,13 @@ TEST_CASE("[Polyphony] Polyphony in hierarchy")
|
||||||
<region> key=64 sample=*sine
|
<region> key=64 sample=*sine
|
||||||
)");
|
)");
|
||||||
REQUIRE( synth.getRegionView(0)->polyphony == 2 );
|
REQUIRE( synth.getRegionView(0)->polyphony == 2 );
|
||||||
REQUIRE( synth.getRegionSetView(1)->getPolyphonyLimit() == 2 );
|
REQUIRE( synth.getRegionSetView(0)->getPolyphonyLimit() == 2 );
|
||||||
REQUIRE( synth.getRegionView(1)->polyphony == 2 );
|
REQUIRE( synth.getRegionView(1)->polyphony == 2 );
|
||||||
REQUIRE( synth.getRegionSetView(2)->getPolyphonyLimit() == 3 );
|
REQUIRE( synth.getRegionSetView(1)->getPolyphonyLimit() == 3 );
|
||||||
REQUIRE( synth.getRegionSetView(2)->getRegions()[0]->polyphony == 3 );
|
REQUIRE( synth.getRegionSetView(1)->getRegions()[0]->polyphony == 3 );
|
||||||
REQUIRE( synth.getRegionSetView(3)->getPolyphonyLimit() == 4 );
|
REQUIRE( synth.getRegionSetView(2)->getPolyphonyLimit() == 4 );
|
||||||
REQUIRE( synth.getRegionSetView(3)->getRegions()[0]->polyphony == 5 );
|
REQUIRE( synth.getRegionSetView(2)->getRegions()[0]->polyphony == 5 );
|
||||||
REQUIRE( synth.getRegionSetView(3)->getRegions()[1]->polyphony == 4 );
|
REQUIRE( synth.getRegionSetView(2)->getRegions()[1]->polyphony == 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("[Polyphony] Polyphony groups")
|
TEST_CASE("[Polyphony] Polyphony groups")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue