gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 52b9f5e49341b8eedb447507435207c1a07bb2a5
parent 8515c79c22daae8b17911900e2408d7fc37bc2f8
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Mon, 14 Mar 2022 20:48:53 +0100

small refactoring

Diffstat:
Msource/jucePlugin/genericUI/uiObject.cpp | 39++++++++++++++++++---------------------
Msource/jucePlugin/genericUI/uiObject.h | 1+
2 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/source/jucePlugin/genericUI/uiObject.cpp b/source/jucePlugin/genericUI/uiObject.cpp @@ -1,6 +1,7 @@ #include "uiObject.h" #include <cassert> + #include <juce_audio_processors/juce_audio_processors.h> #include <utility> @@ -127,30 +128,22 @@ namespace genericUI if(hasComponent("root")) { - auto c = std::make_unique<juce::Component>(); - apply(_editor, *c); - m_juceObjects.emplace_back(std::move(c)); + createJuceObject<juce::Component>(_editor); } else if(hasComponent("rotary")) { - auto c = std::make_unique<juce::Slider>(); - apply(_editor, *c); - m_juceObjects.emplace_back(std::move(c)); + createJuceObject<juce::Slider>(_editor); } else if(hasComponent("image")) { - auto c = std::make_unique<juce::Component>(); - apply(_editor, *c); + auto* c = createJuceObject<juce::Component>(_editor); auto img = _editor.createImageDrawable(getProperty("texture")); c->addAndMakeVisible(img.get()); - m_juceObjects.emplace_back(std::move(c)); m_juceObjects.emplace_back(std::move(img)); } else if(hasComponent("combobox")) { - auto c = std::make_unique<juce::ComboBox>(); - apply(_editor, *c); - m_juceObjects.emplace_back(std::move(c)); + createJuceObject<juce::ComboBox>(_editor); } else if(hasComponent("button")) { @@ -160,24 +153,20 @@ namespace genericUI } else if(hasComponent("textbutton")) { - auto c = std::make_unique<juce::TextButton>(m_name); - apply(_editor, *c); - m_juceObjects.emplace_back(std::move(c)); + createJuceObject<juce::TextButton>(_editor); } else if(hasComponent("label")) { - auto c = std::make_unique<juce::Label>(m_name); - apply(_editor, *c); - m_juceObjects.emplace_back(std::move(c)); + createJuceObject<juce::Label>(_editor); } else if(hasComponent("component")) { - auto c = std::make_unique<juce::Component>(); - apply(_editor, *c); - m_juceObjects.emplace_back(std::move(c)); + createJuceObject<juce::Component>(_editor); } else + { assert(false && "unknown object type"); + } return m_juceObjects.empty() ? nullptr : m_juceObjects.front().get(); } @@ -258,6 +247,14 @@ namespace genericUI return true; } + template <typename T> T* UiObject::createJuceObject(Editor& _editor) + { + auto c = std::make_unique<T>(); + apply(_editor, *c); + m_juceObjects.emplace_back(std::move(c)); + return c.get(); + } + template<typename T> void UiObject::bindParameter(const Editor& _editor, T& _target) const { diff --git a/source/jucePlugin/genericUI/uiObject.h b/source/jucePlugin/genericUI/uiObject.h @@ -50,6 +50,7 @@ namespace genericUI private: bool hasComponent(const std::string& _component) const; + template<typename T> T* createJuceObject(Editor& _editor); bool parse(juce::DynamicObject* _obj);