Vital
Loading...
Searching...
No Matches
modulation_matrix.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "line_map_editor.h"
5#include "open_gl_image.h"
6#include "overlay.h"
7#include "preset_selector.h"
8#include "synth_section.h"
9#include "synth_constants.h"
10
13class SynthButton;
16
22 public:
28 static void modulationSelectionCallback(int result, ModulationSelector* selector) {
29 if (selector != nullptr && result != 0)
30 selector->setValue(result - 1);
31 }
32
40 ModulationSelector(String name, const std::vector<String>* selections, PopupItems* popup_items, bool dual_menu) :
41 OpenGlSlider(std::move(name)), selections_(selections), popup_items_(popup_items), dual_menu_(dual_menu) {
42 setRange(0.0, selections_->size() - 1.0, 1.0);
43 setTextBoxStyle(Slider::NoTextBox, true, 0, 0);
44 }
45
51 String getTextFromValue(double value) override;
52
57 String getSelection() {
58 int index = std::round(getValue());
59 return selections_->at(index);
60 }
61
66 bool connected() const {
67 return getValue() != 0.0f;
68 }
69
75 void setValueFromName(const String& name, NotificationType notification_type);
76
81 void mouseDown(const juce::MouseEvent &e) override;
82
83 private:
84 const std::vector<String>* selections_;
85 PopupItems* popup_items_;
86 bool dual_menu_;
87};
88
93class ModulationViewport : public Viewport {
94 public:
99 class Listener {
100 public:
101 virtual ~Listener() = default;
102
107 virtual void modulationScrolled(int position) = 0;
108
112 virtual void startScroll() = 0;
113
117 virtual void endScroll() = 0;
118 };
119
125 void mouseWheelMove(const MouseEvent& e, const MouseWheelDetails& wheel) override {
126 for (Listener* listener : listeners_)
127 listener->startScroll();
128
129 Viewport::mouseWheelMove(e, wheel);
130
131 for (Listener* listener : listeners_)
132 listener->endScroll();
133 }
134
139 void addListener(Listener* listener) { listeners_.push_back(listener); }
140
145 void visibleAreaChanged(const Rectangle<int>& visible_area) override {
146 for (Listener* listener : listeners_)
147 listener->modulationScrolled(visible_area.getY());
148
149 Viewport::visibleAreaChanged(visible_area);
150 }
151
152 private:
153 std::vector<Listener*> listeners_;
154};
155
161 public:
166 class Listener {
167 public:
168 virtual ~Listener() = default;
169
174 virtual void rowSelected(ModulationMatrixRow* selected_row) = 0;
175 };
176
185 ModulationMatrixRow(int index, PopupItems* source_items, PopupItems* destination_items,
186 const std::vector<String>* sources, const std::vector<String>* destinations);
187
191 void resized() override;
192
196 void repaintBackground() override { }
197
202 void setGuiParent(SynthGuiInterface* parent) { parent_ = parent; }
203
208 void setConnection(vital::ModulationConnection* connection) { connection_ = connection; }
209
214 void paintBackground(Graphics& g) override;
215
220 void sliderValueChanged(Slider* changed_slider) override;
221
226 void buttonClicked(Button* button) override;
227
231 void updateDisplay();
232
236 void updateDisplayValue();
237
242 bool connected() const;
243
250 bool matchesSourceAndDestination(const std::string& source, const std::string& destination) const;
251
256 Rectangle<int> getMeterBounds();
257
261 void select() {
262 for (Listener* listener : listeners_)
263 listener->rowSelected(this);
264 }
265
270 void mouseDown(const MouseEvent& e) override { select(); }
271
276 void select(bool select);
277
282 bool selected() const { return selected_; }
283
288 void addListener(Listener* listener) { listeners_.push_back(listener); }
289
294 force_inline int index() const { return index_; }
295
300 force_inline int source() const { return source_->getValue(); }
301
306 force_inline int destination() const { return destination_->getValue(); }
307
312 force_inline int stereo() const { return stereo_->getToggleState(); }
313
318 force_inline int bipolar() const { return bipolar_->getToggleState(); }
319
324 force_inline float morph() const { return power_slider_->getValue(); }
325
330 force_inline float amount() const { return amount_slider_->getValue(); }
331
332 protected:
333 std::vector<Listener*> listeners_;
334
335 int index_;
338
339 std::unique_ptr<ModulationSelector> source_;
340 std::unique_ptr<ModulationSelector> destination_;
344 std::unique_ptr<SynthSlider> amount_slider_;
345 std::unique_ptr<SynthSlider> power_slider_;
346 std::unique_ptr<OpenGlShapeButton> bipolar_;
347 std::unique_ptr<SynthButton> stereo_;
348 std::unique_ptr<SynthButton> bypass_;
350
353};
354
360 public ModulationMatrixRow::Listener, public ScrollBar::Listener,
362 public:
364 static constexpr int kRowPadding = 1;
366 static constexpr int kDefaultGridSizeX = 8;
367 static constexpr int kDefaultGridSizeY = 1;
368
374 static String getMenuSourceDisplayName(const String& original);
375
381 static String getUiSourceDisplayName(const String& original);
382
397
402 class Listener {
403 public:
404 virtual ~Listener() = default;
408 virtual void modulationsScrolled() = 0;
409 };
410
416 ModulationMatrix(const vital::output_map& sources, const vital::output_map& destinations);
417
421 virtual ~ModulationMatrix();
422
427 void paintBackground(Graphics& g) override;
428
433 void paintBackgroundShadow(Graphics& g) override;
434
439
443 void resized() override;
444
448 void setMeterBounds();
449
454 void setVisible(bool should_be_visible) override {
455 SynthSection::setVisible(should_be_visible);
457 }
458
462 void setRowPositions();
463
467 void parentHierarchyChanged() override;
468
473 void sliderValueChanged(Slider* changed_slider) override;
474
479 void buttonClicked(Button* button) override;
480
485 void setAllValues(vital::control_map& controls) override;
486
491 void initOpenGlComponents(OpenGlWrapper& open_gl) override;
492
498 void renderOpenGlComponents(OpenGlWrapper& open_gl, bool animate) override;
499
504 void destroyOpenGlComponents(OpenGlWrapper& open_gl) override;
505
509 void prevClicked() override;
510
514 void nextClicked() override;
515
520 void textMouseDown(const MouseEvent& e) override;
521
526 void setPhase(float phase) override { }
527
533 void lineEditorScrolled(const MouseEvent& e, const MouseWheelDetails& wheel) override;
534
540 void togglePaintMode(bool enabled, bool temporary_switch) override;
541
545 void importLfo() override;
546
550 void exportLfo() override;
551
555 void fileLoaded() override;
556
561 void loadFile(const File& file) override;
562
567 File getCurrentFile() override { return current_file_; }
568
574 void scrollBarMoved(ScrollBar* scroll_bar, double range_start) override;
575
579 void setScrollBarRange();
580
584 void updateModulations();
585
590 void updateModulationValue(int index);
591
596
601 void addListener(Listener* listener) { listeners_.push_back(listener); }
602
606 void startScroll() override {
607 open_gl_critical_section_.enter();
608 }
609
613 void endScroll() override {
614 open_gl_critical_section_.exit();
615 }
616
621 void modulationScrolled(int position) override {
623 scroll_bar_->setCurrentRange(position, viewport_.getHeight());
624 for (Listener* listener : listeners_)
625 listener->modulationsScrolled();
626 }
627
632 void rowSelected(ModulationMatrixRow* selected_row) override;
633
638 void mouseDown(const MouseEvent& e) override;
639
640 private:
644 void sort();
645
650 int getRowHeight() { return getSizeRatio() * 34.0f; }
651
652 std::vector<Listener*> listeners_;
653
654 PopupItems source_popup_items_;
655 PopupItems destination_popup_items_;
656
657 File current_file_;
658 SortColumn sort_column_;
659 bool sort_ascending_;
660 int selected_index_;
661 int num_shown_;
662 std::vector<ModulationMatrixRow*> row_order_;
663 std::unique_ptr<OpenGlScrollBar> scroll_bar_;
664
665 CriticalSection open_gl_critical_section_;
666 std::unique_ptr<ModulationMatrixRow> rows_[vital::kMaxModulationConnections];
667 std::unique_ptr<LineMapEditor> map_editors_[vital::kMaxModulationConnections];
668 std::vector<String> source_strings_;
669 std::vector<String> destination_strings_;
670 std::unique_ptr<ModulationMeterReadouts> readouts_;
671
672 ModulationViewport viewport_;
673 Component container_;
674
675 OpenGlImage background_;
676
677 std::unique_ptr<PlainTextComponent> remap_name_;
678 std::unique_ptr<PresetSelector> preset_selector_;
679 std::unique_ptr<PaintPatternSelector> paint_pattern_;
680
681 std::unique_ptr<SynthSlider> grid_size_x_;
682 std::unique_ptr<SynthSlider> grid_size_y_;
683 std::unique_ptr<OpenGlShapeButton> paint_;
684 std::unique_ptr<OpenGlShapeButton> smooth_;
685
686 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModulationMatrix)
687};
688
Interface for classes that want to receive notifications about line editor changes.
Definition line_editor.h:86
Interface for objects that need to respond to modulation matrix scrolling events.
Definition modulation_matrix.h:402
virtual void modulationsScrolled()=0
Called when the modulation matrix is scrolled.
virtual ~Listener()=default
The main modulation matrix component displaying multiple modulation rows and related controls.
Definition modulation_matrix.h:361
SortColumn
Columns available for sorting the modulation matrix rows.
Definition modulation_matrix.h:387
@ kAmount
Definition modulation_matrix.h:393
@ kDestination
Definition modulation_matrix.h:394
@ kNumber
Definition modulation_matrix.h:388
@ kSource
Definition modulation_matrix.h:389
@ kBipolar
Definition modulation_matrix.h:390
@ kMorph
Definition modulation_matrix.h:392
@ kStereo
Definition modulation_matrix.h:391
@ kNumColumns
Definition modulation_matrix.h:395
void resized() override
Handles resizing of the component.
Definition modulation_matrix.cpp:848
void setVisible(bool should_be_visible) override
Sets visibility of this component, and updates modulations if visible.
Definition modulation_matrix.h:454
void setAllValues(vital::control_map &controls) override
Sets all parameter values from a control map.
Definition modulation_matrix.cpp:934
void initOpenGlComponents(OpenGlWrapper &open_gl) override
Initializes OpenGL components.
Definition modulation_matrix.cpp:1102
void addListener(Listener *listener)
Adds a listener to the modulation matrix.
Definition modulation_matrix.h:601
void importLfo() override
Imports an LFO file to the current line editor.
Definition modulation_matrix.cpp:1178
void nextClicked() override
Called when 'next' is clicked on the preset selector.
Definition modulation_matrix.cpp:1145
static constexpr int kDefaultGridSizeX
Definition modulation_matrix.h:366
void setScrollBarRange()
Sets the range of the scroll bar based on the current rows.
Definition modulation_matrix.cpp:1237
void prevClicked() override
Called when 'previous' is clicked on the preset selector.
Definition modulation_matrix.cpp:1136
void lineEditorScrolled(const MouseEvent &e, const MouseWheelDetails &wheel) override
Handles line editor scrolling for pattern or grid adjustments.
Definition modulation_matrix.cpp:1166
void startScroll() override
Called when scrolling starts (from ModulationViewport::Listener).
Definition modulation_matrix.h:606
static constexpr int kRowPadding
Definition modulation_matrix.h:364
void paintBackground(Graphics &g) override
Paints the background of the modulation matrix.
Definition modulation_matrix.cpp:693
void mouseDown(const MouseEvent &e) override
Handles mouse down events for sorting column selection.
Definition modulation_matrix.cpp:1007
void loadFile(const File &file) override
Loads a specific file (LFO configuration).
Definition modulation_matrix.cpp:1208
void paintBackgroundShadow(Graphics &g) override
Paints background shadows for the matrix sections.
Definition modulation_matrix.cpp:791
void renderOpenGlComponents(OpenGlWrapper &open_gl, bool animate) override
Renders OpenGL components, including animated elements.
Definition modulation_matrix.cpp:1107
void togglePaintMode(bool enabled, bool temporary_switch) override
Toggles paint mode for the line editors.
Definition modulation_matrix.cpp:1173
static String getMenuSourceDisplayName(const String &original)
Returns a user-friendly display name for a given source string in menu context.
Definition modulation_matrix.cpp:513
virtual ~ModulationMatrix()
Destructor.
Definition modulation_matrix.cpp:664
void modulationScrolled(int position) override
Called when the modulation viewport is scrolled (from ModulationViewport::Listener).
Definition modulation_matrix.h:621
void setMeterBounds()
Sets the meter bounds for each modulation row.
Definition modulation_matrix.cpp:897
void sliderValueChanged(Slider *changed_slider) override
Handles slider value changes.
Definition modulation_matrix.cpp:903
void setRowPositions()
Positions rows within the viewport.
Definition modulation_matrix.cpp:826
void exportLfo() override
Exports the current LFO to a file.
Definition modulation_matrix.cpp:1187
void endScroll() override
Called when scrolling ends (from ModulationViewport::Listener).
Definition modulation_matrix.h:613
File getCurrentFile() override
Gets the currently loaded file.
Definition modulation_matrix.h:567
static String getUiSourceDisplayName(const String &original)
Returns a display name suitable for the UI given a source string.
Definition modulation_matrix.cpp:529
void scrollBarMoved(ScrollBar *scroll_bar, double range_start) override
Called when the scroll bar moves.
Definition modulation_matrix.cpp:1232
void paintScrollableBackground()
Paints the portion of the matrix that scrolls, i.e., the rows.
Definition modulation_matrix.cpp:666
void textMouseDown(const MouseEvent &e) override
Handles mouse down events on text components (for loading browser).
Definition modulation_matrix.cpp:1154
void buttonClicked(Button *button) override
Handles button clicks.
Definition modulation_matrix.cpp:920
void destroyOpenGlComponents(OpenGlWrapper &open_gl) override
Destroys OpenGL components.
Definition modulation_matrix.cpp:1131
ModulationMatrix(const vital::output_map &sources, const vital::output_map &destinations)
Constructs a ModulationMatrix.
Definition modulation_matrix.cpp:533
void setPhase(float phase) override
Sets the LFO phase (no-op in this class).
Definition modulation_matrix.h:526
static constexpr int kDefaultGridSizeY
Definition modulation_matrix.h:367
void updateModulations()
Updates the displayed modulations when changes occur.
Definition modulation_matrix.cpp:940
void updateModulationValue(int index)
Updates the modulation value for a given index.
Definition modulation_matrix.cpp:957
void checkNumModulationsShown()
Ensures the correct number of modulation rows is displayed based on connectivity.
Definition modulation_matrix.cpp:962
void parentHierarchyChanged() override
Called when this component's parent hierarchy changes, used to initialize rows and connections.
Definition modulation_matrix.cpp:800
void fileLoaded() override
Called when a file is loaded.
Definition modulation_matrix.cpp:1203
void rowSelected(ModulationMatrixRow *selected_row) override
Called when a modulation row is selected (from ModulationMatrixRow::Listener).
Definition modulation_matrix.cpp:982
Interface for objects that need to respond to row selection changes.
Definition modulation_matrix.h:166
virtual ~Listener()=default
virtual void rowSelected(ModulationMatrixRow *selected_row)=0
Called when this row is selected.
Represents a single row in the modulation matrix, showing source, destination, and associated paramet...
Definition modulation_matrix.h:160
ModulationMatrixRow(int index, PopupItems *source_items, PopupItems *destination_items, const std::vector< String > *sources, const std::vector< String > *destinations)
Constructs a ModulationMatrixRow.
Definition modulation_matrix.cpp:305
std::unique_ptr< SynthSlider > amount_slider_
The slider for modulation amount.
Definition modulation_matrix.h:344
std::unique_ptr< SynthSlider > power_slider_
The slider for the morph/power parameter.
Definition modulation_matrix.h:345
double last_destination_value_
The last known destination value.
Definition modulation_matrix.h:342
void sliderValueChanged(Slider *changed_slider) override
Callback when a slider's value changes.
Definition modulation_matrix.cpp:472
force_inline float morph() const
Gets the morph value of this modulation.
Definition modulation_matrix.h:324
force_inline int stereo() const
Gets whether this row is set to stereo modulation.
Definition modulation_matrix.h:312
int index_
The index of this row.
Definition modulation_matrix.h:335
std::unique_ptr< ModulationSelector > source_
The source selector.
Definition modulation_matrix.h:339
void resized() override
Handles component resizing.
Definition modulation_matrix.cpp:365
bool connected() const
Checks if this row represents a connected modulation.
Definition modulation_matrix.cpp:462
double last_source_value_
The last known source value.
Definition modulation_matrix.h:341
bool matchesSourceAndDestination(const std::string &source, const std::string &destination) const
Checks if this row matches the given source and destination names.
Definition modulation_matrix.cpp:466
force_inline int bipolar() const
Gets whether this row is set to bipolar modulation.
Definition modulation_matrix.h:318
force_inline int index() const
Gets the row index.
Definition modulation_matrix.h:294
Rectangle< int > getMeterBounds()
Gets the bounds where a modulation meter may be drawn.
Definition modulation_matrix.cpp:499
void mouseDown(const MouseEvent &e) override
Called when the mouse is pressed down. Selects this row.
Definition modulation_matrix.h:270
std::vector< Listener * > listeners_
Registered row listeners.
Definition modulation_matrix.h:333
void select()
Selects this row and notifies listeners.
Definition modulation_matrix.h:261
bool selected_
Whether this row is currently selected.
Definition modulation_matrix.h:352
OverlayBackgroundRenderer highlight_
Renders a highlight overlay when selected.
Definition modulation_matrix.h:349
void addListener(Listener *listener)
Adds a listener to this row.
Definition modulation_matrix.h:288
std::unique_ptr< SynthButton > stereo_
The stereo toggle button.
Definition modulation_matrix.h:347
force_inline int source() const
Gets the selected source index.
Definition modulation_matrix.h:300
SynthGuiInterface * parent_
The parent GUI interface.
Definition modulation_matrix.h:337
void setConnection(vital::ModulationConnection *connection)
Assigns a modulation connection to this row.
Definition modulation_matrix.h:208
bool selected() const
Checks if this row is currently selected.
Definition modulation_matrix.h:282
force_inline float amount() const
Gets the modulation amount value.
Definition modulation_matrix.h:330
void updateDisplayValue()
Updates only the display values (like amount) without changing source/destination selection.
Definition modulation_matrix.cpp:438
std::unique_ptr< OpenGlShapeButton > bipolar_
The bipolar toggle button.
Definition modulation_matrix.h:346
force_inline int destination() const
Gets the selected destination index.
Definition modulation_matrix.h:306
void buttonClicked(Button *button) override
Callback when a button is clicked.
Definition modulation_matrix.cpp:417
vital::ModulationConnection * connection_
The modulation connection for this row.
Definition modulation_matrix.h:336
void setGuiParent(SynthGuiInterface *parent)
Sets the parent SynthGuiInterface.
Definition modulation_matrix.h:202
void updateDisplay()
Updates the display of the row based on the current connection state.
Definition modulation_matrix.cpp:426
double last_amount_value_
The last known amount value.
Definition modulation_matrix.h:343
void paintBackground(Graphics &g) override
Paints the background of this row.
Definition modulation_matrix.cpp:404
bool updating_
Indicates if the row is currently updating to avoid recursive changes.
Definition modulation_matrix.h:351
std::unique_ptr< ModulationSelector > destination_
The destination selector.
Definition modulation_matrix.h:340
std::unique_ptr< SynthButton > bypass_
The bypass button for this modulation row.
Definition modulation_matrix.h:348
void repaintBackground() override
Overrides to repaint the background. (Empty override)
Definition modulation_matrix.h:196
Definition modulation_matrix.cpp:184
A specialized slider-like component allowing selection of modulation sources or destinations from a p...
Definition modulation_matrix.h:21
void mouseDown(const juce::MouseEvent &e) override
Handles mouse down events, showing the popup selection menu.
Definition modulation_matrix.cpp:292
bool connected() const
Checks if the selector is currently connected (not at default/off selection).
Definition modulation_matrix.h:66
String getSelection()
Gets the currently selected modulation string.
Definition modulation_matrix.h:57
static void modulationSelectionCallback(int result, ModulationSelector *selector)
Callback for modulation popup menu selections.
Definition modulation_matrix.h:28
String getTextFromValue(double value) override
Converts a numeric value to a display text representing the currently selected modulation.
Definition modulation_matrix.cpp:268
void setValueFromName(const String &name, NotificationType notification_type)
Sets the current value based on a given name.
Definition modulation_matrix.cpp:274
ModulationSelector(String name, const std::vector< String > *selections, PopupItems *popup_items, bool dual_menu)
Constructs a ModulationSelector.
Definition modulation_matrix.h:40
A listener interface for responding to scrolling events in the modulation viewport.
Definition modulation_matrix.h:99
virtual void modulationScrolled(int position)=0
Called when the modulation view is scrolled.
virtual void startScroll()=0
Called when scrolling starts.
virtual ~Listener()=default
virtual void endScroll()=0
Called when scrolling ends.
A specialized viewport for the modulation matrix allowing for scroll listeners.
Definition modulation_matrix.h:93
void visibleAreaChanged(const Rectangle< int > &visible_area) override
Called when the visible area changes, updating listeners with the new scroll position.
Definition modulation_matrix.h:145
void addListener(Listener *listener)
Adds a listener to be notified of scrolling changes.
Definition modulation_matrix.h:139
void mouseWheelMove(const MouseEvent &e, const MouseWheelDetails &wheel) override
Handles mouse wheel movement, notifying listeners before and after scrolling.
Definition modulation_matrix.h:125
A utility class for rendering a single image using OpenGL.
Definition open_gl_image.h:16
An extended JUCE Slider that leverages OpenGL for rendering.
Definition synth_slider.h:52
A component that renders a full-screen overlay background using OpenGL.
Definition overlay.h:16
A specialized TextSelector that draws a visual pattern instead of text.
Definition text_selector.h:47
Interface for objects that want to be notified of PresetSelector events.
Definition preset_selector.h:24
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
virtual void animate(bool animate)
Triggers animation state change in sub-sections if needed.
Definition synth_section.cpp:822
float getSizeRatio() const
Definition synth_section.h:765
#define force_inline
Definition common.h:23
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
constexpr int kMaxModulationConnections
Maximum number of modulation connections allowed.
Definition synth_constants.h:49
Declares the PresetSelector class which provides a UI component for selecting presets.
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
A hierarchical structure of popup menu items for a selector component.
Definition synth_section.h:29
A structure representing a single modulation connection between a modulation source and a destination...
Definition synth_types.h:30