From 3417d52d83aa80b048e73eb127cb93e753da1023 Mon Sep 17 00:00:00 2001 From: George Reales Date: Sun, 20 Feb 2022 19:51:30 +0100 Subject: [PATCH] Implemented shift + click to reset panning knobs --- Source/Gui/Knob.h | 22 +++++++++++++++++++++- Source/PluginEditor.cpp | 34 ++++++++++++++++++++++++++++++++++ Source/PluginEditor.h | 6 ++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Source/Gui/Knob.h b/Source/Gui/Knob.h index 8d8b36b..99b75a1 100644 --- a/Source/Gui/Knob.h +++ b/Source/Gui/Knob.h @@ -25,7 +25,7 @@ #include "../Source/Engine/SynthEngine.h" #include "../Components/ScaleComponent.h" class ObxdAudioProcessor; -class Knob : public Slider, public ScalableComponent +class Knob : public Slider, public ScalableComponent, public ActionBroadcaster { juce::String img_name; public: @@ -57,6 +57,18 @@ public: */ repaint(); } + + void mouseDown(const MouseEvent& event) override + { + if (event.mods.isShiftDown()) + { + if (shouldResetOnShiftClick) + { + sendActionMessage(resetActionMessage); + } + } + Slider::mouseDown(event); + } // Source: https://git.iem.at/audioplugins/IEMPluginSuite/-/blob/master/resources/customComponents/ReverseSlider.h public: class KnobAttachment : public juce::AudioProcessorValueTreeState::SliderAttachment @@ -106,9 +118,17 @@ public: } ~Knob() override {}; + + void resetOnShiftClick(bool value, const String& identifier) + { + shouldResetOnShiftClick = value; + resetActionMessage = identifier; + } private: Image kni; int fh, numFr; int w2, h2; + bool shouldResetOnShiftClick{ false }; + String resetActionMessage{}; AudioProcessorParameter* parameter {nullptr}; }; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index deb5cb1..86b61da 100755 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -420,35 +420,51 @@ void ObxdAudioProcessorEditor::loadSkin (ObxdAudioProcessor& ownerFilter) if (name == "pan1Knob"){ pan1Knob = addKnob (x, y, d, ownerFilter, PAN1, "1", 0.5); + pan1Knob->resetOnShiftClick(true, Action::panReset); + pan1Knob->addActionListener(this); mappingComps["pan1Knob"] = pan1Knob; } if (name == "pan2Knob"){ pan2Knob = addKnob (x, y, d, ownerFilter, PAN2, "2", 0.5); + pan2Knob->resetOnShiftClick(true, Action::panReset); + pan2Knob->addActionListener(this); mappingComps["pan2Knob"] = pan2Knob; } if (name == "pan3Knob"){ pan3Knob = addKnob (x, y, d, ownerFilter, PAN3, "3", 0.5); + pan3Knob->resetOnShiftClick(true, Action::panReset); + pan3Knob->addActionListener(this); mappingComps["pan3Knob"] = pan3Knob; } if (name == "pan4Knob"){ pan4Knob = addKnob (x, y, d, ownerFilter, PAN4, "4", 0.5); + pan4Knob->resetOnShiftClick(true, Action::panReset); + pan4Knob->addActionListener(this); mappingComps["pan4Knob"] = pan4Knob; } if (name == "pan5Knob"){ pan5Knob = addKnob (x, y, d, ownerFilter, PAN5, "5", 0.5); + pan5Knob->resetOnShiftClick(true, Action::panReset); + pan5Knob->addActionListener(this); mappingComps["pan5Knob"] = pan5Knob; } if (name == "pan6Knob"){ pan6Knob = addKnob (x, y, d, ownerFilter, PAN6, "6", 0.5); + pan6Knob->resetOnShiftClick(true, Action::panReset); + pan6Knob->addActionListener(this); mappingComps["pan6Knob"] = pan6Knob; } if (name == "pan7Knob"){ pan7Knob = addKnob (x, y, d, ownerFilter, PAN7, "7", 0.5); + pan7Knob->resetOnShiftClick(true, Action::panReset); + pan7Knob->addActionListener(this); mappingComps["pan7Knob"] = pan7Knob; } if (name == "pan8Knob"){ pan8Knob = addKnob (x, y, d, ownerFilter, PAN8, "8", 0.5); + pan8Knob->resetOnShiftClick(true, Action::panReset); + pan8Knob->addActionListener(this); mappingComps["pan8Knob"] = pan8Knob; } @@ -730,6 +746,22 @@ TooglableButton* ObxdAudioProcessorEditor::addButton (int x, int y, int w, int h return button; } + +void ObxdAudioProcessorEditor::actionListenerCallback(const String& message) +{ + if (message.equalsIgnoreCase(Action::panReset)) + { + const StringArray parameters{ "pan1Knob", "pan2Knob", "pan3Knob", "pan4Knob", "pan5Knob", "pan6Knob", "pan7Knob", "pan8Knob" }; + for (const auto& parameter : parameters) + { + if (auto* knob = dynamic_cast(mappingComps[parameter])) + { + knob->setValue(knob->getDoubleClickReturnValue()); + } + } + } +} + Rectangle ObxdAudioProcessorEditor::transformBounds(int x, int y, int w, int h) { if (getScaleFactor() == 1.0f) @@ -1449,6 +1481,8 @@ void ObxdAudioProcessorEditor::filesDropped(const StringArray& files, int x, int //createMenu(); } } + +const String ObxdAudioProcessorEditor::Action::panReset{ "panReset" }; /* bool ObxdAudioProcessorEditor::keyPressed(const KeyPress & press) { if (press.getKeyCode() == '+' || press.getKeyCode() == KeyPress::numberPadAdd) diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 06e20ae..5efb1dd 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -55,6 +55,7 @@ class ObxdAudioProcessorEditor : public AudioProcessorEditor // , public Slider::Listener , public Button::Listener // , public ComboBox::Listener + , public ActionListener , public ApplicationCommandTarget , public Timer , public FileDragAndDropTarget @@ -177,6 +178,7 @@ public: { return processor.physicalPixelScaleFactor > 1.0; } + void actionListenerCallback(const String& message) override; private: Rectangle transformBounds(int x, int y, int w, int h); Knob* addKnob (int x, int y, int d, ObxdAudioProcessor& filter, int parameter, String name, float defval); @@ -304,6 +306,10 @@ private: int menuScaleNum; int countTimerForLed = 0; + struct Action + { + static const String panReset; + }; }; #endif // PLUGINEDITOR_H_INCLUDED