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 da4fb910a5417ee4484e5249d781404fc24ab21e
parent fb8d55cb2d93f5f69b79dac03545395994a79744
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sun, 21 Apr 2024 16:51:27 +0200

support to toggle logo animation

Diffstat:
Msource/jucePlugin/PluginEditorState.cpp | 18++++++++++++++++++
Msource/jucePlugin/ui3/Leds.cpp | 42++++++++++++++++++++++++++++++++++++++----
Msource/jucePlugin/ui3/Leds.h | 40+++++++++++++++++++++++++++++++++++++++-
Msource/jucePlugin/ui3/VirusEditor.h | 2++
Msource/jucePluginEditorLib/pluginEditorState.h | 4++--
5 files changed, 99 insertions(+), 7 deletions(-)

diff --git a/source/jucePlugin/PluginEditorState.cpp b/source/jucePlugin/PluginEditorState.cpp @@ -39,6 +39,24 @@ void PluginEditorState::initContextMenu(juce::PopupMenu& _menu) _menu.addSubMenu("Output Gain", gainMenu); } + + if(const auto* editor = dynamic_cast<genericVirusUI::VirusEditor*>(getEditor())) + { + const auto& leds = editor->getLeds(); + + if(leds && leds->supportsLogoAnimation()) + { + _menu.addItem("Enable Logo Animation", true, leds->isLogoAnimationEnabled(), [this] + { + const auto* editor = dynamic_cast<genericVirusUI::VirusEditor*>(getEditor()); + if(editor) + { + const auto& leds = editor->getLeds(); + leds->toggleLogoAnimation(); + } + }); + } + } } bool PluginEditorState::initAdvancedContextMenu(juce::PopupMenu& _menu, bool _enabled) diff --git a/source/jucePlugin/ui3/Leds.cpp b/source/jucePlugin/ui3/Leds.cpp @@ -6,9 +6,11 @@ namespace genericVirusUI { + constexpr const char* const g_logoAnimKey = "logoAnimation"; + constexpr const char* g_lfoNames[3] = {"Lfo1LedOn", "Lfo2LedOn", "Lfo3LedOn"}; - Leds::Leds(const genericUI::Editor& _editor, AudioPluginAudioProcessor& _processor) + Leds::Leds(const genericUI::Editor& _editor, AudioPluginAudioProcessor& _processor) : m_processor(_processor), m_logoAnimationEnabled(_processor.getConfig().getBoolValue(g_logoAnimKey, true)) { for(size_t i=0; i<m_lfos.size(); ++i) { @@ -28,12 +30,16 @@ namespace genericVirusUI } } - if(auto* comp = _editor.findComponentT<juce::Component>("logolight", false)) + if(auto* logoAnim = _editor.findComponentT<juce::Component>("logolight", false)) { - m_logo.reset(new jucePluginEditorLib::Led(comp)); + m_logoAnim = logoAnim; + + m_logoLed.reset(new jucePluginEditorLib::Led(logoAnim)); - m_logo->setSourceCallback([&_processor] + m_logoLed->setSourceCallback([this, &_processor] { + if(!m_logoAnimationEnabled) + return 0.0f; auto* d = dynamic_cast<virusLib::Device*>(_processor.getPlugin().getDevice()); if(!d) @@ -45,6 +51,19 @@ namespace genericVirusUI return std::pow(1.0f - v, 0.2f); }); + + m_logoClickListener.reset(new LogoMouseListener(*this)); + + m_logoAnim->addMouseListener(m_logoClickListener.get(), false); + m_logoAnim->setInterceptsMouseClicks(true, true); + + m_logo = _editor.findComponent("logo", false); + + if(m_logo) + { + m_logo->addMouseListener(m_logoClickListener.get(), false); + m_logo->setInterceptsMouseClicks(true, true); + } } } @@ -52,5 +71,20 @@ namespace genericVirusUI { for (auto& led : m_lfos) led.reset(); + + if(m_logo) + m_logo->removeMouseListener(m_logoClickListener.get()); + if(m_logoAnim) + m_logoAnim->removeMouseListener(m_logoClickListener.get()); + + m_logoClickListener.reset(); + } + + void Leds::toggleLogoAnimation() + { + m_logoAnimationEnabled = !m_logoAnimationEnabled; + + m_processor.getConfig().setValue(g_logoAnimKey, m_logoAnimationEnabled); + m_processor.getConfig().saveIfNeeded(); } } diff --git a/source/jucePlugin/ui3/Leds.h b/source/jucePlugin/ui3/Leds.h @@ -5,6 +5,13 @@ #include "../../jucePluginEditorLib/led.h" +#include "juce_gui_basics/juce_gui_basics.h" + +namespace juce +{ + class MouseListener; +} + class AudioPluginAudioProcessor; namespace genericUI @@ -17,11 +24,42 @@ namespace genericVirusUI class Leds { public: + class LogoMouseListener final : public juce::MouseListener + { + public: + LogoMouseListener(Leds& _leds) : m_leds(_leds) + { + } + void mouseDown(const juce::MouseEvent& e) override + { + if(e.mods.isPopupMenu()) + return; + m_leds.toggleLogoAnimation(); + } + + private: + Leds& m_leds; + }; + Leds(const genericUI::Editor& _editor, AudioPluginAudioProcessor& _processor); ~Leds(); + void toggleLogoAnimation(); + + bool supportsLogoAnimation() const { return m_logoLed.get(); } + bool isLogoAnimationEnabled() const { return m_logoAnimationEnabled; } + private: + AudioPluginAudioProcessor& m_processor; + bool m_logoAnimationEnabled = true; + std::array<std::unique_ptr<jucePluginEditorLib::Led>, 3> m_lfos; - std::unique_ptr<jucePluginEditorLib::Led> m_logo; + + std::unique_ptr<jucePluginEditorLib::Led> m_logoLed; + + juce::Component* m_logo = nullptr; + juce::Component* m_logoAnim = nullptr; + + std::unique_ptr<LogoMouseListener> m_logoClickListener; }; } diff --git a/source/jucePlugin/ui3/VirusEditor.h b/source/jucePlugin/ui3/VirusEditor.h @@ -61,6 +61,8 @@ namespace genericVirusUI genericUI::Button<juce::TextButton>* createJuceComponent(genericUI::Button<juce::TextButton>*, genericUI::UiObject& _object) override; juce::Component* createJuceComponent(juce::Component*, genericUI::UiObject& _object) override; + const auto& getLeds() const { return m_leds; } + private: void onProgramChange(int _part); void onPlayModeChanged(); diff --git a/source/jucePluginEditorLib/pluginEditorState.h b/source/jucePluginEditorLib/pluginEditorState.h @@ -83,12 +83,12 @@ namespace jucePluginEditorLib Processor& m_processor; pluginLib::ParameterBinding m_parameterBinding; + genericUI::Editor* getEditor() const; + private: void loadSkin(const Skin& _skin); void setGuiScale(int _scale) const; - genericUI::Editor* getEditor() const; - std::unique_ptr<juce::Component> m_editor; Skin m_currentSkin; float m_rootScale = 1.0f;