From dfd777fd3e039eb318e71e2670e5aa7c63b9cd55 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Wed, 10 Mar 2021 14:18:09 +0100 Subject: [PATCH] Move LFO modulation keys into the description --- demos/PlotLFO.cpp | 3 +-- src/sfizz/LFO.cpp | 32 +++++++++------------------ src/sfizz/LFO.h | 7 ++---- src/sfizz/LFODescription.h | 5 +++++ src/sfizz/Region.cpp | 4 ++++ src/sfizz/Voice.cpp | 3 +-- src/sfizz/modulations/sources/LFO.cpp | 2 +- tests/LFOT.cpp | 3 +-- 8 files changed, 26 insertions(+), 33 deletions(-) diff --git a/demos/PlotLFO.cpp b/demos/PlotLFO.cpp index 680ee721..57e94f51 100644 --- a/demos/PlotLFO.cpp +++ b/demos/PlotLFO.cpp @@ -116,8 +116,7 @@ int main(int argc, char* argv[]) std::vector> lfos(numLfos); for (size_t l = 0; l < numLfos; ++l) { - const NumericId id { static_cast(l) }; - sfz::LFO* lfo = new sfz::LFO(id, bufferPool); + sfz::LFO* lfo = new sfz::LFO(bufferPool); lfos[l].reset(lfo); lfo->setSampleRate(sampleRate); lfo->configure(&desc[l]); diff --git a/src/sfizz/LFO.cpp b/src/sfizz/LFO.cpp index 053ef1b1..24aa8d6e 100644 --- a/src/sfizz/LFO.cpp +++ b/src/sfizz/LFO.cpp @@ -21,9 +21,8 @@ namespace sfz { struct LFO::Impl { - explicit Impl(NumericId id, BufferPool& bufferPool, BeatClock* beatClock, ModMatrix* modMatrix) - : id_(id), - bufferPool_(bufferPool), + explicit Impl(BufferPool& bufferPool, BeatClock* beatClock, ModMatrix* modMatrix) + : bufferPool_(bufferPool), beatClock_(beatClock), modMatrix_(modMatrix), sampleRate_(config::defaultSampleRate), @@ -31,7 +30,6 @@ struct LFO::Impl { { } - NumericId id_; BufferPool& bufferPool_; BeatClock* beatClock_ = nullptr; ModMatrix* modMatrix_ = nullptr; @@ -48,8 +46,8 @@ struct LFO::Impl { std::array sampleHoldState_ {{}}; }; -LFO::LFO(NumericId id, BufferPool& bufferPool, BeatClock* beatClock, ModMatrix* modMatrix) - : impl_(new Impl(id, bufferPool, beatClock, modMatrix)) +LFO::LFO(BufferPool& bufferPool, BeatClock* beatClock, ModMatrix* modMatrix) + : impl_(new Impl(bufferPool, beatClock, modMatrix)) { } @@ -57,11 +55,6 @@ LFO::~LFO() { } -NumericId LFO::getId() const noexcept -{ - return impl_->id_; -} - void LFO::setSampleRate(double sampleRate) { impl_->sampleRate_ = sampleRate; @@ -221,7 +214,7 @@ void LFO::processSteps(absl::Span out, const float* phaseIn) } } -void LFO::process(absl::Span out, NumericId regionId) +void LFO::process(absl::Span out) { Impl& impl = *impl_; const LFODescription& desc = *impl.desc_; @@ -252,13 +245,13 @@ void LFO::process(absl::Span out, NumericId regionId) absl::Span phases = *phasesTemp; if (desc.seq) { - generatePhase(0, phases, regionId); + generatePhase(0, phases); processSteps(out, phases.data()); ++subno; } for (; subno < countSubs; ++subno) { - generatePhase(subno, phases, regionId); + generatePhase(subno, phases); switch (desc.sub[subno].wave) { case LFOWave::Triangle: processWave(subno, out, phases.data()); @@ -315,13 +308,12 @@ void LFO::processFadeIn(absl::Span out) impl.fadePosition_ = fadePosition; } -void LFO::generatePhase(unsigned nth, absl::Span phases, NumericId regionId) +void LFO::generatePhase(unsigned nth, absl::Span phases) { Impl& impl = *impl_; BufferPool& bufferPool = impl.bufferPool_; BeatClock* beatClock = impl.beatClock_; ModMatrix* modMatrix = impl.modMatrix_; - const NumericId id { impl.id_ }; const LFODescription& desc = *impl.desc_; const LFODescription::Sub& sub = desc.sub[nth]; const float samplePeriod = 1.0f / impl.sampleRate_; @@ -337,13 +329,11 @@ void LFO::generatePhase(unsigned nth, absl::Span phases, NumericIdgetModulationByKey(beatsKey); - freqMod = modMatrix->getModulationByKey(freqKey); + beatsMod = modMatrix->getModulationByKey(desc.beatsKey); + freqMod = modMatrix->getModulationByKey(desc.freqKey); } if (beatClock && beatClock->isPlaying() && beats > 0) { diff --git a/src/sfizz/LFO.h b/src/sfizz/LFO.h index caac1c27..ab2f415b 100644 --- a/src/sfizz/LFO.h +++ b/src/sfizz/LFO.h @@ -55,14 +55,11 @@ struct LFODescription; class LFO { public: explicit LFO( - NumericId id, BufferPool& bufferPool, BeatClock* beatClock = nullptr, ModMatrix* modMatrix = nullptr); ~LFO(); - NumericId getId() const noexcept; - /** Sets the sample rate. */ @@ -85,7 +82,7 @@ public: TODO(jpc) frequency modulations */ - void process(absl::Span out, NumericId regionId = {}); + void process(absl::Span out); private: /** @@ -123,7 +120,7 @@ private: /** Generate the phase of the N-th generator */ - void generatePhase(unsigned nth, absl::Span phases, NumericId regionId); + void generatePhase(unsigned nth, absl::Span phases); private: struct Impl; diff --git a/src/sfizz/LFODescription.h b/src/sfizz/LFODescription.h index 82859779..a4abfa62 100644 --- a/src/sfizz/LFODescription.h +++ b/src/sfizz/LFODescription.h @@ -6,6 +6,7 @@ #pragma once #include "Defaults.h" +#include "modulations/ModKey.h" #include #include @@ -32,6 +33,10 @@ struct LFODescription { }; absl::optional seq; std::vector sub; + + // modulations + ModKey beatsKey; + ModKey freqKey; }; } // namespace sfz diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 453e432f..feb7cb4a 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -955,6 +955,10 @@ bool sfz::Region::parseLFOOpcodeV2(const Opcode& opcode) const unsigned lfoNumber = lfoNumber1Based - 1; LFODescription& lfo = lfos[lfoNumber]; + // + lfo.beatsKey = ModKey::createNXYZ(ModId::LFOBeats, id, lfoNumber); + lfo.freqKey = ModKey::createNXYZ(ModId::LFOFrequency, id, lfoNumber); + // auto getOrCreateLFOStep = [&opcode, &lfo]() -> float* { const unsigned stepNumber1Based = opcode.parameters[1]; diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index e6a67170..dbffda04 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -1604,8 +1604,7 @@ void Voice::setMaxLFOsPerVoice(size_t numLFOs) impl.lfos_.resize(numLFOs); for (size_t i = 0; i < numLFOs; ++i) { - const NumericId id { static_cast(i) }; - auto lfo = absl::make_unique(id, resources.bufferPool, &resources.beatClock, &resources.modMatrix); + auto lfo = absl::make_unique(resources.bufferPool, &resources.beatClock, &resources.modMatrix); lfo->setSampleRate(impl.sampleRate_); impl.lfos_[i] = std::move(lfo); } diff --git a/src/sfizz/modulations/sources/LFO.cpp b/src/sfizz/modulations/sources/LFO.cpp index 206f0ca1..a485833d 100644 --- a/src/sfizz/modulations/sources/LFO.cpp +++ b/src/sfizz/modulations/sources/LFO.cpp @@ -59,7 +59,7 @@ void LFOSource::generate(const ModKey& sourceKey, NumericId voiceId, absl } LFO* lfo = voice->getLFO(lfoIndex); - lfo->process(buffer, region->getId()); + lfo->process(buffer); } } // namespace sfz diff --git a/tests/LFOT.cpp b/tests/LFOT.cpp index 26bd0fb1..486a8cc6 100644 --- a/tests/LFOT.cpp +++ b/tests/LFOT.cpp @@ -28,8 +28,7 @@ static bool computeLFO(DataPoints& dp, const fs::path& sfzPath, double sampleRat std::vector> lfos(numLfos); for (size_t l = 0; l < numLfos; ++l) { - const NumericId id { static_cast(l) }; - sfz::LFO* lfo = new sfz::LFO(id, resources.bufferPool); + sfz::LFO* lfo = new sfz::LFO(resources.bufferPool); lfos[l].reset(lfo); lfo->setSampleRate(sampleRate); lfo->configure(&desc[l]);