diff options
| -rw-r--r-- | src/UI/KnobWithLabel.cpp | 34 | ||||
| -rw-r--r-- | src/UI/KnobWithLabel.h | 20 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/UI/KnobWithLabel.cpp b/src/UI/KnobWithLabel.cpp new file mode 100644 index 0000000..9a09307 --- /dev/null +++ b/src/UI/KnobWithLabel.cpp @@ -0,0 +1,34 @@ +#include "KnobWithLabel.h" + +KnobWithLabel::KnobWithLabel(const juce::String& text, juce::AudioParameterFloat* param) + : param(param) +{ + addAndMakeVisible(label); + label.setText(text, juce::dontSendNotification); + label.setJustificationType(juce::Justification::centred); + label.setFont(juce::Font(juce::FontOptions().withHeight(10.0f))); + addAndMakeVisible(knob); + knob.setSliderStyle(juce::Slider::Rotary); + knob.setTextBoxStyle(juce::Slider::TextBoxBelow, false, 50, 20); + knob.setValue(param->get()); + + auto range = param->getNormalisableRange(); + knob.setRange(range.start, range.end, range.interval); + + knob.onValueChange = [this]() + { + if (this->param != nullptr) + { + *this->param = (float) knob.getValue(); + } + }; +} + +KnobWithLabel::~KnobWithLabel() {} + +void +KnobWithLabel::resized() +{ + knob.setBounds(0, 0, getWidth(), getHeight()); + label.setBounds(0, -10, getWidth(), getHeight()); +} diff --git a/src/UI/KnobWithLabel.h b/src/UI/KnobWithLabel.h new file mode 100644 index 0000000..6be2316 --- /dev/null +++ b/src/UI/KnobWithLabel.h @@ -0,0 +1,20 @@ +#pragma once + +#include <juce_audio_processors/juce_audio_processors.h> +#include <juce_gui_basics/juce_gui_basics.h> + +class KnobWithLabel : public juce::Component +{ + public: + KnobWithLabel(const juce::String& text, juce::AudioParameterFloat* param); + ~KnobWithLabel(); + + void resized() override; + + private: + juce::Slider knob; + juce::Label label; + juce::AudioParameterFloat* param = nullptr; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(KnobWithLabel); +}; |
