Vital
Loading...
Searching...
No Matches
compressor_editor.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4
5#include "line_generator.h"
6#include "open_gl_component.h"
8#include "synth_slider.h"
9#include "synth_module.h"
10
12
23 public:
25 static constexpr float kGrabRadius = 8.0f;
26
28 static constexpr float kMinDb = -80.0f;
30 static constexpr float kMaxDb = 0.0f;
31
33 static constexpr float kDbEditBuffer = 1.0f;
35 static constexpr float kMinEditDb = kMinDb + kDbEditBuffer;
37 static constexpr float kMaxEditDb = kMaxDb - kDbEditBuffer;
38
40 static constexpr float kMinLowerRatio = -1.0f;
42 static constexpr float kMaxLowerRatio = 1.0f;
44 static constexpr float kMinUpperRatio = 0.0f;
46 static constexpr float kMaxUpperRatio = 1.0f;
47
49 static constexpr float kRatioEditMultiplier = 0.6f;
50
52 static constexpr float kCompressorAreaBuffer = 0.05f;
54 static constexpr float kBarWidth = 1.0f / 5.0f;
55
57 static constexpr float kInputLineRadius = 0.02f;
58
60 static constexpr float kMouseMultiplier = 1.0f;
61
63 static constexpr int kMaxBands = 3;
65 static constexpr int kNumChannels = kMaxBands * 2;
66
68 static constexpr int kDbLineSections = 8;
70 static constexpr int kExtraDbLines = 6;
75
80
84 virtual ~CompressorEditor();
85
90 void paintBackground(Graphics& g) override;
91
95 void resized() override;
96
101 void mouseDown(const MouseEvent& e) override;
102
107 void mouseDoubleClick(const MouseEvent& e) override;
108
113 void mouseMove(const MouseEvent& e) override;
114
119 void mouseDrag(const MouseEvent& e) override;
120
125 void mouseUp(const MouseEvent& e) override;
126
131 void mouseExit(const MouseEvent& e) override;
132
136 void parentHierarchyChanged() override;
137
142 void init(OpenGlWrapper& open_gl) override;
143
149 void render(OpenGlWrapper& open_gl, bool animate) override;
150
156 void renderCompressor(OpenGlWrapper& open_gl, bool animate);
157
162 void destroy(OpenGlWrapper& open_gl) override;
163
168 void setSizeRatio(float ratio) { size_ratio_ = ratio; }
169
174 void setAllValues(vital::control_map& controls);
175
180 void setHighBandActive(bool active) { high_band_active_ = active; }
181
186 void setLowBandActive(bool active) { low_band_active_ = active; }
187
192 void setActive(bool active) { active_ = active; }
193
194 private:
199 enum DragPoint {
200 kNone,
201 kLowUpperThreshold,
202 kBandUpperThreshold,
203 kHighUpperThreshold,
204 kLowLowerThreshold,
205 kBandLowerThreshold,
206 kHighLowerThreshold,
207 kLowUpperRatio,
208 kBandUpperRatio,
209 kHighUpperRatio,
210 kLowLowerRatio,
211 kBandLowerRatio,
212 kHighLowerRatio,
213 kNumDragPoints
214 };
215
221 bool isRatio(DragPoint drag_point) {
222 return drag_point == kLowLowerRatio || drag_point == kBandLowerRatio || drag_point == kHighLowerRatio ||
223 drag_point == kLowUpperRatio || drag_point == kBandUpperRatio || drag_point == kHighUpperRatio;
224 }
225
236 void setThresholdPositions(int low_start, int low_end, int band_start, int band_end,
237 int high_start, int high_end, float ratio_match);
238
249 void setRatioLines(int start_index, int start_x, int end_x, float threshold, float ratio, bool upper, bool hover);
250
260 void setRatioLinePositions(int low_start, int low_end, int band_start, int band_end,
261 int high_start, int high_end);
262
273 void renderHover(OpenGlWrapper& open_gl, int low_start, int low_end,
274 int band_start, int band_end, int high_start, int high_end);
275
281 void setLowUpperThreshold(float db, bool clamp);
282 void setBandUpperThreshold(float db, bool clamp);
283 void setHighUpperThreshold(float db, bool clamp);
284 void setLowLowerThreshold(float db, bool clamp);
285 void setBandLowerThreshold(float db, bool clamp);
286 void setHighLowerThreshold(float db, bool clamp);
287
292 void setLowUpperRatio(float ratio);
293 void setBandUpperRatio(float ratio);
294 void setHighUpperRatio(float ratio);
295 void setLowLowerRatio(float ratio);
296 void setBandLowerRatio(float ratio);
297 void setHighLowerRatio(float ratio);
298
304 String formatValue(float value);
305
311 DragPoint getHoverPoint(const MouseEvent& e);
312
318 float getYForDb(float db);
319
329 float getCompressedDb(float input_db, float upper_threshold, float upper_ratio,
330 float lower_threshold, float lower_ratio);
331
337 Colour getColorForRatio(float ratio);
338
339 SynthGuiInterface* parent_;
340 SynthSection* section_parent_;
341
342 DragPoint hover_;
343 Point<int> last_mouse_position_;
344
345 OpenGlQuad hover_quad_;
346 OpenGlMultiQuad input_dbs_;
347 OpenGlMultiQuad output_dbs_;
348 OpenGlMultiQuad thresholds_;
349 OpenGlMultiQuad ratio_lines_;
350
351 float low_upper_threshold_;
352 float band_upper_threshold_;
353 float high_upper_threshold_;
354 float low_lower_threshold_;
355 float band_lower_threshold_;
356 float high_lower_threshold_;
357
358 float low_upper_ratio_;
359 float band_upper_ratio_;
360 float high_upper_ratio_;
361 float low_lower_ratio_;
362 float band_lower_ratio_;
363 float high_lower_ratio_;
364
365 const vital::StatusOutput* low_input_ms_;
366 const vital::StatusOutput* band_input_ms_;
367 const vital::StatusOutput* high_input_ms_;
368
369 const vital::StatusOutput* low_output_ms_;
370 const vital::StatusOutput* band_output_ms_;
371 const vital::StatusOutput* high_output_ms_;
372
373 float size_ratio_;
374 bool animate_;
375 bool active_;
376 bool high_band_active_;
377 bool low_band_active_;
378
379 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CompressorEditor)
380};
A graphical interface component for editing a multiband compressor's thresholds and ratios.
Definition compressor_editor.h:22
void mouseUp(const MouseEvent &e) override
Handles mouse up events.
Definition compressor_editor.cpp:269
static constexpr float kMouseMultiplier
General multiplier for mouse-drag edits.
Definition compressor_editor.h:60
static constexpr int kMaxBands
Maximum number of bands supported.
Definition compressor_editor.h:63
CompressorEditor()
Constructs a new CompressorEditor.
Definition compressor_editor.cpp:84
void destroy(OpenGlWrapper &open_gl) override
Destroys and cleans up OpenGL-related objects.
Definition compressor_editor.cpp:532
static constexpr float kMinLowerRatio
Minimum ratio value for the lower ratio segments.
Definition compressor_editor.h:40
void mouseDown(const MouseEvent &e) override
Handles mouse down events.
Definition compressor_editor.cpp:166
void mouseDrag(const MouseEvent &e) override
Handles mouse drag events.
Definition compressor_editor.cpp:207
static constexpr float kGrabRadius
Grab radius in pixels for clickable points (thresholds, ratio handles).
Definition compressor_editor.h:25
static constexpr float kMinUpperRatio
Minimum ratio value for the upper ratio segments.
Definition compressor_editor.h:44
static constexpr int kTotalRatioLines
Total number of ratio lines drawn for all bands.
Definition compressor_editor.h:74
static constexpr float kCompressorAreaBuffer
Buffer area around the compressor visualization.
Definition compressor_editor.h:52
static constexpr float kMaxEditDb
Maximum editable dB value (slightly below kMaxDb).
Definition compressor_editor.h:37
static constexpr float kMinDb
Minimum decibel value displayed in the compressor editor.
Definition compressor_editor.h:28
static constexpr float kMinEditDb
Minimum editable dB value (slightly above kMinDb).
Definition compressor_editor.h:35
void renderCompressor(OpenGlWrapper &open_gl, bool animate)
Renders the compressor-specific elements.
Definition compressor_editor.cpp:438
void resized() override
Called when the component is resized.
Definition compressor_editor.cpp:292
static constexpr int kDbLineSections
Number of dB line sections in the display.
Definition compressor_editor.h:68
static constexpr int kExtraDbLines
Extra dB lines to draw for extended resolution.
Definition compressor_editor.h:70
static constexpr int kRatioDbLines
Total number of dB lines for ratio calculations.
Definition compressor_editor.h:72
void setActive(bool active)
Sets the active state of the entire compressor editor.
Definition compressor_editor.h:192
static constexpr float kBarWidth
Width of the displayed bars relative to the component width.
Definition compressor_editor.h:54
void init(OpenGlWrapper &open_gl) override
Initializes the OpenGL context and related objects.
Definition compressor_editor.cpp:301
void setSizeRatio(float ratio)
Sets the size ratio, scaling the display proportionally.
Definition compressor_editor.h:168
void setAllValues(vital::control_map &controls)
Sets all threshold and ratio values from a given control map.
Definition compressor_editor.cpp:541
static constexpr float kRatioEditMultiplier
Multiplier applied to ratio edits for finer control.
Definition compressor_editor.h:49
virtual ~CompressorEditor()
Destructor.
Definition compressor_editor.cpp:128
static constexpr float kInputLineRadius
Radius for input line rendering in normalized coordinates.
Definition compressor_editor.h:57
static constexpr float kMaxLowerRatio
Maximum ratio value for the lower ratio segments.
Definition compressor_editor.h:42
static constexpr float kMaxDb
Maximum decibel value displayed in the compressor editor.
Definition compressor_editor.h:30
static constexpr float kMaxUpperRatio
Maximum ratio value for the upper ratio segments.
Definition compressor_editor.h:46
void parentHierarchyChanged() override
Called when the component's parent hierarchy changes, used for initialization.
Definition compressor_editor.cpp:696
void setHighBandActive(bool active)
Sets the activity state of the high band.
Definition compressor_editor.h:180
void paintBackground(Graphics &g) override
Draws the background of the editor.
Definition compressor_editor.cpp:281
void mouseDoubleClick(const MouseEvent &e) override
Handles mouse double-click events.
Definition compressor_editor.cpp:171
void mouseMove(const MouseEvent &e) override
Handles mouse move events (primarily used for updating hover state).
Definition compressor_editor.cpp:198
void mouseExit(const MouseEvent &e) override
Handles mouse exit events.
Definition compressor_editor.cpp:276
static constexpr float kDbEditBuffer
Decibel buffer around the min and max dB edit range.
Definition compressor_editor.h:33
void render(OpenGlWrapper &open_gl, bool animate) override
Renders the compressor visualization.
Definition compressor_editor.cpp:310
void setLowBandActive(bool active)
Sets the activity state of the low band.
Definition compressor_editor.h:186
static constexpr int kNumChannels
Number of channels (2 channels per band).
Definition compressor_editor.h:65
A base component class that integrates JUCE's Component with OpenGL rendering.
Definition open_gl_component.h:20
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
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
Listener interface for receiving slider events such as mouse interactions, modulation changes,...
Definition synth_slider.h:347
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, 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
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...