From 8d08c6700d5644ca0fa9141b8ffc9fdde5852451 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Fri, 11 Sep 2020 18:07:01 +0200 Subject: [PATCH] Replace auto for ease of reading --- src/sfizz/modulations/ModMatrix.cpp | 39 +++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/sfizz/modulations/ModMatrix.cpp b/src/sfizz/modulations/ModMatrix.cpp index 06a5fe2b..4533d156 100644 --- a/src/sfizz/modulations/ModMatrix.cpp +++ b/src/sfizz/modulations/ModMatrix.cpp @@ -49,6 +49,9 @@ struct ModMatrix::Impl { absl::flat_hash_map sourceIndex_; absl::flat_hash_map targetIndex_; + std::vector sourceIndicesForGlobal_; + std::vector targetIndicesForGlobal_; + int maxRegionIdx_ { -1 }; std::vector> sourceIndicesForRegion_; std::vector> targetIndicesForRegion_; @@ -76,6 +79,8 @@ void ModMatrix::clear() impl.targetIndex_.clear(); impl.sources_.clear(); impl.targets_.clear(); + impl.sourceIndicesForGlobal_.clear(); + impl.targetIndicesForGlobal_.clear(); impl.sourceIndicesForRegion_.clear(); impl.targetIndicesForRegion_.clear(); impl.maxRegionIdx_ = -1; @@ -217,6 +222,7 @@ void ModMatrix::init() if (flags & kModIsPerCycle) { ASSERT(!source.key.region()); source.gen->init(source.key, {}, 0); + impl.sourceIndicesForGlobal_.push_back(i); } else if (flags & kModIsPerVoice) { ASSERT(source.key.region()); @@ -227,7 +233,11 @@ void ModMatrix::init() for (unsigned i = 0; i < impl.targets_.size(); ++i) { Impl::Target& target = impl.targets_[i]; const int flags = target.key.flags(); - if (flags & kModIsPerVoice) { + if (flags & kModIsPerCycle) { + ASSERT(!target.key.region()); + impl.targetIndicesForGlobal_.push_back(i); + } + else if (flags & kModIsPerVoice) { ASSERT(target.key.region()); impl.targetIndicesForRegion_[target.key.region().number()].push_back(i); } @@ -242,7 +252,7 @@ void ModMatrix::initVoice(NumericId voiceId, NumericId regionId, const auto idNumber = static_cast(regionId.number()); for (auto idx: impl.sourceIndicesForRegion_[idNumber]) { - const auto& source = impl.sources_[idx]; + const Impl::Source& source = impl.sources_[idx]; source.gen->init(source.key, voiceId, delay); } } @@ -255,7 +265,7 @@ void ModMatrix::releaseVoice(NumericId voiceId, NumericId regionI const auto idNumber = static_cast(regionId.number()); for (auto idx: impl.sourceIndicesForRegion_[idNumber]) { - const auto& source = impl.sources_[idx]; + const Impl::Source& source = impl.sources_[idx]; source.gen->release(source.key, voiceId, delay); } } @@ -266,10 +276,14 @@ void ModMatrix::beginCycle(unsigned numFrames) impl.numFrames_ = numFrames; - for (Impl::Source &source : impl.sources_) + for (auto idx: impl.sourceIndicesForGlobal_) { + Impl::Source& source = impl.sources_[idx]; source.bufferReady = false; - for (Impl::Target &target : impl.targets_) + } + for (auto idx: impl.targetIndicesForGlobal_) { + Impl::Target& target = impl.targets_[idx]; target.bufferReady = false; + } } void ModMatrix::endCycle() @@ -277,12 +291,11 @@ void ModMatrix::endCycle() Impl& impl = *impl_; const uint32_t numFrames = impl.numFrames_; - for (Impl::Source &source : impl.sources_) { + for (auto idx: impl.sourceIndicesForGlobal_) { + Impl::Source& source = impl.sources_[idx]; if (!source.bufferReady) { - if (source.key.flags() & kModIsPerCycle) { - absl::Span buffer(source.buffer.data(), numFrames); - source.gen->generateDiscarded(source.key, {}, buffer); - } + absl::Span buffer(source.buffer.data(), numFrames); + source.gen->generateDiscarded(source.key, {}, buffer); } } @@ -300,12 +313,12 @@ void ModMatrix::beginVoice(NumericId voiceId, NumericId regionId) const auto idNumber = static_cast(regionId.number()); for (auto idx: impl.sourceIndicesForRegion_[idNumber]) { - auto& source = impl.sources_[idx]; + Impl::Source& source = impl.sources_[idx]; source.bufferReady = false; } for (auto idx: impl.targetIndicesForRegion_[idNumber]) { - auto& target = impl.targets_[idx]; + Impl::Target& target = impl.targets_[idx]; target.bufferReady = false; } } @@ -323,7 +336,7 @@ void ModMatrix::endVoice() const auto idNumber = static_cast(regionId.number()); for (auto idx: impl.sourceIndicesForRegion_[idNumber]) { - const auto& source = impl.sources_[idx]; + const Impl::Source& source = impl.sources_[idx]; if (!source.bufferReady) { absl::Span buffer(source.buffer.data(), numFrames); source.gen->generateDiscarded(source.key, voiceId, buffer);