Vital
Loading...
Searching...
No Matches
oscillator_section.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "synth_section.h"
6#include "preset_selector.h"
8#include "wavetable_3d.h"
9
12class PresetSelector;
13class SaveSection;
14class TextSelector;
15class UnisonViewer;
17
29 public TextEditor::Listener,
32 public Timer {
33public:
35 static constexpr float kSectionWidthRatio = 0.19f;
36
41 class Listener {
42 public:
43 virtual ~Listener() = default;
49 virtual void distortionTypeChanged(OscillatorSection* section, int type) = 0;
50
56 virtual void oscillatorDestinationChanged(OscillatorSection* section, int destination) = 0;
57 };
58
67 int index,
68 const vital::output_map& mono_modulations,
69 const vital::output_map& poly_modulations);
70
75
81 void setSkinValues(const Skin& skin, bool top_level) override;
82
87 void paintBackground(Graphics& g) override;
88
93 void paintBackgroundShadow(Graphics& g) override { if (isActive()) paintTabShadow(g); }
94
98 void resized() override;
99
103 void reset() override {
105 wavetable_->setDirty();
106 }
107
112 void buttonClicked(Button* clicked_button) override;
113
118 void setAllValues(vital::control_map& controls) override;
119
124 void textEditorReturnKeyPressed(TextEditor& text_editor) override;
125
130 void textEditorFocusLost(TextEditor& text_editor) override;
131
135 void timerCallback() override;
136
141 void setActive(bool active) override;
142
147 void setName(String name);
148
153
158 void addListener(Listener* listener) { listeners_.push_back(listener); }
159
165 std::string loadWavetableFromText(const String& text);
166
171 Slider* getWaveFrameSlider();
172
177 void setDistortionSelected(int selection);
178
183 int getDistortion() const { return current_distortion_type_; }
184
189 void setSpectralMorphSelected(int selection);
190
195 void setDestinationSelected(int selection);
196
202 void toggleFilterInput(int filter_index, bool on);
203
207 void loadBrowserState();
208
212 void setIndexSelected();
213
218 void setLanguage(int index);
219
224
228 void prevClicked() override;
229
233 void nextClicked() override;
234
239 void textMouseDown(const MouseEvent& e) override;
240
244 void quantizeUpdated() override;
245
253 bool loadAudioAsWavetable(String name, InputStream* audio_stream,
255
260 void loadWavetable(json& wavetable_data) override;
261
265 void loadDefaultWavetable() override;
266
270 void resynthesizeToWavetable() override;
271
275 void textToWavetable() override;
276
280 void saveWavetable() override;
281
286 void loadFile(const File& wavetable_file) override;
287
292 File getCurrentFile() override { return current_file_; }
293
298 std::string getFileName() override { return wavetable_->getWavetable()->getName(); }
299
304 std::string getFileAuthor() override { return wavetable_->getWavetable()->getAuthor(); }
305
310 int index() const { return index_; }
311
316 SynthSlider* getVoicesSlider() const { return unison_voices_.get(); }
317
322 const SynthSlider* getWaveFrameSlider() const { return wave_frame_.get(); }
323
328 const SynthSlider* getSpectralMorphSlider() const { return spectral_morph_amount_.get(); }
329
334 const SynthSlider* getDistortionSlider() const { return distortion_amount_.get(); }
335
340 Rectangle<float> getWavetableRelativeBounds();
341
342private:
346 void showTtwtSettings();
347
351 void setupSpectralMorph();
352
356 void setupDistortion();
357
361 void setupDestination();
362
367 void setDistortionPhaseVisible(bool visible);
368
372 void notifySpectralMorphTypeChange();
373
377 void notifyDistortionTypeChange();
378
382 void notifyDestinationChange();
383
384 Authentication* auth_;
385 std::vector<Listener*> listeners_;
386 int index_;
387 File current_file_;
388
389 std::string distortion_control_name_;
390 std::string spectral_morph_control_name_;
391 std::string destination_control_name_;
392 std::string quantize_control_name_;
393 int current_distortion_type_;
394 int current_spectral_morph_type_;
395 int current_destination_;
396 bool show_ttwt_error_;
397 bool showing_language_menu_;
398 int ttwt_language_;
399
400 std::unique_ptr<SynthButton> oscillator_on_;
401 std::unique_ptr<SynthButton> dimension_button_;
402 std::unique_ptr<SynthSlider> dimension_value_;
403 std::unique_ptr<PresetSelector> preset_selector_;
404 std::unique_ptr<Wavetable3d> wavetable_;
405 std::unique_ptr<UnisonViewer> unison_viewer_;
406
407 std::unique_ptr<TransposeQuantizeButton> transpose_quantize_button_;
408 std::unique_ptr<SynthSlider> transpose_;
409 std::unique_ptr<SynthSlider> tune_;
410
411 std::unique_ptr<PlainTextComponent> distortion_type_text_;
412 std::unique_ptr<ShapeButton> distortion_type_selector_;
413 std::unique_ptr<SynthSlider> distortion_amount_;
414 std::unique_ptr<SynthSlider> distortion_phase_;
415 std::unique_ptr<SynthSlider> phase_;
416 std::unique_ptr<SynthSlider> random_phase_;
417
418 std::unique_ptr<PlainTextComponent> spectral_morph_type_text_;
419 std::unique_ptr<ShapeButton> spectral_morph_type_selector_;
420 std::unique_ptr<SynthSlider> spectral_morph_amount_;
421
422 std::unique_ptr<PlainTextComponent> destination_text_;
423 std::unique_ptr<ShapeButton> destination_selector_;
424
425 std::unique_ptr<SynthSlider> level_;
426 std::unique_ptr<SynthSlider> pan_;
427 std::unique_ptr<SynthSlider> wave_frame_;
428
429 std::unique_ptr<SynthSlider> unison_voices_;
430 std::unique_ptr<SynthSlider> unison_detune_;
431 std::unique_ptr<SynthSlider> unison_detune_power_;
432 std::unique_ptr<OpenGlShapeButton> edit_button_;
433
434 OpenGlQuad ttwt_overlay_;
435 std::unique_ptr<OpenGlTextEditor> ttwt_;
436 std::unique_ptr<SynthButton> ttwt_settings_;
437 std::unique_ptr<PlainTextComponent> ttwt_error_text_;
438
439 std::unique_ptr<OpenGlShapeButton> prev_destination_;
440 std::unique_ptr<OpenGlShapeButton> next_destination_;
441 std::unique_ptr<OpenGlShapeButton> prev_spectral_;
442 std::unique_ptr<OpenGlShapeButton> next_spectral_;
443 std::unique_ptr<OpenGlShapeButton> prev_distortion_;
444 std::unique_ptr<OpenGlShapeButton> next_distortion_;
445
446 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OscillatorSection)
447};
A no-op stub implementation used when authentication is disabled.
Definition authentication.h:163
A pair of buttons for incrementing and decrementing a Slider's value.
Definition incrementer_buttons.h:16
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
A ToggleButton that uses an OpenGlShapeButtonComponent for its rendering.
Definition synth_button.h:110
Listener interface for receiving oscillator section changes.
Definition oscillator_section.h:41
virtual ~Listener()=default
virtual void distortionTypeChanged(OscillatorSection *section, int type)=0
Callback triggered when the distortion type changes.
virtual void oscillatorDestinationChanged(OscillatorSection *section, int destination)=0
Callback triggered when the oscillator destination changes.
A UI section representing an oscillator in the synthesizer.
Definition oscillator_section.h:32
void textEditorReturnKeyPressed(TextEditor &text_editor) override
Handles the return key press in the text editor.
Definition oscillator_section.cpp:940
void setIndexSelected()
Sets the language index for the text-to-wavetable functionality.
Definition oscillator_section.cpp:1078
void paintBackgroundShadow(Graphics &g) override
Paints the background shadow if active.
Definition oscillator_section.h:93
const SynthSlider * getWaveFrameSlider() const
Gets the wave frame slider.
Definition oscillator_section.h:322
void setLanguage(int index)
Sets the language for text-to-wavetable processing.
Definition oscillator_section.cpp:1085
virtual ~OscillatorSection()
Destructor.
void textToWavetable() override
Converts entered text to a wavetable (TTWT).
Definition oscillator_section.cpp:1203
const SynthSlider * getDistortionSlider() const
Gets the distortion slider.
Definition oscillator_section.h:334
void languageSelectCancelled()
Cancels the language selection for TTWT.
Definition oscillator_section.cpp:1096
void reset() override
Resets the oscillator section and marks the wavetable as dirty.
Definition oscillator_section.h:103
void loadBrowserState()
Loads the browser state for wavetable preset selection.
Definition oscillator_section.cpp:1071
void resetOscillatorModulationDistortionType()
Resets the oscillator modulation distortion type to default.
Definition oscillator_section.cpp:1143
Rectangle< float > getWavetableRelativeBounds()
Gets the relative bounds of the wavetable display area.
Definition oscillator_section.cpp:1244
void setName(String name)
Sets the display name of the oscillator section.
Definition oscillator_section.cpp:988
void loadWavetable(json &wavetable_data) override
Loads a wavetable from JSON data.
Definition oscillator_section.cpp:1170
std::string getFileAuthor() override
Gets the author of the loaded wavetable file.
Definition oscillator_section.h:304
void setSkinValues(const Skin &skin, bool top_level) override
Sets visual skin values.
Definition oscillator_section.cpp:633
void setSpectralMorphSelected(int selection)
Sets the currently selected spectral morph type.
Definition oscillator_section.cpp:1048
File getCurrentFile() override
Gets the current wavetable file.
Definition oscillator_section.h:292
void setActive(bool active) override
Sets the active state of the oscillator section.
Definition oscillator_section.cpp:980
void buttonClicked(Button *clicked_button) override
Handles button clicks.
Definition oscillator_section.cpp:840
Slider * getWaveFrameSlider()
Gets the wave frame slider.
Definition oscillator_section.cpp:1034
void nextClicked() override
Loads the next wavetable in the browser.
Definition oscillator_section.cpp:1114
void timerCallback() override
Timer callback for handling transient states (e.g. error messages).
Definition oscillator_section.cpp:972
void textEditorFocusLost(TextEditor &text_editor) override
Handles focus loss in the text editor.
Definition oscillator_section.cpp:962
void setDistortionSelected(int selection)
Sets the currently selected distortion type.
Definition oscillator_section.cpp:1039
void addListener(Listener *listener)
Adds a listener for oscillator section events.
Definition oscillator_section.h:158
bool loadAudioAsWavetable(String name, InputStream *audio_stream, WavetableCreator::AudioFileLoadStyle style) override
Loads audio data as a wavetable.
Definition oscillator_section.cpp:1152
void setDestinationSelected(int selection)
Sets the currently selected destination routing.
Definition oscillator_section.cpp:1055
void loadDefaultWavetable() override
Loads the default (init) wavetable.
Definition oscillator_section.cpp:1183
static constexpr float kSectionWidthRatio
Relative width ratio of the oscillator section.
Definition oscillator_section.h:35
void resynthesizeToWavetable() override
Resynthesizes the current source to a wavetable.
Definition oscillator_section.cpp:1194
void quantizeUpdated() override
Called when transpose quantization is updated.
Definition oscillator_section.cpp:1135
void loadFile(const File &wavetable_file) override
Loads a wavetable file from disk.
Definition oscillator_section.cpp:1223
void resized() override
Called when the component is resized. Handles layout.
Definition oscillator_section.cpp:701
void paintBackground(Graphics &g) override
Paints the background of this section.
Definition oscillator_section.cpp:644
OscillatorSection(Authentication *auth, int index, const vital::output_map &mono_modulations, const vital::output_map &poly_modulations)
Constructs a new OscillatorSection.
Definition oscillator_section.cpp:366
void prevClicked() override
Loads the previous wavetable in the browser.
Definition oscillator_section.cpp:1104
std::string getFileName() override
Gets the name of the loaded wavetable file.
Definition oscillator_section.h:298
void textMouseDown(const MouseEvent &e) override
Handles mouse-down events on textual components.
Definition oscillator_section.cpp:1124
std::string loadWavetableFromText(const String &text)
Loads a wavetable from text input (TTWT - text to wavetable).
Definition oscillator_section.cpp:1005
void saveWavetable() override
Saves the current wavetable to disk.
Definition oscillator_section.cpp:1216
int getDistortion() const
Gets the current distortion type.
Definition oscillator_section.h:183
void toggleFilterInput(int filter_index, bool on)
Toggles filter input on or off.
Definition oscillator_section.cpp:1061
void setAllValues(vital::control_map &controls) override
Sets all control values from a given control map.
Definition oscillator_section.cpp:919
const SynthSlider * getSpectralMorphSlider() const
Gets the spectral morph slider.
Definition oscillator_section.h:328
SynthSlider * getVoicesSlider() const
Gets the unison voices slider.
Definition oscillator_section.h:316
int index() const
Gets the oscillator index.
Definition oscillator_section.h:310
Interface for objects that want to be notified of PresetSelector events.
Definition preset_selector.h:24
A UI component for selecting presets within the synthesizer.
Definition preset_selector.h:14
A UI overlay for saving presets or other files.
Definition save_section.h:21
Manages the overall color and value theme (or "skin") of the user interface.
Definition skin.h:24
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 reset()
Resets the section and all sub-sections.
Definition synth_section.cpp:30
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 specialized SynthSlider that displays a popup menu of text options.
Definition text_selector.h:14
Interface for objects that want to be notified of quantization changes.
Definition transpose_quantize.h:97
A component for visualizing unison voices distribution and detune.
Definition oscillator_section.cpp:236
Interface for components that need to respond to wavetable loading or transformations.
Definition wavetable_3d.h:89
A class responsible for creating complete wavetables from groups of wavetable components.
Definition wavetable_creator.h:27
AudioFileLoadStyle
Defines how audio files are interpreted when loading into a wavetable.
Definition wavetable_creator.h:33
nlohmann::json json
Definition line_generator.h:7
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
Declares the PresetSelector class which provides a UI component for selecting presets.
Declares classes for selecting and applying transpose quantization to notes.
Declares the Wavetable3d class, which provides a 3D and 2D visualization for wavetables.