Merge pull request #171 from paulfd/master-polyphony

Handle group opcodes now reads the master opcodes
This commit is contained in:
JP Cimalando 2020-04-11 23:47:53 +02:00 committed by GitHub
commit 1e6c0da220
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 5 deletions

View file

@ -55,6 +55,8 @@ void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector<O
switch (hash(header)) {
case hash("global"):
globalOpcodes = members;
groupOpcodes.clear();
masterOpcodes.clear();
handleGlobalOpcodes(members);
break;
case hash("control"):
@ -63,11 +65,12 @@ void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector<O
break;
case hash("master"):
masterOpcodes = members;
groupOpcodes.clear();
numMasters++;
break;
case hash("group"):
groupOpcodes = members;
handleGroupOpcodes(members);
handleGroupOpcodes(members, masterOpcodes);
numGroups++;
break;
case hash("region"):
@ -177,12 +180,12 @@ void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members)
}
}
void sfz::Synth::handleGroupOpcodes(const std::vector<Opcode>& members)
void sfz::Synth::handleGroupOpcodes(const std::vector<Opcode>& members, const std::vector<Opcode>& masterMembers)
{
absl::optional<unsigned> groupIdx;
unsigned maxPolyphony { config::maxVoices };
for (auto& member : members) {
const auto parseOpcode = [&](const Opcode& member) {
switch (member.lettersOnlyHash) {
case hash("group"):
setValueFromOpcode(member, groupIdx, Default::groupRange);
@ -191,7 +194,13 @@ void sfz::Synth::handleGroupOpcodes(const std::vector<Opcode>& members)
setValueFromOpcode(member, maxPolyphony, Range<unsigned>(0, config::maxVoices));
break;
}
}
};
for (auto& member : masterMembers)
parseOpcode(member);
for (auto& member : members)
parseOpcode(member);
if (groupIdx)
setGroupPolyphony(*groupIdx, maxPolyphony);

View file

@ -454,7 +454,7 @@ private:
*
* @param members the opcodes of the <group> block
*/
void handleGroupOpcodes(const std::vector<Opcode>& members);
void handleGroupOpcodes(const std::vector<Opcode>& members, const std::vector<Opcode>& masterMembers);
/**
* @brief Helper function to dispatch <control> opcodes
*

View file

@ -397,3 +397,25 @@ TEST_CASE("[Synth] Not self-masking")
REQUIRE(synth.getVoiceView(2)->getTriggerValue() == 64_norm);
REQUIRE(!synth.getVoiceView(2)->canBeStolen());
}
TEST_CASE("[Synth] Polyphony in master")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/master_polyphony.sfz");
synth.noteOn(0, 65, 64);
synth.noteOn(0, 65, 64);
synth.noteOn(0, 65, 64);
REQUIRE(synth.getNumActiveVoices() == 2); // group polyphony should block the last note
synth.allSoundOff();
REQUIRE(synth.getNumActiveVoices() == 0);
synth.noteOn(0, 63, 64);
synth.noteOn(0, 63, 64);
synth.noteOn(0, 63, 64);
REQUIRE(synth.getNumActiveVoices() == 2); // group polyphony should block the last note
synth.allSoundOff();
REQUIRE(synth.getNumActiveVoices() == 0);
synth.noteOn(0, 61, 64);
synth.noteOn(0, 61, 64);
synth.noteOn(0, 61, 64);
REQUIRE(synth.getNumActiveVoices() == 3);
}

View file

@ -0,0 +1,7 @@
<master> polyphony=2
<group> group=2
<region> sample=*sine key=65
<group> group=3
<region> sample=*sine key=63
<master> // Empty master resets the polyphony
<region> sample=*sine key=61