Vital
Loading...
Searching...
No Matches
line_map_editor.cpp
Go to the documentation of this file.
1#include "line_map_editor.h"
2
3#include "skin.h"
4#include "shaders.h"
6#include "utils.h"
7
8LineMapEditor::LineMapEditor(LineGenerator* line_source, String name) : LineEditor(line_source) {
9 animate_ = true;
10 raw_input_ = nullptr;
11 last_phase_ = 0.0f;
12
13 setFill(true);
14 setFillCenter(-1.0f);
15 setLoop(false);
16 setName(name);
17 setBoostAmount(0.0f);
19}
20
22
24 SynthGuiInterface* parent = findParentComponentOfClass<SynthGuiInterface>();
25
26 if (parent && raw_input_ == nullptr)
27 raw_input_ = parent->getSynth()->getStatusOutput(getName().toStdString());
28
30}
31
32void LineMapEditor::render(OpenGlWrapper& open_gl, bool animate) {
34 renderGrid(open_gl, animate);
35
37
38 Colour envelope_graph_fill = findColour(Skin::kWidgetSecondary1, true);
39 Colour envelope_graph_fill_stereo = findColour(Skin::kWidgetSecondary2, true);
40
41 float fill_fade = findValue(Skin::kWidgetFillFade);
42 if (!active_) {
43 envelope_graph_fill = findColour(Skin::kWidgetSecondaryDisabled, true);
44 envelope_graph_fill_stereo = envelope_graph_fill;
45 }
46 Colour envelope_graph_fill_fade = envelope_graph_fill.withMultipliedAlpha(1.0f - fill_fade);
47 Colour envelope_graph_fill_stereo_fade = envelope_graph_fill_stereo.withMultipliedAlpha(1.0f - fill_fade);
48
49 Colour position_color = findColour(Skin::kWidgetPrimary1, true);
50 Colour position_color_stereo = findColour(Skin::kWidgetPrimary2, true);
51 Colour center = findColour(Skin::kWidgetCenterLine, true);
52 if (!active_) {
53 position_color = findColour(Skin::kWidgetPrimaryDisabled, true);
54 center = position_color;
55 position_color_stereo = position_color;
56 }
57
58 if (animate && animate_) {
59 // Animated mode: decay boosts and update positions.
61
62 vital::poly_float phase = raw_input_->value();
63 if (!raw_input_->isClearValue(phase)) {
64 vital::poly_float adjusted_phase = adjustBoostPhase(phase);
65 boostRange(last_phase_, adjusted_phase, kNumWrapPoints, kTailDecay);
66 last_phase_ = adjusted_phase;
67 }
68
69 setFill(true);
72
73 // Draw the stereo line variant.
74 setIndex(1);
75 setColor(position_color_stereo);
76 setFillColors(envelope_graph_fill_stereo_fade, envelope_graph_fill_stereo);
77 drawLines(open_gl, false);
78
79 // Draw the main line variant.
80 setIndex(0);
81 setColor(position_color);
82 setFillColors(envelope_graph_fill_fade, envelope_graph_fill);
83 drawLines(open_gl, true);
84
85 setFill(false);
86 setBoostAmount(0.0f);
88 setColor(center);
89 LineEditor::render(open_gl, false);
90
91 setViewPort(open_gl);
92 // Draw position indicators for both stereo voices if applicable.
93 drawPosition(open_gl, position_color_stereo, phase[1]);
94 drawPosition(open_gl, position_color, phase[0]);
95 }
96 else {
97 // Non-animated mode: draw the lines statically.
98 setBoostAmount(0.0f);
100 decayBoosts(0.0f);
101
102 setFill(true);
103 setColor(position_color_stereo);
104 setFillColors(envelope_graph_fill_stereo_fade, envelope_graph_fill_stereo);
105 drawLines(open_gl, false);
106
107 setColor(position_color);
108 setFillColors(envelope_graph_fill_fade, envelope_graph_fill);
109 drawLines(open_gl, true);
110
111 setFill(false);
112 setColor(center);
113 drawLines(open_gl, true);
114 }
115
116 renderPoints(open_gl, animate);
117 renderCorners(open_gl, animate);
118}
A GUI component for editing and visualizing a user-defined line shape (curve or envelope).
Definition line_editor.h:27
vital::poly_float adjustBoostPhase(vital::poly_float phase)
Adjusts a given phase value for boost calculations.
Definition line_editor.cpp:1061
bool active_
Definition line_editor.h:481
void renderGrid(OpenGlWrapper &open_gl, bool animate)
Renders the grid lines that show snapping lines or painting sections.
Definition line_editor.cpp:763
void render(OpenGlWrapper &open_gl, bool animate) override
Renders the line using OpenGL.
Definition line_editor.cpp:788
void setLoop(bool loop)
Enables or disables looping of the line at the edges.
Definition line_editor.h:300
static constexpr int kNumWrapPoints
Number of wrap points for looping lines.
Definition line_editor.h:43
void setGlPositions()
Updates OpenGL buffers with the latest positions if needed.
Definition line_editor.cpp:963
void drawPosition(OpenGlWrapper &open_gl, Colour color, float fraction_x)
Draws a position marker at a specific fraction of the X-axis.
Definition line_editor.cpp:838
void renderPoints(OpenGlWrapper &open_gl, bool animate)
Renders the points and power handles on the curve.
Definition line_editor.cpp:768
A class for generating and storing a line shape, defined by a series of points and associated powers.
Definition line_generator.h:20
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the line map with optional animation.
Definition line_map_editor.cpp:32
static constexpr float kTailDecay
Decay factor for reducing line boost effects over time (for animation smoothing).
Definition line_map_editor.h:23
virtual ~LineMapEditor()
Destructor.
Definition line_map_editor.cpp:21
LineMapEditor(LineGenerator *line_source, String name)
Constructs the LineMapEditor.
Definition line_map_editor.cpp:8
void parentHierarchyChanged() override
Called when the component’s parent hierarchy changes.
Definition line_map_editor.cpp:23
static bool setViewPort(Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
Sets the OpenGL viewport to match a specified rectangle within a component.
Definition open_gl_component.cpp:42
void renderCorners(OpenGlWrapper &open_gl, bool animate, Colour color, float rounding)
Renders the corner shapes using the given color and rounding amount.
Definition open_gl_component.cpp:153
float findValue(Skin::ValueId value_id)
Finds a float value from the skin associated with this component's parent.
Definition open_gl_component.cpp:173
virtual void parentHierarchyChanged() override
Called when the component's parent hierarchy changes.
Definition open_gl_component.cpp:128
force_inline void setFillCenter(float fill_center)
Sets the vertical center for the fill area.
Definition open_gl_line_renderer.h:138
force_inline void setFill(bool fill)
Enables or disables filling below the line.
Definition open_gl_line_renderer.h:124
void decayBoosts(vital::poly_float mult)
Decays all boosts by a multiplicative factor, allowing animated damping.
Definition open_gl_line_renderer.cpp:185
force_inline void setFillBoostAmount(float boost_amount)
Sets the boost amount that affects fill thickness.
Definition open_gl_line_renderer.h:147
force_inline void setBoostAmount(float boost_amount)
Sets the boost amount that affects line thickness.
Definition open_gl_line_renderer.h:144
force_inline void setFillColors(Colour fill_color_from, Colour fill_color_to)
Sets a gradient fill from one color to another.
Definition open_gl_line_renderer.h:132
force_inline void setLineWidth(float width)
Sets the line width in pixels.
Definition open_gl_line_renderer.h:66
force_inline void setColor(Colour color)
Sets the line color.
Definition open_gl_line_renderer.h:63
void boostRange(float *boosts, float start, float end, int buffer_vertices, float min)
Boosts a range for the given boost array.
Definition open_gl_line_renderer.cpp:128
void drawLines(OpenGlWrapper &open_gl, bool left)
Draws the line and optional fill using OpenGL.
Definition open_gl_line_renderer.cpp:386
force_inline void setIndex(int index)
Sets an index used for custom behavior (e.g., multiple line sets).
Definition open_gl_line_renderer.h:150
@ kWidgetLineWidth
Definition skin.h:105
@ kWidgetFillFade
Definition skin.h:108
@ kWidgetLineBoost
Definition skin.h:106
@ kWidgetFillBoost
Definition skin.h:109
@ kWidgetPrimaryDisabled
Definition skin.h:167
@ kWidgetPrimary2
Definition skin.h:166
@ kWidgetPrimary1
Definition skin.h:165
@ kWidgetSecondary1
Definition skin.h:168
@ kWidgetSecondaryDisabled
Definition skin.h:170
@ kWidgetCenterLine
Definition skin.h:164
@ kWidgetSecondary2
Definition skin.h:169
const vital::StatusOutput * getStatusOutput(const std::string &name)
Retrieves a status output by name.
Definition synth_base.cpp:262
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
force_inline bool isClearValue(poly_float value) const
Checks if a given poly_float is the special "clear" value.
Definition synth_module.h:81
force_inline poly_float value() const
Returns the current status value.
Definition synth_module.h:49
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...