12 const std::string kFadeLookup[] = {
18 const std::string kPhaseLookup[] = {
35 float windowTextToSize(String text,
int sample_rate) {
36 static constexpr float kMaxWindowSize = 9999.9f;
37 String trimmed = text.trim();
49 float positionTextToSize(String text) {
50 return text.trim().getFloatValue();
55 dragging_quad_(
Shaders::kRoundedRectangleFragment), sample_rate_(0),
56 file_source_(nullptr) {
57 window_position_ = 0.0f;
64 top_.setInterceptsMouseClicks(
false,
false);
65 bottom_.setInterceptsMouseClicks(
false,
false);
74 static constexpr float kBuffer = 0.1f;
75 static constexpr float kCenterAlpha = 0.1f;
77 int buffer = getHeight() * kBuffer;
78 Rectangle<int> bounds(0, buffer, getWidth(), getHeight() - 2 * buffer);
79 top_.setBounds(bounds);
80 bottom_.setBounds(bounds);
101 top_.
setXAt(i, delta * i);
102 bottom_.
setXAt(i, delta * i);
109 float center = top_.getHeight() * 0.5f;
112 bottom_.
setYAt(i, center);
117 if (file_source_ ==
nullptr) {
123 if (sample_buffer->
size == 0 || sample_buffer->
data ==
nullptr) {
128 const float* buffer = sample_buffer->
data.get();
129 int sample_length = sample_buffer->
size;
131 float center = top_.getHeight() * 0.5f;
133 int start_index = std::min<int>(sample_length * i /
kResolution, sample_length);
135 float max = buffer[start_index];
136 for (
int i = start_index + 1; i < end_index; ++i)
137 max = std::max(max, buffer[i]);
138 top_.
setYAt(i, center - max * center);
139 bottom_.
setYAt(i, center + max * center);
146 if (file_source_ ==
nullptr)
150 if (sample_buffer->
size == 0 || sample_buffer->
data ==
nullptr)
155 float fade_length = std::max(window_fade_ * window_size_, 1.0f /
kResolution);
156 float start = window_position_ - fade_length * 0.5f;
157 float end = window_position_ + window_size_ + fade_length * 0.5f;
161 float window_phase = std::min(position - start, end - position) / fade_length;
162 window_phase = std::max(std::min(window_phase, 1.0f), 0.0f) *
vital::kPi;
163 float window_value = 0.5f - cosf(window_phase) * 0.5f;
171 static constexpr int kMaxFileSamples = 176400;
172 std::unique_ptr<AudioFormatReader> format_reader(
format_manager_.createReaderFor(file));
175 int num_samples = (int)std::min<long long>(format_reader->lengthInSamples, kMaxFileSamples);
176 sample_buffer_.setSize(format_reader->numChannels, num_samples);
177 format_reader->read(&sample_buffer_, 0, num_samples, 0,
true,
true);
192 float ratio = (position.x - last_mouse_position_.x) / getWidth();
193 last_mouse_position_ = position;
205 listener->positionMovedRelative(ratio,
false);
212 listener->positionMovedRelative(ratio,
true);
223 fade_style_ = std::make_unique<TextSelector>(
"Fade Style");
226 fade_style_->getImageComponent()->setAlwaysOnTop(
true);
229 fade_style_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
234 phase_style_ = std::make_unique<TextSelector>(
"Phase Style");
237 phase_style_->getImageComponent()->setAlwaysOnTop(
true);
240 phase_style_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
260#if !defined(NO_TEXT_ENTRY)
261 start_position_ = std::make_unique<OpenGlTextEditor>(
"Start Position");
270 window_size_ = std::make_unique<OpenGlTextEditor>(
"Window Size");
274 window_size_->getImageComponent()->setAlwaysOnTop(
true);
280 window_fade_ = std::make_unique<SynthSlider>(
"File Source Window Fade");
283 window_fade_->getImageComponent()->setAlwaysOnTop(
true);
288 window_fade_->setSliderStyle(Slider::RotaryHorizontalVerticalDrag);
303 if (keyframe ==
nullptr)
314 window_fade_->setValue(window_fade, dontSendNotification);
339 static constexpr float kTextBoxWidthHeightRatio = 2.5f;
340 static constexpr float kWindowFadeWidthHeightRatio = 3.0f;
341 static constexpr float kSelectorWidthHeightRatio = 3.0f;
342 static constexpr float kNormalizeWidthHeightRatio = 2.5f;
343 static constexpr float kBorderWidthHeightRatio = 1.5f;
345 if (bounds.getWidth() <= 0)
349 int text_box_width = bounds.getHeight() * kTextBoxWidthHeightRatio;
350 int window_fade_width = bounds.getHeight() * kWindowFadeWidthHeightRatio;
351 int selector_width = bounds.getHeight() * kSelectorWidthHeightRatio;
352 int normalize_width = bounds.getHeight() * kNormalizeWidthHeightRatio;
353 int border_width = bounds.getHeight() * kBorderWidthHeightRatio;
354 int total_width = bounds.getWidth() - 2 * border_width;
355 int audio_width = total_width - normalize_width - 2 * selector_width - window_fade_width -
356 2 * text_box_width - 6 * padding;
362 int x = border_width;
363 int y = bounds.getY();
364 int y_title = y + title_height;
365 int height = bounds.getHeight();
366 int height_title = height - title_height;
373 start_position_->setBounds(edit_x, y_title, text_box_width, height_title - 1);
377 window_fade_->setBounds(edit_x, y_title, window_fade_width, height_title);
380 int normalize_padding = height / 6;
382 normalize_width, height - 2 * normalize_padding);
433 file_source_->
loadBuffer(sample_buffer->getReadPointer(0, 0), sample_buffer->getNumSamples(), sample_rate);
445 FileChooser load_file(
"Load Audio File", File::getSpecialLocation(File::userHomeDirectory), String(
"*.wav"));
446 if (load_file.browseForFileToOpen())
486 float position = 0.0f;
489 position += ratio * max_position;
490 position = std::max(0.0f, std::min(max_position, position));
504 text_editor->setColour(TextEditor::textColourId, findColour(
Skin::kBodyText,
true));
505 text_editor->setColour(TextEditor::highlightedTextColourId, findColour(
Skin::kBodyText,
true));
509 text_editor->setFont(font);
510 text_editor->applyFontToAllText(font);
511 text_editor->resized();
519 if (window_size > 0.0f) {
527 getParentComponent()->grabKeyboardFocus();
537 float position = 0.0f;
540 if (position >= 0.0f) {
547 getParentComponent()->grabKeyboardFocus();
565 position = std::max(0.0f, std::min(position, max_position));
AudioFormatManager format_manager_
Manages and recognizes different audio file formats.
Definition audio_file_drop_source.h:113
Interface for listening to mouse drag movements relative to the waveform.
Definition file_source_overlay.h:33
void resized() override
Resizes the component, adjusting the waveform display and line positions.
Definition file_source_overlay.cpp:73
static constexpr float kResolution
Definition file_source_overlay.h:46
void mouseUp(const MouseEvent &e) override
Definition file_source_overlay.cpp:208
void fileDragEnter(const StringArray &files, int x, int y) override
Called when files are dragged into this component.
Definition file_source_overlay.cpp:183
void fileDragExit(const StringArray &files) override
Called when files are dragged out of this component.
Definition file_source_overlay.cpp:187
void mouseDrag(const MouseEvent &e) override
Definition file_source_overlay.cpp:201
void clearAudioPositions()
Clears the currently displayed audio positions in the waveform.
Definition file_source_overlay.cpp:108
void audioFileLoaded(const File &file) override
Called when an audio file is loaded via drag-and-drop.
Definition file_source_overlay.cpp:170
float updateMousePosition(Point< float > position)
Updates the mouse position and returns the relative movement ratio.
Definition file_source_overlay.cpp:191
void setWindowValues()
Updates the display to reflect new window position and size.
Definition file_source_overlay.cpp:145
void mouseDown(const MouseEvent &e) override
Mouse event handlers for adjusting audio window start on drag.
Definition file_source_overlay.cpp:197
void setAudioPositions()
Updates the waveform visualization based on the current audio file data.
Definition file_source_overlay.cpp:116
AudioFileViewer()
Constructs an AudioFileViewer.
Definition file_source_overlay.cpp:54
force_inline void setWindowFade(double window_fade)
Definition file_source.h:120
double getWindowFade()
Gets the fade size for window blending.
Definition file_source.h:115
double getStartPosition()
Gets the current start position of the wave segment in samples.
Definition file_source.h:107
force_inline void setStartPosition(double start_position)
Definition file_source.h:119
A WavetableComponent that uses an external audio sample as its source.
Definition file_source.h:23
void loadBuffer(const float *buffer, int size, int sample_rate)
Loads audio data into the file source buffer.
Definition file_source.cpp:363
double getWindowSize()
Definition file_source.h:181
void detectPitch(int max_period=vital::WaveFrame::kWaveformSize)
Attempts to detect pitch in the loaded sample to determine window size automatically.
Definition file_source.cpp:376
FadeStyle
Different methods to blend or interpolate the loaded audio window into a wavetable frame.
Definition file_source.h:38
@ kNumFadeStyles
Definition file_source.h:43
void setNormalizeGain(bool normalize_gain)
Definition file_source.h:176
PhaseStyle getPhaseStyle()
Definition file_source.h:173
bool getNormalizeGain()
Definition file_source.h:174
void setFadeStyle(FadeStyle fade_style)
Definition file_source.h:178
void setPhaseStyle(PhaseStyle phase_style)
Definition file_source.cpp:337
const SampleBuffer * buffer() const
Definition file_source.h:171
void setWindowSize(double window_size)
Definition file_source.h:177
FileSourceKeyframe * getKeyframe(int index)
Definition file_source.cpp:332
PhaseStyle
Methods for handling phase information in the transformed wave.
Definition file_source.h:50
@ kNumPhaseStyles
Definition file_source.h:54
FadeStyle getFadeStyle()
Definition file_source.h:172
void textEditorFocusLost(TextEditor &text_editor) override
Called when text editors lose focus, updating values.
Definition file_source_overlay.cpp:473
void loadFilePressed()
Opens a file chooser to load an audio file into the FileSource.
Definition file_source_overlay.cpp:444
FileSourceOverlay()
Constructs a FileSourceOverlay.
Definition file_source_overlay.cpp:215
void sliderDragEnded(Slider *moved_slider) override
Called when slider drag ends, finalizing changes.
Definition file_source_overlay.cpp:422
std::unique_ptr< OpenGlTextEditor > start_position_
Definition file_source_overlay.h:286
virtual void setEditBounds(Rectangle< int > bounds) override
Sets the editing bounds for controls in this overlay.
Definition file_source_overlay.cpp:338
void positionMovedRelative(float ratio, bool mouse_up) override
Called by AudioFileViewer when the mouse moves relative to waveform position.
Definition file_source_overlay.cpp:480
void loadStartingPositionText()
Updates the FileSource's starting position from text input.
Definition file_source_overlay.cpp:532
std::unique_ptr< AudioFileViewer > audio_thumbnail_
Definition file_source_overlay.h:293
void loadFile(const File &file) override
Loads an audio file into the FileSource and updates UI.
Definition file_source_overlay.cpp:426
std::unique_ptr< OpenGlTextEditor > window_size_
Definition file_source_overlay.h:287
void audioFileLoaded(const File &file) override
Called when an audio file is loaded (via drag-drop or load button).
Definition file_source_overlay.cpp:462
void setFileSource(FileSource *file_source)
Sets the FileSource this overlay edits.
Definition file_source_overlay.cpp:552
std::unique_ptr< TextSelector > phase_style_
Definition file_source_overlay.h:291
void buttonClicked(Button *clicked_button) override
Handles button clicks (e.g., load button, normalize toggle).
Definition file_source_overlay.cpp:450
void clampStartingPosition()
Ensures the starting position is within valid range.
Definition file_source_overlay.cpp:559
FileSource::FileSourceKeyframe * current_frame_
Definition file_source_overlay.h:284
std::unique_ptr< SynthSlider > window_fade_
Definition file_source_overlay.h:288
FileSource * file_source_
Definition file_source_overlay.h:283
std::unique_ptr< OpenGlToggleButton > normalize_gain_
Definition file_source_overlay.h:292
void setTextEditorVisuals(TextEditor *text_editor, float height)
Applies visuals and font settings to a text editor.
Definition file_source_overlay.cpp:502
void textEditorReturnKeyPressed(TextEditor &text_editor) override
Called when return key is pressed in text editors (start position, window size).
Definition file_source_overlay.cpp:466
std::unique_ptr< TextButton > load_button_
Definition file_source_overlay.h:289
virtual void frameSelected(WavetableKeyframe *keyframe) override
Called when a keyframe is selected in the Wavetable.
Definition file_source_overlay.cpp:302
virtual ~FileSourceOverlay()
Definition file_source_overlay.cpp:300
void loadWindowSizeText()
Updates the FileSource's window size from text input.
Definition file_source_overlay.cpp:514
std::unique_ptr< TextSelector > fade_style_
Definition file_source_overlay.h:290
void sliderValueChanged(Slider *moved_slider) override
Responds to slider changes (window fade, fade style, phase style).
Definition file_source_overlay.cpp:404
Font & monospace()
Returns a reference to the monospace font.
Definition fonts.h:46
static Fonts * instance()
Gets the singleton instance of the Fonts class.
Definition fonts.h:52
force_inline void setYAt(int index, float val)
Sets the y-coordinate of a point, marking data as dirty.
Definition open_gl_line_renderer.h:98
force_inline void setFill(bool fill)
Enables or disables filling below the line.
Definition open_gl_line_renderer.h:124
force_inline void setFillBoostAmount(float boost_amount)
Sets the boost amount that affects fill thickness.
Definition open_gl_line_renderer.h:147
force_inline void setBoostAmount(float boost_amount)
Sets the boost amount that affects line thickness.
Definition open_gl_line_renderer.h:144
force_inline void setFillColor(Colour fill_color)
Sets a uniform fill color if only one color is needed.
Definition open_gl_line_renderer.h:127
force_inline void setXAt(int index, float val)
Sets the x-coordinate of a point, marking data as dirty.
Definition open_gl_line_renderer.h:105
force_inline void setLineWidth(float width)
Sets the line width in pixels.
Definition open_gl_line_renderer.h:66
force_inline void setColor(Colour color)
Sets the line color.
Definition open_gl_line_renderer.h:63
force_inline void setBoostLeft(int index, float val)
Sets the left-side boost for a point, marking data as dirty.
Definition open_gl_line_renderer.h:84
void setActive(bool active)
Activates or deactivates rendering of this component.
Definition open_gl_multi_quad.h:331
void setTargetComponent(Component *target_component)
Sets a target component to help position the quads.
Definition open_gl_multi_quad.h:358
force_inline void setColor(Colour color)
Sets the base color for the quads.
Definition open_gl_multi_quad.h:102
Manages and provides access to vertex and fragment shaders used by the OpenGL rendering pipeline.
Definition shaders.h:19
@ kWidgetLineBoost
Definition skin.h:106
@ kWidgetPrimary1
Definition skin.h:165
@ kBodyText
Definition skin.h:133
@ kWidgetSecondary1
Definition skin.h:168
@ kOverlayScreen
Definition skin.h:140
@ kTextEditorSelection
Definition skin.h:203
@ kTextEditorCaret
Definition skin.h:202
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
void addSlider(SynthSlider *slider, bool show=true, bool listen=true)
Definition synth_section.cpp:445
void addSubSection(SynthSection *section, bool show=true)
Adds a subsection (another SynthSection) as a child.
Definition synth_section.cpp:457
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
static int noteToMidiKey(const String ¬e)
Converts a note name (e.g. "A4") to a MIDI key number.
Definition tuning.cpp:99
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
force_inline poly_float clamp(poly_float value, mono_float min, mono_float max)
Clamps each lane of a vector to [min, max].
Definition poly_utils.h:306
force_inline poly_float midiNoteToFrequency(poly_float value)
Converts a MIDI note to a frequency (vectorized).
Definition poly_utils.h:123
constexpr int kMidiSize
MIDI note count (0-127).
Definition common.h:44
constexpr mono_float kPi
Pi constant.
Definition common.h:36
Declares the SampleViewer class that displays and animates a waveform sample.
A simple structure holding a buffer of samples loaded from the file source.
Definition file_source.h:60
int size
Number of samples in the buffer.
Definition file_source.h:63
int sample_rate
Sample rate of the audio data.
Definition file_source.h:64
std::unique_ptr< float[]> data
Pointer to raw audio data.
Definition file_source.h:62