commit 15ceccf59ed158c7c3df9829c71d739d07f27452
parent b9b1828369950faae731dc3be7041c98e82e22ae
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Wed, 16 Mar 2022 18:15:36 +0100
decouple generic UI system from Virus specific code
Diffstat:
7 files changed, 115 insertions(+), 61 deletions(-)
diff --git a/source/jucePlugin/CMakeLists.txt b/source/jucePlugin/CMakeLists.txt
@@ -90,6 +90,7 @@ set(SOURCES_UI3
set(SOURCES_GENERICUI
genericUI/editor.cpp genericUI/editor.h
+ genericUI/editorInterface.h
genericUI/image.cpp genericUI/image.h
genericUI/rotaryStyle.cpp genericUI/rotaryStyle.h
genericUI/comboboxStyle.cpp genericUI/comboboxStyle.h
diff --git a/source/jucePlugin/genericUI/editor.cpp b/source/jucePlugin/genericUI/editor.cpp
@@ -2,11 +2,13 @@
#include "uiObject.h"
-#include "BinaryData.h"
-
namespace genericUI
{
- Editor::Editor(const std::string& _json, VirusParameterBinding& _binding, Virus::Controller& _controller) : m_parameterBinding(_binding), m_controller(_controller)
+ Editor::Editor(EditorInterface& _interface) : m_interface(_interface)
+ {
+ }
+
+ void Editor::create(const std::string& _json)
{
juce::var json;
@@ -24,8 +26,8 @@ namespace genericUI
{
const auto dataName = texture + ".png";
- int dataSize;
- const auto* data = getResourceByFilename(dataName, dataSize);
+ uint32_t dataSize;
+ const auto* data = m_interface.getResourceByFilename(dataName, dataSize);
if (!data)
throw std::runtime_error("Failed to find image named " + dataName);
auto drawable = juce::Drawable::createFromImageData(data, dataSize);
@@ -97,18 +99,4 @@ namespace genericUI
throw std::runtime_error("Failed to find component named " + _name);
return comps.empty() ? nullptr : comps.front();
}
-
- const char* Editor::getResourceByFilename(const std::string& _filename, int& _outDataSize)
- {
- for(size_t i=0; i<BinaryData::namedResourceListSize; ++i)
- {
- if (BinaryData::originalFilenames[i] != _filename)
- continue;
-
- return BinaryData::getNamedResource(BinaryData::namedResourceList[i], _outDataSize);
- }
-
- _outDataSize = 0;
- return nullptr;
- }
}
diff --git a/source/jucePlugin/genericUI/editor.h b/source/jucePlugin/genericUI/editor.h
@@ -6,28 +6,26 @@
#include "uiObject.h"
-namespace Virus
-{
- class Controller;
-}
-
-class VirusParameterBinding;
+#include "editorInterface.h"
namespace genericUI
{
class Editor : public juce::Component
{
public:
- explicit Editor(const std::string& _json, VirusParameterBinding& _binding, Virus::Controller& _controller);
+ explicit Editor(EditorInterface& _interface);
+ Editor(const Editor&) = delete;
+ Editor(Editor&&) = delete;
+
+ void create(const std::string& _json);
juce::Drawable* getImageDrawable(const std::string& _texture);
std::unique_ptr<juce::Drawable> createImageDrawable(const std::string& _texture);
- VirusParameterBinding& getParameterBinding() const { return m_parameterBinding; }
- Virus::Controller& getController() const { return m_controller; }
-
void registerComponent(const std::string& _name, juce::Component* _component);
+ EditorInterface& getInterface() const { return m_interface; }
+
const std::vector<juce::Component*>& findComponents(const std::string& _name, uint32_t _expectedCount = 0) const;
template<typename T>
@@ -54,14 +52,11 @@ namespace genericUI
float getScale() const { return m_scale; }
private:
- static const char* getResourceByFilename(const std::string& _filename, int& _outDataSize);
+ EditorInterface& m_interface;
std::map<std::string, std::unique_ptr<juce::Drawable>> m_drawables;
std::unique_ptr<UiObject> m_rootObject;
- VirusParameterBinding& m_parameterBinding;
- Virus::Controller& m_controller;
-
std::map<std::string, std::vector<juce::Component*>> m_componentsByName;
float m_scale = 1.0f;
diff --git a/source/jucePlugin/genericUI/editorInterface.h b/source/jucePlugin/genericUI/editorInterface.h
@@ -0,0 +1,18 @@
+#pragma once
+
+namespace genericUI
+{
+ class EditorInterface
+ {
+ public:
+ virtual ~EditorInterface() = default;
+
+ virtual const char* getResourceByFilename(const std::string& _name, uint32_t& _dataSize) = 0;
+
+ virtual int getParameterIndexByName(const std::string& _name) = 0;
+
+ virtual bool bindParameter(juce::Slider& _target, int _parameterIndex) = 0;
+ virtual bool bindParameter(juce::Button& _target, int _parameterIndex) = 0;
+ virtual bool bindParameter(juce::ComboBox& _target, int _parameterIndex) = 0;
+ };
+}
diff --git a/source/jucePlugin/genericUI/uiObject.cpp b/source/jucePlugin/genericUI/uiObject.cpp
@@ -13,9 +13,6 @@
#include "hyperlinkbuttonStyle.h"
#include "labelStyle.h"
-#include "../VirusController.h"
-#include "../VirusParameterBinding.h"
-
namespace genericUI
{
UiObject::UiObject(const juce::var& _json)
@@ -302,16 +299,14 @@ namespace genericUI
if(param.empty())
return;
- const auto index = _editor.getController().getParameterTypeByName(param);
+ const auto index = _editor.getInterface().getParameterIndexByName(param);
- if(index == Virus::Param_Invalid)
+ if(index < 0)
throw std::runtime_error("Parameter named " + param + " not found");
- auto& binding = _editor.getParameterBinding();
-
- binding.bind(_target, index);
+ _editor.getInterface().bindParameter(_target, index);
- _target.getProperties().set("parameter", static_cast<int>(index));
+ _target.getProperties().set("parameter", index);
}
template <typename Target, typename Style> void UiObject::createStyle(Editor& _editor, Target& _target, Style* _style)
diff --git a/source/jucePlugin/ui3/VirusEditor.cpp b/source/jucePlugin/ui3/VirusEditor.cpp
@@ -10,14 +10,18 @@
namespace genericVirusUI
{
VirusEditor::VirusEditor(VirusParameterBinding& _binding, Virus::Controller& _controller, AudioPluginAudioProcessor &_processorRef) :
- Editor(std::string(BinaryData::VirusC_json, BinaryData::VirusC_jsonSize), _binding, _controller),
+ Editor(static_cast<EditorInterface&>(*this)),
m_processor(_processorRef),
- m_parts(*this),
- m_tabs(*this),
- m_midiPorts(*this),
- m_fxPage(*this),
- m_patchBrowser(*this)
+ m_parameterBinding(_binding)
{
+ create(std::string(BinaryData::VirusC_json, BinaryData::VirusC_jsonSize));
+
+ m_parts.reset(new Parts(*this));
+ m_tabs.reset(new Tabs(*this));
+ m_midiPorts.reset(new MidiPorts(*this));
+ m_fxPage.reset(new FxPage(*this));
+ m_patchBrowser.reset(new PatchBrowser(*this));
+
m_presetName = findComponentT<juce::Label>("PatchName");
m_controlLabel = findComponentT<juce::Label>("ControlLabel");
m_romSelector = findComponentT<juce::ComboBox>("RomSelector");
@@ -71,22 +75,67 @@ namespace genericVirusUI
};
}
+ Virus::Controller& VirusEditor::getController() const
+ {
+ return m_processor.getController();
+ }
+
+ const char* VirusEditor::getResourceByFilename(const std::string& _name, uint32_t& _dataSize)
+ {
+ for(size_t i=0; i<BinaryData::namedResourceListSize; ++i)
+ {
+ if (BinaryData::originalFilenames[i] != _name)
+ continue;
+
+ int size = 0;
+ const auto res = BinaryData::getNamedResource(BinaryData::namedResourceList[i], size);
+ _dataSize = static_cast<uint32_t>(size);
+ return res;
+ }
+
+ _dataSize = 0;
+ return nullptr;
+ }
+
+ int VirusEditor::getParameterIndexByName(const std::string& _name)
+ {
+ return getController().getParameterTypeByName(_name);
+ }
+
+ bool VirusEditor::bindParameter(juce::Button& _target, int _parameterIndex)
+ {
+ m_parameterBinding.bind(_target, static_cast<Virus::ParameterType>(_parameterIndex));
+ return true;
+ }
+
+ bool VirusEditor::bindParameter(juce::ComboBox& _target, int _parameterIndex)
+ {
+ m_parameterBinding.bind(_target, static_cast<Virus::ParameterType>(_parameterIndex));
+ return true;
+ }
+
+ bool VirusEditor::bindParameter(juce::Slider& _target, int _parameterIndex)
+ {
+ m_parameterBinding.bind(_target, static_cast<Virus::ParameterType>(_parameterIndex));
+ return true;
+ }
+
void VirusEditor::onProgramChange()
{
- m_parts.onProgramChange();
+ m_parts->onProgramChange();
updatePresetName();
}
void VirusEditor::onPlayModeChanged()
{
- m_parts.onPlayModeChanged();
+ m_parts->onPlayModeChanged();
updatePresetName();
updatePlayModeButtons();
}
void VirusEditor::onCurrentPartChanged()
{
- m_parts.onCurrentPartChanged();
+ m_parts->onCurrentPartChanged();
updatePresetName();
}
@@ -258,14 +307,14 @@ namespace genericVirusUI
{
getController().getParameter(Virus::Param_PlayMode)->setValue(_playMode);
if (_playMode == virusLib::PlayModeSingle && getController().getCurrentPart() != 0)
- getParameterBinding().setPart(0);
+ m_parameterBinding.setPart(0);
onPlayModeChanged();
}
void VirusEditor::setPart(size_t _part)
{
- getParameterBinding().setPart(static_cast<uint8_t>(_part));
+ m_parameterBinding.setPart(static_cast<uint8_t>(_part));
onCurrentPartChanged();
}
}
diff --git a/source/jucePlugin/ui3/VirusEditor.h b/source/jucePlugin/ui3/VirusEditor.h
@@ -12,16 +12,24 @@ class AudioPluginAudioProcessor;
namespace genericVirusUI
{
- class VirusEditor : public genericUI::Editor
+ class VirusEditor : public genericUI::EditorInterface, public genericUI::Editor
{
public:
VirusEditor(VirusParameterBinding& _binding, Virus::Controller& _controller, AudioPluginAudioProcessor &_processorRef);
void setPart(size_t _part);
- AudioPluginAudioProcessor& getProcessor() { return m_processor; }
+ AudioPluginAudioProcessor& getProcessor() const { return m_processor; }
+ VirusParameterBinding& getParameterBinding() const { return m_parameterBinding; }
+ Virus::Controller& getController() const;
private:
+ const char* getResourceByFilename(const std::string& _name, uint32_t& _dataSize) override;
+ int getParameterIndexByName(const std::string& _name) override;
+ bool bindParameter(juce::Button& _target, int _parameterIndex) override;
+ bool bindParameter(juce::ComboBox& _target, int _parameterIndex) override;
+ bool bindParameter(juce::Slider& _target, int _parameterIndex) override;
+
void onProgramChange();
void onPlayModeChanged();
void onCurrentPartChanged();
@@ -41,9 +49,13 @@ namespace genericVirusUI
void setPlayMode(uint8_t _playMode);
AudioPluginAudioProcessor& m_processor;
+ VirusParameterBinding& m_parameterBinding;
- Parts m_parts;
- Tabs m_tabs;
+ std::unique_ptr<Parts> m_parts;
+ std::unique_ptr<Tabs> m_tabs;
+ std::unique_ptr<MidiPorts> m_midiPorts;
+ std::unique_ptr<FxPage> m_fxPage;
+ std::unique_ptr<PatchBrowser> m_patchBrowser;
juce::Label* m_presetName = nullptr;
juce::Label* m_controlLabel = nullptr;
@@ -54,10 +66,6 @@ namespace genericVirusUI
juce::TooltipWindow m_tooltipWindow;
- MidiPorts m_midiPorts;
- FxPage m_fxPage;
- PatchBrowser m_patchBrowser;
-
std::unique_ptr<juce::FileChooser> m_fileChooser;
juce::String m_previousPath;
};