From 5c5dd07da109c8373b74340797d793858ec197ae Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 29 Mar 2020 00:07:44 +0100 Subject: [PATCH] Store polyphony information in the synth --- src/sfizz/Synth.cpp | 34 ++++++++++++++++++++++++++++++++++ src/sfizz/Synth.h | 16 ++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 6882030c..fd25c42e 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -67,6 +67,7 @@ void sfz::Synth::onParseFullBlock(const std::string& header, const std::vector& members) } } +void sfz::Synth::handleGroupOpcodes(const std::vector& members) +{ + absl::optional groupIdx; + absl::optional maxPolyphony; + + for (auto& member : members) { + switch (member.lettersOnlyHash) { + case hash("group"): + setValueFromOpcode(member, groupIdx, Default::groupRange); + break; + case hash("polyphony"): + setValueFromOpcode(member, maxPolyphony, Range(0, config::maxVoices)); + break; + } + } + + if (groupIdx && maxPolyphony) + setGroupPolyphony(*groupIdx, *maxPolyphony); +} + void sfz::Synth::handleControlOpcodes(const std::vector& members) { for (auto& member : members) { @@ -1010,3 +1033,14 @@ void sfz::Synth::allSoundOff() noexcept for (auto& effectBus : effectBuses) 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; +} diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index b18a453b..e0c5390e 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -410,6 +410,16 @@ protected: void onParseWarning(const SourceRange& range, const std::string& message) override; 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 groupPolyphony; + std::vector groupMaxPolyphony; + /** * @brief Reset all CCs; to be used on CC 121 * @@ -440,6 +450,12 @@ private: * @param members the opcodes of the block */ void handleGlobalOpcodes(const std::vector& members); + /** + * @brief Helper function to dispatch opcodes + * + * @param members the opcodes of the block + */ + void handleGroupOpcodes(const std::vector& members); /** * @brief Helper function to dispatch opcodes *