12 mono_total_(mono_total), poly_total_(poly_total), destination_(slider),
13 quads_(quads), index_(index), current_value_(0.0), mod_percent_(0.0) {
15 rotary_ = destination_->isRotary() && !destination_->
isTextOrCurve();
18 if (destination_->getSliderStyle() == Slider::LinearBarVertical || destination_->
isTextOrCurve())
21 setInterceptsMouseClicks(
false,
false);
31 std::vector<vital::ModulationConnection*> connections;
49Rectangle<float> ModulationMeter::getMeterBounds() {
50 float width = getWidth();
51 float height = getHeight();
54 if (!destination_->isRotary() && !destination_->
isTextOrCurve()) {
55 SynthSection* parent = findParentComponentOfClass<SynthSection>();
58 int total_width = destination_->isHorizontal() ? destination_->getHeight() : destination_->getWidth();
59 int extra = total_width % 2;
62 int inner_area = (total_width - slider_width) / 2;
63 int outer_area = inner_area - widget_margin;
65 int border = std::max<int>(1, (widget_margin - meter_width) * 0.5f);
67 if (destination_->isHorizontal()) {
69 return Rectangle<float>(0.0f, outer_area + border, width, inner_area - outer_area - 2.0f * border);
73 return Rectangle<float>(outer_area + border, 0.0f, inner_area - outer_area - 2.0f * border, height);
82 float center_x = getWidth() * 0.5f;
83 float center_y = getHeight() * 0.5f;
84 return Rectangle<float>(center_x - meter_width * 0.5f, center_y - meter_width * 0.5f + offset,
85 meter_width, meter_width);
89 return getLocalBounds().toFloat();
92void ModulationMeter::setVertices() {
93 Rectangle<int> parent_bounds = getParentComponent()->getBounds();
94 Rectangle<int> bounds = getBounds();
95 Rectangle<float> meter_bounds = getMeterBounds();
96 float left = bounds.getX() + meter_bounds.getX();
97 float right = bounds.getX() + meter_bounds.getRight();
98 float top = parent_bounds.getHeight() - (bounds.getY() + meter_bounds.getY());
99 float bottom = parent_bounds.getHeight() - (bounds.getY() + meter_bounds.getBottom());
101 left_ = 2.0f * left / parent_bounds.getWidth() - 1.0f;
102 right_ = 2.0f * right / parent_bounds.getWidth() - 1.0f;
103 top_ = 2.0f * top / parent_bounds.getHeight() - 1.0f;
104 bottom_ = 2.0f * bottom / parent_bounds.getHeight() - 1.0f;
105 quads_->
setQuad(index_, left_, bottom_, right_ - left_, top_ - bottom_);
108void ModulationMeter::collapseVertices() {
109 left_ = right_ = top_ = bottom_= 0.0f;
111 quads_->
setQuad(index_, left_, bottom_, right_ - left_, top_ - bottom_);
116 Rectangle<float> meter_bounds = getMeterBounds();
118 meter_bounds.expand(2.0f, 2.0f);
120 float width = getWidth();
121 float height = getHeight();
122 float left = 2.0f * meter_bounds.getX() / width - 1.0f;
123 float bottom = 1.0f - 2.0f * meter_bounds.getBottom() / height;
125 bool vertical_bar = destination_->getSliderStyle() == Slider::LinearBarVertical || destination_->
isTextOrCurve();
132 quad.
setQuad(0, left, bottom, 2.0f * meter_bounds.getWidth() / width, 2.0f * meter_bounds.getHeight() / height);
133 else if (vertical_bar) {
134 float thickness = 2.0f / width;
135 quad.
setQuad(0, left, bottom, thickness, 2.0f * meter_bounds.getHeight() / height);
138 float thickness = 2.0f / height;
139 quad.
setQuad(0, left, bottom + 2.0f * meter_bounds.getHeight() / height - thickness,
140 2.0f * meter_bounds.getWidth() / width, thickness);
147 if (poly_total_ && use_poly)
151 float range = destination_->getMaximum() - destination_->getMinimum();
152 vital::poly_float value = (current_value_ - destination_->getMinimum()) * (1.0f / range);
154 float knob_percent = (destination_->getValue() - destination_->getMinimum()) / range;
159 quads_->
setQuad(index_, left_, bottom_, right_ - left_, top_ - bottom_);
181 float range = destination_->getMaximum() - destination_->getMinimum();
182 float knob_percent = (destination_->getValue() - destination_->getMinimum()) / range;
184 float min_percent = std::min(knob_percent + amount, knob_percent);
185 float max_percent = std::max(knob_percent + amount, knob_percent);
187 min_percent = std::min(knob_percent + amount * 0.5f, knob_percent - amount * 0.5f);
188 max_percent = std::max(knob_percent + amount * 0.5f, knob_percent - amount * 0.5f);
201 min_percent = std::max(-angle, min_percent);
202 max_percent = std::min(angle, max_percent);
void resized() override
Called when the component is resized.
Definition modulation_meter.cpp:27
void setModulationAmountQuad(OpenGlQuad &quad, float amount, bool bipolar)
Sets the given quad to represent a modulation amount line or arc.
Definition modulation_meter.cpp:180
void updateDrawing(bool use_poly)
Updates the drawing of the modulation meter, recalculating mod percent and visuals.
Definition modulation_meter.cpp:144
void setActive(bool active)
Sets whether the modulation meter is active (visible and updating).
Definition modulation_meter.cpp:42
ModulationMeter(const vital::Output *mono_total, const vital::Output *poly_total, const SynthSlider *slider, OpenGlMultiQuad *quads, int index)
Constructs a ModulationMeter.
Definition modulation_meter.cpp:10
void setModulated(bool modulated)
Sets the modulated state of the meter.
Definition modulation_meter.h:88
void setAmountQuadVertices(OpenGlQuad &quad)
Sets up the quad coordinates for the modulation amount indicator.
Definition modulation_meter.cpp:115
virtual ~ModulationMeter()
Destructor.
Definition modulation_meter.cpp:25
A component for rendering multiple quads using OpenGL, with customizable colors, rounding,...
Definition open_gl_multi_quad.h:16
void setShaderValue(int i, float shader_value, int value_index=0)
Sets a shader value for all four vertices of a quad.
Definition open_gl_multi_quad.h:254
void setQuad(int i, float x, float y, float w, float h)
Sets the position and size of a quad in normalized device space.
Definition open_gl_multi_quad.h:313
void setCoordinates(int i, float x, float y, float w, float h)
Sets coordinates for a quad in normalized device space.
Definition open_gl_multi_quad.h:234
void setRotatedCoordinates(int i, float x, float y, float w, float h)
Sets rotated coordinates for a quad, adjusting its texture mapping.
Definition open_gl_multi_quad.h:217
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
bool isTextOrCurve() const
Definition synth_slider.h:105
static constexpr float kRotaryAngle
The default rotary arc angle used for rotary sliders.
Definition synth_slider.h:55
@ kKnobModMeterArcThickness
Definition skin.h:96
@ kKnobOffset
Definition skin.h:97
@ kKnobModMeterArcSize
Definition skin.h:95
std::vector< vital::ModulationConnection * > getSourceConnections(const std::string &source)
Returns all modulation connections from a particular source.
Definition synth_base.cpp:236
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 getWidgetMargin()
Definition synth_section.cpp:676
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
float findValue(Skin::ValueId value_id) const override
Definition synth_slider.h:681
static constexpr float kLinearWidthPercent
Definition synth_slider.h:341
static constexpr float kLinearModulationPercent
Definition synth_slider.h:343
float getKnobSizeScale() const override
Definition synth_slider.h:641
static TextLookAndFeel * instance()
Singleton instance access.
Definition text_look_and_feel.h:106
force_inline poly_float clamp(poly_float value, mono_float min, mono_float max)
Clamps each lane of a vector to [min, max].
Definition poly_utils.h:306
force_inline poly_float min(poly_float left, poly_float right)
Returns the minimum of two poly_floats lane-by-lane.
Definition poly_utils.h:334
force_inline poly_float max(poly_float left, poly_float right)
Returns the maximum of two poly_floats lane-by-lane.
Definition poly_utils.h:327
force_inline poly_float interpolate(poly_float from, poly_float to, mono_float t)
Performs a linear interpolation between two poly_floats using a scalar t in [0..1].
Definition poly_utils.h:182
constexpr mono_float kPi
Pi constant.
Definition common.h:36
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
poly_float trigger_value
Trigger values for voices.
Definition processor.h:116
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...