Vital
Loading...
Searching...
No Matches
wave_warp_overlay.cpp
Go to the documentation of this file.
1#include "wave_warp_overlay.h"
2
3#include "skin.h"
4#include "wave_frame.h"
6
7WaveWarpOverlay::WaveWarpOverlay() : WavetableComponentOverlay("WAVE WARPER"), warp_modifier_(nullptr) {
8 current_frame_ = nullptr;
9
10 // Initialize horizontal warp slider
11 horizontal_warp_ = std::make_unique<SynthSlider>("wave_warp_horizontal");
13 horizontal_warp_->getImageComponent()->setAlwaysOnTop(true);
14 horizontal_warp_->setAlwaysOnTop(true);
15 horizontal_warp_->addListener(this);
16 horizontal_warp_->setRange(-20.0f, 20.0f);
17 horizontal_warp_->setDoubleClickReturnValue(true, 0.0f);
19 horizontal_warp_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
20
21 // Initialize vertical warp slider
22 vertical_warp_ = std::make_unique<SynthSlider>("wave_warp_vertical");
24 vertical_warp_->getImageComponent()->setAlwaysOnTop(true);
25 vertical_warp_->setAlwaysOnTop(true);
26 vertical_warp_->addListener(this);
27 vertical_warp_->setRange(-20.0f, 20.0f);
28 vertical_warp_->setDoubleClickReturnValue(true, 0.0f);
30 vertical_warp_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
31
32 // Initialize horizontal asymmetry toggle
33 horizontal_asymmetric_ = std::make_unique<OpenGlToggleButton>("X Asymmetric");
34 addAndMakeVisible(horizontal_asymmetric_.get());
36 horizontal_asymmetric_->getGlComponent()->setAlwaysOnTop(true);
37 horizontal_asymmetric_->setAlwaysOnTop(true);
38 horizontal_asymmetric_->setNoBackground();
40 horizontal_asymmetric_->addListener(this);
41
42 // Initialize vertical asymmetry toggle
43 vertical_asymmetric_ = std::make_unique<OpenGlToggleButton>("Y Asymmetric");
44 addAndMakeVisible(vertical_asymmetric_.get());
46 vertical_asymmetric_->getGlComponent()->setAlwaysOnTop(true);
47 vertical_asymmetric_->setAlwaysOnTop(true);
48 vertical_asymmetric_->setNoBackground();
50 vertical_asymmetric_->addListener(this);
51
52 // Set the controls layout titles
58}
59
61 if (keyframe == nullptr) {
62 // No keyframe selected
63 current_frame_ = nullptr;
64 }
65 else if (keyframe->owner() == warp_modifier_) {
66 // Keyframe belongs to the WarpModifier
68 horizontal_warp_->setValue(current_frame_->getHorizontalPower(), dontSendNotification);
69 vertical_warp_->setValue(current_frame_->getVerticalPower(), dontSendNotification);
70 horizontal_warp_->redoImage();
71 vertical_warp_->redoImage();
72
73 horizontal_asymmetric_->setToggleState(warp_modifier_->getHorizontalAsymmetric(), dontSendNotification);
74 vertical_asymmetric_->setToggleState(warp_modifier_->getVerticalAsymmetric(), dontSendNotification);
75 }
76}
77
78void WaveWarpOverlay::setEditBounds(Rectangle<int> bounds) {
79 // Calculate sizes based on constants
80 static constexpr float kSymmetryWidthHeightRatio = 3.5f;
81 static constexpr float kWarpWidthHeightRatio = 5.0f;
82 static constexpr float kWarpPaddingRatio = 0.5f;
83
84 int padding = getPadding();
85 int symmetry_width = bounds.getHeight() * kSymmetryWidthHeightRatio;
86 int warp_width = bounds.getHeight() * kWarpWidthHeightRatio;
87 int warp_padding = bounds.getHeight() * kWarpPaddingRatio;
88 int total_width = 2 * symmetry_width + 2 * warp_width + 3 * padding;
89 setControlsWidth(total_width);
91
92 int x = bounds.getX() + (bounds.getWidth() - total_width) / 2;
93 int title_height = WavetableComponentOverlay::kTitleHeightRatio * bounds.getHeight();
94 int y = bounds.getY();
95 int y_title = y + title_height;
96 int height = bounds.getHeight();
97 int height_title = height - title_height;
98 int symmetry_padding = height / 6.0f;
99
100 // Set positions of the toggles and sliders
101 horizontal_asymmetric_->setBounds(x, y + symmetry_padding, symmetry_width, height - 2 * symmetry_padding);
102 horizontal_warp_->setBounds(horizontal_asymmetric_->getRight() + padding + warp_padding, y_title,
103 warp_width - 2 * warp_padding, height_title);
104 vertical_asymmetric_->setBounds(horizontal_warp_->getRight() + padding + warp_padding, y + symmetry_padding,
105 symmetry_width, height - 2 * symmetry_padding);
106 vertical_warp_->setBounds(vertical_asymmetric_->getRight() + padding + warp_padding, y_title,
107 warp_width - 2 * warp_padding, height_title);
108
109 // Set line separators for the background layout
111 controls_background_.addLine(symmetry_width);
112 controls_background_.addLine(symmetry_width + warp_width + padding);
113 controls_background_.addLine(2 * symmetry_width + warp_width + 2 * padding);
114 controls_background_.addLine(2 * symmetry_width + 2 * warp_width + 3 * padding);
115
116 horizontal_warp_->redoImage();
117 vertical_warp_->redoImage();
118}
119
120void WaveWarpOverlay::sliderValueChanged(Slider* moved_slider) {
121 if (warp_modifier_ == nullptr || current_frame_ == nullptr)
122 return;
123
124 // Update current frame's warp parameters
125 if (moved_slider == horizontal_warp_.get()) {
126 float value = horizontal_warp_->getValue();
128 }
129 else if (moved_slider == vertical_warp_.get()) {
130 float value = vertical_warp_->getValue();
132 }
133
134 notifyChanged(false);
135}
136
137void WaveWarpOverlay::sliderDragEnded(Slider* moved_slider) {
138 notifyChanged(true);
139}
140
141void WaveWarpOverlay::buttonClicked(Button* clicked_button) {
142 if (warp_modifier_ == nullptr)
143 return;
144
145 // Toggle asymmetric flags
146 if (clicked_button == horizontal_asymmetric_.get()) {
148 notifyChanged(true);
149 }
150 else if (clicked_button == vertical_asymmetric_.get()) {
152 notifyChanged(true);
153 }
154}
void addSlider(SynthSlider *slider, bool show=true, bool listen=true)
Definition synth_section.cpp:445
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
static TextLookAndFeel * instance()
Singleton instance access.
Definition text_look_and_feel.h:106
float getVerticalPower()
Gets the vertical warp power.
Definition wave_warp_modifier.h:62
void setHorizontalPower(float horizontal_power)
Sets the horizontal warp power.
Definition wave_warp_modifier.h:69
void setVerticalPower(float vertical_power)
Sets the vertical warp power.
Definition wave_warp_modifier.h:76
float getHorizontalPower()
Gets the horizontal warp power.
Definition wave_warp_modifier.h:55
void setVerticalAsymmetric(bool vertical_asymmetric)
Sets whether vertical warping is asymmetric.
Definition wave_warp_modifier.h:128
bool getHorizontalAsymmetric() const
Checks if horizontal warping is asymmetric.
Definition wave_warp_modifier.h:135
bool getVerticalAsymmetric() const
Checks if vertical warping is asymmetric.
Definition wave_warp_modifier.h:142
void setHorizontalAsymmetric(bool horizontal_asymmetric)
Sets whether horizontal warping is asymmetric.
Definition wave_warp_modifier.h:121
WaveWarpModifierKeyframe * getKeyframe(int index)
Retrieves a WaveWarpModifierKeyframe by index.
Definition wave_warp_modifier.cpp:139
std::unique_ptr< SynthSlider > horizontal_warp_
Slider controlling horizontal warp amount.
Definition wave_warp_overlay.h:94
WaveWarpModifier::WaveWarpModifierKeyframe * current_frame_
Currently selected keyframe's data.
Definition wave_warp_overlay.h:92
std::unique_ptr< OpenGlToggleButton > horizontal_asymmetric_
Toggle for horizontal asymmetry.
Definition wave_warp_overlay.h:96
virtual void setEditBounds(Rectangle< int > bounds) override
Sets the bounds for the overlay's editable UI area.
Definition wave_warp_overlay.cpp:78
virtual void frameSelected(WavetableKeyframe *keyframe) override
Called when a new keyframe is selected.
Definition wave_warp_overlay.cpp:60
void sliderDragEnded(Slider *moved_slider) override
Called when a slider drag ends.
Definition wave_warp_overlay.cpp:137
void buttonClicked(Button *clicked_Button) override
Called when a button (toggle) state changes.
Definition wave_warp_overlay.cpp:141
WaveWarpOverlay()
Constructs a WaveWarpOverlay with default parameters and UI elements.
Definition wave_warp_overlay.cpp:7
WaveWarpModifier * warp_modifier_
The WaveWarpModifier being controlled by this overlay.
Definition wave_warp_overlay.h:91
std::unique_ptr< SynthSlider > vertical_warp_
Slider controlling vertical warp amount.
Definition wave_warp_overlay.h:95
void sliderValueChanged(Slider *moved_slider) override
Called when a slider value changes.
Definition wave_warp_overlay.cpp:120
std::unique_ptr< OpenGlToggleButton > vertical_asymmetric_
Toggle for vertical asymmetry.
Definition wave_warp_overlay.h:97
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
void clearLines()
Clears all line divider positions.
Definition wavetable_component_overlay.h:77
A base overlay component for editing and interacting with a wavetable component's parameters.
Definition wavetable_component_overlay.h:22
void setControlsWidth(int width)
Sets the total width for controls in the overlay.
Definition wavetable_component_overlay.h:267
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
static constexpr float kTitleHeightRatio
Definition wavetable_component_overlay.h:32
int getPadding()
Gets the current padding value.
Definition wavetable_component_overlay.h:248
void notifyChanged(bool mouse_up)
Notifies listeners that a change has occurred to the frame.
Definition wavetable_component_overlay.cpp:86
Represents a single state of a waveform at a specific position in a wavetable.
Definition wavetable_keyframe.h:35
int index()
Gets the index of this keyframe within its owner component.
Definition wavetable_keyframe.cpp:32
WavetableComponent * owner()
Gets the WavetableComponent that owns this keyframe.
Definition wavetable_keyframe.h:152