Vital
Loading...
Searching...
No Matches
wavetable_component_overlay.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4
5#include "open_gl_component.h"
7#include "synth_section.h"
10
23 public:
25 static constexpr int kMaxGrid = 16;
26
28 static constexpr float kTitleHeightForWidth = 0.1f;
29 static constexpr float kWidgetHeightForWidth = 0.08f;
30 static constexpr float kShadowPercent = 0.1f;
31 static constexpr float kDividerPoint = 0.44f;
32 static constexpr float kTitleHeightRatio = 0.4f;
33
43 public:
45 static constexpr int kMaxLines = 16;
46
52 ControlsBackground() : SynthSection("background"), background_(Shaders::kRoundedRectangleFragment),
53 border_(Shaders::kRoundedRectangleBorderFragment),
54 lines_(kMaxLines, Shaders::kColorFragment),
55 title_backgrounds_(kMaxLines + 1, Shaders::kColorFragment) {
56 addOpenGlComponent(&background_);
57 addOpenGlComponent(&border_);
58 addOpenGlComponent(&lines_);
59 addOpenGlComponent(&title_backgrounds_);
60
61 background_.setTargetComponent(this);
62 border_.setTargetComponent(this);
63 lines_.setTargetComponent(this);
64 title_backgrounds_.setTargetComponent(this);
65
66 for (int i = 0; i <= kMaxLines; ++i) {
67 title_texts_[i] = std::make_unique<PlainTextComponent>("text", "");
68 addOpenGlComponent(title_texts_[i].get());
69 title_texts_[i]->setActive(false);
70 title_texts_[i]->setFontType(PlainTextComponent::kLight);
71 }
72 }
73
77 void clearLines() { line_positions_.clear(); setPositions(); }
78
82 void clearTitles() { titles_.clear(); setPositions(); }
83
88 void addLine(int position) { line_positions_.push_back(position); setPositions(); }
89
94 void addTitle(const std::string& title) { titles_.push_back(title); setPositions(); }
95
99 void setPositions();
100
101 private:
102 OpenGlQuad background_;
103 OpenGlQuad border_;
104 OpenGlMultiQuad lines_;
105 OpenGlMultiQuad title_backgrounds_;
106 std::unique_ptr<PlainTextComponent> title_texts_[kMaxLines + 1];
107 std::vector<int> line_positions_;
108 std::vector<std::string> titles_;
109 };
110
118 class Listener {
119 public:
120 virtual ~Listener() { }
121
125 virtual void frameDoneEditing() = 0;
126
130 virtual void frameChanged() = 0;
131 };
132
140 controls_width_(0), initialized_(false), padding_(0) {
141 setInterceptsMouseClicks(false, true);
143 controls_background_.setAlwaysOnTop(true);
144 }
145
150
155 void paintBackground(Graphics& g) override { paintChildrenBackgrounds(g); }
156
161 void playheadMoved(int position) override { }
162
167 virtual void setEditBounds(Rectangle<int> bounds);
168
174 virtual bool setTimeDomainBounds(Rectangle<int> bounds) { return false; }
175
181 virtual bool setFrequencyAmplitudeBounds(Rectangle<int> bounds) { return false; }
182
188 virtual bool setPhaseBounds(Rectangle<int> bounds) { return false; }
189
193 void resetOverlay();
194
199 void initOpenGlComponents(OpenGlWrapper& open_gl) override {
201 initialized_ = true;
202 }
203
208 bool initialized() { return initialized_; }
209
214 void addFrameListener(Listener* listener) {
215 listeners_.push_back(listener);
216 }
217
222 void removeListener(Listener* listener) {
223 listeners_.erase(std::find(listeners_.begin(), listeners_.end(), listener));
224 }
225
230 virtual void setPowerScale(bool scale) { }
231
236 virtual void setFrequencyZoom(float zoom) { }
237
242 void setPadding(int padding) { padding_ = padding; repaint(); }
243
248 int getPadding() { return padding_; }
249
254 void setComponent(WavetableComponent* component);
255
261
262 protected:
267 void setControlsWidth(int width) { controls_width_ = width; repaint(); }
268
273 void notifyChanged(bool mouse_up);
274
279 float getTitleHeight();
280
285 int getDividerX();
286
291 int getWidgetHeight();
292
297 int getWidgetPadding();
298
301 std::vector<Listener*> listeners_;
302 Rectangle<int> edit_bounds_;
306
307 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WavetableComponentOverlay)
308};
309
A component for rendering multiple quads using OpenGL, with customizable colors, rounding,...
Definition open_gl_multi_quad.h:16
void setTargetComponent(Component *target_component)
Sets a target component to help position the quads.
Definition open_gl_multi_quad.h:358
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
@ kLight
Definition open_gl_image_component.h:309
Manages and provides access to vertex and fragment shaders used by the OpenGL rendering pipeline.
Definition shaders.h:19
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
void addSubSection(SynthSection *section, bool show=true)
Adds a subsection (another SynthSection) as a child.
Definition synth_section.cpp:457
void paintChildrenBackgrounds(Graphics &g)
Paints the backgrounds for all child sections.
Definition synth_section.cpp:274
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
virtual void initOpenGlComponents(OpenGlWrapper &open_gl)
Initializes all OpenGL components in this section and sub-sections.
Definition synth_section.cpp:349
A base class representing a component in a wavetable synthesis chain.
Definition wavetable_component.h:32
A background component with lines and titles for the overlay's control section.
Definition wavetable_component_overlay.h:42
void setPositions()
Updates all OpenGL components and text positions after changes to lines or titles.
Definition wavetable_component_overlay.cpp:7
static constexpr int kMaxLines
Maximum possible lines for control divisions.
Definition wavetable_component_overlay.h:45
void addTitle(const std::string &title)
Adds a title string for the next control section.
Definition wavetable_component_overlay.h:94
void addLine(int position)
Adds a vertical line divider at the given position.
Definition wavetable_component_overlay.h:88
void clearTitles()
Clears all control section titles.
Definition wavetable_component_overlay.h:82
ControlsBackground()
Constructs a ControlsBackground component.
Definition wavetable_component_overlay.h:52
void clearLines()
Clears all line divider positions.
Definition wavetable_component_overlay.h:77
A listener interface for receiving changes to the wavetable overlay.
Definition wavetable_component_overlay.h:118
virtual void frameDoneEditing()=0
Called when the user has finished editing the current frame.
virtual void frameChanged()=0
Called when the current frame is changed or updated.
virtual ~Listener()
Definition wavetable_component_overlay.h:120
A base overlay component for editing and interacting with a wavetable component's parameters.
Definition wavetable_component_overlay.h:22
virtual bool setFrequencyAmplitudeBounds(Rectangle< int > bounds)
Optionally set bounds for frequency-amplitude editing UI.
Definition wavetable_component_overlay.h:181
int getWidgetPadding()
Gets the widget padding.
Definition wavetable_component_overlay.cpp:109
void addFrameListener(Listener *listener)
Adds a listener for frame changes.
Definition wavetable_component_overlay.h:214
void setControlsWidth(int width)
Sets the total width for controls in the overlay.
Definition wavetable_component_overlay.h:267
void setComponent(WavetableComponent *component)
Sets the WavetableComponent that this overlay is editing.
Definition wavetable_component_overlay.cpp:81
static constexpr float kWidgetHeightForWidth
Definition wavetable_component_overlay.h:29
WavetableComponentOverlay(String name)
Constructs a WavetableComponentOverlay.
Definition wavetable_component_overlay.h:139
ControlsBackground controls_background_
Definition wavetable_component_overlay.h:300
virtual void setEditBounds(Rectangle< int > bounds)
Sets the editing bounds within which controls and titles are placed.
Definition wavetable_component_overlay.cpp:67
WavetableComponentOverlay()=delete
Deleted default constructor.
static constexpr float kShadowPercent
Definition wavetable_component_overlay.h:30
void setPadding(int padding)
Sets padding around controls and triggers a repaint.
Definition wavetable_component_overlay.h:242
void resetOverlay()
Resets the overlay, clearing any associated component.
Definition wavetable_component_overlay.cpp:76
std::vector< Listener * > listeners_
Definition wavetable_component_overlay.h:301
bool initialized_
Definition wavetable_component_overlay.h:304
static constexpr float kTitleHeightRatio
Definition wavetable_component_overlay.h:32
int getPadding()
Gets the current padding value.
Definition wavetable_component_overlay.h:248
static constexpr float kTitleHeightForWidth
Ratio constants for layout and sizing.
Definition wavetable_component_overlay.h:28
int getDividerX()
Gets the x position of a divider line.
Definition wavetable_component_overlay.cpp:101
Rectangle< int > edit_bounds_
Definition wavetable_component_overlay.h:302
static constexpr float kDividerPoint
Definition wavetable_component_overlay.h:31
void paintBackground(Graphics &g) override
Custom paint method for background.
Definition wavetable_component_overlay.h:155
static constexpr int kMaxGrid
Maximum grid lines used by some overlays.
Definition wavetable_component_overlay.h:25
float getTitleHeight()
Gets the title height based on ratio and current edit bounds.
Definition wavetable_component_overlay.cpp:97
virtual void setPowerScale(bool scale)
Sets whether to scale values like frequency display (optional override).
Definition wavetable_component_overlay.h:230
void initOpenGlComponents(OpenGlWrapper &open_gl) override
Initializes OpenGL components.
Definition wavetable_component_overlay.h:199
int getWidgetHeight()
Gets the widget height for controls.
Definition wavetable_component_overlay.cpp:105
bool initialized()
Checks if the overlay has been initialized.
Definition wavetable_component_overlay.h:208
WavetableComponent * current_component_
Definition wavetable_component_overlay.h:299
virtual void setFrequencyZoom(float zoom)
Sets the frequency zoom factor (optional override).
Definition wavetable_component_overlay.h:236
WavetableComponent * getComponent()
Gets the currently associated WavetableComponent.
Definition wavetable_component_overlay.h:260
int controls_width_
Definition wavetable_component_overlay.h:303
void removeListener(Listener *listener)
Removes a frame listener.
Definition wavetable_component_overlay.h:222
virtual bool setTimeDomainBounds(Rectangle< int > bounds)
Optionally set bounds for time-domain editing UI.
Definition wavetable_component_overlay.h:174
void notifyChanged(bool mouse_up)
Notifies listeners that a change has occurred to the frame.
Definition wavetable_component_overlay.cpp:86
int padding_
Definition wavetable_component_overlay.h:305
virtual bool setPhaseBounds(Rectangle< int > bounds)
Optionally set bounds for phase editing UI.
Definition wavetable_component_overlay.h:188
void playheadMoved(int position) override
Called when the wavetable playhead moves, but default does nothing.
Definition wavetable_component_overlay.h:161
Interface for objects that need to respond to organizer events.
Definition wavetable_organizer.h:109
A listener interface for objects interested in playhead position changes.
Definition wavetable_playhead.h:31
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174