From ea7bb1cf6c14451f36d0b59cd973e4274617599f Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Thu, 1 Apr 2021 02:49:01 +0200 Subject: [PATCH] Implement some oncc for LFOv2 --- src/sfizz/Region.cpp | 73 ++++++++++++++++---------------- src/sfizz/modulations/ModId.cpp | 12 ++++++ src/sfizz/modulations/ModId.h | 6 +++ src/sfizz/modulations/ModKey.cpp | 12 ++++++ 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 8ae0805f..9ec8dde6 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -1161,6 +1161,19 @@ bool sfz::Region::parseLFOOpcodeV2(const Opcode& opcode) return nullptr; return &lfo.sub[subNumber1Based - 1]; }; + auto LFO_target = [this, &opcode, lfoNumber](ModId targetId, ModId depthId, const OpcodeSpec& spec) -> bool { + const ModKey source = ModKey::createNXYZ(ModId::LFO, id, lfoNumber); + const ModKey target = ModKey::createNXYZ(targetId, id); + Connection& conn = getOrCreateConnection(source, target); + if (depthId == ModId::Undefined) + conn.sourceDepth = opcode.read(spec); + else { + const ModKey depth = ModKey::createNXYZ(depthId, id, lfoNumber); + conn.sourceDepthMod = depth; + processGenericCc(opcode, spec, depth); + } + return true; + }; auto LFO_EG_filter_EQ_target = [this, &opcode, lfoNumber](ModId sourceId, ModId targetId, const OpcodeSpec& spec) -> bool { const unsigned index = opcode.parameters.size() == 2 ? opcode.parameters.back() - 1 : 0; if (!extendIfNecessary(filters, index + 1, Default::numFilters)) @@ -1252,52 +1265,40 @@ bool sfz::Region::parseLFOOpcodeV2(const Opcode& opcode) // Modulation: LFO (targets) case hash("lfo&_amplitude"): - { - const ModKey source = ModKey::createNXYZ(ModId::LFO, id, lfoNumber); - const ModKey target = ModKey::createNXYZ(ModId::Amplitude, id); - getOrCreateConnection(source, target).sourceDepth = - opcode.read(Default::amplitudeMod); - } + LFO_target(ModId::Amplitude, {}, Default::amplitudeMod); + break; + case_any_ccN("lfo&_amplitude"): + LFO_target(ModId::Amplitude, ModId::LFOAmplitudeDepth, Default::amplitudeMod); break; case hash("lfo&_pan"): - { - const ModKey source = ModKey::createNXYZ(ModId::LFO, id, lfoNumber); - const ModKey target = ModKey::createNXYZ(ModId::Pan, id); - getOrCreateConnection(source, target).sourceDepth = - opcode.read(Default::panMod); - } + LFO_target(ModId::Pan, {}, Default::panMod); + break; + case_any_ccN("lfo&_pan"): + LFO_target(ModId::Pan, ModId::LFOPanDepth, Default::panMod); break; case hash("lfo&_width"): - { - const ModKey source = ModKey::createNXYZ(ModId::LFO, id, lfoNumber); - const ModKey target = ModKey::createNXYZ(ModId::Width, id); - getOrCreateConnection(source, target).sourceDepth = - opcode.read(Default::widthMod); - } + LFO_target(ModId::Width, {}, Default::widthMod); + break; + case_any_ccN("lfo&_width"): + LFO_target(ModId::Width, ModId::LFOWidthDepth, Default::widthMod); break; case hash("lfo&_position"): // sfizz extension - { - const ModKey source = ModKey::createNXYZ(ModId::LFO, id, lfoNumber); - const ModKey target = ModKey::createNXYZ(ModId::Position, id); - getOrCreateConnection(source, target).sourceDepth = - opcode.read(Default::positionMod); - } + LFO_target(ModId::Position, {}, Default::positionMod); + break; + case_any_ccN("lfo&_position"): // sfizz extension + LFO_target(ModId::Position, ModId::LFOPositionDepth, Default::positionMod); break; case hash("lfo&_pitch"): - { - const ModKey source = ModKey::createNXYZ(ModId::LFO, id, lfoNumber); - const ModKey target = ModKey::createNXYZ(ModId::Pitch, id); - getOrCreateConnection(source, target).sourceDepth = - opcode.read(Default::pitchMod); - } + LFO_target(ModId::Pitch, {}, Default::pitchMod); + break; + case_any_ccN("lfo&_pitch"): + LFO_target(ModId::Pitch, ModId::LFOPitchDepth, Default::pitchMod); break; case hash("lfo&_volume"): - { - const ModKey source = ModKey::createNXYZ(ModId::LFO, id, lfoNumber); - const ModKey target = ModKey::createNXYZ(ModId::Volume, id); - getOrCreateConnection(source, target).sourceDepth = - opcode.read(Default::volumeMod); - } + LFO_target(ModId::Volume, {}, Default::volumeMod); + break; + case_any_ccN("lfo&_volume"): + LFO_target(ModId::Volume, ModId::LFOVolumeDepth, Default::volumeMod); break; case hash("lfo&_cutoff&"): diff --git a/src/sfizz/modulations/ModId.cpp b/src/sfizz/modulations/ModId.cpp index dcc70a44..67d66b0d 100644 --- a/src/sfizz/modulations/ModId.cpp +++ b/src/sfizz/modulations/ModId.cpp @@ -100,6 +100,18 @@ int ModIds::flags(ModId id) noexcept return kModIsPerVoice|kModIsAdditive; case ModId::LFOPhase: return kModIsPerVoice|kModIsAdditive; + case ModId::LFOAmplitudeDepth: + return kModIsPerVoice|kModIsMultiplicative; + case ModId::LFOPanDepth: + return kModIsPerVoice|kModIsAdditive; + case ModId::LFOWidthDepth: + return kModIsPerVoice|kModIsAdditive; + case ModId::LFOPositionDepth: + return kModIsPerVoice|kModIsAdditive; + case ModId::LFOPitchDepth: + return kModIsPerVoice|kModIsAdditive; + case ModId::LFOVolumeDepth: + return kModIsPerVoice|kModIsAdditive; // unknown default: diff --git a/src/sfizz/modulations/ModId.h b/src/sfizz/modulations/ModId.h index 1e18356f..95bacaf8 100644 --- a/src/sfizz/modulations/ModId.h +++ b/src/sfizz/modulations/ModId.h @@ -64,6 +64,12 @@ enum class ModId : int { LFOFrequency, LFOBeats, LFOPhase, + LFOAmplitudeDepth, + LFOPanDepth, + LFOWidthDepth, + LFOPositionDepth, + LFOPitchDepth, + LFOVolumeDepth, _TargetsEnd, // [/targets] -------------------------------------------------------------- diff --git a/src/sfizz/modulations/ModKey.cpp b/src/sfizz/modulations/ModKey.cpp index 3fef944f..cbf1b49c 100644 --- a/src/sfizz/modulations/ModKey.cpp +++ b/src/sfizz/modulations/ModKey.cpp @@ -170,6 +170,18 @@ std::string ModKey::toString() const return absl::StrCat("LFOBeats {", region_.number(), ", N=", 1 + params_.N, "}"); case ModId::LFOPhase: return absl::StrCat("LFOPhase {", region_.number(), ", N=", 1 + params_.N, "}"); + case ModId::LFOAmplitudeDepth: + return absl::StrCat("LFOAmplitudeDepth {", region_.number(), ", N=", 1 + params_.N, "}"); + case ModId::LFOPanDepth: + return absl::StrCat("LFOPanDepth {", region_.number(), ", N=", 1 + params_.N, "}"); + case ModId::LFOWidthDepth: + return absl::StrCat("LFOWidthDepth {", region_.number(), ", N=", 1 + params_.N, "}"); + case ModId::LFOPositionDepth: + return absl::StrCat("LFOPositionDepth {", region_.number(), ", N=", 1 + params_.N, "}"); + case ModId::LFOPitchDepth: + return absl::StrCat("LFOPitchDepth {", region_.number(), ", N=", 1 + params_.N, "}"); + case ModId::LFOVolumeDepth: + return absl::StrCat("LFOVolumeDepth {", region_.number(), ", N=", 1 + params_.N, "}"); default: return {};