From f8b98e05d1f4055af5a43743d1c256708c8d758c Mon Sep 17 00:00:00 2001 From: xenakios Date: Fri, 22 Dec 2017 22:59:45 +0200 Subject: [PATCH] Move parameter component methods to cpp --- Source/PluginEditor.cpp | 109 ++++++++++++++++++++++++++++++++++++++++ Source/PluginEditor.h | 109 +++------------------------------------- 2 files changed, 116 insertions(+), 102 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index f388e10..4dddf29 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -749,3 +749,112 @@ void SpectralChainEditor::drawBox(Graphics & g, int index, int x, int y, int w, g.drawRect(x, y, w, h); g.drawFittedText(txt, x,y,w,h, Justification::centred, 3); } + +ParameterComponent::ParameterComponent(AudioProcessorParameter * par, bool notifyOnlyOnRelease) : m_par(par) +{ + addAndMakeVisible(&m_label); + m_label.setText(par->getName(50), dontSendNotification); + AudioParameterFloat* floatpar = dynamic_cast(par); + if (floatpar) + { + m_slider = std::make_unique(&floatpar->range); + m_notify_only_on_release = notifyOnlyOnRelease; + m_slider->setRange(floatpar->range.start, floatpar->range.end, floatpar->range.interval); + m_slider->setValue(*floatpar, dontSendNotification); + m_slider->addListener(this); + addAndMakeVisible(m_slider.get()); + } + AudioParameterInt* intpar = dynamic_cast(par); + if (intpar) + { + m_slider = std::make_unique(); + m_notify_only_on_release = notifyOnlyOnRelease; + m_slider->setRange(intpar->getRange().getStart(), intpar->getRange().getEnd(), 1.0); + m_slider->setValue(*intpar, dontSendNotification); + m_slider->addListener(this); + addAndMakeVisible(m_slider.get()); + } + AudioParameterChoice* choicepar = dynamic_cast(par); + if (choicepar) + { + + } + AudioParameterBool* boolpar = dynamic_cast(par); + if (boolpar) + { + m_togglebut = std::make_unique(); + m_togglebut->setToggleState(*boolpar, dontSendNotification); + m_togglebut->addListener(this); + m_togglebut->setButtonText(par->getName(50)); + addAndMakeVisible(m_togglebut.get()); + } +} + +void ParameterComponent::resized() +{ + if (m_slider) + { + m_label.setBounds(0, 0, 200, 24); + m_slider->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24); + } + if (m_togglebut) + m_togglebut->setBounds(1, 0, getWidth() - 1, 24); +} + +void ParameterComponent::sliderValueChanged(Slider * slid) +{ + if (m_notify_only_on_release == true) + return; + AudioParameterFloat* floatpar = dynamic_cast(m_par); + if (floatpar != nullptr) + *floatpar = slid->getValue(); + AudioParameterInt* intpar = dynamic_cast(m_par); + if (intpar != nullptr) + *intpar = slid->getValue(); +} + +void ParameterComponent::sliderDragStarted(Slider * slid) +{ + m_dragging = true; +} + +void ParameterComponent::sliderDragEnded(Slider * slid) +{ + m_dragging = false; + if (m_notify_only_on_release == false) + return; + AudioParameterFloat* floatpar = dynamic_cast(m_par); + if (floatpar != nullptr) + *floatpar = slid->getValue(); + AudioParameterInt* intpar = dynamic_cast(m_par); + if (intpar != nullptr) + *intpar = slid->getValue(); +} + +void ParameterComponent::buttonClicked(Button * but) +{ + AudioParameterBool* boolpar = dynamic_cast(m_par); + if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) + { + *boolpar = m_togglebut->getToggleState(); + } +} + +void ParameterComponent::updateComponent() +{ + AudioParameterFloat* floatpar = dynamic_cast(m_par); + if (floatpar != nullptr && m_slider != nullptr && m_dragging == false && (float)m_slider->getValue() != *floatpar) + { + m_slider->setValue(*floatpar, dontSendNotification); + } + AudioParameterInt* intpar = dynamic_cast(m_par); + if (intpar != nullptr && m_slider != nullptr && m_dragging == false && (int)m_slider->getValue() != *intpar) + { + m_slider->setValue(*intpar, dontSendNotification); + } + AudioParameterBool* boolpar = dynamic_cast(m_par); + if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) + { + m_togglebut->setToggleState(*boolpar, dontSendNotification); + } +} diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index e7d8191..75c10c6 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -95,108 +95,13 @@ class ParameterComponent : public Component, public Slider::Listener, public Button::Listener { public: - ParameterComponent(AudioProcessorParameter* par, bool notifyOnlyOnRelease) : m_par(par) - { - addAndMakeVisible(&m_label); - m_label.setText(par->getName(50),dontSendNotification); - AudioParameterFloat* floatpar = dynamic_cast(par); - if (floatpar) - { - m_slider = std::make_unique(&floatpar->range); - m_notify_only_on_release = notifyOnlyOnRelease; - m_slider->setRange(floatpar->range.start, floatpar->range.end, floatpar->range.interval); - m_slider->setValue(*floatpar, dontSendNotification); - m_slider->addListener(this); - addAndMakeVisible(m_slider.get()); - } - AudioParameterInt* intpar = dynamic_cast(par); - if (intpar) - { - m_slider = std::make_unique(); - m_notify_only_on_release = notifyOnlyOnRelease; - m_slider->setRange(intpar->getRange().getStart(), intpar->getRange().getEnd(), 1.0); - m_slider->setValue(*intpar, dontSendNotification); - m_slider->addListener(this); - addAndMakeVisible(m_slider.get()); - } - AudioParameterChoice* choicepar = dynamic_cast(par); - if (choicepar) - { - - } - AudioParameterBool* boolpar = dynamic_cast(par); - if (boolpar) - { - m_togglebut = std::make_unique(); - m_togglebut->setToggleState(*boolpar, dontSendNotification); - m_togglebut->addListener(this); - m_togglebut->setButtonText(par->getName(50)); - addAndMakeVisible(m_togglebut.get()); - } - } - void resized() override - { - if (m_slider) - { - m_label.setBounds(0, 0, 200, 24); - m_slider->setBounds(m_label.getRight() + 1, 0, getWidth() - 2 - m_label.getWidth(), 24); - } - if (m_togglebut) - m_togglebut->setBounds(1, 0, getWidth() -1, 24); - } - void sliderValueChanged(Slider* slid) override - { - if (m_notify_only_on_release == true) - return; - AudioParameterFloat* floatpar = dynamic_cast(m_par); - if (floatpar!=nullptr) - *floatpar = slid->getValue(); - AudioParameterInt* intpar = dynamic_cast(m_par); - if (intpar != nullptr) - *intpar = slid->getValue(); - } - void sliderDragStarted(Slider* slid) override - { - m_dragging = true; - } - void sliderDragEnded(Slider* slid) override - { - m_dragging = false; - if (m_notify_only_on_release == false) - return; - AudioParameterFloat* floatpar = dynamic_cast(m_par); - if (floatpar!=nullptr) - *floatpar = slid->getValue(); - AudioParameterInt* intpar = dynamic_cast(m_par); - if (intpar != nullptr) - *intpar = slid->getValue(); - } - void buttonClicked(Button* but) override - { - AudioParameterBool* boolpar = dynamic_cast(m_par); - if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) - { - *boolpar = m_togglebut->getToggleState(); - } - } - void updateComponent() - { - AudioParameterFloat* floatpar = dynamic_cast(m_par); - if (floatpar!=nullptr && m_slider != nullptr && m_dragging == false && (float)m_slider->getValue() != *floatpar) - { - m_slider->setValue(*floatpar, dontSendNotification); - } - AudioParameterInt* intpar = dynamic_cast(m_par); - if (intpar != nullptr && m_slider != nullptr && m_dragging == false && (int)m_slider->getValue() != *intpar) - { - m_slider->setValue(*intpar, dontSendNotification); - } - AudioParameterBool* boolpar = dynamic_cast(m_par); - if (m_togglebut != nullptr && m_togglebut->getToggleState() != *boolpar) - { - m_togglebut->setToggleState(*boolpar, dontSendNotification); - } - } + ParameterComponent(AudioProcessorParameter* par, bool notifyOnlyOnRelease); + void resized() override; + void sliderValueChanged(Slider* slid) override; + void sliderDragStarted(Slider* slid) override; + void sliderDragEnded(Slider* slid) override; + void buttonClicked(Button* but) override; + void updateComponent(); private: Label m_label; AudioProcessorParameter* m_par = nullptr;