Vital
Loading...
Searching...
No Matches
envelope_editor.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "skin.h"
5#include "open_gl_image.h"
7#include "synth_module.h"
8#include "synth_slider.h"
9
20public:
22 static constexpr float kMarkerWidth = 9.0f;
24 static constexpr float kRingThickness = 0.45f;
26 static constexpr float kPowerMarkerWidth = 7.0f;
28 static constexpr float kMarkerHoverRadius = 12.0f;
30 static constexpr float kMarkerGrabRadius = 20.0f;
32 static constexpr float kTailDecay = 0.965f;
34 static constexpr float kPaddingX = 0.018f;
36 static constexpr float kPaddingY = 0.06f;
38 static constexpr float kMinPointDistanceForPower = 3.0f;
40 static constexpr float kPowerMouseMultiplier = 0.06f;
42 static constexpr float kTimeDisplaySize = 0.05f;
43
45 static constexpr int kRulerDivisionSize = 4;
47 static constexpr int kMaxGridLines = 36;
49 static constexpr int kMaxTimesShown = 24;
51 static constexpr int kNumPointsPerSection = 98;
53 static constexpr int kNumSections = 4;
55 static constexpr int kTotalPoints = kNumSections * kNumPointsPerSection + 1;
56
63 EnvelopeEditor(const String& prefix,
64 const vital::output_map& mono_modulations, const vital::output_map& poly_modulations);
65
70
75 void paintBackground(Graphics& g) override;
76
80 void resized() override {
82 drag_circle_.setBounds(getLocalBounds());
83 hover_circle_.setBounds(getLocalBounds());
84 grid_lines_.setBounds(getLocalBounds());
85 sub_grid_lines_.setBounds(getLocalBounds());
86 position_circle_.setBounds(getLocalBounds());
87 point_circles_.setBounds(getLocalBounds());
88 power_circles_.setBounds(getLocalBounds());
89
90 float font_height = kTimeDisplaySize * getHeight();
91 for (int i = 0; i < kMaxTimesShown; ++i)
92 times_[i]->setTextSize(font_height);
93
94 setTimePositions();
95 reset_positions_ = true;
96 }
97
102 void resetEnvelopeLine(int index);
103
108 void guiChanged(SynthSlider* slider) override;
109
111 void setDelaySlider(SynthSlider* delay_slider);
112 void setAttackSlider(SynthSlider* attack_slider);
113 void setAttackPowerSlider(SynthSlider* attack_slider);
114 void setHoldSlider(SynthSlider* hold_slider);
115 void setDecaySlider(SynthSlider* decay_slider);
116 void setDecayPowerSlider(SynthSlider* decay_slider);
117 void setSustainSlider(SynthSlider* sustain_slider);
118 void setReleaseSlider(SynthSlider* release_slider);
119 void setReleasePowerSlider(SynthSlider* release_slider);
120
125 void setSizeRatio(float ratio) { size_ratio_ = ratio; }
126
130 void parentHierarchyChanged() override;
131
136 void pickHoverPosition(Point<float> position);
137
141 void mouseMove(const MouseEvent& e) override;
142 void mouseExit(const MouseEvent& e) override;
143 void mouseDown(const MouseEvent& e) override;
144 void mouseDrag(const MouseEvent& e) override;
145 void mouseDoubleClick(const MouseEvent& e) override;
146 void mouseUp(const MouseEvent& e) override;
147
153 void mouseWheelMove(const MouseEvent& e, const MouseWheelDetails& wheel) override;
154
159 void magnifyZoom(Point<float> delta);
160
164 void magnifyReset();
165
170 void init(OpenGlWrapper& open_gl) override;
171
177 void render(OpenGlWrapper& open_gl, bool animate) override;
178
183 void destroy(OpenGlWrapper& open_gl) override;
184
188 void resetPositions() { reset_positions_ = true; }
189
190 private:
194 void setEditingCircleBounds();
195
199 void setGridPositions();
200
204 void setTimePositions();
205
209 void setPointPositions();
210
214 void setGlPositions();
215
219 void setColors();
220
225 void zoom(float amount);
226
234 static std::pair<vital::Output*, vital::Output*> getOutputs(const vital::output_map& mono_modulations,
235 const vital::output_map& poly_modulations,
236 const String& name) {
237 return {
238 mono_modulations.at(name.toStdString()),
239 poly_modulations.at(name.toStdString())
240 };
241 }
242
249 vital::poly_float getOutputsTotal(std::pair<vital::Output*, vital::Output*> outputs,
250 vital::poly_float default_value);
251
257 void drawPosition(OpenGlWrapper& open_gl, int index);
258
264 std::pair<float, float> getPosition(int index);
265
266 // Utility functions for coordinate padding and unpadding.
267 float padX(float x);
268 float padY(float y);
269 float unpadX(float x);
270 float unpadY(float y);
271 float padOpenGlX(float x);
272 float padOpenGlY(float y);
273
274 // Slider-specific getter methods for times and positions.
275 float getSliderDelayX();
276 float getSliderAttackX();
277 float getSliderHoldX();
278 float getSliderDecayX();
279 float getSliderSustainY();
280 float getSliderReleaseX();
281 float getDelayTime(int index);
282 float getAttackTime(int index);
283 float getHoldTime(int index);
284 float getDecayTime(int index);
285 float getReleaseTime(int index);
286 float getDelayX(int index);
287 float getAttackX(int index);
288 float getHoldX(int index);
289 float getDecayX(int index);
290 float getSustainY(int index);
291 float getReleaseX(int index);
292
293 float getBackupPhase(float phase, int index);
294 vital::poly_float getBackupPhase(vital::poly_float phase);
295 float getEnvelopeValue(float t, float power, float start, float end);
296 float getSliderAttackValue(float t);
297 float getSliderDecayValue(float t);
298 float getSliderReleaseValue(float t);
299 float getAttackValue(float t, int index);
300 float getDecayValue(float t, int index);
301 float getReleaseValue(float t, int index);
302
303 // Setters for envelope parameters based on mouse interactions.
304 void setDelayX(float x);
305 void setAttackX(float x);
306 void setHoldX(float x);
307 void setDecayX(float x);
308 void setSustainY(float y);
309 void setReleaseX(float x);
310
311 void setPower(SynthSlider* slider, float power);
312 void setAttackPower(float power);
313 void setDecayPower(float power);
314 void setReleasePower(float power);
315
316 SynthGuiInterface* parent_;
317 bool delay_hover_;
318 bool attack_hover_;
319 bool hold_hover_;
320 bool sustain_hover_;
321 bool release_hover_;
322 bool attack_power_hover_;
323 bool decay_power_hover_;
324 bool release_power_hover_;
325 bool mouse_down_;
326 Point<float> last_edit_position_;
327
328 bool animate_;
329 float size_ratio_;
330 float window_time_;
331
332 vital::poly_float current_position_alpha_;
333 vital::poly_float last_phase_;
334
335 Colour line_left_color_;
336 Colour line_right_color_;
337 Colour line_center_color_;
338 Colour fill_left_color_;
339 Colour fill_right_color_;
340 Colour background_color_;
341 Colour time_color_;
342
343 bool reset_positions_;
344 OpenGlQuad drag_circle_;
345 OpenGlQuad hover_circle_;
346 OpenGlMultiQuad grid_lines_;
347 OpenGlMultiQuad sub_grid_lines_;
348 OpenGlQuad position_circle_;
349 OpenGlMultiQuad point_circles_;
350 OpenGlMultiQuad power_circles_;
351 std::unique_ptr<PlainTextComponent> times_[kMaxTimesShown];
352
353 const vital::StatusOutput* envelope_phase_;
354
355 SynthSlider* delay_slider_;
356 SynthSlider* attack_slider_;
357 SynthSlider* hold_slider_;
358 SynthSlider* attack_power_slider_;
359 SynthSlider* decay_slider_;
360 SynthSlider* decay_power_slider_;
361 SynthSlider* sustain_slider_;
362 SynthSlider* release_slider_;
363 SynthSlider* release_power_slider_;
364
365 std::pair<vital::Output*, vital::Output*> delay_outputs_;
366 std::pair<vital::Output*, vital::Output*> attack_outputs_;
367 std::pair<vital::Output*, vital::Output*> hold_outputs_;
368 std::pair<vital::Output*, vital::Output*> decay_outputs_;
369 std::pair<vital::Output*, vital::Output*> sustain_outputs_;
370 std::pair<vital::Output*, vital::Output*> release_outputs_;
371
372 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EnvelopeEditor)
373};
A graphical editor for envelope shapes with interactive points and power curves.
Definition envelope_editor.h:19
void setDecayPowerSlider(SynthSlider *decay_slider)
Definition envelope_editor.cpp:590
static constexpr int kNumSections
Number of envelope sections (e.g., Delay->Attack->Hold->Decay->Release mapped to 4 sections plus 1 ex...
Definition envelope_editor.h:53
void parentHierarchyChanged() override
Called when the component’s parent hierarchy changes.
Definition envelope_editor.cpp:105
void mouseDrag(const MouseEvent &e) override
Definition envelope_editor.cpp:204
void mouseWheelMove(const MouseEvent &e, const MouseWheelDetails &wheel) override
Handles mouse wheel events for zooming.
Definition envelope_editor.cpp:244
static constexpr int kTotalPoints
Total number of points for the entire envelope line.
Definition envelope_editor.h:55
void setAttackPowerSlider(SynthSlider *attack_slider)
Definition envelope_editor.cpp:580
void resetEnvelopeLine(int index)
Resets the envelope line for a given voice index.
Definition envelope_editor.cpp:620
static constexpr float kRingThickness
Thickness fraction for the marker rings.
Definition envelope_editor.h:24
void render(OpenGlWrapper &open_gl, bool animate) override
Renders the envelope using OpenGL.
Definition envelope_editor.cpp:735
static constexpr int kNumPointsPerSection
Number of points per envelope section.
Definition envelope_editor.h:51
static constexpr float kTailDecay
Decay factor for tail end animations.
Definition envelope_editor.h:32
~EnvelopeEditor()
Destructor.
Definition envelope_editor.cpp:96
void setHoldSlider(SynthSlider *hold_slider)
Definition envelope_editor.cpp:575
void setSustainSlider(SynthSlider *sustain_slider)
Definition envelope_editor.cpp:595
void init(OpenGlWrapper &open_gl) override
Initializes OpenGL resources.
Definition envelope_editor.cpp:721
void mouseMove(const MouseEvent &e) override
Mouse event callbacks for interactions.
Definition envelope_editor.cpp:181
static constexpr float kTimeDisplaySize
Display size ratio for time text.
Definition envelope_editor.h:42
void mouseDown(const MouseEvent &e) override
Definition envelope_editor.cpp:198
void setDecaySlider(SynthSlider *decay_slider)
Definition envelope_editor.cpp:585
static constexpr float kPaddingX
Horizontal padding ratio for the display.
Definition envelope_editor.h:34
static constexpr int kMaxGridLines
Maximum number of grid lines displayed.
Definition envelope_editor.h:47
EnvelopeEditor(const String &prefix, const vital::output_map &mono_modulations, const vital::output_map &poly_modulations)
Constructs an EnvelopeEditor.
Definition envelope_editor.cpp:29
static constexpr float kMarkerGrabRadius
Radius in pixels for grabbing markers.
Definition envelope_editor.h:30
static constexpr int kMaxTimesShown
Maximum number of time markers shown.
Definition envelope_editor.h:49
void mouseDoubleClick(const MouseEvent &e) override
Definition envelope_editor.cpp:230
void setReleasePowerSlider(SynthSlider *release_slider)
Definition envelope_editor.cpp:605
void guiChanged(SynthSlider *slider) override
Called when a slider value changes.
Definition envelope_editor.cpp:272
void magnifyZoom(Point< float > delta)
Zooms the envelope display via magnification (e.g., pinch gestures).
Definition envelope_editor.cpp:250
void mouseUp(const MouseEvent &e) override
Definition envelope_editor.cpp:239
void setReleaseSlider(SynthSlider *release_slider)
Definition envelope_editor.cpp:600
void pickHoverPosition(Point< float > position)
Determines hover state based on mouse position.
Definition envelope_editor.cpp:119
void setAttackSlider(SynthSlider *attack_slider)
Definition envelope_editor.cpp:570
void resized() override
Resized callback to layout and reposition components.
Definition envelope_editor.h:80
static constexpr float kMarkerWidth
Width in pixels of the main markers (ADHSR points).
Definition envelope_editor.h:22
static constexpr float kPowerMouseMultiplier
Multiplier for mouse movements when adjusting power.
Definition envelope_editor.h:40
void magnifyReset()
Resets the magnification zoom to a default level.
Definition envelope_editor.cpp:256
static constexpr float kMinPointDistanceForPower
Minimum point distance for enabling power handle editing.
Definition envelope_editor.h:38
void setDelaySlider(SynthSlider *delay_slider)
Sets the sliders corresponding to different envelope parameters.
Definition envelope_editor.cpp:565
void resetPositions()
Flags that the positions need to be reset and recalculated.
Definition envelope_editor.h:188
void destroy(OpenGlWrapper &open_gl) override
Destroys the OpenGL resources.
Definition envelope_editor.cpp:842
void mouseExit(const MouseEvent &e) override
Definition envelope_editor.cpp:186
void paintBackground(Graphics &g) override
Paints the background of the editor.
Definition envelope_editor.cpp:98
static constexpr int kRulerDivisionSize
Division size for major time ruler lines.
Definition envelope_editor.h:45
static constexpr float kMarkerHoverRadius
Radius in pixels for hovering detection over markers.
Definition envelope_editor.h:28
static constexpr float kPaddingY
Vertical padding ratio for the display.
Definition envelope_editor.h:36
void setSizeRatio(float ratio)
Sets the size ratio for UI scaling.
Definition envelope_editor.h:125
static constexpr float kPowerMarkerWidth
Width in pixels of the power markers (for adjusting curve power).
Definition envelope_editor.h:26
virtual void resized() override
Called when the component is resized.
Definition open_gl_component.cpp:121
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
A component for rendering multiple quads using OpenGL, with customizable colors, rounding,...
Definition open_gl_multi_quad.h:16
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
An interface class linking the Vital synthesizer backend (SynthBase) with a GUI.
Definition synth_gui_interface.h:56
Listener interface for receiving slider events such as mouse interactions, modulation changes,...
Definition synth_slider.h:347
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
A helper class to track the "status" of a particular Output as a poly_float value.
Definition synth_module.h:35
std::map< std::string, Output * > output_map
Maps parameter names to Output pointers, representing output signals from various modules.
Definition synth_types.h:229
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
Defines the SynthModule class which extends ProcessorRouter to form a building block of the Vital syn...
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...