Cache the set of used CCs for quick access

This commit is contained in:
Jean Pierre Cimalando 2020-11-11 14:17:26 +01:00
parent e02a30f56c
commit d74bcd140f
3 changed files with 18 additions and 7 deletions

View file

@ -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<config::numCCs> Synth::getUsedCCs() const noexcept
const std::bitset<config::numCCs>& Synth::getUsedCCs() const noexcept
{
Impl& impl = *impl_;
std::bitset<config::numCCs> 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<config::numCCs>& use
mm.visitSources(vtor);
}
std::bitset<config::numCCs> Synth::Impl::collectAllUsedCCs()
{
std::bitset<config::numCCs> used;
for (const Impl::RegionPtr& region : regions_)
collectUsedCCsFromRegion(used, *region);
collectUsedCCsFromModulations(used, resources_.modMatrix);
return used;
}
Parser& Synth::getParser() noexcept
{
Impl& impl = *impl_;

View file

@ -584,7 +584,7 @@ public:
*
* @return const std::bitset<config::numCCs>&
*/
std::bitset<config::numCCs> getUsedCCs() const noexcept;
const std::bitset<config::numCCs>& getUsedCCs() const noexcept;
/**
* @brief Dispatch the incoming message to the synth engine

View file

@ -177,6 +177,8 @@ struct Synth::Impl final: public Parser::Listener {
static void collectUsedCCsFromRegion(std::bitset<config::numCCs>& usedCCs, const Region& region);
static void collectUsedCCsFromModulations(std::bitset<config::numCCs>& usedCCs, const ModMatrix& mm);
std::bitset<config::numCCs> 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<float, config::numCCs> defaultCCValues_;
std::bitset<config::numCCs> currentUsedCCs_;
// Messaging
sfizz_receive_t* broadcastReceiver = nullptr;