Vital
Loading...
Searching...
No Matches
wavetable_edit_section.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4
5#include "synth_section.h"
6#include "preset_selector.h"
7#include "wave_frame.h"
9#include "wavetable.h"
12#include "wavetable_creator.h"
13#include "wavetable_organizer.h"
14#include "wavetable_playhead.h"
15
16class BarRenderer;
18
36 public:
37 static constexpr float kObscureAmount = 0.4f;
38 static constexpr float kAlphaFade = 0.3f;
39
45 static inline float getZoomScale(int zoom) {
46 return 1 << (zoom - kZoom1);
47 }
48
54 static String getWavetableDataString(InputStream* input_stream);
55
66
78
84 WavetableEditSection(int index, WavetableCreator* wavetable_creator);
85
87 virtual ~WavetableEditSection();
88
93 Rectangle<int> getFrameEditBounds();
94
99 Rectangle<int> getTimelineBounds();
100
105 void paintBackground(Graphics& g) override;
106
111 void paintBackgroundShadow(Graphics& g) override;
112
116 void resized() override;
117
121 void reset() override;
122
126 void visibilityChanged() override;
127
133 void mouseWheelMove(const MouseEvent& e, const MouseWheelDetails& wheel) override;
134
139 void componentAdded(WavetableComponent* component) override;
140
145 void componentRemoved(WavetableComponent* component) override;
146
147 void componentsReordered() override { }
148
152 void componentsChanged() override;
153
159 static constexpr int kTopHeight = 48;
160 return size_ratio_ * kTopHeight;
161 }
162
167 void playheadMoved(int position) override;
168
173 void setWaveFrameSlider(Slider* slider) { wave_frame_slider_ = slider; }
174
178 void frameDoneEditing() override;
179
183 void frameChanged() override;
184
188 void prevClicked() override;
189
193 void nextClicked() override;
194
199 void textMouseDown(const MouseEvent& e) override;
200
205
209 void saveAsWavetable();
210
214 void importWavetable();
215
219 void exportWavetable();
220
224 void exportToWav();
225
230 void loadFile(const File& wavetable_file) override;
231
236 File getCurrentFile() override { return File(wavetable_creator_->getLastFileLoaded()); }
237
242 void loadWavetable(json& wavetable_data);
243
248 json getWavetableJson() { return wavetable_creator_->stateToJson(); }
249
257 bool loadAudioAsWavetable(String name, InputStream* audio_stream, WavetableCreator::AudioFileLoadStyle style);
258
263
268 virtual void buttonClicked(Button* clicked_button) override;
269
273 virtual void positionsUpdated() override;
274
279 virtual void frameSelected(WavetableKeyframe* keyframe) override;
280
286 virtual void frameDragged(WavetableKeyframe* keyframe, int position) override;
287
293 virtual void wheelMoved(const MouseEvent& e, const MouseWheelDetails& wheel) override;
294
300 void renderOpenGlComponents(OpenGlWrapper& open_gl, bool animate) override;
301
306 void setPowerScale(bool power_scale);
307
312 void setZoom(int zoom);
313
317 void clear();
318
322 void init();
323
328 std::string getLastBrowsedWavetable() { return wavetable_creator_->getLastFileLoaded(); }
329
334 std::string getName() { return wavetable_creator_->getName(); }
335
336 private:
337 void setPresetSelectorText();
338 void showPopupMenu();
339 void hideCurrentOverlay();
340 void clearOverlays();
341 void setColors();
342 void render();
343 void render(int position);
344 void updateGlDisplay();
345 void setOverlayPosition();
346 void updateTimeDomain(float* time_domain);
347 void updateFrequencyDomain(float* time_domain);
348 int loadAudioFile(AudioSampleBuffer& destination, InputStream* audio_stream);
349
350 int index_;
351 float zoom_;
352 bool power_scale_;
353 bool obscure_time_domain_;
354 bool obscure_freq_amplitude_;
355 bool obscure_freq_phase_;
356
357 AudioFormatManager format_manager_;
358
359 std::unique_ptr<BarRenderer> frequency_amplitudes_;
360 std::unique_ptr<BarRenderer> frequency_phases_;
361 std::unique_ptr<WaveSourceEditor> oscillator_waveform_;
362 std::unique_ptr<WavetableOrganizer> wavetable_organizer_;
363 std::unique_ptr<WavetableComponentList> wavetable_component_list_;
364 std::unique_ptr<WavetablePlayhead> wavetable_playhead_;
365 std::unique_ptr<WavetablePlayheadInfo> wavetable_playhead_info_;
366 std::unique_ptr<OpenGlShapeButton> exit_button_;
367 std::unique_ptr<OpenGlShapeButton> frequency_amplitude_settings_;
368 std::unique_ptr<PresetSelector> preset_selector_;
369 std::unique_ptr<OpenGlShapeButton> menu_button_;
370
371 Slider* wave_frame_slider_;
372
373 vital::WaveFrame compute_frame_;
374 WavetableCreator* wavetable_creator_;
375 std::map<WavetableComponent*, WavetableComponentFactory::ComponentType> type_lookup_;
376 std::unique_ptr<WavetableComponentOverlay> overlays_[WavetableComponentFactory::kNumComponentTypes];
377 WavetableComponentOverlay* current_overlay_;
378 Rectangle<int> edit_bounds_;
379 Rectangle<int> title_bounds_;
380
381 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WavetableEditSection)
382};
383
A renderer for drawing a series of bars using OpenGL.
Definition bar_renderer.h:18
Interface for objects that want to be notified of PresetSelector events.
Definition preset_selector.h:24
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
virtual void animate(bool animate)
Triggers animation state change in sub-sections if needed.
Definition synth_section.cpp:822
float size_ratio_
Definition synth_section.h:821
@ kNumComponentTypes
Total count of all component types.
Definition wavetable_component_factory.h:42
A base class representing a component in a wavetable synthesis chain.
Definition wavetable_component.h:32
Interface for objects wanting to know when the component list changes.
Definition wavetable_component_list.h:86
A listener interface for receiving changes to the wavetable overlay.
Definition wavetable_component_overlay.h:118
A base overlay component for editing and interacting with a wavetable component's parameters.
Definition wavetable_component_overlay.h:22
A class responsible for creating complete wavetables from groups of wavetable components.
Definition wavetable_creator.h:27
AudioFileLoadStyle
Defines how audio files are interpreted when loading into a wavetable.
Definition wavetable_creator.h:33
json stateToJson()
Definition wavetable_creator.cpp:477
std::string getName() const
Gets the name of the wavetable.
Definition wavetable_creator.h:111
std::string getLastFileLoaded()
Gets the last loaded file path.
Definition wavetable_creator.h:125
A UI section for editing, visualizing, and managing wavetables.
Definition wavetable_edit_section.h:35
void componentsChanged() override
Callback when components in the list change.
Definition wavetable_edit_section.cpp:546
void exportToWav()
Exports the current wavetable frames as a .wav file.
Definition wavetable_edit_section.cpp:579
void setPowerScale(bool power_scale)
Sets whether the frequency display uses power scale or amplitude scale.
Definition wavetable_edit_section.cpp:766
Rectangle< int > getFrameEditBounds()
Gets the bounds of the frame editing area.
Definition wavetable_edit_section.cpp:206
void loadWavetable(json &wavetable_data)
Loads a wavetable from JSON data.
Definition wavetable_edit_section.cpp:640
static float getZoomScale(int zoom)
Computes a zoom scale factor from a zoom menu selection.
Definition wavetable_edit_section.h:45
virtual void positionsUpdated() override
Callback for when positions in the wavetable organizer are updated.
Definition wavetable_edit_section.cpp:717
static constexpr float kAlphaFade
Alpha fade factor for overlay visuals.
Definition wavetable_edit_section.h:38
virtual void frameDragged(WavetableKeyframe *keyframe, int position) override
Callback when a frame is dragged to a new position.
Definition wavetable_edit_section.cpp:741
File getCurrentFile() override
Gets the current wavetable file being edited.
Definition wavetable_edit_section.h:236
void resynthesizeToWavetable()
Resynthesizes the current preset into a wavetable.
Definition wavetable_edit_section.cpp:667
std::string getLastBrowsedWavetable()
Gets the last browsed wavetable file.
Definition wavetable_edit_section.h:328
void resized() override
Called when the component is resized, arranges the layout of UI elements.
Definition wavetable_edit_section.cpp:241
void componentRemoved(WavetableComponent *component) override
Callback when a wavetable component is removed.
Definition wavetable_edit_section.cpp:532
void visibilityChanged() override
Called when visibility changes, e.g., updating UI if made visible.
Definition wavetable_edit_section.cpp:315
void frameDoneEditing() override
Callback when a frame finishes editing, triggers a waveform re-render.
Definition wavetable_edit_section.cpp:348
json getWavetableJson()
Gets the current wavetable state as JSON.
Definition wavetable_edit_section.h:248
static constexpr float kObscureAmount
Opacity factor for obscuring certain visuals.
Definition wavetable_edit_section.h:37
virtual void buttonClicked(Button *clicked_button) override
Handles button clicks for menu, settings, exit, etc.
Definition wavetable_edit_section.cpp:691
void renderOpenGlComponents(OpenGlWrapper &open_gl, bool animate) override
Renders the OpenGL components, including overlays.
Definition wavetable_edit_section.cpp:749
void loadFile(const File &wavetable_file) override
Loads a wavetable file from disk.
Definition wavetable_edit_section.cpp:612
void paintBackgroundShadow(Graphics &g) override
Paints any background shadow or tab shadows for the section.
Definition wavetable_edit_section.cpp:236
void saveAsWavetable()
Saves the current wavetable state as a file.
Definition wavetable_edit_section.cpp:555
BarEditorMenu
Menu items for the bar editor settings.
Definition wavetable_edit_section.h:68
@ kZoom8
Definition wavetable_edit_section.h:75
@ kZoom2
Definition wavetable_edit_section.h:73
@ kCancel
Definition wavetable_edit_section.h:69
@ kZoom16
Definition wavetable_edit_section.h:76
@ kZoom1
Definition wavetable_edit_section.h:72
@ kPowerScale
Definition wavetable_edit_section.h:70
@ kAmplitudeScale
Definition wavetable_edit_section.h:71
@ kZoom4
Definition wavetable_edit_section.h:74
virtual void frameSelected(WavetableKeyframe *keyframe) override
Callback when a frame is selected in the wavetable organizer.
Definition wavetable_edit_section.cpp:721
void playheadMoved(int position) override
Callback for when the playhead moves to a different frame.
Definition wavetable_edit_section.cpp:342
void importWavetable()
Imports an external wavetable file.
Definition wavetable_edit_section.cpp:561
void clear()
Clears the current wavetable editing state.
Definition wavetable_edit_section.cpp:781
void componentAdded(WavetableComponent *component) override
Callback when a wavetable component is added to the list.
Definition wavetable_edit_section.cpp:517
void nextClicked() override
Callback when 'next' is clicked, attempts to load next wavetable.
Definition wavetable_edit_section.cpp:365
std::string getName()
Gets the current wavetable name.
Definition wavetable_edit_section.h:334
void textMouseDown(const MouseEvent &e) override
Callback when text is clicked, possibly showing a browser to load wavetable.
Definition wavetable_edit_section.cpp:372
void frameChanged() override
Callback when a frame changes, triggers a display re-render.
Definition wavetable_edit_section.cpp:352
void init()
Initializes the wavetable state after loading or clearing.
Definition wavetable_edit_section.cpp:785
static String getWavetableDataString(InputStream *input_stream)
Extracts wavetable-specific data embedded in a .wav file's chunk.
Definition wavetable_edit_section.cpp:83
void paintBackground(Graphics &g) override
Paints the background of the wavetable edit section, including children.
Definition wavetable_edit_section.cpp:222
int getTopHeight()
Gets the top section height for title and controls.
Definition wavetable_edit_section.h:158
MenuItems
Menu items for main menu actions.
Definition wavetable_edit_section.h:57
@ kExportWavetable
Definition wavetable_edit_section.h:61
@ kImportWavetable
Definition wavetable_edit_section.h:60
@ kCancelled
Definition wavetable_edit_section.h:58
@ kResynthesizeWavetable
Definition wavetable_edit_section.h:63
@ kSaveAsWavetable
Definition wavetable_edit_section.h:59
@ kNumMenuItems
Definition wavetable_edit_section.h:64
@ kExportWav
Definition wavetable_edit_section.h:62
void reset() override
Resets the editing section, clearing and re-initializing components.
Definition wavetable_edit_section.cpp:302
void exportWavetable()
Exports the current wavetable as a .vitaltable file.
Definition wavetable_edit_section.cpp:570
Rectangle< int > getTimelineBounds()
Gets the bounds of the timeline area.
Definition wavetable_edit_section.cpp:215
void setWaveFrameSlider(Slider *slider)
Sets the WaveFrame slider to reflect current editing frame position.
Definition wavetable_edit_section.h:173
virtual void wheelMoved(const MouseEvent &e, const MouseWheelDetails &wheel) override
Callback for wheel movements in the component list area.
Definition wavetable_edit_section.cpp:745
bool loadAudioAsWavetable(String name, InputStream *audio_stream, WavetableCreator::AudioFileLoadStyle style)
Loads audio data as a wavetable.
Definition wavetable_edit_section.cpp:649
void setZoom(int zoom)
Sets the zoom level for frequency domain rendering.
Definition wavetable_edit_section.cpp:773
void componentsReordered() override
Called when components are reordered.
Definition wavetable_edit_section.h:147
WavetableEditSection(int index, WavetableCreator *wavetable_creator)
Constructs a WavetableEditSection.
Definition wavetable_edit_section.cpp:110
virtual ~WavetableEditSection()
Destructor.
Definition wavetable_edit_section.cpp:202
void prevClicked() override
Callback when 'previous' is clicked, attempts to load previous wavetable.
Definition wavetable_edit_section.cpp:358
void loadDefaultWavetable()
Loads the default wavetable (initializes a blank state).
Definition wavetable_edit_section.cpp:550
void mouseWheelMove(const MouseEvent &e, const MouseWheelDetails &wheel) override
Handles mouse wheel movement for zooming frequency domain views.
Definition wavetable_edit_section.cpp:325
Represents a single state of a waveform at a specific position in a wavetable.
Definition wavetable_keyframe.h:35
Interface for objects that need to respond to organizer events.
Definition wavetable_organizer.h:109
A listener interface for objects interested in playhead position changes.
Definition wavetable_playhead.h:31
A UI component that displays the current playhead position in a wavetable editor.
Definition wavetable_playhead_info.h:20
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
Definition wave_frame.h:16
nlohmann::json json
Definition line_generator.h:7
Declares the PresetSelector class which provides a UI component for selecting presets.
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174