Store polyphony information in the synth

This commit is contained in:
Paul Ferrand 2020-03-29 00:07:44 +01:00
parent 6a66077911
commit 5c5dd07da1
2 changed files with 50 additions and 0 deletions

View file

@ -67,6 +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);
numGroups++; numGroups++;
break; break;
case hash("region"): case hash("region"):
@ -156,6 +157,8 @@ void sfz::Synth::clear()
masterOpcodes.clear(); masterOpcodes.clear();
groupOpcodes.clear(); groupOpcodes.clear();
unknownOpcodes.clear(); unknownOpcodes.clear();
groupPolyphony.clear();
groupMaxPolyphony.clear();
modificationTime = fs::file_time_type::min(); modificationTime = fs::file_time_type::min();
} }
@ -174,6 +177,26 @@ void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members)
} }
} }
void sfz::Synth::handleGroupOpcodes(const std::vector<Opcode>& members)
{
absl::optional<unsigned> groupIdx;
absl::optional<unsigned> maxPolyphony;
for (auto& member : members) {
switch (member.lettersOnlyHash) {
case hash("group"):
setValueFromOpcode(member, groupIdx, Default::groupRange);
break;
case hash("polyphony"):
setValueFromOpcode(member, maxPolyphony, Range<unsigned>(0, config::maxVoices));
break;
}
}
if (groupIdx && maxPolyphony)
setGroupPolyphony(*groupIdx, *maxPolyphony);
}
void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members) void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
{ {
for (auto& member : members) { for (auto& member : members) {
@ -1010,3 +1033,14 @@ void sfz::Synth::allSoundOff() noexcept
for (auto& effectBus : effectBuses) for (auto& effectBus : effectBuses)
effectBus->clear(); effectBus->clear();
} }
void sfz::Synth::setGroupPolyphony(unsigned groupIdx, unsigned polyphony) noexcept
{
if (groupIdx >= groupMaxPolyphony.size())
groupMaxPolyphony.resize(groupIdx + 1);
if (groupIdx >= groupPolyphony.size())
groupPolyphony.resize(groupIdx + 1);
groupMaxPolyphony[groupIdx] = polyphony;
}

View file

@ -410,6 +410,16 @@ protected:
void onParseWarning(const SourceRange& range, const std::string& message) override; void onParseWarning(const SourceRange& range, const std::string& message) override;
private: private:
/**
* @brief change the group maximum polyphony
*
* @param groupIdx the group index
* @param polyphone the max polyphony
*/
void setGroupPolyphony(unsigned groupIdx, unsigned polyphony) noexcept;
std::vector<unsigned> groupPolyphony;
std::vector<unsigned> groupMaxPolyphony;
/** /**
* @brief Reset all CCs; to be used on CC 121 * @brief Reset all CCs; to be used on CC 121
* *
@ -440,6 +450,12 @@ private:
* @param members the opcodes of the <global> block * @param members the opcodes of the <global> block
*/ */
void handleGlobalOpcodes(const std::vector<Opcode>& members); void handleGlobalOpcodes(const std::vector<Opcode>& members);
/**
* @brief Helper function to dispatch <group> opcodes
*
* @param members the opcodes of the <group> block
*/
void handleGroupOpcodes(const std::vector<Opcode>& members);
/** /**
* @brief Helper function to dispatch <control> opcodes * @brief Helper function to dispatch <control> opcodes
* *