gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 61b4faa30859cc304a5af58468a170521c78ac39
parent 60b1938f78383a7ebdde38ebafe969accafc599e
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sat, 10 Aug 2024 01:43:45 +0200

common base class for oct and arp leds

Diffstat:
Msource/nord/n2x/n2xJucePlugin/CMakeLists.txt | 1+
Msource/nord/n2x/n2xJucePlugin/n2xArp.cpp | 42+++++++-----------------------------------
Msource/nord/n2x/n2xJucePlugin/n2xArp.h | 23+++++------------------
Msource/nord/n2x/n2xJucePlugin/n2xOctLed.cpp | 35++++-------------------------------
Msource/nord/n2x/n2xJucePlugin/n2xOctLed.h | 23++++-------------------
Asource/nord/n2x/n2xJucePlugin/n2xParameterDrivenLed.cpp | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Asource/nord/n2x/n2xJucePlugin/n2xParameterDrivenLed.h | 38++++++++++++++++++++++++++++++++++++++
7 files changed, 112 insertions(+), 103 deletions(-)

diff --git a/source/nord/n2x/n2xJucePlugin/CMakeLists.txt b/source/nord/n2x/n2xJucePlugin/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCES n2xFocusedParameter.cpp n2xFocusedParameter.h n2xMasterVolume.cpp n2xMasterVolume.h n2xOctLed.cpp n2xOctLed.h + n2xParameterDrivenLed.cpp n2xParameterDrivenLed.h n2xLcd.cpp n2xLcd.h n2xPart.cpp n2xPart.h n2xParts.cpp n2xParts.h diff --git a/source/nord/n2x/n2xJucePlugin/n2xArp.cpp b/source/nord/n2x/n2xJucePlugin/n2xArp.cpp @@ -1,51 +1,23 @@ #include "n2xArp.h" #include "n2xController.h" -#include "n2xEditor.h" - -#include "juce_gui_basics/juce_gui_basics.h" namespace n2xJucePlugin { - Arp::Arp(Editor& _editor) : m_editor(_editor), m_btArpActive(_editor.findComponentT<juce::Button>("ArpEnabled")) + Arp::Arp(Editor& _editor) : ParameterDrivenLed(_editor, "ArpEnabled", "Lfo2Dest") { - auto& c = _editor.getN2xController(); - - m_onCurrentPartChanged.set(c.onCurrentPartChanged, [this](const uint8_t&) - { - bind(); - }); - - m_btArpActive->onClick = [this] - { - if(!m_param) - return; - m_param->setUnnormalizedValueNotifyingHost(m_btArpActive->getToggleState() ? 0 : 3, pluginLib::Parameter::Origin::Ui); - }; - bind(); } - void Arp::bind() - { - const auto& c = m_editor.getN2xController(); - - m_param = c.getParameter("Lfo2Dest", c.getCurrentPart()); - - m_onParamChanged.set(m_param, [this](const pluginLib::Parameter* _parameter) - { - updateStateFromParameter(_parameter); - }); - - updateStateFromParameter(m_param); - } - - void Arp::updateStateFromParameter(const pluginLib::Parameter* _parameter) const + bool Arp::updateToggleState(const pluginLib::Parameter* _parameter) const { const auto v = _parameter->getUnnormalizedValue(); - const bool arpActive = v != 3 && v != 4 && v != 7; + return arpActive; + } - m_btArpActive->setToggleState(arpActive, juce::dontSendNotification); + void Arp::onClick(pluginLib::Parameter* _targetParameter, const bool _toggleState) + { + _targetParameter->setUnnormalizedValueNotifyingHost(_toggleState ? 0 : 3, pluginLib::Parameter::Origin::Ui); } } diff --git a/source/nord/n2x/n2xJucePlugin/n2xArp.h b/source/nord/n2x/n2xJucePlugin/n2xArp.h @@ -1,29 +1,16 @@ #pragma once -#include "jucePluginLib/parameterlistener.h" - -namespace juce -{ - class Button; -} +#include "n2xParameterDrivenLed.h" namespace n2xJucePlugin { - class Editor; - - class Arp + class Arp : ParameterDrivenLed { public: explicit Arp(Editor& _editor); - private: - void bind(); - void updateStateFromParameter(const pluginLib::Parameter* _parameter) const; - - Editor& m_editor; - juce::Button* m_btArpActive; - pluginLib::ParameterListener m_onParamChanged; - pluginLib::EventListener<uint8_t> m_onCurrentPartChanged; - pluginLib::Parameter* m_param = nullptr; + protected: + bool updateToggleState(const pluginLib::Parameter* _parameter) const override; + void onClick(pluginLib::Parameter* _targetParameter, bool _toggleState) override; }; } diff --git a/source/nord/n2x/n2xJucePlugin/n2xOctLed.cpp b/source/nord/n2x/n2xJucePlugin/n2xOctLed.cpp @@ -1,46 +1,19 @@ #include "n2xOctLed.h" #include "n2xController.h" -#include "n2xEditor.h" - -#include "juce_gui_basics/juce_gui_basics.h" namespace n2xJucePlugin { - OctLed::OctLed(Editor& _editor) : m_editor(_editor), m_octLed(_editor.findComponentT<juce::Button>("O2Pitch_LED")) + OctLed::OctLed(Editor& _editor) : ParameterDrivenLed(_editor, "O2Pitch_LED", "O2Pitch") { - auto& c = _editor.getN2xController(); - - m_onCurrentPartChanged.set(c.onCurrentPartChanged, [this](const uint8_t&) - { - bind(); - }); - - m_octLed->setInterceptsMouseClicks(false, false); - + disableClick(); bind(); } - void OctLed::bind() - { - const auto& c = m_editor.getN2xController(); - - m_param = c.getParameter("O2Pitch", c.getCurrentPart()); - - m_onParamChanged.set(m_param, [this](const pluginLib::Parameter* _parameter) - { - updateStateFromParameter(_parameter); - }); - - updateStateFromParameter(m_param); - } - - void OctLed::updateStateFromParameter(const pluginLib::Parameter* _parameter) const + bool OctLed::updateToggleState(const pluginLib::Parameter* _parameter) const { const auto v = _parameter->getUnnormalizedValue(); - const bool active = v / 12 * 12 == v; - - m_octLed->setToggleState(active, juce::dontSendNotification); + return active; } } diff --git a/source/nord/n2x/n2xJucePlugin/n2xOctLed.h b/source/nord/n2x/n2xJucePlugin/n2xOctLed.h @@ -1,29 +1,14 @@ #pragma once -#include "jucePluginLib/parameterlistener.h" - -namespace juce -{ - class Button; -} +#include "n2xParameterDrivenLed.h" namespace n2xJucePlugin { - class Editor; - - class OctLed + class OctLed : ParameterDrivenLed { public: explicit OctLed(Editor& _editor); - - private: - void bind(); - void updateStateFromParameter(const pluginLib::Parameter* _parameter) const; - - Editor& m_editor; - juce::Button* m_octLed; - pluginLib::ParameterListener m_onParamChanged; - pluginLib::EventListener<uint8_t> m_onCurrentPartChanged; - pluginLib::Parameter* m_param = nullptr; + protected: + bool updateToggleState(const pluginLib::Parameter* _parameter) const override; }; } diff --git a/source/nord/n2x/n2xJucePlugin/n2xParameterDrivenLed.cpp b/source/nord/n2x/n2xJucePlugin/n2xParameterDrivenLed.cpp @@ -0,0 +1,53 @@ +#include "n2xParameterDrivenLed.h" + +#include "n2xController.h" +#include "n2xEditor.h" + +#include "juce_gui_basics/juce_gui_basics.h" + +namespace n2xJucePlugin +{ + ParameterDrivenLed::ParameterDrivenLed(Editor& _editor, const std::string& _component, const std::string& _parameter) + : m_editor(_editor) + , m_parameterName(_parameter) + , m_led(_editor.findComponentT<juce::Button>(_component)) + { + auto& c = _editor.getN2xController(); + + m_onCurrentPartChanged.set(c.onCurrentPartChanged, [this](const uint8_t&) + { + bind(); + }); + + m_led->onClick = [this] + { + if(!m_param) + return; + onClick(m_param, m_led->getToggleState()); + }; + } + + void ParameterDrivenLed::bind() + { + const auto& c = m_editor.getN2xController(); + + m_param = c.getParameter(m_parameterName, c.getCurrentPart()); + + m_onParamChanged.set(m_param, [this](const pluginLib::Parameter* _parameter) + { + updateStateFromParameter(_parameter); + }); + + updateStateFromParameter(m_param); + } + + void ParameterDrivenLed::disableClick() const + { + m_led->setInterceptsMouseClicks(false, false); + } + + void ParameterDrivenLed::updateStateFromParameter(const pluginLib::Parameter* _parameter) const + { + m_led->setToggleState(updateToggleState(_parameter), juce::dontSendNotification); + } +} diff --git a/source/nord/n2x/n2xJucePlugin/n2xParameterDrivenLed.h b/source/nord/n2x/n2xJucePlugin/n2xParameterDrivenLed.h @@ -0,0 +1,38 @@ +#pragma once + +#include "jucePluginLib/parameterlistener.h" + +namespace juce +{ + class Button; +} + +namespace n2xJucePlugin +{ + class Editor; + + class ParameterDrivenLed + { + public: + explicit ParameterDrivenLed(Editor& _editor, const std::string& _component, const std::string& _parameter); + virtual ~ParameterDrivenLed() = default; + + protected: + virtual bool updateToggleState(const pluginLib::Parameter* _parameter) const = 0; + virtual void onClick(pluginLib::Parameter* _targetParameter, bool _toggleState) {} + + void bind(); + void disableClick() const; + + private: + void updateStateFromParameter(const pluginLib::Parameter* _parameter) const; + + Editor& m_editor; + const std::string m_parameterName; + juce::Button* m_led; + + pluginLib::ParameterListener m_onParamChanged; + pluginLib::EventListener<uint8_t> m_onCurrentPartChanged; + pluginLib::Parameter* m_param = nullptr; + }; +}