Vital
Loading...
Searching...
No Matches
equalizer_response.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "digital_svf.h"
7#include "synth_slider.h"
8
19 public:
21 static constexpr int kResolution = 128;
22
24 static constexpr int kViewSampleRate = 100000;
25
27 static constexpr float kDefaultDbBufferRatio = 0.2f;
28
30 static constexpr float kMouseMultiplier = 0.3f;
31
36 class Listener {
37 public:
38 virtual ~Listener() = default;
39
43 virtual void lowBandSelected() = 0;
44
48 virtual void midBandSelected() = 0;
49
53 virtual void highBandSelected() = 0;
54 };
55
60
65
70 void initEq(const vital::output_map& mono_modulations);
71
76 void initReverb(const vital::output_map& mono_modulations);
77
82 virtual void init(OpenGlWrapper& open_gl) override;
83
89 virtual void render(OpenGlWrapper& open_gl, bool animate) override;
90
95 virtual void destroy(OpenGlWrapper& open_gl) override;
96
97
107 void setControlPointBounds(float selected_x, float selected_y,
108 float unselected_x1, float unselected_y1,
109 float unselected_x2, float unselected_y2);
110
115 void drawControlPoints(OpenGlWrapper& open_gl);
116
122 void drawResponse(OpenGlWrapper& open_gl, int index);
123
128
133 void moveFilterSettings(Point<float> position);
134
142
150
158
163 void setSelectedBand(int selected_band);
164
169 Point<float> getLowPosition();
170
175 Point<float> getBandPosition();
176
181 Point<float> getHighPosition();
182
186 void resized() override {
188
189 unselected_points_.setBounds(getLocalBounds());
190 selected_point_.setBounds(getLocalBounds());
191 dragging_point_.setBounds(getLocalBounds());
192 }
193
198 void paintBackground(Graphics& g) override;
199
205 void mouseWheelMove(const MouseEvent& e, const MouseWheelDetails& wheel) override;
206
211 void mouseDown(const MouseEvent& e) override;
212
217 void mouseDrag(const MouseEvent& e) override;
218
223 void mouseUp(const MouseEvent& e) override;
224
229 void mouseExit(const MouseEvent& e) override;
230
236 int getHoveredBand(const MouseEvent& e);
237
242 void setActive(bool active);
243
248 void setHighPass(bool high_pass);
249
254 void setNotch(bool notch);
255
260 void setLowPass(bool low_pass);
261
266 void setDbBufferRatio(float ratio) { db_buffer_ratio_ = ratio; }
267
272 void setDrawFrequencyLines(bool draw_lines) { draw_frequency_lines_ = draw_lines; }
273
278 void addListener(Listener* listener) { listeners_.push_back(listener); }
279
280 private:
287 vital::poly_float getOutputTotal(vital::Output* output, Slider* slider);
288
289 int resolution_;
290 bool active_;
291 bool high_pass_;
292 bool notch_;
293 bool low_pass_;
294 bool animate_;
295 bool draw_frequency_lines_;
296
297 int selected_band_;
298 float db_buffer_ratio_;
299 float min_db_;
300 float max_db_;
301
302 OpenGlMultiQuad unselected_points_;
303 OpenGlQuad selected_point_;
304 OpenGlQuad dragging_point_;
305
306 vital::DigitalSvf low_filter_;
307 vital::DigitalSvf band_filter_;
308 vital::DigitalSvf high_filter_;
309
310 vital::SynthFilter::FilterState low_filter_state_;
311 vital::SynthFilter::FilterState band_filter_state_;
312 vital::SynthFilter::FilterState high_filter_state_;
313
314 SynthSlider* low_cutoff_;
315 SynthSlider* low_resonance_;
316 SynthSlider* low_gain_;
317 SynthSlider* band_cutoff_;
318 SynthSlider* band_resonance_;
319 SynthSlider* band_gain_;
320 SynthSlider* high_cutoff_;
321 SynthSlider* high_resonance_;
322 SynthSlider* high_gain_;
323
324 vital::Output* low_cutoff_output_;
325 vital::Output* low_resonance_output_;
326 vital::Output* low_gain_output_;
327 vital::Output* band_cutoff_output_;
328 vital::Output* band_resonance_output_;
329 vital::Output* band_gain_output_;
330 vital::Output* high_cutoff_output_;
331 vital::Output* high_resonance_output_;
332 vital::Output* high_gain_output_;
333
334 SynthSlider* current_cutoff_;
335 SynthSlider* current_gain_;
336
337 std::unique_ptr<float[]> line_data_;
338 OpenGLShaderProgram* shader_;
339 std::unique_ptr<OpenGLShaderProgram::Attribute> position_attribute_;
340
341 std::unique_ptr<OpenGLShaderProgram::Uniform> midi_cutoff_uniform_;
342 std::unique_ptr<OpenGLShaderProgram::Uniform> resonance_uniform_;
343 std::unique_ptr<OpenGLShaderProgram::Uniform> low_amount_uniform_;
344 std::unique_ptr<OpenGLShaderProgram::Uniform> band_amount_uniform_;
345 std::unique_ptr<OpenGLShaderProgram::Uniform> high_amount_uniform_;
346
347 GLuint vertex_array_object_;
348 GLuint line_buffer_;
349 GLuint response_buffer_;
350 std::vector<Listener*> listeners_;
351
352 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EqualizerResponse)
353};
354
Interface for objects that want to be notified when a band is selected.
Definition equalizer_response.h:36
virtual void lowBandSelected()=0
Called when the low band is selected by the user.
virtual void midBandSelected()=0
Called when the mid band is selected by the user.
virtual ~Listener()=default
virtual void highBandSelected()=0
Called when the high band is selected by the user.
A visualization component for an equalizer or filter response curve.
Definition equalizer_response.h:18
void drawControlPoints(OpenGlWrapper &open_gl)
Draws the control points (markers) for the EQ bands.
Definition equalizer_response.cpp:253
void moveFilterSettings(Point< float > position)
Moves the currently selected filter's cutoff and gain based on a mouse drag position.
Definition equalizer_response.cpp:473
void setHighSliders(SynthSlider *cutoff, SynthSlider *resonance, SynthSlider *gain)
Assigns the sliders for the high band.
Definition equalizer_response.cpp:522
void mouseUp(const MouseEvent &e) override
Handles mouse up events, finalizing any changes made during drag.
Definition equalizer_response.cpp:360
void setControlPointBounds(float selected_x, float selected_y, float unselected_x1, float unselected_y1, float unselected_x2, float unselected_y2)
Sets the bounds for the control points (selected and unselected) in normalized coordinates.
Definition equalizer_response.cpp:227
void setActive(bool active)
Sets the active state of the EQ visualization.
Definition equalizer_response.cpp:539
void setDrawFrequencyLines(bool draw_lines)
Sets whether to draw frequency grid lines in the background.
Definition equalizer_response.h:272
virtual void destroy(OpenGlWrapper &open_gl) override
Destroys OpenGL resources.
Definition equalizer_response.cpp:206
void mouseExit(const MouseEvent &e) override
Handles mouse exit events to hide popups or reset state.
Definition equalizer_response.cpp:371
void resized() override
Called when the component is resized.
Definition equalizer_response.h:186
static constexpr float kDefaultDbBufferRatio
Ratio of dB range used as a buffer around min/max gain values.
Definition equalizer_response.h:27
void setNotch(bool notch)
Configures the mid band as a notch filter (or a shelf).
Definition equalizer_response.cpp:549
void mouseDown(const MouseEvent &e) override
Handles mouse down events to select a band.
Definition equalizer_response.cpp:330
void setHighPass(bool high_pass)
Configures the low band as a high-pass filter (or a shelf).
Definition equalizer_response.cpp:544
void mouseDrag(const MouseEvent &e) override
Handles mouse drag events to adjust filter settings.
Definition equalizer_response.cpp:355
void initEq(const vital::output_map &mono_modulations)
Initializes the Equalizer response for a standard 3-band EQ using the provided outputs.
Definition equalizer_response.cpp:72
~EqualizerResponse()
Destructor.
EqualizerResponse()
Constructs an EqualizerResponse component.
Definition equalizer_response.cpp:7
void setLowPass(bool low_pass)
Configures the high band as a low-pass filter (or a shelf).
Definition equalizer_response.cpp:554
void paintBackground(Graphics &g) override
Paints the background and optionally draws frequency lines.
Definition equalizer_response.cpp:288
int getHoveredBand(const MouseEvent &e)
Determines which band is currently hovered by the mouse.
Definition equalizer_response.cpp:379
static constexpr float kMouseMultiplier
Mouse drag multiplier for gain/cutoff adjustments.
Definition equalizer_response.h:30
void mouseWheelMove(const MouseEvent &e, const MouseWheelDetails &wheel) override
Handles mouse wheel movements for adjusting resonance if hovering over a band.
Definition equalizer_response.cpp:317
static constexpr int kResolution
Number of points used for resolution in the frequency response display.
Definition equalizer_response.h:21
void setLowSliders(SynthSlider *cutoff, SynthSlider *resonance, SynthSlider *gain)
Assigns the sliders for the low band.
Definition equalizer_response.cpp:495
static constexpr int kViewSampleRate
A high view sample rate for accurate visualization (not actual audio processing).
Definition equalizer_response.h:24
void addListener(Listener *listener)
Adds a listener to be notified of band selections.
Definition equalizer_response.h:278
void initReverb(const vital::output_map &mono_modulations)
Initializes the Equalizer response for a reverb's shelving EQ.
Definition equalizer_response.cpp:84
void setDbBufferRatio(float ratio)
Sets the ratio of the dB range used as buffer.
Definition equalizer_response.h:266
virtual void init(OpenGlWrapper &open_gl) override
Initializes OpenGL resources.
Definition equalizer_response.cpp:91
void setBandSliders(SynthSlider *cutoff, SynthSlider *resonance, SynthSlider *gain)
Assigns the sliders for the mid (band) band.
Definition equalizer_response.cpp:510
void setSelectedBand(int selected_band)
Sets the currently selected band.
Definition equalizer_response.cpp:534
void computeFilterCoefficients()
Computes the filter coefficients based on current slider values and states.
Definition equalizer_response.cpp:434
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the EQ response and control points.
Definition equalizer_response.cpp:189
Point< float > getLowPosition()
Returns the current low band control point position in component coordinates.
Definition equalizer_response.cpp:401
void drawResponse(OpenGlWrapper &open_gl, int index)
Draws the response of the filters.
Definition equalizer_response.cpp:122
Point< float > getHighPosition()
Returns the current high band control point position in component coordinates.
Definition equalizer_response.cpp:424
Point< float > getBandPosition()
Returns the current mid (band) control point position in component coordinates.
Definition equalizer_response.cpp:411
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
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 state-variable filter (SVF) implementation, supporting multiple filter types (12/24 dB,...
Definition digital_svf.h:17
Holds the parameters necessary to configure a SynthFilter at runtime.
Definition synth_filter.h:92
cr::Value gain
Relative gain for this formant stage.
Definition formant_filter.cpp:17
cr::Value resonance
Resonance factor for this formant.
Definition formant_filter.cpp:18
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
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
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...