From 65b7e2275fa4cf76ab88f8e09bced179f0c83f8e Mon Sep 17 00:00:00 2001 From: George Reales Date: Tue, 27 Apr 2021 09:46:19 +0200 Subject: [PATCH] Preliminary preset bar implementation --- OB-Xd.jucer | 11 +- Source/Components/PresetBar.cpp | 253 +++++++++++++++++++++++++++++ Source/Components/PresetBar.h | 79 +++++++++ Source/Images/presetnavigation.svg | 19 +++ Source/PluginEditor.cpp | 33 +++- Source/PluginEditor.h | 11 +- 6 files changed, 400 insertions(+), 6 deletions(-) create mode 100644 Source/Components/PresetBar.cpp create mode 100644 Source/Components/PresetBar.h create mode 100644 Source/Images/presetnavigation.svg diff --git a/OB-Xd.jucer b/OB-Xd.jucer index 9aceccb..d71f44f 100644 --- a/OB-Xd.jucer +++ b/OB-Xd.jucer @@ -1,6 +1,6 @@ - + + + @@ -76,7 +80,7 @@ stripLocalSymbols="0" linkTimeOptimisation="0"/> + enablePluginBinaryCopyStep="1"/> @@ -124,7 +128,8 @@ + targetName="OB-Xd" headerPath="../../Modules/asiosdk2.3.2/common" + enablePluginBinaryCopyStep="1"/> diff --git a/Source/Components/PresetBar.cpp b/Source/Components/PresetBar.cpp new file mode 100644 index 0000000..80213d7 --- /dev/null +++ b/Source/Components/PresetBar.cpp @@ -0,0 +1,253 @@ +/* + ============================================================================== + + This is an automatically generated GUI class created by the Projucer! + + Be careful when adding custom code to these files, as only the code within + the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded + and re-saved. + + Created with Projucer version: 6.0.8 + + ------------------------------------------------------------------------------ + + The Projucer is part of the JUCE library. + Copyright (c) 2020 - Raw Material Software Limited. + + ============================================================================== +*/ + +//[Headers] You can add your own extra header files here... +#include "../PluginEditor.h" +//[/Headers] + +#include "PresetBar.h" + + +//[MiscUserDefs] You can add your own user definitions and misc code here... +//[/MiscUserDefs] + +//============================================================================== +PresetBar::PresetBar (ObxdAudioProcessorEditor &gui) + : editor(gui) +{ + //[Constructor_pre] You can add your own custom stuff here.. + //[/Constructor_pre] + + presetNameLb.reset (new juce::Label ("new label", + TRANS("---\n"))); + addAndMakeVisible (presetNameLb.get()); + presetNameLb->setFont (juce::Font (15.00f, juce::Font::plain).withTypefaceStyle ("Regular")); + presetNameLb->setJustificationType (juce::Justification::centred); + presetNameLb->setEditable (false, false, false); + presetNameLb->setColour (juce::TextEditor::textColourId, juce::Colours::black); + presetNameLb->setColour (juce::TextEditor::backgroundColourId, juce::Colour (0x00000000)); + + presetNameLb->setBounds (24, 8, 368, 24); + + previousBtn.reset (new juce::ImageButton ("new button")); + addAndMakeVisible (previousBtn.get()); + previousBtn->setButtonText (juce::String()); + previousBtn->addListener (this); + + previousBtn->setImages (false, true, true, + juce::Image(), 1.000f, juce::Colour (0x00000000), + juce::Image(), 1.000f, juce::Colour (0x00000000), + juce::Image(), 1.000f, juce::Colour (0x00000000)); + previousBtn->setBounds (407, 8, 20, 24); + + nextBtn.reset (new juce::ImageButton ("new button")); + addAndMakeVisible (nextBtn.get()); + nextBtn->setButtonText (juce::String()); + nextBtn->addListener (this); + + nextBtn->setImages (false, true, true, + juce::Image(), 1.000f, juce::Colour (0x00000000), + juce::Image(), 1.000f, juce::Colour (0x00000000), + juce::Image(), 1.000f, juce::Colour (0x00000000)); + nextBtn->setBounds (435, 8, 20, 24); + + drawable1 = juce::Drawable::createFromImageData (presetnavigation_svg, presetnavigation_svgSize); + + //[UserPreSize] + //[/UserPreSize] + + setSize (471, 40); + + + //[Constructor] You can add your own custom stuff here.. + startTimer(500); + //[/Constructor] +} + +PresetBar::~PresetBar() +{ + //[Destructor_pre]. You can add your own custom destruction code here.. + //[/Destructor_pre] + + presetNameLb = nullptr; + previousBtn = nullptr; + nextBtn = nullptr; + drawable1 = nullptr; + + + //[Destructor]. You can add your own custom destruction code here.. + //[/Destructor] +} + +//============================================================================== +void PresetBar::paint (juce::Graphics& g) +{ + //[UserPrePaint] Add your own custom painting code here.. + //[/UserPrePaint] + + g.fillAll (juce::Colours::black); + + { + int x = 0, y = 0, width = 471, height = 40; + //[UserPaintCustomArguments] Customize the painting arguments here.. + //[/UserPaintCustomArguments] + g.setColour (juce::Colours::black); + jassert (drawable1 != nullptr); + if (drawable1 != nullptr) + drawable1->drawWithin (g, juce::Rectangle (x, y, width, height).toFloat(), + juce::RectanglePlacement::centred, 1.000f); + } + + //[UserPaint] Add your own custom painting code here.. + //[/UserPaint] +} + +void PresetBar::resized() +{ + //[UserPreResize] Add your own custom resize code here.. + //[/UserPreResize] + + //[UserResized] Add your own custom resize handling here.. + //[/UserResized] +} + +void PresetBar::buttonClicked (juce::Button* buttonThatWasClicked) +{ + //[UserbuttonClicked_Pre] + //[/UserbuttonClicked_Pre] + + if (buttonThatWasClicked == previousBtn.get()) + { + //[UserButtonCode_previousBtn] -- add your button handler code here.. + editor.prevProgram(); + //[/UserButtonCode_previousBtn] + } + else if (buttonThatWasClicked == nextBtn.get()) + { + //[UserButtonCode_nextBtn] -- add your button handler code here.. + editor.nextProgram(); + //[/UserButtonCode_nextBtn] + } + + //[UserbuttonClicked_Post] + //[/UserbuttonClicked_Post] +} + + + +//[MiscUserCode] You can add your own definitions of your custom methods or any other code here... +void PresetBar::timerCallback() { + update(); +} + +void PresetBar::update(){ + presetNameLb->setText(editor.getCurrentProgramName(), NotificationType::dontSendNotification); +} +//[/MiscUserCode] + + +//============================================================================== +#if 0 +/* -- Projucer information section -- + + This is where the Projucer stores the metadata that describe this GUI layout, so + make changes in here at your peril! + +BEGIN_JUCER_METADATA + + + + + + + +END_JUCER_METADATA +*/ +#endif + +//============================================================================== +// Binary resources - be careful not to edit any of these sections! + +// JUCER_RESOURCE: presetnavigation_svg, 2220, "../Images/presetnavigation.svg" +static const unsigned char resource_PresetBar_presetnavigation_svg[] = { 60,63,120,109,108,32,118,101,114,115,105,111,110,61,34,49,46,48,34,32,101,110,99,111,100,105,110,103,61,34,85,84,70,45,56,34,32, +115,116,97,110,100,97,108,111,110,101,61,34,110,111,34,63,62,10,60,33,68,79,67,84,89,80,69,32,115,118,103,32,80,85,66,76,73,67,32,34,45,47,47,87,51,67,47,47,68,84,68,32,83,86,71,32,49,46,49,47,47,69,78, +34,32,34,104,116,116,112,58,47,47,119,119,119,46,119,51,46,111,114,103,47,71,114,97,112,104,105,99,115,47,83,86,71,47,49,46,49,47,68,84,68,47,115,118,103,49,49,46,100,116,100,34,62,10,60,115,118,103,32, +119,105,100,116,104,61,34,49,48,48,37,34,32,104,101,105,103,104,116,61,34,49,48,48,37,34,32,118,105,101,119,66,111,120,61,34,48,32,48,32,52,55,49,32,51,57,34,32,118,101,114,115,105,111,110,61,34,49,46, +49,34,32,120,109,108,110,115,61,34,104,116,116,112,58,47,47,119,119,119,46,119,51,46,111,114,103,47,50,48,48,48,47,115,118,103,34,32,120,109,108,110,115,58,120,108,105,110,107,61,34,104,116,116,112,58, +47,47,119,119,119,46,119,51,46,111,114,103,47,49,57,57,57,47,120,108,105,110,107,34,32,120,109,108,58,115,112,97,99,101,61,34,112,114,101,115,101,114,118,101,34,32,120,109,108,110,115,58,115,101,114,105, +102,61,34,104,116,116,112,58,47,47,119,119,119,46,115,101,114,105,102,46,99,111,109,47,34,32,115,116,121,108,101,61,34,102,105,108,108,45,114,117,108,101,58,101,118,101,110,111,100,100,59,99,108,105,112, +45,114,117,108,101,58,101,118,101,110,111,100,100,59,115,116,114,111,107,101,45,108,105,110,101,106,111,105,110,58,114,111,117,110,100,59,115,116,114,111,107,101,45,109,105,116,101,114,108,105,109,105, +116,58,50,59,34,62,10,32,32,32,32,60,114,101,99,116,32,120,61,34,48,34,32,121,61,34,48,34,32,119,105,100,116,104,61,34,52,55,49,34,32,104,101,105,103,104,116,61,34,51,57,34,47,62,10,32,32,32,32,60,103, +32,116,114,97,110,115,102,111,114,109,61,34,109,97,116,114,105,120,40,49,44,48,44,48,44,49,46,48,50,57,52,49,44,48,44,45,48,46,48,53,56,56,50,51,53,41,34,62,10,32,32,32,32,32,32,32,32,60,112,97,116,104, +32,100,61,34,77,52,54,53,44,49,48,46,53,67,52,54,53,44,53,46,56,48,57,32,52,54,49,46,48,55,57,44,50,32,52,53,54,46,50,53,44,50,76,49,50,46,55,53,44,50,67,55,46,57,50,49,44,50,32,52,44,53,46,56,48,57,32, +52,44,49,48,46,53,76,52,44,50,55,46,53,67,52,44,51,50,46,49,57,49,32,55,46,57,50,49,44,51,54,32,49,50,46,55,53,44,51,54,76,52,53,54,46,50,53,44,51,54,67,52,54,49,46,48,55,57,44,51,54,32,52,54,53,44,51, +50,46,49,57,49,32,52,54,53,44,50,55,46,53,76,52,54,53,44,49,48,46,53,90,34,32,115,116,121,108,101,61,34,102,105,108,108,58,114,103,98,40,49,50,49,44,49,50,49,44,49,50,49,41,59,34,47,62,10,32,32,32,32, +60,47,103,62,10,32,32,32,32,60,112,97,116,104,32,100,61,34,77,51,57,56,44,57,46,50,48,53,67,51,57,56,44,55,46,52,51,54,32,51,57,54,46,53,54,52,44,54,32,51,57,52,46,55,57,53,44,54,76,50,52,46,50,48,53, +44,54,67,50,50,46,52,51,54,44,54,32,50,49,44,55,46,52,51,54,32,50,49,44,57,46,50,48,53,76,50,49,44,50,57,46,55,57,53,67,50,49,44,51,49,46,53,54,52,32,50,50,46,52,51,54,44,51,51,32,50,52,46,50,48,53,44, +51,51,76,51,57,52,46,55,57,53,44,51,51,67,51,57,54,46,53,54,52,44,51,51,32,51,57,56,44,51,49,46,53,54,52,32,51,57,56,44,50,57,46,55,57,53,76,51,57,56,44,57,46,50,48,53,90,34,47,62,10,32,32,32,32,60,103, +32,116,114,97,110,115,102,111,114,109,61,34,109,97,116,114,105,120,40,49,44,48,44,48,44,49,44,49,44,49,53,46,52,49,57,49,41,34,62,10,32,32,32,32,32,32,32,32,60,103,32,116,114,97,110,115,102,111,114,109, +61,34,109,97,116,114,105,120,40,51,54,44,48,44,48,44,51,54,44,52,48,54,46,54,50,49,44,49,55,46,50,54,52,53,41,34,62,10,32,32,32,32,32,32,32,32,32,32,32,32,60,112,97,116,104,32,100,61,34,77,48,46,52,50, +53,44,45,48,46,49,53,54,67,48,46,52,51,53,44,45,48,46,49,52,55,32,48,46,52,51,57,44,45,48,46,49,51,53,32,48,46,52,51,57,44,45,48,46,49,50,50,67,48,46,52,51,57,44,45,48,46,49,48,57,32,48,46,52,51,53,44, +45,48,46,48,57,55,32,48,46,52,50,53,44,45,48,46,48,56,56,67,48,46,52,49,53,44,45,48,46,48,55,56,32,48,46,52,48,52,44,45,48,46,48,55,51,32,48,46,51,57,49,44,45,48,46,48,55,51,67,48,46,51,55,55,44,45,48, +46,48,55,51,32,48,46,51,54,54,44,45,48,46,48,55,56,32,48,46,51,53,54,44,45,48,46,48,56,55,76,48,46,49,49,50,44,45,48,46,51,51,50,67,48,46,49,48,50,44,45,48,46,51,52,49,32,48,46,48,57,56,44,45,48,46,51, +53,51,32,48,46,48,57,56,44,45,48,46,51,54,54,67,48,46,48,57,56,44,45,48,46,51,56,32,48,46,49,48,51,44,45,48,46,51,57,49,32,48,46,49,49,50,44,45,48,46,52,48,49,76,48,46,51,53,54,44,45,48,46,54,52,53,67, +48,46,51,54,54,44,45,48,46,54,53,52,32,48,46,51,55,55,44,45,48,46,54,53,57,32,48,46,51,57,49,44,45,48,46,54,53,57,67,48,46,52,48,52,44,45,48,46,54,53,57,32,48,46,52,49,53,44,45,48,46,54,53,52,32,48,46, +52,50,53,44,45,48,46,54,52,53,67,48,46,52,51,53,44,45,48,46,54,51,53,32,48,46,52,51,57,44,45,48,46,54,50,52,32,48,46,52,51,57,44,45,48,46,54,49,67,48,46,52,51,57,44,45,48,46,53,57,55,32,48,46,52,51,53, +44,45,48,46,53,56,53,32,48,46,52,50,53,44,45,48,46,53,55,54,76,48,46,50,49,53,44,45,48,46,51,54,54,76,48,46,52,50,53,44,45,48,46,49,53,54,90,34,32,115,116,121,108,101,61,34,102,105,108,108,45,114,117, +108,101,58,110,111,110,122,101,114,111,59,34,47,62,10,32,32,32,32,32,32,32,32,60,47,103,62,10,32,32,32,32,60,47,103,62,10,32,32,32,32,60,103,32,116,114,97,110,115,102,111,114,109,61,34,109,97,116,114, +105,120,40,49,44,48,44,48,44,49,44,50,56,44,49,53,46,52,49,57,49,41,34,62,10,32,32,32,32,32,32,32,32,60,103,32,116,114,97,110,115,102,111,114,109,61,34,109,97,116,114,105,120,40,51,54,44,48,44,48,44,51, +54,44,52,48,54,46,54,50,49,44,49,55,46,50,54,52,53,41,34,62,10,32,32,32,32,32,32,32,32,32,32,32,32,60,112,97,116,104,32,100,61,34,77,48,46,51,50,50,44,45,48,46,51,54,54,76,48,46,49,49,50,44,45,48,46,53, +55,54,67,48,46,49,48,51,44,45,48,46,53,56,53,32,48,46,48,57,56,44,45,48,46,53,57,55,32,48,46,48,57,56,44,45,48,46,54,49,67,48,46,48,57,56,44,45,48,46,54,50,52,32,48,46,49,48,50,44,45,48,46,54,51,53,32, +48,46,49,49,50,44,45,48,46,54,52,53,67,48,46,49,50,50,44,45,48,46,54,53,52,32,48,46,49,51,51,44,45,48,46,54,53,57,32,48,46,49,52,54,44,45,48,46,54,53,57,67,48,46,49,54,44,45,48,46,54,53,57,32,48,46,49, +55,49,44,45,48,46,54,53,52,32,48,46,49,56,49,44,45,48,46,54,52,53,76,48,46,52,50,53,44,45,48,46,52,48,49,67,48,46,52,51,53,44,45,48,46,51,57,49,32,48,46,52,51,57,44,45,48,46,51,56,32,48,46,52,51,57,44, +45,48,46,51,54,54,67,48,46,52,51,57,44,45,48,46,51,53,51,32,48,46,52,51,53,44,45,48,46,51,52,49,32,48,46,52,50,53,44,45,48,46,51,51,50,76,48,46,49,56,49,44,45,48,46,48,56,55,67,48,46,49,55,49,44,45,48, +46,48,55,56,32,48,46,49,54,44,45,48,46,48,55,51,32,48,46,49,52,54,44,45,48,46,48,55,51,67,48,46,49,51,51,44,45,48,46,48,55,51,32,48,46,49,50,50,44,45,48,46,48,55,56,32,48,46,49,49,50,44,45,48,46,48,56, +56,67,48,46,49,48,50,44,45,48,46,48,57,55,32,48,46,48,57,56,44,45,48,46,49,48,57,32,48,46,48,57,56,44,45,48,46,49,50,50,67,48,46,48,57,56,44,45,48,46,49,51,53,32,48,46,49,48,51,44,45,48,46,49,52,55,32, +48,46,49,49,50,44,45,48,46,49,53,54,76,48,46,51,50,50,44,45,48,46,51,54,54,90,34,32,115,116,121,108,101,61,34,102,105,108,108,45,114,117,108,101,58,110,111,110,122,101,114,111,59,34,47,62,10,32,32,32, +32,32,32,32,32,60,47,103,62,10,32,32,32,32,60,47,103,62,10,60,47,115,118,103,62,10,0,0}; + +const char* PresetBar::presetnavigation_svg = (const char*) resource_PresetBar_presetnavigation_svg; +const int PresetBar::presetnavigation_svgSize = 2220; + + +//[EndFile] You can add extra defines here... +//[/EndFile] + diff --git a/Source/Components/PresetBar.h b/Source/Components/PresetBar.h new file mode 100644 index 0000000..dd05f21 --- /dev/null +++ b/Source/Components/PresetBar.h @@ -0,0 +1,79 @@ +/* + ============================================================================== + + This is an automatically generated GUI class created by the Projucer! + + Be careful when adding custom code to these files, as only the code within + the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded + and re-saved. + + Created with Projucer version: 6.0.8 + + ------------------------------------------------------------------------------ + + The Projucer is part of the JUCE library. + Copyright (c) 2020 - Raw Material Software Limited. + + ============================================================================== +*/ + +#pragma once + +//[Headers] -- You can add your own extra header files here -- +#include +class ObxdAudioProcessorEditor; +//[/Headers] + + + +//============================================================================== +/** + //[Comments] + An auto-generated component, created by the Projucer. + + Describe your class and how it works here! + //[/Comments] +*/ +class PresetBar : public juce::Component, + public Timer, + public juce::Button::Listener +{ +public: + //============================================================================== + PresetBar (ObxdAudioProcessorEditor &gui); + ~PresetBar() override; + + //============================================================================== + //[UserMethods] -- You can add your own custom methods in this section. + void timerCallback() override; + void update(); + //[/UserMethods] + + void paint (juce::Graphics& g) override; + void resized() override; + void buttonClicked (juce::Button* buttonThatWasClicked) override; + + // Binary resources: + static const char* presetnavigation_svg; + static const int presetnavigation_svgSize; + + +private: + //[UserVariables] -- You can add your own custom variables in this section. + ObxdAudioProcessorEditor &editor; + //[/UserVariables] + + //============================================================================== + std::unique_ptr presetNameLb; + std::unique_ptr previousBtn; + std::unique_ptr nextBtn; + std::unique_ptr drawable1; + + + //============================================================================== + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PresetBar) +}; + +//[EndFile] You can add extra defines here... +//[/EndFile] + diff --git a/Source/Images/presetnavigation.svg b/Source/Images/presetnavigation.svg new file mode 100644 index 0000000..04bd397 --- /dev/null +++ b/Source/Images/presetnavigation.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 40bf916..8e5be25 100755 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -50,7 +50,11 @@ ObxdAudioProcessorEditor::ObxdAudioProcessorEditor (ObxdAudioProcessor& ownerFil #else startTimer(100); // This will fix the issue #endif + + DBG("W: " <setVisible(showPresetBar); + presetBar->setBounds( + (getWidth() - presetBar->getWidth())/2, getHeight(), presetBar->getWidth(), presetBar->getHeight()); + updatePresetBar(); repaint(); } ObxdAudioProcessorEditor::~ObxdAudioProcessorEditor() @@ -505,7 +517,7 @@ void ObxdAudioProcessorEditor::createMenu () menu->addSubMenu ("Themes", skinMenu); // About // menu.addItem(1, String("Release ") + String(JucePlugin_VersionString).dropLastCharacters(2), false); } - + menu->addItem(progStart + 1000, "Preset Bar", true, false, Image()); popupMenus.add (menu); } @@ -546,6 +558,25 @@ void ObxdAudioProcessorEditor::resultFromMenu (const Point pos) else if (result < progStart){ MenuActionCallback(result); } + else if (result == progStart + 1000){ + this->showPresetBar = !this->showPresetBar; + updatePresetBar(); + } +} + +void ObxdAudioProcessorEditor::updatePresetBar(){ + DBG(" H: " << getHeight() <<" W:" <getWidth() << " CH" <getHeight() << " CX:" <getX() << " CY: " <getY()); + if (this->showPresetBar){ + this->setSize(this->getWidth(), this->getHeight() + 40); + presetBar->setVisible(true); + } + else if (presetBar->isVisible()) { + this->setSize(this->getWidth(), this->getHeight() - 40); + presetBar->setVisible(false); + } + + presetBar->update(); + } void ObxdAudioProcessorEditor::MenuActionCallback(int action){ diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 7d63dbd..cab6d9f 100755 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -18,7 +18,7 @@ #include "Gui/TooglableButton.h" #include "Gui/ButtonList.h" #include "Components/SetPresetNameWindow.h" - +#include "Components/PresetBar.h" enum KeyPressCommandIDs { buttonNextProgram = 1, @@ -66,7 +66,10 @@ public: void paint (Graphics& g) override; void updateFromHost(); - + String getCurrentProgramName(){ + return processor.getProgramName(processor.getCurrentProgram()); + } + void updatePresetBar(); //============================================================================== void changeListenerCallback (ChangeBroadcaster* source) override; void buttonClicked (Button *) override; @@ -154,6 +157,7 @@ private: void resultFromMenu (const Point); void clean(); + void rebuildComponents (ObxdAudioProcessor&); void loadSkin(ObxdAudioProcessor&); //============================================================================== @@ -248,9 +252,12 @@ private: int progStart; int bankStart; int skinStart; + + bool showPresetBar = false; Array skins; Array banks; std::unique_ptr setPresetNameWindow; + std::unique_ptr presetBar; std::unique_ptr fileChooser; // Command manager ApplicationCommandManager commandManager;