Vital
Loading...
Searching...
No Matches
phaser_section.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "synth_section.h"
6#include "phaser_filter.h"
7#include "synth_module.h"
8
9class SynthButton;
10class TempoSelector;
11class SynthSlider;
13
23public:
25 static constexpr int kResolution = 256;
27 static constexpr int kDefaultVisualSampleRate = 200000;
28
33 PhaserResponse(const vital::output_map& mono_modulations);
34
36 virtual ~PhaserResponse();
37
42 void init(OpenGlWrapper& open_gl) override;
43
49 void render(OpenGlWrapper& open_gl, bool animate) override;
50
55 void destroy(OpenGlWrapper& open_gl) override;
56
61 void mouseDown(const MouseEvent& e) override {
62 last_mouse_position_ = e.getPosition();
63 }
64
69 void mouseDrag(const MouseEvent& e) override {
70 Point<int> delta = e.getPosition() - last_mouse_position_;
71 last_mouse_position_ = e.getPosition();
72
73 float cutoff_range = cutoff_slider_->getMaximum() - cutoff_slider_->getMinimum();
74 cutoff_slider_->setValue(cutoff_slider_->getValue() + delta.x * cutoff_range / getWidth());
75 float resonance_range = resonance_slider_->getMaximum() - resonance_slider_->getMinimum();
76 resonance_slider_->setValue(resonance_slider_->getValue() - delta.y * resonance_range / getHeight());
77 }
78
83 void setCutoffSlider(SynthSlider* slider) { cutoff_slider_ = slider; }
84
89 void setResonanceSlider(SynthSlider* slider) { resonance_slider_ = slider; }
90
95 void setBlendSlider(SynthSlider* slider) { blend_slider_ = slider; }
96
101 void setMixSlider(SynthSlider* slider) { mix_slider_ = slider; }
102
107 void setActive(bool active) { active_ = active; }
108
113 void setStyle(int style) { filter_state_.style = style; }
114
119 void setDefaultBlend(vital::poly_float blend) { blend_setting_ = blend; }
120
121private:
126 struct FilterResponseShader {
127 static constexpr int kMaxStages = 3;
128 OpenGLShaderProgram* shader;
129 std::unique_ptr<OpenGLShaderProgram::Attribute> position;
130
131 std::unique_ptr<OpenGLShaderProgram::Uniform> mix;
132 std::unique_ptr<OpenGLShaderProgram::Uniform> midi_cutoff;
133 std::unique_ptr<OpenGLShaderProgram::Uniform> resonance;
134 std::unique_ptr<OpenGLShaderProgram::Uniform> db24;
135 std::unique_ptr<OpenGLShaderProgram::Uniform> stages[kMaxStages];
136 };
137
143 void drawFilterResponse(OpenGlWrapper& open_gl, bool animate);
144
151 vital::poly_float getOutputTotal(const vital::Output* output, vital::poly_float default_value);
152
156 void setupFilterState();
157
162 void loadShader(int index);
163
168 void bind(OpenGLContext& open_gl_context);
169
174 void unbind(OpenGLContext& open_gl_context);
175
180 void renderLineResponse(OpenGlWrapper& open_gl);
181
182 SynthGuiInterface* parent_;
183 bool active_;
184 Point<int> last_mouse_position_;
185
186 vital::PhaserFilter phaser_filter_;
189
190 SynthSlider* cutoff_slider_;
191 SynthSlider* resonance_slider_;
192 SynthSlider* blend_slider_;
193 SynthSlider* mix_slider_;
194
195 const vital::StatusOutput* phaser_cutoff_;
196 const vital::Output* filter_mix_output_;
197 const vital::Output* resonance_output_;
198 const vital::Output* blend_output_;
199
200 vital::poly_float blend_setting_;
201
202 FilterResponseShader response_shader_;
203 std::unique_ptr<float[]> line_data_;
204 GLuint vertex_array_object_;
205 GLuint line_buffer_;
206 GLuint response_buffer_;
207
208 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PhaserResponse)
209};
210
220public:
226 PhaserSection(String name, const vital::output_map& mono_modulations);
227
229 virtual ~PhaserSection();
230
235 void paintBackground(Graphics& g) override;
236
241 void paintBackgroundShadow(Graphics& g) override { if (isActive()) paintTabShadow(g); }
242
246 void resized() override;
247
252 void setActive(bool active) override;
253
254private:
255 std::unique_ptr<SynthButton> on_;
256 std::unique_ptr<SynthSlider> frequency_;
257 std::unique_ptr<SynthSlider> tempo_;
258 std::unique_ptr<TempoSelector> sync_;
259 std::unique_ptr<SynthSlider> feedback_;
260 std::unique_ptr<SynthSlider> center_;
261 std::unique_ptr<SynthSlider> mod_depth_;
262 std::unique_ptr<SynthSlider> phase_offset_;
263 std::unique_ptr<SynthSlider> dry_wet_;
264 std::unique_ptr<SynthSlider> blend_;
265
266 std::unique_ptr<PhaserResponse> phaser_response_;
267
268 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PhaserSection)
269};
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
Visualizes the frequency response of the phaser effect.
Definition phaser_section.h:22
void init(OpenGlWrapper &open_gl) override
Initializes the OpenGL context and shaders for rendering the phaser response.
Definition phaser_section.cpp:49
virtual ~PhaserResponse()
Destructor.
Definition phaser_section.cpp:47
void setCutoffSlider(SynthSlider *slider)
Sets the cutoff slider that controls the phaser cutoff.
Definition phaser_section.h:83
void setActive(bool active)
Sets whether this phaser response visualization is active.
Definition phaser_section.h:107
void mouseDown(const MouseEvent &e) override
Handles mouse down events on the phaser response view.
Definition phaser_section.h:61
PhaserResponse(const vital::output_map &mono_modulations)
Constructs a PhaserResponse object.
Definition phaser_section.cpp:13
void destroy(OpenGlWrapper &open_gl) override
Cleans up the OpenGL resources used by this class.
Definition phaser_section.cpp:94
void setDefaultBlend(vital::poly_float blend)
Sets the default blend setting for the phaser.
Definition phaser_section.h:119
void setMixSlider(SynthSlider *slider)
Sets the mix slider that controls the dry/wet mix of the phaser.
Definition phaser_section.h:101
void setStyle(int style)
Sets the filter style.
Definition phaser_section.h:113
static constexpr int kDefaultVisualSampleRate
The default visual sample rate used for filter calculations.
Definition phaser_section.h:27
static constexpr int kResolution
The resolution of the frequency response drawing.
Definition phaser_section.h:25
void mouseDrag(const MouseEvent &e) override
Handles mouse drag events to adjust phaser parameters (cutoff/resonance).
Definition phaser_section.h:69
void setResonanceSlider(SynthSlider *slider)
Sets the resonance slider that controls the phaser resonance.
Definition phaser_section.h:89
void render(OpenGlWrapper &open_gl, bool animate) override
Renders the phaser response curve.
Definition phaser_section.cpp:89
void setBlendSlider(SynthSlider *slider)
Sets the blend slider that controls the phaser pass blend parameter.
Definition phaser_section.h:95
A UI section for controlling a phaser effect in the synthesizer.
Definition phaser_section.h:219
void resized() override
Called when the component is resized.
Definition phaser_section.cpp:306
PhaserSection(String name, const vital::output_map &mono_modulations)
Constructs a PhaserSection.
Definition phaser_section.cpp:226
virtual ~PhaserSection()
Destructor.
Definition phaser_section.cpp:287
void setActive(bool active) override
Sets the active state of the phaser section.
Definition phaser_section.cpp:344
void paintBackgroundShadow(Graphics &g) override
Paints the background shadow if the section is active.
Definition phaser_section.h:241
void paintBackground(Graphics &g) override
Paints the background of the phaser section, including labels and backgrounds.
Definition phaser_section.cpp:289
A specialized OpenGlToggleButton with additional functionality for the Vital synth.
Definition synth_button.h:450
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
bool isActive() const
Checks if the section is currently active.
Definition synth_section.h:683
virtual void paintTabShadow(Graphics &g)
Paints a tab-like shadow effect around the component.
Definition synth_section.cpp:188
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
A slider component that allows selection between different tempo modes (seconds, tempo,...
Definition tempo_selector.h:14
A multi-stage phaser filter for the Vital synthesizer.
Definition phaser_filter.h:19
A helper class to track the "status" of a particular Output as a poly_float value.
Definition synth_module.h:35
Holds the parameters necessary to configure a SynthFilter at runtime.
Definition synth_filter.h:92
int style
Filter style enum (e.g., k12Db, k24Db)
Definition synth_filter.h:116
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
Defines the SynthModule class which extends ProcessorRouter to form a building block of the Vital syn...