Vital
Loading...
Searching...
No Matches
macro_knob_section.cpp
Go to the documentation of this file.
2
3#include "fonts.h"
4#include "modulation_button.h"
5#include "synth_slider.h"
7
16 public:
23 MacroLabel(String name, String text) : OpenGlImageComponent(name), text_(std::move(text)), text_size_(1.0f) {
24 setInterceptsMouseClicks(false, false);
25 }
26
32 void setText(String text) { text_ = text; redrawImage(true); }
33
39 void setTextSize(float size) { text_size_ = size; redrawImage(true); }
40
46 String getText() { return text_; }
47
53 void paint(Graphics& g) override {
54 g.setColour(findColour(Skin::kBodyText, true));
55 g.setFont(Fonts::instance()->proportional_regular().withPointHeight(text_size_));
56 g.drawText(text_, 0, 0, getWidth(), getHeight(), Justification::centred, false);
57 }
58
59 private:
60 String text_;
61 float text_size_;
62};
63
76class SingleMacroSection : public SynthSection, public TextEditor::Listener {
77 public:
84 SingleMacroSection(String name, int index) : SynthSection(name), index_(index) {
85 std::string number = std::to_string(index_ + 1);
86 std::string control_name = "macro_control_" + number;
87
88 macro_knob_ = std::make_unique<SynthSlider>(control_name);
89 addSlider(macro_knob_.get());
90 macro_knob_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
91 macro_knob_->setPopupPlacement(BubbleComponent::right);
92
93 macro_source_ = std::make_unique<ModulationButton>(control_name);
94 addModulationButton(macro_source_.get());
95 macro_source_->overrideText("");
96
97 macro_label_ = std::make_unique<MacroLabel>("Macro Label " + number, "MACRO " + number);
98 addOpenGlComponent(macro_label_.get());
99
100 edit_label_ = std::make_unique<OpenGlShapeButton>("Edit " + number);
101 addAndMakeVisible(edit_label_.get());
102 addOpenGlComponent(edit_label_->getGlComponent());
103 edit_label_->addListener(this);
104 edit_label_->setShape(Paths::pencil());
105 edit_label_->setTriggeredOnMouseDown(true);
106
108
109#if !defined(NO_TEXT_ENTRY)
110 macro_label_editor_ = std::make_unique<OpenGlTextEditor>("Search");
111 macro_label_editor_->addListener(this);
112 macro_label_editor_->setSelectAllWhenFocused(true);
113 macro_label_editor_->setMultiLine(false, false);
114 macro_label_editor_->setJustification(Justification::centred);
115 addChildComponent(macro_label_editor_.get());
116 addOpenGlComponent(macro_label_editor_->getImageComponent());
117#endif
118 }
119
125 void resized() override {
126 int knob_height = getHeight() / 2;
127 int button_height = getHeight() - knob_height;
128 int width = getWidth();
129
130 macro_knob_->setBounds(0, 0, width, knob_height);
131 placeRotaryOption(edit_label_.get(), macro_knob_.get());
132
133 macro_source_->setBounds(0, knob_height, width, button_height);
134 macro_source_->setFontSize(0);
135
136 macro_label_->setBounds(getLabelBackgroundBounds(macro_knob_.get()));
137 macro_label_->setTextSize(findValue(Skin::kLabelHeight));
138 }
139
145 void paintBackground(Graphics& g) override {
146 paintBody(g);
148 setLabelFont(g);
149
150 drawLabelBackgroundForComponent(g, macro_knob_.get());
153 paintBorder(g);
154 }
155
161 void paintBackgroundShadow(Graphics& g) override { paintTabShadow(g); }
162
168 void paintMacroSourceBackground(Graphics& g) {
169 g.saveState();
170 Rectangle<int> bounds = getLocalArea(macro_source_.get(), macro_source_->getLocalBounds());
171 g.reduceClipRegion(bounds);
172 g.setOrigin(bounds.getTopLeft());
173 macro_source_->paintBackground(g);
174 g.restoreState();
175 }
176
182 void buttonClicked(Button* clicked_button) override {
183 if (macro_label_editor_) {
184 if (macro_label_editor_->isVisible()) {
186 return;
187 }
188
189 Rectangle<int> bounds = macro_label_->getBounds();
190 float text_height = findValue(Skin::kLabelHeight);
191 macro_label_editor_->setFont(Fonts::instance()->proportional_regular().withPointHeight(text_height));
192 macro_label_editor_->setText(macro_label_->getText());
193 macro_label_editor_->setBounds(bounds.translated(0, -1));
194 macro_label_editor_->setVisible(true);
195 macro_label_editor_->grabKeyboardFocus();
196 }
197 }
198
205 macro_label_editor_->setVisible(false);
206 String text = macro_label_editor_->getText().trim().toUpperCase();
207 if (text.isEmpty())
208 return;
209
210 macro_label_->setText(text);
211
212 SynthGuiInterface* synth_gui_interface = findParentComponentOfClass<SynthGuiInterface>();
213 if (synth_gui_interface)
214 synth_gui_interface->getSynth()->setMacroName(index_, text);
215 }
216
222 void textEditorReturnKeyPressed(TextEditor& text_editor) override {
224 }
225
231 void textEditorFocusLost(TextEditor& text_editor) override {
233 }
234
242 void textEditorEscapeKeyPressed(TextEditor& editor) override {
243 macro_label_editor_->setVisible(false);
244 }
245
249 void reset() override {
250 SynthGuiInterface* synth_gui_interface = findParentComponentOfClass<SynthGuiInterface>();
251 if (synth_gui_interface == nullptr)
252 return;
253
254 macro_label_->setText(synth_gui_interface->getSynth()->getMacroName(index_));
255 }
256
257 private:
258 int index_;
259 std::unique_ptr<SynthSlider> macro_knob_;
260 std::unique_ptr<ModulationButton> macro_source_;
261 std::unique_ptr<MacroLabel> macro_label_;
262 std::unique_ptr<OpenGlTextEditor> macro_label_editor_;
263 std::unique_ptr<OpenGlShapeButton> edit_label_;
264};
265
267 setWantsKeyboardFocus(true);
268 for (int i = 0; i < vital::kNumMacros; ++i) {
269 macros_[i] = std::make_unique<SingleMacroSection>(name + String(i), i);
270 addSubSection(macros_[i].get());
271 }
272
274}
275
277
281
283 int padding = getPadding();
284 int knob_section_height = getKnobSectionHeight();
285 int widget_margin = getWidgetMargin();
286 int width = getWidth();
287 int y = 0;
288 for (int i = 0; i < vital::kNumMacros; ++i) {
289 float next_y = (i + 1) * (2 * knob_section_height - widget_margin + padding);
290 macros_[i]->setBounds(0, y, width, next_y - y - padding);
291 y = next_y;
292 }
293
294 int last_y = macros_[vital::kNumMacros - 2]->getBottom() + padding;
295 macros_[vital::kNumMacros - 1]->setBounds(0, last_y, width, getHeight() - last_y);
296
297 reset();
299}
static Fonts * instance()
Gets the singleton instance of the Fonts class.
Definition fonts.h:52
MacroKnobSection(String name)
Constructs a new MacroKnobSection.
Definition macro_knob_section.cpp:266
void resized() override
Called when the component is resized.
Definition macro_knob_section.cpp:282
void paintBackground(Graphics &g) override
Paints the background of the macro knob section.
Definition macro_knob_section.cpp:278
~MacroKnobSection()
Destructor.
Definition macro_knob_section.cpp:276
A custom label for displaying macro names.
Definition macro_knob_section.cpp:15
void setTextSize(float size)
Sets the text size in point height.
Definition macro_knob_section.cpp:39
void paint(Graphics &g) override
Paints the label text.
Definition macro_knob_section.cpp:53
void setText(String text)
Sets the label text.
Definition macro_knob_section.cpp:32
String getText()
Gets the current text.
Definition macro_knob_section.cpp:46
MacroLabel(String name, String text)
Constructs a MacroLabel.
Definition macro_knob_section.cpp:23
A component that uses OpenGL to render a cached image of a JUCE component or custom drawing.
Definition open_gl_image_component.h:18
virtual void redrawImage(bool force)
Redraws the image if necessary, creating or updating the internal Image.
Definition open_gl_image_component.cpp:16
static Path pencil()
Definition paths.h:725
Represents a single macro knob and associated controls (label, edit button, source button).
Definition macro_knob_section.cpp:76
void reset() override
Resets the macro label to the current synthesizer's macro name.
Definition macro_knob_section.cpp:249
void textEditorReturnKeyPressed(TextEditor &text_editor) override
Called when the return key is pressed in the text editor.
Definition macro_knob_section.cpp:222
SingleMacroSection(String name, int index)
Constructs a SingleMacroSection.
Definition macro_knob_section.cpp:84
void paintMacroSourceBackground(Graphics &g)
Paints the background for the macro source area.
Definition macro_knob_section.cpp:168
void saveMacroLabel()
Saves the macro label name after editing.
Definition macro_knob_section.cpp:204
void buttonClicked(Button *clicked_button) override
Handles button click events, including toggling the label editor.
Definition macro_knob_section.cpp:182
void textEditorFocusLost(TextEditor &text_editor) override
Called when the text editor loses focus.
Definition macro_knob_section.cpp:231
void textEditorEscapeKeyPressed(TextEditor &editor) override
Called when the escape key is pressed in the text editor.
Definition macro_knob_section.cpp:242
void paintBackgroundShadow(Graphics &g) override
Paints a background shadow if needed.
Definition macro_knob_section.cpp:161
void resized() override
Called when the component is resized.
Definition macro_knob_section.cpp:125
void paintBackground(Graphics &g) override
Paints the background for the macro section.
Definition macro_knob_section.cpp:145
@ kLabelHeight
Definition skin.h:72
@ kBodyText
Definition skin.h:133
@ kMacro
Definition skin.h:43
void setMacroName(int index, const String &macro_name)
Sets the name of a macro control by index.
Definition synth_base.cpp:697
String getMacroName(int index)
Gets the name of a macro control by index.
Definition synth_base.cpp:717
An interface class linking the Vital synthesizer backend (SynthBase) with a GUI.
Definition synth_gui_interface.h:56
SynthBase * getSynth()
Returns the SynthBase instance this interface is managing.
Definition synth_gui_interface.h:85
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
float getPadding()
Definition synth_section.cpp:660
void addSlider(SynthSlider *slider, bool show=true, bool listen=true)
Definition synth_section.cpp:445
void addSubSection(SynthSection *section, bool show=true)
Adds a subsection (another SynthSection) as a child.
Definition synth_section.cpp:457
virtual void resized() override
Called when the component is resized. Arranges layout of child components.
Definition synth_section.cpp:35
virtual void paintBody(Graphics &g, Rectangle< int > bounds)
Paints the body background within given bounds.
Definition synth_section.cpp:165
void paintChildrenBackgrounds(Graphics &g)
Paints the backgrounds for all child sections.
Definition synth_section.cpp:274
void paintKnobShadows(Graphics &g)
Paints knob shadows for all sliders.
Definition synth_section.cpp:253
void drawLabelBackgroundForComponent(Graphics &g, Component *component)
Draws label background for a specific component.
Definition synth_section.cpp:764
void addModulationButton(ModulationButton *button, bool show=true)
Adds a modulation button to this section.
Definition synth_section.cpp:438
void setLabelFont(Graphics &g)
Sets the Graphics context font and color for labels.
Definition synth_section.cpp:740
Rectangle< int > getLabelBackgroundBounds(Rectangle< int > bounds, bool text_component=false)
Gets the background bounds for a label.
Definition synth_section.cpp:782
float findValue(Skin::ValueId value_id) const
Finds a value in the skin overrides or from the parent if not found locally.
Definition synth_section.cpp:18
virtual void paintBorder(Graphics &g, Rectangle< int > bounds)
Paints the border around given bounds.
Definition synth_section.cpp:170
float getKnobSectionHeight()
Definition synth_section.cpp:633
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
void placeRotaryOption(Component *option, SynthSlider *rotary)
Definition synth_section.cpp:593
virtual void reset()
Resets the section and all sub-sections.
Definition synth_section.cpp:30
void setSkinOverride(Skin::SectionOverride skin_override)
Definition synth_section.h:303
virtual void paintTabShadow(Graphics &g)
Paints a tab-like shadow effect around the component.
Definition synth_section.cpp:188
float getWidgetMargin()
Definition synth_section.cpp:676
constexpr int kNumMacros
Number of macro controls available.
Definition synth_constants.h:28
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...