13 Path getPathForEffect(String effect) {
14 if (effect ==
"compressor")
16 if (effect ==
"chorus")
18 if (effect ==
"delay")
20 if (effect ==
"distortion")
24 if (effect ==
"filter")
26 if (effect ==
"flanger")
28 if (effect ==
"phaser")
30 if (effect ==
"reverb")
38 setInterceptsMouseClicks(
false,
true);
41 tokens.addTokens(getName(),
"_",
"");
42 icon_ = getPathForEffect(tokens[0].toLowerCase());
44 background_ = std::make_unique<OpenGlImageComponent>(
"background");
46 background_->setComponent(
this);
47 background_->paintEntireComponent(
false);
49 enable_ = std::make_unique<SynthButton>(name +
"_on");
50 enable_->setPowerButton();
52 enable_->setButtonText(
"");
53 enable_->getGlComponent()->setAlwaysOnTop(
true);
57 static constexpr float kLeftPadding = 0.07f;
58 static constexpr float kIconSize = 0.6f;
59 static constexpr int kTextureRows = 2;
60 static constexpr int kTextureColumns = 3;
61 static constexpr float kTextureYStart = 0.13f;
62 static constexpr float kTexturePadding = 0.45f;
63 static constexpr float kTextureCircleRadiusPercent = 0.25f;
65 g.setColour(getParentComponent()->findColour(
Skin::kBody,
true));
67 g.fillRoundedRectangle(0, 0, getWidth(), getHeight(), round_amount);
69 if (enable_->getToggleState())
73 g.drawRoundedRectangle(0.5f, 0.5f, getWidth() - 1.0f, getHeight() - 1.0f, round_amount, 1.0f);
76 float text_x = getWidth() * kLeftPadding;
78 tokens.addTokens(getName(),
"_",
"");
79 String text = tokens[0];
80 text = text.substring(0, 1).toUpperCase() + text.substring(1);
81 g.drawText(text, text_x, 0, getWidth() - text_x, getHeight(), Justification::centredLeft,
true);
83 float icon_width = kIconSize * getHeight();
84 float icon_x = getWidth() / 2.0f + (getWidth() / 2.0f - icon_width) / 2.0f;
85 float icon_y = (getHeight() - icon_width) / 2.0f;
86 Rectangle<float> icon_bounds(icon_x, icon_y, icon_width, icon_width);
87 g.fillPath(icon_, icon_.getTransformToScaleToFit(icon_bounds,
true));
92 int width = getWidth();
93 int height = getHeight();
94 float spacing = width * (1.0f - 2.0f * kTexturePadding) / (kTextureColumns - 1.0f);
95 float radius = spacing * kTextureCircleRadiusPercent;
96 float x = width * kTexturePadding;
97 float y = height * kTextureYStart;
98 for (
int c = 0; c < kTextureColumns; ++c) {
99 for (
int r = 0; r < kTextureRows; ++r) {
100 g.fillEllipse(x + spacing * c - radius, y + spacing * r - radius, 2.0f * radius, 2.0f * radius);
101 g.fillEllipse(x + spacing * c - radius, height - y - spacing * r - radius, 2.0f * radius, 2.0f * radius);
109 enable_->setBounds(0, 0, width, width);
110 background_->redrawImage(
true);
114 for (
Listener* listener : listeners_)
115 listener->effectEnabledChanged(
this, clicked_button->getToggleState());
117 background_->redrawImage(
true);
122 if (hover_ !=
hover) {
124 background_->redrawImage(
true);
129 currently_dragged_ =
nullptr;
130 currently_hovered_ =
nullptr;
131 last_dragged_index_ = 0;
133 dragged_starting_y_ = 0;
135 effect_order_[i] = i;
138 effect_list_[i]->addListener(
this);
150 int from_y = getEffectY(i);
151 int to_y = getEffectY(i + 1);
152 effect->setBounds(0, from_y, getWidth(), to_y - from_y - padding);
157 static constexpr float kConnectionWidth = 0.1f;
159 int width = getWidth() * kConnectionWidth;
161 g.fillRect(center - width / 2, 0, width, getHeight());
174 DraggableEffect* hover = effect_list_[effect_order_[current_index]].get();
175 if (hover != currently_hovered_) {
176 if (currently_hovered_)
177 currently_hovered_->
hover(
false);
180 currently_hovered_ = hover;
187 currently_dragged_ = effect_list_[effect_order_[last_dragged_index_]].get();
188 dragged_starting_y_ = currently_dragged_->getY();
190 currently_dragged_->setAlwaysOnTop(
true);
194 if (currently_dragged_ ==
nullptr)
197 int delta_y = e.y - mouse_down_y_;
199 getHeight() - currently_dragged_->getHeight());
200 currently_dragged_->setTopLeftPosition(currently_dragged_->getX(), clamped_y);
203 if (next_index != last_dragged_index_) {
205 last_dragged_index_ = next_index;
210 if (currently_dragged_)
211 currently_dragged_->setAlwaysOnTop(
false);
213 currently_dragged_ =
nullptr;
218 if (currently_hovered_) {
219 currently_hovered_->
hover(
false);
220 currently_hovered_ =
nullptr;
225 for (
Listener* listener : listeners_)
226 listener->effectEnabledChanged(effect->
order(), enabled);
231 float order = controls[getName().toStdString()]->value();
237 for (
Listener* listener : listeners_)
238 listener->orderChanged(
this);
242 int delta_index = end_index - start_index;
243 if (delta_index == 0)
246 int moving = effect_order_[start_index];
248 int direction = delta_index / abs(delta_index);
249 for (
int i = start_index; i != end_index; i += direction) {
250 effect_order_[i] = effect_order_[i + direction];
254 effect_order_[end_index] = moving;
261 for (
Listener* listener : listeners_)
262 listener->orderChanged(
this);
268 int from_y = getEffectY(index);
269 int to_y = getEffectY(index + 1);
270 effect->setBounds(0, from_y, getWidth(), to_y - from_y - padding);
275 return effect_order_[i];
292int DragDropEffectOrder::getEffectY(
int index)
const {
Listener interface for responding to changes in the drag/drop order or effect states.
Definition drag_drop_effect_order.h:129
void resized() override
Positions the DraggableEffect components based on the current order.
Definition drag_drop_effect_order.cpp:145
void setAllValues(vital::control_map &controls) override
Sets all values from a control map (e.g., restoring order from saved state).
Definition drag_drop_effect_order.cpp:229
virtual ~DragDropEffectOrder()
Destructor.
Definition drag_drop_effect_order.cpp:143
int getEffectIndexFromY(float y) const
Converts a vertical mouse position (y) to an ordered effect index.
Definition drag_drop_effect_order.cpp:286
void effectEnabledChanged(DraggableEffect *effect, bool enabled) override
Responds to enable state changes from a DraggableEffect.
Definition drag_drop_effect_order.cpp:224
int getEffectIndex(int index) const
Gets the effect’s internal index from an ordered position.
Definition drag_drop_effect_order.cpp:273
void moveEffect(int start_index, int end_index)
Moves an effect from one position to another, adjusting the order of all affected effects.
Definition drag_drop_effect_order.cpp:241
Component * getEffect(int index) const
Gets the effect component at a given ordered position.
Definition drag_drop_effect_order.cpp:278
void mouseUp(const MouseEvent &e) override
Handles mouse up events to finalize the dragged effect’s position.
Definition drag_drop_effect_order.cpp:209
void mouseDrag(const MouseEvent &e) override
Handles mouse drag events to reorder the effects dynamically.
Definition drag_drop_effect_order.cpp:193
bool effectEnabled(int index) const
Checks if the effect at a given ordered position is enabled.
Definition drag_drop_effect_order.cpp:282
void mouseExit(const MouseEvent &e) override
Resets hover states when the mouse exits the component.
Definition drag_drop_effect_order.cpp:217
static constexpr int kEffectPadding
Padding between individual effects.
Definition drag_drop_effect_order.h:123
void renderOpenGlComponents(OpenGlWrapper &open_gl, bool animate) override
Renders all nested OpenGL components, including dragged effects.
Definition drag_drop_effect_order.cpp:164
void mouseDown(const MouseEvent &e) override
Handles mouse down events to initiate dragging.
Definition drag_drop_effect_order.cpp:184
DragDropEffectOrder(String name)
Constructs a DragDropEffectOrder component.
Definition drag_drop_effect_order.cpp:128
void mouseMove(const MouseEvent &e) override
Handles mouse movement to update hover states.
Definition drag_drop_effect_order.cpp:172
void setStationaryEffectPosition(int index)
Repositions the effect at the given index to its stationary position (no dragging).
Definition drag_drop_effect_order.cpp:265
void paintBackground(Graphics &g) override
Paints the background behind the effects.
Definition drag_drop_effect_order.cpp:156
Listener interface for responding to changes in the DraggableEffect’s enabled state.
Definition drag_drop_effect_order.h:24
A UI component representing an individual effect that can be enabled, disabled, and rearranged.
Definition drag_drop_effect_order.h:18
int order() const
Gets the current order (position) of this effect.
Definition drag_drop_effect_order.h:93
void hover(bool hover)
Updates the hover state visually.
Definition drag_drop_effect_order.cpp:121
void resized() override
Positions the subcomponents (like enable button) within the DraggableEffect.
Definition drag_drop_effect_order.cpp:107
void buttonClicked(Button *clicked_button) override
Handles button clicks, primarily the enable button.
Definition drag_drop_effect_order.cpp:113
DraggableEffect(const String &name, int order)
Constructs a DraggableEffect.
Definition drag_drop_effect_order.cpp:37
void paint(Graphics &g) override
Paints the DraggableEffect’s background and icon.
Definition drag_drop_effect_order.cpp:56
void renderOpenGlComponents(OpenGlWrapper &open_gl, bool animate) override
Renders all nested OpenGL components.
Definition drag_drop_effect_order.h:62
static Fonts * instance()
Gets the singleton instance of the Fonts class.
Definition fonts.h:52
static Path delay()
Creates a delay effect icon path from embedded SVG data.
Definition paths.h:93
static Path phaser()
Creates a phaser effect icon path.
Definition paths.h:141
static Path equalizer()
Creates an equalizer icon path.
Definition paths.h:109
static Path chorus()
Creates a chorus icon path from embedded SVG data.
Definition paths.h:77
static Path compressor()
Creates a compressor icon path from embedded SVG data.
Definition paths.h:85
static Path reverb()
Creates a reverb effect icon path.
Definition paths.h:149
static Path distortion()
Creates a distortion effect icon path.
Definition paths.h:101
static Path flanger()
Creates a flanger effect icon path.
Definition paths.h:125
static Path effectsFilter()
Creates an effects filter icon path.
Definition paths.h:117
@ kBodyRounding
Definition skin.h:71
@ kWidgetRoundedCorner
Definition skin.h:104
@ kPowerButtonOff
Definition skin.h:138
@ kPowerButtonOn
Definition skin.h:137
@ kLightenScreen
Definition skin.h:141
@ kBody
Definition skin.h:129
SectionOverride
Identifiers for different UI sections that can have color or value overrides.
Definition skin.h:30
@ kAllEffects
Definition skin.h:45
void valueChangedInternal(const std::string &name, vital::mono_float value)
Handles internal value changes, updating the parameter and optionally notifying the host.
Definition synth_base.cpp:54
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
virtual void buttonClicked(Button *clicked_button) override
Called when a button is clicked. Updates the synth parameter accordingly.
Definition synth_section.cpp:398
virtual void renderOpenGlComponents(OpenGlWrapper &open_gl, bool animate)
Renders all OpenGL components in this section and sub-sections.
Definition synth_section.cpp:357
virtual void animate(bool animate)
Triggers animation state change in sub-sections if needed.
Definition synth_section.cpp:822
void addSubSection(SynthSection *section, bool show=true)
Adds a subsection (another SynthSection) as a child.
Definition synth_section.cpp:457
float size_ratio_
Definition synth_section.h:821
void addButton(OpenGlToggleButton *button, bool show=true)
Definition synth_section.cpp:428
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
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
virtual void setAllValues(vital::control_map &controls)
Sets values for all known parameters from a control map.
Definition synth_section.cpp:827
float getTitleWidth()
Definition synth_section.cpp:629
const std::string kEffectOrder[]
Defines the processing order of various effects.
Definition synth_strings.h:225
@ kNumEffects
Definition synth_constants.h:187
force_inline int iclamp(int value, int min_val, int max_val)
Clamps an integer between [min_val, max_val].
Definition utils.h:250
void decodeFloatToOrder(int *order, mono_float float_code, int size)
Decodes a float-encoded permutation back into order.
Definition utils.cpp:55
mono_float encodeOrderToFloat(int *order, int size)
Encodes a permutation (stored in order) into a single float.
Definition utils.cpp:32
std::map< std::string, Value * > control_map
Maps parameter names to Value pointers representing synth control parameters.
Definition synth_types.h:214
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...