Vital
Loading...
Searching...
No Matches
wave_source_editor.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4
9#include "common.h"
10
21 public:
26 class Listener {
27 public:
28 virtual ~Listener() { }
29
37 virtual void valuesChanged(int start, int end, bool mouse_up) = 0;
38 };
39
43 static constexpr int kNumCircles = kMaxGridParts * kMaxGridParts;
44
56
62 WaveSourceEditor(int size);
63
67 virtual ~WaveSourceEditor();
68
74 void paintBackground(Graphics& g) override;
75
79 void resized() override;
80
86 virtual void init(OpenGlWrapper& open_gl) override {
87 grid_lines_.init(open_gl);
88 grid_circles_.init(open_gl);
89 hover_circle_.init(open_gl);
90 editing_line_.init(open_gl);
92 }
93
100 virtual void render(OpenGlWrapper& open_gl, bool animate) override {
101 grid_lines_.render(open_gl, animate);
102 grid_circles_.render(open_gl, animate);
103 hover_circle_.render(open_gl, animate);
104 if (editing_)
105 editing_line_.render(open_gl, animate);
106 OpenGlLineRenderer::render(open_gl, animate);
107 }
108
114 virtual void destroy(OpenGlWrapper& open_gl) override {
115 grid_lines_.destroy(open_gl);
116 grid_circles_.destroy(open_gl);
117 hover_circle_.destroy(open_gl);
118 editing_line_.destroy(open_gl);
120 }
121
127 void mouseDown(const MouseEvent& e) override;
128
134 void mouseUp(const MouseEvent& e) override;
135
141 void mouseMove(const MouseEvent& e) override;
142
148 void mouseDrag(const MouseEvent& e) override;
149
155 void mouseExit(const MouseEvent& e) override;
156
163 float valueAt(int index) { return values_[index]; }
164
170 void loadWaveform(float* waveform);
171
177 void addListener(Listener* listener) { listeners_.push_back(listener); }
178
184 void setEditable(bool editable);
185
192 void setGrid(int horizontal, int vertical);
193
199 void audioFileLoaded(const File& file) override;
200
208 void fileDragEnter(const StringArray& files, int x, int y) override;
209
215 void fileDragExit(const StringArray& files) override;
216
220 void clear();
221
225 void flipVertical();
226
230 void flipHorizontal();
231
232 private:
236 void setGridPositions();
237
241 void setHoverPosition();
242
249 void changeValues(const MouseEvent& e);
250
257 Point<int> getSnappedPoint(Point<int> input);
258
265 Point<int> snapToGrid(Point<int> input);
266
273 int getHoveredIndex(Point<int> position);
274
280 float getSnapRadius();
281
285 void setLineValues();
286
287 std::vector<Listener*> listeners_;
288 Point<int> last_edit_position_;
289 Point<int> current_mouse_position_;
291 OpenGlMultiQuad grid_lines_;
292 OpenGlMultiQuad grid_circles_;
293 OpenGlQuad hover_circle_;
294 OpenGlLineRenderer editing_line_;
296 std::unique_ptr<AudioFileDropSource> audio_file_drop_source_;
297 std::unique_ptr<float[]> values_;
298 bool editing_;
299 bool dragging_audio_file_;
300 bool editable_;
301 int horizontal_grid_;
302 int vertical_grid_;
304 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveSourceEditor)
305};
306
A helper class for handling drag-and-drop of audio files into a JUCE component.
Definition audio_file_drop_source.h:19
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
virtual void init(OpenGlWrapper &open_gl) override
Initializes OpenGL resources for rendering the line.
Definition open_gl_line_renderer.cpp:78
virtual void destroy(OpenGlWrapper &open_gl) override
Destroys OpenGL resources allocated by this line renderer.
Definition open_gl_line_renderer.cpp:468
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the line using OpenGL.
Definition open_gl_line_renderer.cpp:464
A component for rendering multiple quads using OpenGL, with customizable colors, rounding,...
Definition open_gl_multi_quad.h:16
virtual void init(OpenGlWrapper &open_gl) override
Initializes OpenGL buffers and shader attributes.
Definition open_gl_multi_quad.cpp:37
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the quads using OpenGL.
Definition open_gl_multi_quad.cpp:92
virtual void destroy(OpenGlWrapper &open_gl) override
Releases OpenGL resources when the component is destroyed.
Definition open_gl_multi_quad.cpp:69
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
Interface for receiving notifications about waveform modifications.
Definition wave_source_editor.h:26
virtual void valuesChanged(int start, int end, bool mouse_up)=0
Called when a portion of the waveform's values have changed.
virtual ~Listener()
Definition wave_source_editor.h:28
A graphical editor for manipulating a single-cycle waveform's sample values.
Definition wave_source_editor.h:20
void mouseUp(const MouseEvent &e) override
Handles a mouse up event to finalize editing and notify listeners.
Definition wave_source_editor.cpp:107
void flipHorizontal()
Flips the waveform horizontally, reversing its sample order.
Definition wave_source_editor.cpp:315
void resized() override
Adjusts layout and internal structures on component resize.
Definition wave_source_editor.cpp:66
void setGrid(int horizontal, int vertical)
Defines a grid overlay for snapping points.
Definition wave_source_editor.cpp:229
static constexpr int kNumCircles
Definition wave_source_editor.h:43
WaveSourceEditor(int size)
Constructs a WaveSourceEditor with a given waveform size.
Definition wave_source_editor.cpp:30
void loadWaveform(float *waveform)
Loads a complete waveform into the editor.
Definition wave_source_editor.cpp:217
void mouseMove(const MouseEvent &e) override
Handles a mouse move event to update the hover position.
Definition wave_source_editor.cpp:116
void clear()
Clears the entire waveform to zero.
Definition wave_source_editor.cpp:295
void fileDragEnter(const StringArray &files, int x, int y) override
Called when dragging audio files enters the component.
Definition wave_source_editor.cpp:287
void addListener(Listener *listener)
Adds a listener to be notified of value changes.
Definition wave_source_editor.h:177
virtual void init(OpenGlWrapper &open_gl) override
Initializes the OpenGL objects for drawing.
Definition wave_source_editor.h:86
float valueAt(int index)
Retrieves the waveform sample value at a given index.
Definition wave_source_editor.h:163
void mouseDrag(const MouseEvent &e) override
Handles a mouse drag event to continuously update waveform samples.
Definition wave_source_editor.cpp:121
void paintBackground(Graphics &g) override
Paints the background of the waveform editor.
Definition wave_source_editor.cpp:56
void setEditable(bool editable)
Enables or disables editing of the waveform.
Definition wave_source_editor.cpp:224
void fileDragExit(const StringArray &files) override
Called when dragging audio files leaves the component.
Definition wave_source_editor.cpp:291
virtual void destroy(OpenGlWrapper &open_gl) override
Cleans up the OpenGL resources used by the editor.
Definition wave_source_editor.h:114
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the waveform, grid lines, circles, and hover elements.
Definition wave_source_editor.h:100
void mouseExit(const MouseEvent &e) override
Handles a mouse exit event to clear the hover indication.
Definition wave_source_editor.cpp:132
virtual ~WaveSourceEditor()
Destructor.
Definition wave_source_editor.cpp:53
void flipVertical()
Flips the waveform vertically, inverting all sample values.
Definition wave_source_editor.cpp:305
void mouseDown(const MouseEvent &e) override
Handles a mouse down event to start editing or show the context menu.
Definition wave_source_editor.cpp:83
void audioFileLoaded(const File &file) override
Called when an audio file is dropped and loaded successfully.
Definition wave_source_editor.cpp:283
WaveSourceMenu
Context menu actions for waveform editing.
Definition wave_source_editor.h:49
@ kClear
Definition wave_source_editor.h:53
@ kFlipHorizontal
Definition wave_source_editor.h:51
@ kInitSaw
Definition wave_source_editor.h:54
@ kFlipVertical
Definition wave_source_editor.h:52
@ kCancel
Definition wave_source_editor.h:50
static constexpr int kMaxGridParts
Definition wave_source_editor.h:41
static constexpr int kMaxGrid
Maximum grid lines used by some overlays.
Definition wavetable_component_overlay.h:25
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174