Vital
Loading...
Searching...
No Matches
wavetable_component_list.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
5#include "synth_section.h"
7
10class WavetableGroup;
11
20class WavetableComponentViewport : public Viewport {
21 public:
26 class Listener {
27 public:
28 virtual ~Listener() { }
32 virtual void componentsScrolled() = 0;
33 };
34
39 void addListener(Listener* listener) { listeners_.push_back(listener); }
40
45 void visibleAreaChanged(const Rectangle<int>& newVisibleArea) override {
46 for (Listener* listener : listeners_)
47 listener->componentsScrolled();
48
49 Viewport::visibleAreaChanged(newVisibleArea);
50 }
51
52 private:
53 std::vector<Listener*> listeners_;
54};
55
64class WavetableComponentList : public SynthSection, ScrollBar::Listener,
66 public:
67 static constexpr int kMaxRows = 128;
68 static constexpr int kMaxSources = 16;
69
81
86 class Listener {
87 public:
88 virtual ~Listener() { }
89
94 virtual void componentAdded(WavetableComponent* component) = 0;
95
100 virtual void componentRemoved(WavetableComponent* component) = 0;
101
105 virtual void componentsReordered() = 0;
106
110 virtual void componentsChanged() = 0;
111
116 virtual void componentsScrolled(int offset) { }
117 };
118
123 WavetableComponentList(WavetableCreator* wavetable_creator);
124
128 void clear();
129
133 void init();
134
138 void resized() override;
139
144 void paintBackground(Graphics& g) override;
145
150 void addListener(Listener* listener) { listeners_.push_back(listener); }
151
156 void setRowHeight(int row_height) {
157 row_height_ = row_height;
158 resetGroups();
159 }
160
166 std::pair<int, int> getIndicesForRow(int row_index);
167
172 void groupMenuClicked(int row_index);
173
178 void modifierMenuClicked(int row_index);
179
184 void menuClicked(int row_index);
185
190 void addModifierClicked(int group_index);
194 void addSourceClicked();
195
200 void buttonClicked(Button* button) override;
201
205 void componentsScrolled() override;
206
211 void addSource(int index);
212
217 void removeGroup(int index);
218
223 void addComponent(int type);
224
228 void removeComponent();
229
233 void resetComponent();
234
238 void removeGroup();
239
243 void moveGroupUp();
244
248 void moveGroupDown();
252 void moveModifierUp();
253
257 void moveModifierDown();
258
263
269
275
280
285
291 void scrollBarMoved(ScrollBar* scroll_bar, double range_start) override;
292
298 void scroll(const MouseEvent& e, const MouseWheelDetails& wheel) {
299 viewport_.mouseWheelMove(e, wheel);
300 }
301
302 protected:
306 void resetGroups();
307
311 void positionGroups();
312
316 void setScrollBarRange();
317
320 std::unique_ptr<OpenGlScrollBar> scroll_bar_;
321
325 std::vector<Listener*> listeners_;
327 std::unique_ptr<PlainTextComponent> names_[kMaxRows];
328 std::unique_ptr<OpenGlShapeButton> menu_buttons_[kMaxRows];
329 std::unique_ptr<OpenGlToggleButton> create_component_button_;
330 std::unique_ptr<OpenGlToggleButton> add_modifier_buttons_[kMaxSources];
331 std::unique_ptr<PlainShapeComponent> plus_icons_[kMaxSources + 1];
333
334 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WavetableComponentList)
335};
A component for rendering multiple quads using OpenGL, with customizable colors, rounding,...
Definition open_gl_multi_quad.h:16
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
A base class representing a component in a wavetable synthesis chain.
Definition wavetable_component.h:32
Interface for objects wanting to know when the component list changes.
Definition wavetable_component_list.h:86
virtual void componentAdded(WavetableComponent *component)=0
Called when a component is added.
virtual void componentsChanged()=0
Called when components change (e.g., after add/remove/reset).
virtual void componentsScrolled(int offset)
Called when components are scrolled.
Definition wavetable_component_list.h:116
virtual void componentsReordered()=0
Called when components are reordered.
virtual void componentRemoved(WavetableComponent *component)=0
Called when a component is removed.
virtual ~Listener()
Definition wavetable_component_list.h:88
A UI component that lists and manages the wavetable sources and modifiers.
Definition wavetable_component_list.h:65
void paintBackground(Graphics &g) override
Overridden to paint the background and related elements.
Definition wavetable_component_list.cpp:111
std::unique_ptr< OpenGlToggleButton > add_modifier_buttons_[kMaxSources]
Buttons to add modifiers.
Definition wavetable_component_list.h:330
void moveModifierUp()
Moves the currently selected modifier up in its group.
Definition wavetable_component_list.cpp:450
int current_component_index_
The currently selected component index.
Definition wavetable_component_list.h:324
std::unique_ptr< PlainShapeComponent > plus_icons_[kMaxSources+1]
Plus icons next to buttons.
Definition wavetable_component_list.h:331
int numGroups()
Returns the number of groups in the wavetable.
Definition wavetable_component_list.h:262
int row_height_
Height of each row in pixels.
Definition wavetable_component_list.h:332
WavetableComponentViewport viewport_
Viewport for scrolling the component list.
Definition wavetable_component_list.h:318
void modifierMenuClicked(int row_index)
Displays a menu for the modifier row at the given index.
Definition wavetable_component_list.cpp:275
void addComponent(int type)
Adds a new component (modifier) of the given type.
Definition wavetable_component_list.cpp:383
void addListener(Listener *listener)
Adds a listener interested in component changes.
Definition wavetable_component_list.h:150
void positionGroups()
Positions the groups and modifiers in the scrollable list.
Definition wavetable_component_list.cpp:150
std::unique_ptr< OpenGlScrollBar > scroll_bar_
A custom scrollbar for vertical scrolling.
Definition wavetable_component_list.h:320
void moveModifierDown()
Moves the currently selected modifier down in its group.
Definition wavetable_component_list.cpp:459
std::unique_ptr< OpenGlShapeButton > menu_buttons_[kMaxRows]
Menu buttons for each row.
Definition wavetable_component_list.h:328
void menuClicked(int row_index)
Displays a general menu for the given row index, determining if it's a group or modifier.
Definition wavetable_component_list.cpp:297
void buttonClicked(Button *button) override
Overridden to handle button clicks (menus, add source/modifier).
Definition wavetable_component_list.cpp:330
WavetableComponentList(WavetableCreator *wavetable_creator)
Constructs a WavetableComponentList for managing sources and modifiers.
Definition wavetable_component_list.cpp:38
std::unique_ptr< PlainTextComponent > names_[kMaxRows]
Text labels for each component row.
Definition wavetable_component_list.h:327
void scroll(const MouseEvent &e, const MouseWheelDetails &wheel)
Scrolls the viewport by mouse wheel.
Definition wavetable_component_list.h:298
void groupMenuClicked(int row_index)
Displays a menu for the group row at the given index.
Definition wavetable_component_list.cpp:253
void init()
Initializes the component list after construction.
Definition wavetable_component_list.cpp:107
static constexpr int kMaxSources
Maximum number of source groups.
Definition wavetable_component_list.h:68
std::vector< Listener * > listeners_
Listeners for changes in the component list.
Definition wavetable_component_list.h:325
void addSource(int index)
Adds a new source of the given index (maps to a component type).
Definition wavetable_component_list.cpp:361
void removeGroup()
Removes the currently selected group.
Definition wavetable_component_list.cpp:418
void componentsScrolled() override
Called when the components are scrolled.
Definition wavetable_component_list.cpp:349
WavetableCreator * wavetable_creator_
The wavetable creator managing group/components.
Definition wavetable_component_list.h:322
void notifyComponentAdded(WavetableComponent *component)
Notifies listeners that a component was added.
Definition wavetable_component_list.cpp:469
void addModifierClicked(int group_index)
Called when the "Add Modifier" button is clicked for a particular group.
Definition wavetable_component_list.cpp:304
Component component_container_
Container holding all UI elements for the list.
Definition wavetable_component_list.h:319
void removeComponent()
Removes the currently selected component.
Definition wavetable_component_list.cpp:397
void moveGroupUp()
Moves the currently selected group up in the list.
Definition wavetable_component_list.cpp:432
std::unique_ptr< OpenGlToggleButton > create_component_button_
Button to add a new source.
Definition wavetable_component_list.h:329
void notifyComponentRemoved(WavetableComponent *component)
Notifies listeners that a component was removed.
Definition wavetable_component_list.cpp:475
OpenGlMultiQuad component_backgrounds_
Background rectangles for each row.
Definition wavetable_component_list.h:326
void setRowHeight(int row_height)
Sets the height of each row in the list.
Definition wavetable_component_list.h:156
std::pair< int, int > getIndicesForRow(int row_index)
Retrieves the group and component indices for a given row index.
Definition wavetable_component_list.cpp:239
void setScrollBarRange()
Sets the scrollbar range based on content size.
Definition wavetable_component_list.cpp:234
int current_group_index_
The currently selected group index.
Definition wavetable_component_list.h:323
void moveGroupDown()
Moves the currently selected group down in the list.
Definition wavetable_component_list.cpp:441
static constexpr int kMaxRows
Maximum number of rows for components.
Definition wavetable_component_list.h:67
void resetGroups()
Resets the display of groups and modifiers in the UI.
Definition wavetable_component_list.cpp:131
void addSourceClicked()
Called when the "Add Source" button is clicked.
Definition wavetable_component_list.cpp:318
void notifyComponentsReordered()
Notifies listeners that components have been reordered.
Definition wavetable_component_list.cpp:481
void resized() override
Overridden to layout and refresh the UI.
Definition wavetable_component_list.cpp:123
void scrollBarMoved(ScrollBar *scroll_bar, double range_start) override
Called when the scroll bar moves.
Definition wavetable_component_list.cpp:357
void clear()
Clears the list of sources and modifiers.
Definition wavetable_component_list.cpp:103
void notifyComponentsChanged()
Notifies listeners that components have changed.
Definition wavetable_component_list.cpp:487
ComponentRowMenu
Menu options for component rows.
Definition wavetable_component_list.h:74
@ kMoveUp
Definition wavetable_component_list.h:77
@ kReset
Definition wavetable_component_list.h:76
@ kRemove
Definition wavetable_component_list.h:79
@ kRowCancel
Definition wavetable_component_list.h:75
@ kMoveDown
Definition wavetable_component_list.h:78
void resetComponent()
Resets the currently selected component to default state.
Definition wavetable_component_list.cpp:407
Interface for objects wanting to know when the viewport scrolls.
Definition wavetable_component_list.h:26
virtual ~Listener()
Definition wavetable_component_list.h:28
virtual void componentsScrolled()=0
Called whenever the visible area changes, e.g., due to scrolling.
A Viewport subclass that notifies listeners when the visible area changes.
Definition wavetable_component_list.h:20
void visibleAreaChanged(const Rectangle< int > &newVisibleArea) override
Overridden to notify listeners when the visible area changes.
Definition wavetable_component_list.h:45
void addListener(Listener *listener)
Adds a listener that will be notified on scroll events.
Definition wavetable_component_list.h:39
A class responsible for creating complete wavetables from groups of wavetable components.
Definition wavetable_creator.h:27
int numGroups() const
Gets the total number of WavetableGroups.
Definition wavetable_creator.h:63
A class representing a group of WavetableComponents combined to form part of a wavetable.
Definition wavetable_group.h:24