n2xParameterDrivenLed.h (1109B)
1 #pragma once 2 3 #include "jucePluginLib/parameterlistener.h" 4 5 #include <string> 6 #include <cstdint> 7 8 namespace juce 9 { 10 class Button; 11 } 12 13 namespace n2xJucePlugin 14 { 15 class Editor; 16 17 class ParameterDrivenLed 18 { 19 public: 20 static constexpr uint8_t CurrentPart = 0xff; 21 22 explicit ParameterDrivenLed(Editor& _editor, const std::string& _component, std::string _parameter, uint8_t _part = CurrentPart); 23 virtual ~ParameterDrivenLed() = default; 24 25 protected: 26 virtual void updateState(juce::Button& _target, const pluginLib::Parameter* _source) const; 27 virtual bool updateToggleState(const pluginLib::Parameter* _parameter) const = 0; 28 virtual void onClick(pluginLib::Parameter* _targetParameter, bool _toggleState) {} 29 30 void bind(); 31 void disableClick() const; 32 33 private: 34 void updateStateFromParameter(const pluginLib::Parameter* _parameter) const; 35 36 Editor& m_editor; 37 const std::string m_parameterName; 38 juce::Button* m_led; 39 const uint8_t m_part; 40 41 pluginLib::ParameterListener m_onParamChanged; 42 baseLib::EventListener<uint8_t> m_onCurrentPartChanged; 43 pluginLib::Parameter* m_param = nullptr; 44 }; 45 }