From 81b17f1a0a533fba959bea3ce12d5c7812d39b51 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Mon, 18 Aug 2025 11:52:21 +0100 Subject: [PATCH] start adding parameters --- plugin/Makefile | 2 +- plugin/parameters.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++ plugin/sonnenlicht.cpp | 10 ------ plugin/sonnenlicht.hpp | 7 +++- 4 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 plugin/parameters.cpp diff --git a/plugin/Makefile b/plugin/Makefile index 5225f39..d3f8c6e 100644 --- a/plugin/Makefile +++ b/plugin/Makefile @@ -9,7 +9,7 @@ NAME = sonnenlicht -FILES_DSP = assigner.cpp generator.cpp chorus.cpp svf.cpp sonnenlicht.cpp +FILES_DSP = assigner.cpp generator.cpp chorus.cpp svf.cpp parameters.cpp sonnenlicht.cpp include ../dpf/Makefile.plugins.mk TARGETS += vst2 vst3 jack lv2_dsp diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp new file mode 100644 index 0000000..8fbdd4c --- /dev/null +++ b/plugin/parameters.cpp @@ -0,0 +1,80 @@ +/* + sonnenlicht poly ensemble + + Copyright 2025 Gordon JC Pearce + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "sonnenlicht.hpp" + +void Sonnenlicht::initParameter(uint32_t index, Parameter& parameter) { + // define all the different control input parameters + switch (index) { + case pViola: + parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; + parameter.name = "Viola"; + parameter.symbol = "s_viola"; + parameter.ranges.def = 1; + break; + + case pViolin: + parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; + parameter.name = "Violin"; + parameter.symbol = "s_violin"; + parameter.ranges.def = 1; + break; + + case pBassVolume: + parameter.hints = kParameterIsAutomatable; + parameter.name = "Bass Volume"; + parameter.symbol = "s_bassvol"; + parameter.ranges.min = 0.0f; + parameter.ranges.max = 1.0f; + parameter.ranges.def = 0.7f; + break; + } +} + +void Sonnenlicht::setParameterValue(uint32_t index, float value) { + switch (index) { + case pViola: + viola = value; + break; + case pViolin: + violin = value; + break; + case pBassVolume: + bassVolume = value; + default: + break; + } + // we don't need to handle a default condition + // if there's a parameter left unhandled, it's probably + // a mistake by the plugin host, and we don't much care +} + +float Sonnenlicht::getParameterValue(uint32_t index) const { + switch (index) { + case pViola: + return viola; + + case pBassVolume: + return bassVolume; + + default: + return 0; + } + // if we fall all the way through... + return 2; +} diff --git a/plugin/sonnenlicht.cpp b/plugin/sonnenlicht.cpp index 289a990..4f0cdd8 100644 --- a/plugin/sonnenlicht.cpp +++ b/plugin/sonnenlicht.cpp @@ -35,10 +35,6 @@ Sonnenlicht::~Sonnenlicht() { delete chorus; } -void Sonnenlicht::setParameterValue(uint32_t index, float value) { - printf("got parameter %d, %f\n", index, value); -} - void Sonnenlicht::initAudioPort(bool input, uint32_t index, AudioPort& port) { port.groupId = kPortGroupStereo; Plugin::initAudioPort(input, index, port); @@ -53,12 +49,6 @@ void Sonnenlicht::activate() { void Sonnenlicht::deactivate() { } -void Sonnenlicht::initParameter(uint32_t index, Parameter& parameter) { - (void)index; - (void)¶meter; // pretend these aren't here - return; -} - void Sonnenlicht::run(const float**, float** outputs, uint32_t frames, const MidiEvent* ev, uint32_t evCount) { for (uint32_t i = 0; i < evCount; i++) { diff --git a/plugin/sonnenlicht.hpp b/plugin/sonnenlicht.hpp index 2739e03..af5913a 100644 --- a/plugin/sonnenlicht.hpp +++ b/plugin/sonnenlicht.hpp @@ -21,14 +21,17 @@ #include "DistrhoPlugin.hpp" #include "assigner.hpp" -#include "generator.hpp" #include "chorus.hpp" +#include "generator.hpp" START_NAMESPACE_DISTRHO class Sonnenlicht : public Plugin { public: enum Parameters { + pViola, + pViolin, + pBassVolume, kParameterCount }; @@ -47,6 +50,7 @@ class Sonnenlicht : public Plugin { void initParameter(uint32_t index, Parameter ¶meter) override; void setParameterValue(uint32_t index, float value) override; + float getParameterValue(uint32_t index) const override; // Initialisation void initAudioPort(bool input, uint32_t index, AudioPort &port) override; @@ -59,6 +63,7 @@ class Sonnenlicht : public Plugin { const MidiEvent *midiEvents, uint32_t midiEventCount) override; private: + float viola = 0, violin = 0, bassVolume = 0; double fSampleRate; Assigner *assigner; Generator *genny;