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 {
|
||||
//! unknown scope or other
|
||||
kOpcodeScopeGeneric,
|
||||
kOpcodeScopeGeneric = 0,
|
||||
//! global scope
|
||||
kOpcodeScopeGlobal,
|
||||
//! control scope
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "Region.h"
|
||||
#include "Voice.h"
|
||||
#include "Opcode.h"
|
||||
#include "SwapAndPop.h"
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -16,6 +17,13 @@ namespace sfz
|
|||
|
||||
class RegionSet {
|
||||
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
|
||||
*
|
||||
|
|
@ -73,6 +81,13 @@ public:
|
|||
* @return RegionSet*
|
||||
*/
|
||||
RegionSet* getParent() const noexcept { return parent; }
|
||||
|
||||
/**
|
||||
* @brief Get the set level
|
||||
*
|
||||
* @return OpcodeScope
|
||||
*/
|
||||
OpcodeScope getLevel() const noexcept { return level; }
|
||||
/**
|
||||
* @brief Set the parent set
|
||||
*
|
||||
|
|
@ -109,6 +124,7 @@ public:
|
|||
const std::vector<RegionSet*>& getSubsets() const noexcept { return subsets; }
|
||||
private:
|
||||
RegionSet* parent { nullptr };
|
||||
OpcodeScope level { kOpcodeScopeGeneric };
|
||||
std::vector<Region*> regions;
|
||||
std::vector<RegionSet*> subsets;
|
||||
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)
|
||||
{
|
||||
const auto newRegionSet = [&](RegionSet* parentSet) {
|
||||
ASSERT(parentSet != nullptr);
|
||||
sets.emplace_back(new RegionSet);
|
||||
auto newSet = sets.back().get();
|
||||
parentSet->addSubset(newSet);
|
||||
newSet->setParent(parentSet);
|
||||
currentSet = newSet;
|
||||
const auto newRegionSet = [&](OpcodeScope level) {
|
||||
auto parent = currentSet;
|
||||
while (parent && parent->getLevel() >= level)
|
||||
parent = parent->getParent();
|
||||
|
||||
sets.emplace_back(new RegionSet(parent, level));
|
||||
currentSet = sets.back().get();
|
||||
};
|
||||
|
||||
switch (hash(header)) {
|
||||
case hash("global"):
|
||||
globalOpcodes = members;
|
||||
currentSet = sets.front().get();
|
||||
lastHeader = OpcodeScope::kOpcodeScopeGlobal;
|
||||
newRegionSet(OpcodeScope::kOpcodeScopeGlobal);
|
||||
groupOpcodes.clear();
|
||||
masterOpcodes.clear();
|
||||
handleGlobalOpcodes(members);
|
||||
|
|
@ -101,19 +100,14 @@ void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector<O
|
|||
break;
|
||||
case hash("master"):
|
||||
masterOpcodes = members;
|
||||
newRegionSet(sets.front().get());
|
||||
newRegionSet(OpcodeScope::kOpcodeScopeMaster);
|
||||
groupOpcodes.clear();
|
||||
lastHeader = OpcodeScope::kOpcodeScopeMaster;
|
||||
handleMasterOpcodes(members);
|
||||
numMasters++;
|
||||
break;
|
||||
case hash("group"):
|
||||
groupOpcodes = members;
|
||||
if (lastHeader == OpcodeScope::kOpcodeScopeGroup)
|
||||
newRegionSet(currentSet->getParent());
|
||||
else
|
||||
newRegionSet(currentSet);
|
||||
lastHeader = OpcodeScope::kOpcodeScopeGroup;
|
||||
newRegionSet(OpcodeScope::kOpcodeScopeGroup);
|
||||
handleGroupOpcodes(members, masterOpcodes);
|
||||
numGroups++;
|
||||
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)
|
||||
{
|
||||
ASSERT(currentSet != nullptr);
|
||||
|
||||
int regionNumber = static_cast<int>(regions.size());
|
||||
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)
|
||||
setGroupPolyphony(lastRegion->group, lastRegion->polyphony);
|
||||
|
||||
lastRegion->parent = currentSet;
|
||||
currentSet->addRegion(lastRegion.get());
|
||||
if (currentSet != nullptr) {
|
||||
lastRegion->parent = currentSet;
|
||||
currentSet->addRegion(lastRegion.get());
|
||||
}
|
||||
|
||||
// Adapt the size of the delayed releases to avoid allocating later on
|
||||
lastRegion->delayedReleases.reserve(lastRegion->keyRange.length());
|
||||
|
|
@ -204,10 +198,8 @@ void sfz::Synth::clear()
|
|||
for (auto& list : ccActivationLists)
|
||||
list.clear();
|
||||
|
||||
lastHeader = OpcodeScope::kOpcodeScopeGlobal;
|
||||
currentSet = nullptr;
|
||||
sets.clear();
|
||||
sets.emplace_back(new RegionSet);
|
||||
currentSet = sets.front().get();
|
||||
regions.clear();
|
||||
effectBuses.clear();
|
||||
effectBuses.emplace_back(new EffectBus);
|
||||
|
|
|
|||
|
|
@ -817,8 +817,7 @@ private:
|
|||
std::vector<VoicePtr> voices;
|
||||
|
||||
// These are more general "groups" than sfz and encapsulates the full hierarchy
|
||||
RegionSet* currentSet;
|
||||
OpcodeScope lastHeader { OpcodeScope::kOpcodeScopeGlobal };
|
||||
RegionSet* currentSet { nullptr };
|
||||
std::vector<RegionSetPtr> sets;
|
||||
|
||||
// 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
|
||||
)");
|
||||
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.getRegionSetView(2)->getPolyphonyLimit() == 3 );
|
||||
REQUIRE( synth.getRegionSetView(2)->getRegions()[0]->polyphony == 3 );
|
||||
REQUIRE( synth.getRegionSetView(3)->getPolyphonyLimit() == 4 );
|
||||
REQUIRE( synth.getRegionSetView(3)->getRegions()[0]->polyphony == 5 );
|
||||
REQUIRE( synth.getRegionSetView(3)->getRegions()[1]->polyphony == 4 );
|
||||
REQUIRE( synth.getRegionSetView(1)->getPolyphonyLimit() == 3 );
|
||||
REQUIRE( synth.getRegionSetView(1)->getRegions()[0]->polyphony == 3 );
|
||||
REQUIRE( synth.getRegionSetView(2)->getPolyphonyLimit() == 4 );
|
||||
REQUIRE( synth.getRegionSetView(2)->getRegions()[0]->polyphony == 5 );
|
||||
REQUIRE( synth.getRegionSetView(2)->getRegions()[1]->polyphony == 4 );
|
||||
}
|
||||
|
||||
TEST_CASE("[Polyphony] Polyphony groups")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue