2
0
Fork 0

Preset navigation

+ and - keys navigate between presets. Also works with numeric keyboard
This commit is contained in:
George Reales 2020-12-13 19:06:22 +01:00
parent 3f32716745
commit 4ad33fded0
2 changed files with 97 additions and 1 deletions

View file

@ -23,6 +23,23 @@ ObxdAudioProcessorEditor::ObxdAudioProcessorEditor (ObxdAudioProcessor& ownerFil
banks (processor.getBankFiles()) banks (processor.getBankFiles())
{ {
// skinFolder = ownerFilter.getCurrentSkinFolder(); // initialized above // 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); loadSkin (processor);
repaint(); repaint();

View file

@ -18,7 +18,14 @@
#include "Gui/TooglableButton.h" #include "Gui/TooglableButton.h"
#include "Gui/ButtonList.h" #include "Gui/ButtonList.h"
enum KeyPressCommandIDs
{
buttonNextProgram = 1,
buttonPrevProgram,
buttonPadNextProgram,
buttonPadPrevProgram,
};
//============================================================================== //==============================================================================
/** /**
*/ */
@ -28,6 +35,9 @@ class ObxdAudioProcessorEditor : public AudioProcessorEditor
// , public Slider::Listener // , public Slider::Listener
, public Button::Listener , public Button::Listener
// , public ComboBox::Listener // , public ComboBox::Listener
, public ApplicationCommandTarget
, public Timer
{ {
public: public:
ObxdAudioProcessorEditor(ObxdAudioProcessor& ownerFilter); ObxdAudioProcessorEditor(ObxdAudioProcessor& ownerFilter);
@ -42,7 +52,73 @@ public:
//============================================================================== //==============================================================================
void changeListenerCallback (ChangeBroadcaster* source) override; void changeListenerCallback (ChangeBroadcaster* source) override;
void buttonClicked (Button *) override; void buttonClicked (Button *) override;
//bool keyPressed(const KeyPress & press) override;
void timerCallback() override {
this->grabKeyboardFocus();
}
ApplicationCommandTarget* getNextCommandTarget() override {
return nullptr;
};
void getAllCommands (Array<CommandID>& commands) override {
Array<CommandID> 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: private:
Knob* addKnob (int x, int y, int d, ObxdAudioProcessor& filter, int parameter, String name, float defval); Knob* addKnob (int x, int y, int d, ObxdAudioProcessor& filter, int parameter, String name, float defval);
void placeLabel (int x, int y, String text); void placeLabel (int x, int y, String text);
@ -149,6 +225,9 @@ private:
int skinStart; int skinStart;
Array<File> skins; Array<File> skins;
Array<File> banks; Array<File> banks;
// Command manager
ApplicationCommandManager commandManager;
}; };
#endif // PLUGINEDITOR_H_INCLUDED #endif // PLUGINEDITOR_H_INCLUDED