diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index cefacad2..3ea3236f 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -722,6 +722,9 @@ void Synth::Impl::finalizeSfzLoad() applySettingsPerVoice(); setupModMatrix(); + + // cache the set of used CCs for future access + currentUsedCCs_ = collectAllUsedCCs(); } bool Synth::loadScalaFile(const fs::path& path) @@ -1677,14 +1680,10 @@ void Synth::allSoundOff() noexcept effectBus->clear(); } -std::bitset Synth::getUsedCCs() const noexcept +const std::bitset& Synth::getUsedCCs() const noexcept { Impl& impl = *impl_; - std::bitset used; - for (const Impl::RegionPtr& region : impl.regions_) - impl.collectUsedCCsFromRegion(used, *region); - impl.collectUsedCCsFromModulations(used, impl.resources_.modMatrix); - return used; + return impl.currentUsedCCs_; } void sfz::Synth::setBroadcastCallback(sfizz_receive_t* broadcast, void* data) @@ -1750,6 +1749,15 @@ void Synth::Impl::collectUsedCCsFromModulations(std::bitset& use mm.visitSources(vtor); } +std::bitset Synth::Impl::collectAllUsedCCs() +{ + std::bitset used; + for (const Impl::RegionPtr& region : regions_) + collectUsedCCsFromRegion(used, *region); + collectUsedCCsFromModulations(used, resources_.modMatrix); + return used; +} + Parser& Synth::getParser() noexcept { Impl& impl = *impl_; diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 1d971d80..0e53b17e 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -584,7 +584,7 @@ public: * * @return const std::bitset& */ - std::bitset getUsedCCs() const noexcept; + const std::bitset& getUsedCCs() const noexcept; /** * @brief Dispatch the incoming message to the synth engine diff --git a/src/sfizz/SynthPrivate.h b/src/sfizz/SynthPrivate.h index 3c9569af..5daf775b 100644 --- a/src/sfizz/SynthPrivate.h +++ b/src/sfizz/SynthPrivate.h @@ -177,6 +177,8 @@ struct Synth::Impl final: public Parser::Listener { static void collectUsedCCsFromRegion(std::bitset& usedCCs, const Region& region); static void collectUsedCCsFromModulations(std::bitset& usedCCs, const ModMatrix& mm); + std::bitset collectAllUsedCCs(); + /** * @brief Set the default value for a CC * @@ -268,6 +270,7 @@ struct Synth::Impl final: public Parser::Listener { fs::file_time_type modificationTime_ { }; std::array defaultCCValues_; + std::bitset currentUsedCCs_; // Messaging sfizz_receive_t* broadcastReceiver = nullptr;