From 4ad33fded0e67612af0388b3849e378084d9e1a3 Mon Sep 17 00:00:00 2001 From: George Reales Date: Sun, 13 Dec 2020 19:06:22 +0100 Subject: [PATCH] Preset navigation + and - keys navigate between presets. Also works with numeric keyboard --- Source/PluginEditor.cpp | 17 +++++++++ Source/PluginEditor.h | 81 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 0dbc18f..54c766c 100755 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -23,6 +23,23 @@ ObxdAudioProcessorEditor::ObxdAudioProcessorEditor (ObxdAudioProcessor& ownerFil banks (processor.getBankFiles()) { // skinFolder = ownerFilter.getCurrentSkinFolder(); // initialized above + commandManager.registerAllCommandsForTarget(this); + commandManager.setFirstCommandTarget(this); + + // reset KeyPressMappingSet + commandManager.getKeyMappings()->resetToDefaultMappings(); + + // having set up the default key-mappings, you might now want to load the last set + // of mappings that the user configured. + //commandManager.getKeyMappings()->restoreFromXml(lastSavedKeyMappingsXML); + + // Now tell our top-level window to send any keypresses that arrive to the + // KeyPressMappingSet, which will use them to invoke the appropriate commands. + //addKeyListener(commandManager.getKeyMappings()); + getTopLevelComponent()->addKeyListener (commandManager.getKeyMappings()); + + //Timer::callAfterDelay (100, [this] { this->grabKeyboardFocus(); }); // ensure that key presses are sent to the KeyPressTarget object + startTimer(100); loadSkin (processor); repaint(); diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index a8b474c..a8bb5c3 100755 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -18,7 +18,14 @@ #include "Gui/TooglableButton.h" #include "Gui/ButtonList.h" - +enum KeyPressCommandIDs +{ + buttonNextProgram = 1, + buttonPrevProgram, + buttonPadNextProgram, + buttonPadPrevProgram, + +}; //============================================================================== /** */ @@ -28,6 +35,9 @@ class ObxdAudioProcessorEditor : public AudioProcessorEditor // , public Slider::Listener , public Button::Listener // , public ComboBox::Listener + , public ApplicationCommandTarget + , public Timer + { public: ObxdAudioProcessorEditor(ObxdAudioProcessor& ownerFilter); @@ -42,7 +52,73 @@ public: //============================================================================== void changeListenerCallback (ChangeBroadcaster* source) override; void buttonClicked (Button *) override; + //bool keyPressed(const KeyPress & press) override; + void timerCallback() override { + this->grabKeyboardFocus(); + } + ApplicationCommandTarget* getNextCommandTarget() override { + return nullptr; + }; + void getAllCommands (Array& commands) override { + Array ids { KeyPressCommandIDs::buttonNextProgram, KeyPressCommandIDs::buttonPrevProgram, + KeyPressCommandIDs::buttonPadNextProgram, KeyPressCommandIDs::buttonPadPrevProgram + }; + commands.addArray (ids); + }; + void getCommandInfo (CommandID commandID, ApplicationCommandInfo& result) override { + switch (commandID) + { + case KeyPressCommandIDs::buttonNextProgram: + result.setInfo ("Move up", "Move the button + ", "Button", 0); + result.addDefaultKeypress ('+', 0); + result.setActive (true); + break; + case KeyPressCommandIDs::buttonPrevProgram: + result.setInfo ("Move right", "Move the button - ", "Button", 0); + result.addDefaultKeypress ('-', 0); + result.setActive (true); + break; + case KeyPressCommandIDs::buttonPadNextProgram: + result.setInfo ("Move down", "Move the button Pad + ", "Button", 0); + result.addDefaultKeypress (KeyPress::numberPadAdd, 0); + result.setActive (true); + break; + case KeyPressCommandIDs::buttonPadPrevProgram: + result.setInfo ("Move left", "Move the button Pad -", "Button", 0); + result.addDefaultKeypress (KeyPress::numberPadSubtract, 0); + result.setActive (true); + break; + default: + break; + } + }; + bool perform (const InvocationInfo& info) override { + + switch (info.commandID) + { + case KeyPressCommandIDs::buttonNextProgram: + case KeyPressCommandIDs::buttonPadNextProgram: + nextProgram(); + break; + + case KeyPressCommandIDs::buttonPrevProgram: + case KeyPressCommandIDs::buttonPadPrevProgram: + prevProgram(); + break; + default: + return false; + } + return true; + };/* + bool keyPressed (const KeyPress& key, + Component* originatingComponent) override { + DBG("--- " << key.getKeyCode()); + + };*/ + + void nextProgram(); + void prevProgram(); private: Knob* addKnob (int x, int y, int d, ObxdAudioProcessor& filter, int parameter, String name, float defval); void placeLabel (int x, int y, String text); @@ -149,6 +225,9 @@ private: int skinStart; Array skins; Array banks; + + // Command manager + ApplicationCommandManager commandManager; }; #endif // PLUGINEDITOR_H_INCLUDED