Vital
Loading...
Searching...
No Matches
wave_window_overlay.cpp
Go to the documentation of this file.
2
3#include "skin.h"
4#include "wave_frame.h"
6#include "text_selector.h"
7
8namespace {
9 // Lookup table for window shape names.
10 const std::string kWindowShapeLookup[WaveWindowModifier::kNumWindowShapes] = {
11 "Raised Cos",
12 "Half Sin",
13 "Linear",
14 "Square",
15 "Wiggle"
16 };
17} // namespace
18
19WaveWindowOverlay::WaveWindowOverlay() : WavetableComponentOverlay("WAVE WINDOW"), wave_window_modifier_(nullptr) {
20 editor_ = std::make_unique<WaveWindowEditor>();
21 addAndMakeVisible(editor_.get());
23 editor_->setAlwaysOnTop(true);
24 editor_->setFit(true);
25 editor_->setFill(true);
26 editor_->addListener(this);
27 editor_->setVisible(false); // Only visible when a frame is selected.
28 current_frame_ = nullptr;
29
30 // Initialize the window shape selector.
31 window_shape_ = std::make_unique<TextSelector>("Window Shape");
33 window_shape_->setAlwaysOnTop(true);
34 window_shape_->getImageComponent()->setAlwaysOnTop(true);
36 window_shape_->setLongStringLookup(kWindowShapeLookup);
37 window_shape_->setStringLookup(kWindowShapeLookup);
38 window_shape_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
40 window_shape_->addListener(this);
41
42 // Initialize the left and right position sliders.
43 left_position_ = std::make_unique<SynthSlider>("Left Position");
45 left_position_->setAlwaysOnTop(true);
46 left_position_->getQuadComponent()->setAlwaysOnTop(true);
47 left_position_->setRange(0.0, 1.0);
48 left_position_->setDoubleClickReturnValue(true, 0.0);
49 left_position_->addListener(this);
50 left_position_->setSliderStyle(Slider::LinearBar);
51
52 right_position_ = std::make_unique<SynthSlider>("Right Position");
54 right_position_->setAlwaysOnTop(true);
55 right_position_->getQuadComponent()->setAlwaysOnTop(true);
56 right_position_->setRange(0.0, 1.0);
57 right_position_->setDoubleClickReturnValue(true, 1.0);
58 right_position_->addListener(this);
59 right_position_->setSliderStyle(Slider::LinearBar);
60
61 // Set up control background titles.
64 controls_background_.addTitle("LEFT POSITION");
65 controls_background_.addTitle("RIGHT POSITION");
66}
67
69 if (keyframe == nullptr) {
70 // No keyframe selected: hide editor and reset current frame.
71 editor_->setVisible(false);
72 current_frame_ = nullptr;
73 }
74 else if (keyframe->owner() == wave_window_modifier_) {
75 // Keyframe belongs to the WaveWindowModifier.
76 editor_->setVisible(true);
78 float left = current_frame_->getLeft();
79 float right = current_frame_->getRight();
80 editor_->setPositions(left, right);
81 left_position_->setValue(left, dontSendNotification);
82 right_position_->setValue(right, dontSendNotification);
83 left_position_->redoImage();
84 right_position_->redoImage();
85 }
86}
87
88void WaveWindowOverlay::setEditBounds(Rectangle<int> bounds) {
89 static constexpr float kWaveShapeWidthHeightRatio = 5.0f;
90 static constexpr float kPositionPaddingRatio = 0.5f;
91 static constexpr float kPositionWidthHeightRatio = 5.0f;
92
93 // Configure line and fill colors.
94 Colour line_color = findColour(Skin::kWidgetPrimary1, true);
95 Colour fill_color = findColour(Skin::kWidgetSecondary1, true).withMultipliedAlpha(0.5f);
96 editor_->setColor(line_color);
97 editor_->setFillColors(fill_color.withMultipliedAlpha(1.0f - findValue(Skin::kWidgetFillFade)), fill_color);
98
99 int padding = getPadding();
100 int window_shape_width = bounds.getHeight() * kWaveShapeWidthHeightRatio;
101 int position_width = bounds.getHeight() * kPositionWidthHeightRatio;
102 int position_padding = bounds.getHeight() * kPositionPaddingRatio;
103 int total_width = window_shape_width + 2 * position_width + 2 * padding;
104 setControlsWidth(total_width);
106
107 int x = bounds.getX() + (bounds.getWidth() - total_width) / 2;
108 int title_height = WavetableComponentOverlay::kTitleHeightRatio * bounds.getHeight();
109 int y = bounds.getY();
110 int y_title = y + title_height;
111 int height = bounds.getHeight();
112 int height_title = height - title_height;
113 window_shape_->setBounds(x, y, window_shape_width, height);
114 window_shape_->setTextHeightPercentage(0.4f);
115 left_position_->setBounds(window_shape_->getRight() + padding + position_padding, y_title,
116 position_width - 2 * position_padding, height_title);
117 right_position_->setBounds(left_position_->getRight() + padding + 2 * position_padding, y_title,
118 position_width - 2 * position_padding, height_title);
119
121 controls_background_.addLine(window_shape_width);
122 controls_background_.addLine(window_shape_width + position_width + padding);
123
124 window_shape_->redoImage();
125 left_position_->redoImage();
126 right_position_->redoImage();
127}
128
129bool WaveWindowOverlay::setTimeDomainBounds(Rectangle<int> bounds) {
130 editor_->setBounds(bounds);
131 return true;
132}
133
134void WaveWindowOverlay::windowChanged(bool left, bool mouse_up) {
135 if (current_frame_ == nullptr)
136 return;
137
138 current_frame_->setLeft(editor_->getLeftPosition());
139 current_frame_->setRight(editor_->getRightPosition());
140 left_position_->setValue(editor_->getLeftPosition(), sendNotificationSync);
141 right_position_->setValue(editor_->getRightPosition(), sendNotificationSync);
142 notifyChanged(mouse_up);
143}
144
145void WaveWindowOverlay::sliderValueChanged(Slider* moved_slider) {
146 if (wave_window_modifier_ == nullptr || current_frame_ == nullptr)
147 return;
148
149 if (moved_slider == window_shape_.get()) {
150 int value = static_cast<int>(window_shape_->getValue());
151 WaveWindowModifier::WindowShape window_shape = static_cast<WaveWindowModifier::WindowShape>(value);
152 editor_->setWindowShape(window_shape);
154 notifyChanged(true);
155 }
156 else if (moved_slider == left_position_.get()) {
157 float value = std::min(left_position_->getValue(), right_position_->getValue());
158 left_position_->setValue(value, dontSendNotification);
159 current_frame_->setLeft(value);
160 editor_->setPositions(value, right_position_->getValue());
161 notifyChanged(false);
162 }
163 else if (moved_slider == right_position_.get()) {
164 float value = std::max(right_position_->getValue(), left_position_->getValue());
165 right_position_->setValue(value, dontSendNotification);
166 current_frame_->setRight(value);
167 editor_->setPositions(left_position_->getValue(), value);
168 notifyChanged(false);
169 }
170}
171
172void WaveWindowOverlay::sliderDragEnded(Slider* moved_slider) {
173 notifyChanged(true);
174}
@ kWidgetFillFade
Definition skin.h:108
@ kWidgetPrimary1
Definition skin.h:165
@ kWidgetSecondary1
Definition skin.h:168
void addSlider(SynthSlider *slider, bool show=true, bool listen=true)
Definition synth_section.cpp:445
float findValue(Skin::ValueId value_id) const
Finds a value in the skin overrides or from the parent if not found locally.
Definition synth_section.cpp:18
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
void setRight(float right)
Sets the right position of the window (0 to 1).
Definition wave_window_modifier.h:82
float getLeft()
Gets the left window position.
Definition wave_window_modifier.h:89
void setLeft(float left)
Sets the left position of the window (0 to 1).
Definition wave_window_modifier.h:73
float getRight()
Gets the right window position.
Definition wave_window_modifier.h:96
WaveWindowModifierKeyframe * getKeyframe(int index)
Retrieves a WaveWindowModifierKeyframe by index.
Definition wave_window_modifier.cpp:112
WindowShape
Defines different windowing curves.
Definition wave_window_modifier.h:25
@ kNumWindowShapes
Definition wave_window_modifier.h:31
void setWindowShape(WindowShape window_shape)
Sets the window shape used by this modifier.
Definition wave_window_modifier.h:146
std::unique_ptr< SynthSlider > left_position_
Slider for the left window position.
Definition wave_window_overlay.h:108
std::unique_ptr< WaveWindowEditor > editor_
Editor for adjusting the window parameters.
Definition wave_window_overlay.h:106
void sliderDragEnded(Slider *moved_slider) override
Called when a slider drag operation ends.
Definition wave_window_overlay.cpp:172
void sliderValueChanged(Slider *moved_slider) override
Called when a slider's value changes.
Definition wave_window_overlay.cpp:145
virtual void setEditBounds(Rectangle< int > bounds) override
Sets the edit bounds for the controls in this overlay.
Definition wave_window_overlay.cpp:88
WaveWindowModifier::WaveWindowModifierKeyframe * current_frame_
The currently active keyframe.
Definition wave_window_overlay.h:105
WaveWindowModifier * wave_window_modifier_
The associated WaveWindowModifier.
Definition wave_window_overlay.h:104
void windowChanged(bool left, bool mouse_up) override
Called when the window editor notifies a window change.
Definition wave_window_overlay.cpp:134
std::unique_ptr< SynthSlider > right_position_
Slider for the right window position.
Definition wave_window_overlay.h:109
virtual bool setTimeDomainBounds(Rectangle< int > bounds) override
Sets the time domain editor's bounds.
Definition wave_window_overlay.cpp:129
virtual void frameSelected(WavetableKeyframe *keyframe) override
Called when a new keyframe is selected.
Definition wave_window_overlay.cpp:68
WaveWindowOverlay()
Constructs a WaveWindowOverlay with default UI elements.
Definition wave_window_overlay.cpp:19
std::unique_ptr< TextSelector > window_shape_
Selector for window shape type.
Definition wave_window_overlay.h:107
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
Declares the TextSelector class and PaintPatternSelector class for selecting text-based options and d...