Vital
Loading...
Searching...
No Matches
distortion_section.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "JuceHeader.h"
8#include "synth_section.h"
9#include "digital_svf.h"
10
11class SynthButton;
12class SynthSlider;
13class TabSelector;
14class TextSelector;
16
24 public:
25 static constexpr int kResolution = 256;
26 static constexpr int kDefaultVisualSampleRate = 200000;
27
30 DistortionFilterResponse(const vital::output_map& mono_modulations);
32
35 void init(OpenGlWrapper& open_gl) override;
36
40 void render(OpenGlWrapper& open_gl, bool animate) override;
41
44 void destroy(OpenGlWrapper& open_gl) override;
45
48 void mouseDown(const MouseEvent& e) override {
49 last_mouse_position_ = e.getPosition();
50 }
51
54 void mouseDrag(const MouseEvent& e) override {
55 Point<int> delta = e.getPosition() - last_mouse_position_;
56 last_mouse_position_ = e.getPosition();
57
58 float cutoff_range = cutoff_slider_->getMaximum() - cutoff_slider_->getMinimum();
59 cutoff_slider_->setValue(cutoff_slider_->getValue() + delta.x * cutoff_range / getWidth());
60 float resonance_range = resonance_slider_->getMaximum() - resonance_slider_->getMinimum();
61 resonance_slider_->setValue(resonance_slider_->getValue() - delta.y * resonance_range / getHeight());
62 }
63
66 void setCutoffSlider(SynthSlider* slider) { cutoff_slider_ = slider; }
67
70 void setResonanceSlider(SynthSlider* slider) { resonance_slider_ = slider; }
71
74 void setBlendSlider(SynthSlider* slider) { blend_slider_ = slider; }
75
78 void setActive(bool active) { active_ = active; }
79
80 private:
82 struct FilterResponseShader {
83 static constexpr int kMaxStages = 5;
84 OpenGLShaderProgram* shader;
85 std::unique_ptr<OpenGLShaderProgram::Attribute> position;
86
87 std::unique_ptr<OpenGLShaderProgram::Uniform> mix;
88 std::unique_ptr<OpenGLShaderProgram::Uniform> midi_cutoff;
89 std::unique_ptr<OpenGLShaderProgram::Uniform> resonance;
90 std::unique_ptr<OpenGLShaderProgram::Uniform> drive;
91 std::unique_ptr<OpenGLShaderProgram::Uniform> db24;
92 std::unique_ptr<OpenGLShaderProgram::Uniform> stages[kMaxStages];
93 };
94
98 void drawFilterResponse(OpenGlWrapper& open_gl, bool animate);
99
101 vital::poly_float getOutputTotal(vital::Output* output, vital::poly_float default_value);
102
104 void setupFilterState();
105
107 void loadShader(int index);
108
111 void bind(OpenGLContext& open_gl_context);
112
115 void unbind(OpenGLContext& open_gl_context);
116
119 void renderLineResponse(OpenGlWrapper& open_gl);
120
121 bool active_;
122 Point<int> last_mouse_position_;
123 vital::DigitalSvf filter_;
125
126 SynthSlider* cutoff_slider_;
127 SynthSlider* resonance_slider_;
128 SynthSlider* blend_slider_;
129
130 vital::Output* cutoff_output_;
131 vital::Output* resonance_output_;
132 vital::Output* blend_output_;
133
134 FilterResponseShader response_shader_;
135 std::unique_ptr<float[]> line_data_;
136 GLuint vertex_array_object_;
137 GLuint line_buffer_;
138 GLuint response_buffer_;
139
140 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistortionFilterResponse)
141};
142
150 public:
151 static constexpr int kViewerResolution = 124;
152
156 DistortionSection(String name, const vital::output_map& mono_modulations);
157
160
163 void paintBackground(Graphics& g) override;
164
167 void paintBackgroundShadow(Graphics& g) override { if (isActive()) paintTabShadow(g); }
168
170 void resized() override;
171
174 void setActive(bool active) override;
175
178 void sliderValueChanged(Slider* changed_slider) override;
179
182 void setAllValues(vital::control_map& controls) override;
183
186 void setFilterActive(bool active);
187
188 private:
189 std::unique_ptr<SynthButton> on_;
190 std::unique_ptr<TextSelector> type_;
191 std::unique_ptr<TextSelector> filter_order_;
192 std::unique_ptr<SynthSlider> drive_;
193 std::unique_ptr<SynthSlider> mix_;
194 std::unique_ptr<SynthSlider> filter_cutoff_;
195 std::unique_ptr<SynthSlider> filter_resonance_;
196 std::unique_ptr<SynthSlider> filter_blend_;
197 std::unique_ptr<DistortionViewer> distortion_viewer_;
198 std::unique_ptr<DistortionFilterResponse> filter_response_;
199
200 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DistortionSection)
201};
202
An OpenGL renderer showing the frequency response of the distortion's filter.
Definition distortion_section.h:23
void render(OpenGlWrapper &open_gl, bool animate) override
Definition distortion_section.cpp:170
virtual ~DistortionFilterResponse()
void destroy(OpenGlWrapper &open_gl) override
Definition distortion_section.cpp:175
void init(OpenGlWrapper &open_gl) override
Definition distortion_section.cpp:135
void setCutoffSlider(SynthSlider *slider)
Definition distortion_section.h:66
static constexpr int kResolution
Resolution of the filter response line.
Definition distortion_section.h:25
void setResonanceSlider(SynthSlider *slider)
Definition distortion_section.h:70
static constexpr int kDefaultVisualSampleRate
Default sample rate for visualization calculations.
Definition distortion_section.h:26
void mouseDrag(const MouseEvent &e) override
Definition distortion_section.h:54
DistortionFilterResponse(const vital::output_map &mono_modulations)
Definition distortion_section.cpp:104
void mouseDown(const MouseEvent &e) override
Definition distortion_section.h:48
void setBlendSlider(SynthSlider *slider)
Definition distortion_section.h:74
void setActive(bool active)
Definition distortion_section.h:78
A UI section for configuring a distortion effect, including type, drive, mix, and filtering.
Definition distortion_section.h:149
virtual ~DistortionSection()
Destructor.
void setActive(bool active) override
Definition distortion_section.cpp:418
void paintBackgroundShadow(Graphics &g) override
Definition distortion_section.h:167
void sliderValueChanged(Slider *changed_slider) override
Definition distortion_section.cpp:424
static constexpr int kViewerResolution
Resolution for visualizing distortion line.
Definition distortion_section.h:151
void paintBackground(Graphics &g) override
Definition distortion_section.cpp:369
void setAllValues(vital::control_map &controls) override
Definition distortion_section.cpp:431
void resized() override
Resizes and lays out child components.
Definition distortion_section.cpp:384
DistortionSection(String name, const vital::output_map &mono_modulations)
Definition distortion_section.cpp:314
void setFilterActive(bool active)
Definition distortion_section.cpp:436
Definition distortion_section.cpp:17
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
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-based UI component that displays selectable tabs.
Definition tab_selector.h:16
A specialized SynthSlider that displays a popup menu of text options.
Definition text_selector.h:14
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
std::map< std::string, Output * > output_map
Maps parameter names to Output pointers, representing output signals from various modules.
Definition synth_types.h:229
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
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