Feed master opcodes to the handleGroupOpcodes

This commit is contained in:
Paul Fd 2020-04-07 16:24:38 +02:00
parent 4e7f15328a
commit c2360bad45
4 changed files with 40 additions and 5 deletions

View file

@ -67,7 +67,7 @@ void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector<O
break; break;
case hash("group"): case hash("group"):
groupOpcodes = members; groupOpcodes = members;
handleGroupOpcodes(members); handleGroupOpcodes(members, masterOpcodes);
numGroups++; numGroups++;
break; break;
case hash("region"): case hash("region"):
@ -177,12 +177,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; absl::optional<unsigned> groupIdx;
unsigned maxPolyphony { config::maxVoices }; unsigned maxPolyphony { config::maxVoices };
for (auto& member : members) { const auto parseOpcode = [&](const Opcode& member) {
switch (member.lettersOnlyHash) { switch (member.lettersOnlyHash) {
case hash("group"): case hash("group"):
setValueFromOpcode(member, groupIdx, Default::groupRange); setValueFromOpcode(member, groupIdx, Default::groupRange);
@ -191,7 +191,13 @@ void sfz::Synth::handleGroupOpcodes(const std::vector<Opcode>& members)
setValueFromOpcode(member, maxPolyphony, Range<unsigned>(0, config::maxVoices)); setValueFromOpcode(member, maxPolyphony, Range<unsigned>(0, config::maxVoices));
break; break;
} }
} };
for (auto& member : masterMembers)
parseOpcode(member);
for (auto& member : members)
parseOpcode(member);
if (groupIdx) if (groupIdx)
setGroupPolyphony(*groupIdx, maxPolyphony); setGroupPolyphony(*groupIdx, maxPolyphony);

View file

@ -454,7 +454,7 @@ private:
* *
* @param members the opcodes of the <group> block * @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 * @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)->getTriggerValue() == 64_norm);
REQUIRE(!synth.getVoiceView(2)->canBeStolen()); 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