Vital
Loading...
Searching...
No Matches
wavetable_3d.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "JuceHeader.h"
13#include "common.h"
14#include "open_gl_image.h"
15#include "synth_oscillator.h"
16#include "synth_types.h"
17#include "wavetable.h"
18#include "wavetable_creator.h"
19
20namespace vital {
21 struct Output;
22 class Wavetable;
23}
24
36public:
38 static constexpr float kDefaultVerticalAngle = 1.132f;
39 static constexpr float kDefaultHorizontalAngle = -0.28f;
40 static constexpr float kDefaultDrawWidthPercent = 0.728f;
41 static constexpr float kDefaultWaveHeightPercent = 0.083f;
42 static constexpr float kPositionWidth = 8.0f;
43 static constexpr float kPositionLineWidthRatio = 1.8f;
44 static constexpr int kColorJump = 16;
45 static constexpr int kDownsampleResolutionAmount = 0;
48 static constexpr int kBackgroundResolution = 128;
49 static constexpr int kExtraShadows = 20;
50 static constexpr float k2dWaveHeightPercent = 0.25f;
51
53 static void paint3dLine(Graphics& g, vital::Wavetable* wavetable, int index, Colour color,
54 float width, float height, float wave_height_percent,
55 float wave_range_x, float frame_range_x, float wave_range_y, float frame_range_y,
56 float start_x, float start_y, float offset_x, float offset_y);
57
59 static void paint3dBackground(Graphics& g, vital::Wavetable* wavetable, bool active,
60 Colour background_color, Colour wave_color1, Colour wave_color2,
61 float width, float height,
62 float wave_height_percent,
63 float wave_range_x, float frame_range_x, float wave_range_y, float frame_range_y,
64 float start_x, float start_y, float offset_x, float offset_y);
65
78
86
89 class Listener {
90 public:
91 virtual ~Listener() { }
92
94 virtual bool loadAudioAsWavetable(String name, InputStream* audio_stream,
96
98 virtual void loadWavetable(json& wavetable_data) = 0;
99
101 virtual void loadDefaultWavetable() = 0;
102
104 virtual void resynthesizeToWavetable() = 0;
105
107 virtual void textToWavetable() = 0;
108
110 virtual void saveWavetable() = 0;
111 };
112
117 Wavetable3d(int index, const vital::output_map& mono_modulations, const vital::output_map& poly_modulations);
118
120 virtual ~Wavetable3d();
121
124 void init(OpenGlWrapper& open_gl) override;
125
129 void render(OpenGlWrapper& open_gl, bool animate) override;
130
133 void renderWave(OpenGlWrapper& open_gl);
134
137 void renderSpectrum(OpenGlWrapper& open_gl);
138
141 void destroy(OpenGlWrapper& open_gl) override;
142
145 void paintBackground(Graphics& g) override;
146
148 void resized() override;
149
152 void mouseDown(const MouseEvent& e) override;
153
156 void mouseDrag(const MouseEvent& e) override;
157
160 void mouseExit(const MouseEvent& e) override;
161
165 void mouseWheelMove(const MouseEvent& e, const MouseWheelDetails& wheel) override;
166
169 void setFrameSlider(SynthSlider* slider) { frame_slider_ = slider; }
170
173 void setSpectralMorphSlider(Slider* slider) { spectral_morph_slider_ = slider; }
174
177 void setDistortionSlider(Slider* slider) { distortion_slider_ = slider; }
178
181 void setDistortionPhaseSlider(Slider* slider) { distortion_phase_slider_ = slider; }
182
184 void setViewSettings(float horizontal_angle, float vertical_angle,
185 float draw_width, float wave_height, float y_offset);
186
189 void setRenderType(RenderType render_type);
190
193 RenderType getRenderType() const { return render_type_; }
194
197 void setSpectralMorphType(int spectral_morph_type) { spectral_morph_type_ = spectral_morph_type; }
198
201 void setDistortionType(int distortion_type) { distortion_type_ = distortion_type; }
202
205 void respondToMenuCallback(int option);
206
210
213 void setActive(bool active) { active_ = active; }
214
217 bool isActive() { return active_; }
218
221 void audioFileLoaded(const File& file) override;
222
226 void updateDraggingPosition(int x, int y);
227
229 void fileDragEnter(const StringArray& files, int x, int y) override {
231 }
232
234 void fileDragMove(const StringArray& files, int x, int y) override {
236 }
237
239 void fileDragExit(const StringArray& files) override {
240 drag_load_style_ = WavetableCreator::kNone;
241 }
242
245 void addListener(Listener* listener) { listeners_.push_back(listener); }
246
249 void setLoadingWavetable(bool loading) { loading_wavetable_ = loading; }
250
252 void setDirty() { last_spectral_morph_type_ = -1; }
253
256 vital::Wavetable* getWavetable() { return wavetable_; }
257
258private:
261 bool updateRenderValues();
262
264 void loadIntoTimeDomain(int index);
265
268 void loadWaveData(int index);
269
272 void loadSpectrumData(int index);
273
277 void drawPosition(OpenGlWrapper& open_gl, int index);
278
280 void setDimensionValues();
281
283 void setColors();
284
286 vital::poly_float getDistortionValue();
287
289 vital::poly_float getSpectralMorphValue();
290
292 vital::poly_int getDistortionPhaseValue();
293
295 void loadFrequencyData(int index);
296
298 void warpSpectrumToWave(int index);
299
301 void warpPhase(int index);
302
304 inline vital::poly_float getOutputsTotal(std::pair<vital::Output*, vital::Output*> outputs,
305 vital::poly_float default_value);
306
307 OpenGlLineRenderer left_line_renderer_;
308 OpenGlLineRenderer right_line_renderer_;
309 OpenGlMultiQuad end_caps_;
310
311 Colour import_text_color_;
312 OpenGlQuad import_overlay_;
313 std::unique_ptr<PlainTextComponent> wavetable_import_text_;
314 std::unique_ptr<PlainTextComponent> vocode_import_text_;
315 std::unique_ptr<PlainTextComponent> pitch_splice_import_text_;
316
317 Colour body_color_;
318 Colour line_left_color_;
319 Colour line_right_color_;
320 Colour line_disabled_color_;
321 Colour fill_left_color_;
322 Colour fill_right_color_;
323 Colour fill_disabled_color_;
324
325 std::vector<Listener*> listeners_;
326 std::pair<vital::Output*, vital::Output*> wave_frame_outputs_;
327 std::pair<vital::Output*, vital::Output*> spectral_morph_outputs_;
328 std::pair<vital::Output*, vital::Output*> distortion_outputs_;
329 std::pair<vital::Output*, vital::Output*> distortion_phase_outputs_;
330
331 int last_spectral_morph_type_;
332 int last_distortion_type_;
333 int spectral_morph_type_;
334 int distortion_type_;
335 vital::poly_float wave_frame_;
336 vital::poly_float spectral_morph_value_;
337 vital::poly_float distortion_value_;
338 vital::poly_int distortion_phase_;
339
340 SynthSlider* frame_slider_;
341 Slider* spectral_morph_slider_;
342 Slider* distortion_slider_;
343 Slider* distortion_phase_slider_;
344 Point<int> last_edit_position_;
346 vital::WaveFrame process_frame_;
347 vital::FourierTransform transform_;
349 const vital::Wavetable::WavetableData* current_wavetable_data_;
350 int wavetable_index_;
351
352 bool animate_;
353 bool loading_wavetable_;
354 bool last_loading_wavetable_;
355 RenderType render_type_;
356 RenderType last_render_type_;
357 bool active_;
358 int size_;
359 int index_;
360 vital::Wavetable* wavetable_;
361
362 double current_value_;
363 float vertical_angle_;
364 float horizontal_angle_;
365 float draw_width_percent_;
366 float wave_height_percent_;
367 float y_offset_;
368
369 float wave_range_x_;
370 float frame_range_x_;
371 float wave_range_y_;
372 float frame_range_y_;
373 float start_x_;
374 float start_y_;
375 float offset_x_;
376 float offset_y_;
377
378 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Wavetable3d)
379};
A helper class for handling drag-and-drop of audio files into a JUCE component.
Definition audio_file_drop_source.h:19
A base component class that integrates JUCE's Component with OpenGL rendering.
Definition open_gl_component.h:20
A component for rendering lines with optional filling and boost effects using OpenGL.
Definition open_gl_line_renderer.h:16
A component for rendering multiple quads using OpenGL, with customizable colors, rounding,...
Definition open_gl_multi_quad.h:16
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
Interface for components that need to respond to wavetable loading or transformations.
Definition wavetable_3d.h:89
virtual void loadWavetable(json &wavetable_data)=0
Called when a JSON representation of a wavetable is loaded.
virtual bool loadAudioAsWavetable(String name, InputStream *audio_stream, WavetableCreator::AudioFileLoadStyle style)=0
Called when audio data is loaded as a wavetable.
virtual ~Listener()
Definition wavetable_3d.h:91
virtual void saveWavetable()=0
Called to save the current wavetable.
virtual void textToWavetable()=0
Called to run a "text to wavetable" conversion.
virtual void resynthesizeToWavetable()=0
Called to resynthesize the current preset into a wavetable.
virtual void loadDefaultWavetable()=0
Called to initialize (reset) the wavetable to a default state.
OpenGL-based component for visualizing wavetables in different formats.
Definition wavetable_3d.h:35
void setViewSettings(float horizontal_angle, float vertical_angle, float draw_width, float wave_height, float y_offset)
Sets view settings for the 3D display (angles, width, height, offset).
Definition wavetable_3d.cpp:609
void resized() override
Handles component resizing, recalculating layout and scaling.
Definition wavetable_3d.cpp:205
static constexpr float kDefaultWaveHeightPercent
Definition wavetable_3d.h:41
vital::Wavetable * getWavetable()
Definition wavetable_3d.h:256
void audioFileLoaded(const File &file) override
Definition wavetable_3d.cpp:687
static constexpr int kResolution
Definition wavetable_3d.h:46
void destroy(OpenGlWrapper &open_gl) override
Definition wavetable_3d.cpp:566
void setActive(bool active)
Definition wavetable_3d.h:213
void init(OpenGlWrapper &open_gl) override
Definition wavetable_3d.cpp:438
bool hasMatchingSystemClipboard()
Definition wavetable_3d.cpp:676
void updateDraggingPosition(int x, int y)
Definition wavetable_3d.cpp:697
void renderWave(OpenGlWrapper &open_gl)
Definition wavetable_3d.cpp:479
void mouseDrag(const MouseEvent &e) override
Definition wavetable_3d.cpp:280
static constexpr int kBackgroundResolution
Definition wavetable_3d.h:48
static constexpr int kExtraShadows
Definition wavetable_3d.h:49
void setDistortionSlider(Slider *slider)
Definition wavetable_3d.h:177
void setRenderType(RenderType render_type)
Definition wavetable_3d.cpp:619
void fileDragExit(const StringArray &files) override
Handles file drag exit events, resetting the load style.
Definition wavetable_3d.h:239
static constexpr int kDownsampleResolutionAmount
Definition wavetable_3d.h:45
static constexpr float kPositionLineWidthRatio
Definition wavetable_3d.h:43
void setDirty()
Marks the internal state as dirty, forcing a redraw.
Definition wavetable_3d.h:252
static constexpr float kPositionWidth
Definition wavetable_3d.h:42
void setLoadingWavetable(bool loading)
Definition wavetable_3d.h:249
void mouseDown(const MouseEvent &e) override
Definition wavetable_3d.cpp:246
static constexpr float kDefaultVerticalAngle
Default angles and scaling parameters for 3D rendering.
Definition wavetable_3d.h:38
static void paint3dBackground(Graphics &g, vital::Wavetable *wavetable, bool active, Colour background_color, Colour wave_color1, Colour wave_color2, float width, float height, float wave_height_percent, float wave_range_x, float frame_range_x, float wave_range_y, float frame_range_y, float start_x, float start_y, float offset_x, float offset_y)
Static helper method for painting the 3D background of the wavetable (all frames) onto a Graphics obj...
Definition wavetable_3d.cpp:50
virtual ~Wavetable3d()
Destructor.
void setFrameSlider(SynthSlider *slider)
Definition wavetable_3d.h:169
void addListener(Listener *listener)
Definition wavetable_3d.h:245
void setSpectralMorphType(int spectral_morph_type)
Definition wavetable_3d.h:197
void mouseWheelMove(const MouseEvent &e, const MouseWheelDetails &wheel) override
Definition wavetable_3d.cpp:295
static constexpr float kDefaultDrawWidthPercent
Definition wavetable_3d.h:40
RenderType
Render types for different visualization modes.
Definition wavetable_3d.h:80
@ kFrequencyAmplitudes
Definition wavetable_3d.h:83
@ kNumRenderTypes
Definition wavetable_3d.h:84
@ kWave2d
Definition wavetable_3d.h:82
@ kWave3d
Definition wavetable_3d.h:81
static constexpr float k2dWaveHeightPercent
Definition wavetable_3d.h:50
void respondToMenuCallback(int option)
Definition wavetable_3d.cpp:624
void render(OpenGlWrapper &open_gl, bool animate) override
Definition wavetable_3d.cpp:448
void fileDragEnter(const StringArray &files, int x, int y) override
Handles file drag enter events.
Definition wavetable_3d.h:229
void paintBackground(Graphics &g) override
Definition wavetable_3d.cpp:182
void mouseExit(const MouseEvent &e) override
Definition wavetable_3d.cpp:299
void setDistortionType(int distortion_type)
Definition wavetable_3d.h:201
static constexpr int kNumBits
Definition wavetable_3d.h:47
RenderType getRenderType() const
Definition wavetable_3d.h:193
void fileDragMove(const StringArray &files, int x, int y) override
Handles file drag move events.
Definition wavetable_3d.h:234
void renderSpectrum(OpenGlWrapper &open_gl)
Definition wavetable_3d.cpp:529
void setSpectralMorphSlider(Slider *slider)
Definition wavetable_3d.h:173
static constexpr int kColorJump
Definition wavetable_3d.h:44
void setDistortionPhaseSlider(Slider *slider)
Definition wavetable_3d.h:181
bool isActive()
Definition wavetable_3d.h:217
static void paint3dLine(Graphics &g, vital::Wavetable *wavetable, int index, Colour color, float width, float height, float wave_height_percent, float wave_range_x, float frame_range_x, float wave_range_y, float frame_range_y, float start_x, float start_y, float offset_x, float offset_y)
Static helper method for painting a single 3D line (waveform frame) onto a Graphics object.
Definition wavetable_3d.cpp:16
static constexpr float kDefaultHorizontalAngle
Definition wavetable_3d.h:39
MenuOptions
Menu options for right-click context menu.
Definition wavetable_3d.h:67
@ kSave
Definition wavetable_3d.h:72
@ kPaste
Definition wavetable_3d.h:70
@ kCopy
Definition wavetable_3d.h:69
@ kLogIn
Definition wavetable_3d.h:75
@ kInit
Definition wavetable_3d.h:71
@ kResynthesizePreset
Definition wavetable_3d.h:74
@ kNumMenuOptions
Definition wavetable_3d.h:76
@ kCancel
Definition wavetable_3d.h:68
@ kTextToWavetable
Definition wavetable_3d.h:73
Wavetable3d(int index, const vital::output_map &mono_modulations, const vital::output_map &poly_modulations)
Definition wavetable_3d.cpp:101
AudioFileLoadStyle
Defines how audio files are interpreted when loading into a wavetable.
Definition wavetable_creator.h:33
@ kNone
Definition wavetable_creator.h:34
A Fourier transform implementation using KissFFT for platforms where other accelerations are unavaila...
Definition fourier_transform.h:210
static constexpr int kSpectralBufferSize
Size of spectral buffer for Fourier transforms.
Definition synth_oscillator.h:207
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
Definition wave_frame.h:16
static constexpr int kWaveformBits
The number of bits that define the size of the waveform (2^kWaveformBits = kWaveformSize).
Definition wave_frame.h:19
A class representing a wavetable, holding multiple frames of waveforms and their frequency-domain rep...
Definition wavetable.h:20
static constexpr int kWaveformSize
Size of each waveform frame.
Definition wavetable.h:25
nlohmann::json json
Definition line_generator.h:7
Contains classes and functions used within the Vital synthesizer framework.
std::map< std::string, Output * > output_map
Maps parameter names to Output pointers, representing output signals from various modules.
Definition synth_types.h:229
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Struct holding all necessary data for the Wavetable, including multiple frames.
Definition wavetable.h:41
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56