Vital
Loading...
Searching...
No Matches
wave_line_source_overlay.cpp
Go to the documentation of this file.
2
3#include "skin.h"
5#include "wave_frame.h"
7
9 static constexpr int kWaveformSize = vital::WaveFrame::kWaveformSize;
10
11 current_frame_ = nullptr;
12
13 // Create a default line generator and associated line editor
14 default_line_generator_ = std::make_unique<LineGenerator>(kWaveformSize);
15 editor_ = std::make_unique<LineEditor>(default_line_generator_.get());
16 editor_->setGridSizeX(kDefaultXGrid);
17 editor_->setGridSizeY(kDefaultYGrid);
18 editor_->addListener(this);
20 addOpenGlComponent(editor_->getTextEditorComponent());
21 editor_->setVisible(false);
22 editor_->setFill(true);
23 editor_->setFillCenter(0.0f);
24 editor_->setAllowFileLoading(false);
25
26 // Pull power slider
27 pull_power_ = std::make_unique<SynthSlider>("wave_line_source_pull_power");
28 pull_power_->setValue(0.0f, dontSendNotification);
30 pull_power_->setAlwaysOnTop(true);
31 pull_power_->getImageComponent()->setAlwaysOnTop(true);
32 pull_power_->addListener(this);
33 pull_power_->setRange(0, 5.0f);
34 pull_power_->setDoubleClickReturnValue(true, 0.0f);
35 pull_power_->setLookAndFeel(TextLookAndFeel::instance());
36 pull_power_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
37
38 // Horizontal grid size slider and incrementers
39 horizontal_grid_ = std::make_unique<SynthSlider>("wave_line_source_horizontal_grid");
40 horizontal_grid_->setValue(kDefaultXGrid, dontSendNotification);
42 horizontal_grid_->setAlwaysOnTop(true);
43 horizontal_grid_->getImageComponent()->setAlwaysOnTop(true);
44 horizontal_grid_->addListener(this);
45 horizontal_grid_->setRange(0, kMaxGrid, 1);
46 horizontal_grid_->setDoubleClickReturnValue(true, kDefaultXGrid);
48 horizontal_grid_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
49
50 horizontal_incrementers_ = std::make_unique<IncrementerButtons>(horizontal_grid_.get());
51 addAndMakeVisible(horizontal_incrementers_.get());
52
53 // Vertical grid size slider and incrementers
54 vertical_grid_ = std::make_unique<SynthSlider>("wave_line_source_vertical_grid");
55 vertical_grid_->setValue(kDefaultYGrid, dontSendNotification);
57 vertical_grid_->setAlwaysOnTop(true);
58 vertical_grid_->getImageComponent()->setAlwaysOnTop(true);
59 vertical_grid_->addListener(this);
60 vertical_grid_->setRange(0, kMaxGrid, 1);
61 vertical_grid_->setDoubleClickReturnValue(true, kDefaultYGrid);
63 vertical_grid_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
64
65 vertical_incrementers_ = std::make_unique<IncrementerButtons>(vertical_grid_.get());
66 addAndMakeVisible(vertical_incrementers_.get());
67
68 // Prepare background titles
70 controls_background_.addTitle("PULL POWER");
73}
74
76
78 editor_->setColor(findColour(Skin::kWidgetPrimary1, true));
79 Colour fill_color = findColour(Skin::kWidgetSecondary1, true);
80 Colour fill_color2 = fill_color.withMultipliedAlpha(1.0f - findValue(Skin::kWidgetFillFade));
81 editor_->setFillColors(fill_color2, fill_color);
82 editor_->setLineWidth(4.0f);
83}
84
86 if (keyframe == nullptr) {
87 editor_->setVisible(false);
88 editor_->setModel(default_line_generator_.get());
89 current_frame_ = nullptr;
90 pull_power_->setValue(0.0f, dontSendNotification);
91 pull_power_->setEnabled(false);
92 pull_power_->redoImage();
93 }
94 else if (keyframe->owner() == line_source_) {
95 editor_->setVisible(true);
98 pull_power_->setValue(current_frame_->getPullPower(), dontSendNotification);
99 pull_power_->setEnabled(true);
100 pull_power_->redoImage();
101 }
102}
103
104void WaveLineSourceOverlay::setEditBounds(Rectangle<int> bounds) {
105 static constexpr float kPullPowerWidthHeightRatio = 2.0f;
106 static constexpr float kGridWidthHeightRatio = 2.0f;
107
108 int padding = getPadding();
109 int pull_power_width = bounds.getHeight() * kPullPowerWidthHeightRatio;
110 int grid_width = bounds.getHeight() * kGridWidthHeightRatio;
111 int total_width = pull_power_width + 2 * grid_width + 2 * padding;
112 setControlsWidth(total_width);
114
115 int x = bounds.getX() + (bounds.getWidth() - total_width) / 2;
116 int title_height = WavetableComponentOverlay::kTitleHeightRatio * bounds.getHeight();
117 int y = bounds.getY() + title_height;
118 int height = bounds.getHeight() - title_height;
119 pull_power_->setBounds(x, y, pull_power_width, height);
120 horizontal_grid_->setBounds(pull_power_->getRight() + padding, y, grid_width, height);
121 vertical_grid_->setBounds(horizontal_grid_->getRight() + padding, y, grid_width, height);
122
123 horizontal_incrementers_->setBounds(horizontal_grid_->getRight() - height, y, height, height);
124 vertical_incrementers_->setBounds(vertical_grid_->getRight() - height, y, height, height);
125
127 controls_background_.addLine(pull_power_width);
128 controls_background_.addLine(pull_power_width + grid_width + padding);
129 controls_background_.addLine(pull_power_width + 2 * (grid_width + padding));
130
131 pull_power_->redoImage();
132 vertical_grid_->redoImage();
133 horizontal_grid_->redoImage();
134}
135
137 editor_->setBounds(bounds);
138 return true;
139}
140
141void WaveLineSourceOverlay::lineEditorScrolled(const MouseEvent& e, const MouseWheelDetails& wheel) {
142 // Scroll modifies horizontal grid size
143 if (wheel.deltaY > 0)
144 horizontal_grid_->setValue(horizontal_grid_->getValue() + 1);
145 else
146 horizontal_grid_->setValue(horizontal_grid_->getValue() - 1);
147}
148
150 // Not implemented
151}
152
153void WaveLineSourceOverlay::pointChanged(int index, Point<float> position, bool mouse_up) {
154 if (current_frame_ == nullptr)
155 return;
156
157 notifyChanged(mouse_up);
158}
159
161 if (current_frame_ == nullptr)
162 return;
163
164 notifyChanged(mouse_up);
165}
166
167void WaveLineSourceOverlay::pointAdded(int index, Point<float> position) {
168 if (line_source_ == nullptr || current_frame_ == nullptr)
169 return;
170
171 int num_points = current_frame_->getNumPoints();
172 line_source_->setNumPoints(num_points);
173 int num_keyframes = line_source_->numFrames();
174 for (int i = 0; i < num_keyframes; ++i) {
176 if (keyframe != current_frame_)
177 keyframe->addMiddlePoint(std::min(index, keyframe->getNumPoints() - 1));
178
179 VITAL_ASSERT(keyframe->getNumPoints() == num_points);
180 }
181
182 notifyChanged(true);
183}
184
185void WaveLineSourceOverlay::pointsAdded(int index, int num_points_added) {
186 if (line_source_ == nullptr)
187 return;
188
189 int num_points = current_frame_->getNumPoints();
190 line_source_->setNumPoints(num_points);
191 int num_keyframes = line_source_->numFrames();
192 for (int i = 0; i < num_keyframes; ++i) {
194
195 if (keyframe != current_frame_) {
196 for (int p = 0; p < num_points_added; ++p)
197 keyframe->addMiddlePoint(index + p);
198 }
199
200 VITAL_ASSERT(keyframe->getNumPoints() == num_points);
201 }
202 notifyChanged(true);
203}
204
206 if (line_source_ == nullptr)
207 return;
208
209 int num_points = current_frame_->getNumPoints();
210 line_source_->setNumPoints(num_points);
211 int num_keyframes = line_source_->numFrames();
212 for (int i = 0; i < num_keyframes; ++i) {
214 if (keyframe != current_frame_)
215 keyframe->removePoint(index);
216
217 VITAL_ASSERT(keyframe->getNumPoints() == num_points);
218 }
219 notifyChanged(true);
220}
221
222void WaveLineSourceOverlay::pointsRemoved(int index, int num_points_removed) {
223 if (line_source_ == nullptr)
224 return;
225
226 int num_points = current_frame_->getNumPoints();
227 line_source_->setNumPoints(num_points);
228 int num_keyframes = line_source_->numFrames();
229 for (int i = 0; i < num_keyframes; ++i) {
231
232 if (keyframe != current_frame_) {
233 for (int p = 0; p < num_points_removed; ++p)
234 keyframe->removePoint(index);
235 }
236
237 VITAL_ASSERT(keyframe->getNumPoints() == num_points);
238 }
239 notifyChanged(true);
240}
241
243 if (line_source_ == nullptr)
244 return;
245
246 if (moved_slider == horizontal_grid_.get())
247 editor_->setGridSizeX(horizontal_grid_->getValue());
248 else if (moved_slider == vertical_grid_.get())
249 editor_->setGridSizeY(vertical_grid_->getValue());
250 else if (moved_slider == pull_power_.get()) {
251 if (current_frame_)
253 }
254
255 notifyChanged(false);
256}
257
258void WaveLineSourceOverlay::sliderDragEnded(Slider* moved_slider) {
259 if (moved_slider != horizontal_grid_.get() && moved_slider != vertical_grid_.get())
260 notifyChanged(true);
261}
@ 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
A keyframe class that represents a particular line-based waveform configuration at a given position.
Definition wave_line_source.h:36
int getNumPoints() const
Gets the number of points defining the line.
Definition wave_line_source.h:104
const LineGenerator * getLineGenerator() const
Provides const access to the underlying LineGenerator.
Definition wave_line_source.h:134
float getPullPower() const
Gets the current pull power value.
Definition wave_line_source.h:127
void removePoint(int index)
Removes a point from the line definition.
Definition wave_line_source.h:90
void addMiddlePoint(int index)
Inserts a middle point between two existing points.
Definition wave_line_source.h:97
void setPullPower(float power)
Sets the pull power, which influences how interpolation occurs between keyframes.
Definition wave_line_source.h:120
WaveLineSourceKeyframe * getKeyframe(int index)
Retrieves a WaveLineSourceKeyframe by index.
Definition wave_line_source.cpp:116
void setNumPoints(int num_points)
Sets the number of points used by the line generator.
Definition wave_line_source.cpp:112
void lineEditorScrolled(const MouseEvent &e, const MouseWheelDetails &wheel) override
Called when the line editor is scrolled.
Definition wave_line_source_overlay.cpp:141
static constexpr int kDefaultXGrid
Default horizontal grid size.
Definition wave_line_source_overlay.h:20
std::unique_ptr< SynthSlider > vertical_grid_
Control for vertical grid size.
Definition wave_line_source_overlay.h:188
std::unique_ptr< LineEditor > editor_
Line editor for modifying line source points.
Definition wave_line_source_overlay.h:184
std::unique_ptr< SynthSlider > horizontal_grid_
Control for horizontal grid size.
Definition wave_line_source_overlay.h:187
std::unique_ptr< LineGenerator > default_line_generator_
Default line generator model.
Definition wave_line_source_overlay.h:183
void powersChanged(bool mouse_up) override
Callback when line powers/curvature change.
Definition wave_line_source_overlay.cpp:160
std::unique_ptr< SynthSlider > pull_power_
Control for pull power parameter.
Definition wave_line_source_overlay.h:186
WaveLineSource * line_source_
The associated WaveLineSource.
Definition wave_line_source_overlay.h:180
std::unique_ptr< Component > vertical_incrementers_
Incrementer buttons for vertical grid slider.
Definition wave_line_source_overlay.h:191
WaveLineSourceOverlay()
Constructor.
Definition wave_line_source_overlay.cpp:8
void sliderValueChanged(Slider *moved_slider) override
Called when a slider in this overlay changes its value.
Definition wave_line_source_overlay.cpp:242
virtual void setEditBounds(Rectangle< int > bounds) override
Sets the editing bounds for the UI controls.
Definition wave_line_source_overlay.cpp:104
void sliderDragEnded(Slider *moved_slider) override
Called when a slider in this overlay finishes being dragged.
Definition wave_line_source_overlay.cpp:258
void pointsRemoved(int index, int num_points_removed) override
Callback when multiple points are removed.
Definition wave_line_source_overlay.cpp:222
void pointAdded(int index, Point< float > position) override
Callback when a line point is added.
Definition wave_line_source_overlay.cpp:167
std::unique_ptr< Component > horizontal_incrementers_
Incrementer buttons for horizontal grid slider.
Definition wave_line_source_overlay.h:190
virtual bool setTimeDomainBounds(Rectangle< int > bounds) override
Sets the bounding box for the time domain display area (line editor).
Definition wave_line_source_overlay.cpp:136
void pointsAdded(int index, int num_points_added) override
Callback when multiple points are added.
Definition wave_line_source_overlay.cpp:185
static constexpr int kDefaultYGrid
Default vertical grid size.
Definition wave_line_source_overlay.h:21
void pointChanged(int index, Point< float > position, bool mouse_up) override
Callback when a line point changes its position.
Definition wave_line_source_overlay.cpp:153
virtual void frameSelected(WavetableKeyframe *keyframe) override
Called when a new frame is selected in the wavetable editor.
Definition wave_line_source_overlay.cpp:85
void fileLoaded() override
Callback for file loading completion (not used here).
Definition wave_line_source_overlay.cpp:149
virtual ~WaveLineSourceOverlay()
Destructor.
Definition wave_line_source_overlay.cpp:75
WaveLineSource::WaveLineSourceKeyframe * current_frame_
Currently selected frame data.
Definition wave_line_source_overlay.h:181
void pointRemoved(int index) override
Callback when a point is removed.
Definition wave_line_source_overlay.cpp:205
void resized() override
Called when the overlay is resized.
Definition wave_line_source_overlay.cpp:77
int numFrames() const
Gets the number of keyframes.
Definition wavetable_component.h:155
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
static constexpr int kMaxGrid
Maximum grid lines used by some overlays.
Definition wavetable_component_overlay.h:25
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
static constexpr int kWaveformSize
The size of the waveform (number of samples per frame).
Definition wave_frame.h:21
#define VITAL_ASSERT(x)
Definition common.h:11