Vital
Loading...
Searching...
No Matches
flanger_section.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "synth_section.h"
6#include "comb_filter.h"
7#include "synth_module.h"
8
9class SynthButton;
10class TempoSelector;
11class SynthSlider;
13
23 public:
27 static constexpr int kResolution = 512;
28
32 static constexpr int kDefaultVisualSampleRate = 200000;
33
37 static constexpr int kCombAlternatePeriod = 2;
38
43 FlangerResponse(const vital::output_map& mono_modulations);
44
48 virtual ~FlangerResponse();
49
54 void init(OpenGlWrapper& open_gl) override;
55
61 void render(OpenGlWrapper& open_gl, bool animate) override;
62
67 void destroy(OpenGlWrapper& open_gl) override;
68
73 void mouseDown(const MouseEvent& e) override {
74 last_mouse_position_ = e.getPosition();
75 }
76
81 void mouseDrag(const MouseEvent& e) override {
82 Point<int> delta = e.getPosition() - last_mouse_position_;
83 last_mouse_position_ = e.getPosition();
84
85 float center_range = center_slider_->getMaximum() - center_slider_->getMinimum();
86 center_slider_->setValue(center_slider_->getValue() + delta.x * center_range / getWidth());
87 float feedback_range = feedback_slider_->getMaximum() - feedback_slider_->getMinimum();
88 feedback_slider_->setValue(feedback_slider_->getValue() - delta.y * feedback_range / getHeight());
89 }
90
95 void setCenterSlider(SynthSlider* slider) { center_slider_ = slider; }
96
101 void setFeedbackSlider(SynthSlider* slider) { feedback_slider_ = slider; }
102
107 void setMixSlider(SynthSlider* slider) { mix_slider_ = slider; }
108
113 void setActive(bool active) { active_ = active; }
114
115 private:
116 struct FilterResponseShader {
117 static constexpr int kMaxStages = 4;
118 OpenGLShaderProgram* shader;
119 std::unique_ptr<OpenGLShaderProgram::Attribute> position;
120
121 std::unique_ptr<OpenGLShaderProgram::Uniform> mix;
122 std::unique_ptr<OpenGLShaderProgram::Uniform> drive;
123 std::unique_ptr<OpenGLShaderProgram::Uniform> midi_cutoff;
124 std::unique_ptr<OpenGLShaderProgram::Uniform> resonance;
125 std::unique_ptr<OpenGLShaderProgram::Uniform> stages[kMaxStages];
126 };
127
133 void drawFilterResponse(OpenGlWrapper& open_gl, bool animate);
134
141 vital::poly_float getOutputTotal(vital::Output* output, vital::poly_float default_value);
142
146 void setupFilterState();
147
152 void loadShader(int index);
153
158 void bind(OpenGLContext& open_gl_context);
159
164 void unbind(OpenGLContext& open_gl_context);
165
171 void renderLineResponse(OpenGlWrapper& open_gl, int index);
172
173 SynthGuiInterface* parent_;
174 bool active_;
175 Point<int> last_mouse_position_;
176
177 vital::CombFilter comb_filter_;
180
181 SynthSlider* center_slider_;
182 SynthSlider* feedback_slider_;
183 SynthSlider* mix_slider_;
184
185 const vital::StatusOutput* flanger_frequency_;
186 vital::Output* feedback_output_;
187 vital::Output* mix_output_;
188
189 FilterResponseShader response_shader_;
190 std::unique_ptr<float[]> line_data_;
191 GLuint vertex_array_object_;
192 GLuint line_buffer_;
193 GLuint response_buffer_;
194
195 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FlangerResponse)
196};
197
208 public:
214 FlangerSection(String name, const vital::output_map& mono_modulations);
215
219 virtual ~FlangerSection();
220
225 void paintBackground(Graphics& g) override;
226
231 void paintBackgroundShadow(Graphics& g) override { if (isActive()) paintTabShadow(g); }
232
236 void resized() override;
237
242 void setActive(bool active) override;
243
244 private:
245 std::unique_ptr<SynthButton> on_;
246 std::unique_ptr<SynthSlider> frequency_;
247 std::unique_ptr<SynthSlider> tempo_;
248 std::unique_ptr<TempoSelector> sync_;
249 std::unique_ptr<SynthSlider> feedback_;
250 std::unique_ptr<SynthSlider> mod_depth_;
251 std::unique_ptr<SynthSlider> center_;
252 std::unique_ptr<SynthSlider> phase_offset_;
253 std::unique_ptr<SynthSlider> dry_wet_;
254
255 std::unique_ptr<FlangerResponse> flanger_response_;
256
257 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FlangerSection)
258};
259
Renders a visual representation of the flanger effect's filter response.
Definition flanger_section.h:22
void mouseDown(const MouseEvent &e) override
Handles mouse down events on the response graph.
Definition flanger_section.h:73
void render(OpenGlWrapper &open_gl, bool animate) override
Renders the flanger response curve.
Definition flanger_section.cpp:82
void setFeedbackSlider(SynthSlider *slider)
Associates a SynthSlider with the feedback parameter.
Definition flanger_section.h:101
void setActive(bool active)
Sets the flanger active state, affecting how the response is drawn.
Definition flanger_section.h:113
static constexpr int kDefaultVisualSampleRate
A default sample rate used for visualization purposes.
Definition flanger_section.h:32
virtual ~FlangerResponse()
Destructor.
Definition flanger_section.cpp:40
void setCenterSlider(SynthSlider *slider)
Associates a SynthSlider with the center frequency parameter.
Definition flanger_section.h:95
void init(OpenGlWrapper &open_gl) override
Initializes the OpenGL state required for rendering.
Definition flanger_section.cpp:42
static constexpr int kCombAlternatePeriod
The period used for alternating comb filtering in the displayed response.
Definition flanger_section.h:37
void setMixSlider(SynthSlider *slider)
Associates a SynthSlider with the mix (dry/wet) parameter.
Definition flanger_section.h:107
static constexpr int kResolution
Number of resolution points used for rendering the response.
Definition flanger_section.h:27
void destroy(OpenGlWrapper &open_gl) override
Cleans up and releases OpenGL resources.
Definition flanger_section.cpp:87
FlangerResponse(const vital::output_map &mono_modulations)
Constructs the FlangerResponse.
Definition flanger_section.cpp:13
void mouseDrag(const MouseEvent &e) override
Handles mouse drag events to adjust flanger parameters interactively.
Definition flanger_section.h:81
A GUI section representing the flanger effect in the synthesizer.
Definition flanger_section.h:207
void paintBackgroundShadow(Graphics &g) override
Paints the background shadow if active.
Definition flanger_section.h:231
void setActive(bool active) override
Sets the active state of the flanger section and updates the flanger response accordingly.
Definition flanger_section.cpp:333
void paintBackground(Graphics &g) override
Paints the background of the flanger section, including labels for each parameter.
Definition flanger_section.cpp:281
void resized() override
Positions and sizes the child components when the flanger section is resized.
Definition flanger_section.cpp:298
FlangerSection(String name, const vital::output_map &mono_modulations)
Constructs a FlangerSection.
Definition flanger_section.cpp:224
virtual ~FlangerSection()
Destructor.
Definition flanger_section.cpp:279
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
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 Processor implementing a comb-based filter with multiple feedback styles.
Definition comb_filter.h:18
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
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...