Vital
Loading...
Searching...
No Matches
sample_viewer.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "JuceHeader.h"
7
9#include "common.h"
11#include "synth_types.h"
12#include "sample_source.h"
13#include "synth_module.h"
14
22public:
24 static constexpr float kResolution = 256;
26 static constexpr float kBoostDecay = 0.9f;
28 static constexpr float kSpeedDecayMult = 5.0f;
29
32 class Listener {
33 public:
35 virtual ~Listener() { }
36
39 virtual void sampleLoaded(const File& file) = 0;
40 };
41
45 virtual ~SampleViewer();
46
49 void init(OpenGlWrapper& open_gl) override {
51 bottom_.init(open_gl);
52 dragging_overlay_.init(open_gl);
53 }
54
58 void render(OpenGlWrapper& open_gl, bool animate) override;
59
62 void destroy(OpenGlWrapper& open_gl) override {
64 bottom_.destroy(open_gl);
65 dragging_overlay_.destroy(open_gl);
66 }
67
69 void resized() override;
70
73 void setActive(bool active) { active_ = active; }
74
77 bool isActive() const { return active_; }
78
81 void audioFileLoaded(const File& file) override;
82
84 void repaintAudio();
85
87 void setLinePositions();
88
93 void fileDragEnter(const StringArray& files, int x, int y) override {
94 dragging_audio_file_ = true;
95 }
96
99 void fileDragExit(const StringArray& files) override {
100 dragging_audio_file_ = false;
101 }
102
105 std::string getName();
106
109 void addListener(Listener* listener) {
110 listeners_.push_back(listener);
111 }
112
115 void setSample(vital::Sample* sample) { sample_ = sample; setLinePositions(); }
116
117private:
118 std::vector<Listener*> listeners_;
119
120 const vital::StatusOutput* sample_phase_output_;
121 vital::poly_float last_phase_;
122 vital::poly_float last_voice_;
123 vital::Sample* sample_;
124
125 OpenGlLineRenderer bottom_;
126 OpenGlQuad dragging_overlay_;
127
128 bool dragging_audio_file_;
129 bool animate_;
130 bool active_;
131
132 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SampleViewer)
133};
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 init(OpenGlWrapper &open_gl) override
Initializes OpenGL buffers and shader attributes.
Definition open_gl_multi_quad.cpp:37
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 objects that want to be notified when a sample is loaded.
Definition sample_viewer.h:32
virtual ~Listener()
Virtual destructor for proper cleanup.
Definition sample_viewer.h:35
virtual void sampleLoaded(const File &file)=0
A UI component for visually displaying and interacting with an audio sample waveform.
Definition sample_viewer.h:21
void addListener(Listener *listener)
Definition sample_viewer.h:109
void fileDragEnter(const StringArray &files, int x, int y) override
Definition sample_viewer.h:93
virtual ~SampleViewer()
Destructor.
Definition sample_viewer.cpp:30
bool isActive() const
Definition sample_viewer.h:77
void setActive(bool active)
Definition sample_viewer.h:73
void setSample(vital::Sample *sample)
Definition sample_viewer.h:115
std::string getName()
Definition sample_viewer.cpp:69
void init(OpenGlWrapper &open_gl) override
Definition sample_viewer.h:49
SampleViewer()
Constructor.
Definition sample_viewer.cpp:10
static constexpr float kResolution
The resolution of the waveform, in number of points.
Definition sample_viewer.h:24
static constexpr float kBoostDecay
The decay factor for line boosts.
Definition sample_viewer.h:26
void repaintAudio()
Repaints the waveform after an audio update.
Definition sample_viewer.cpp:43
void render(OpenGlWrapper &open_gl, bool animate) override
Definition sample_viewer.cpp:101
static constexpr float kSpeedDecayMult
The multiplier for decay when lines move quickly.
Definition sample_viewer.h:28
void audioFileLoaded(const File &file) override
Definition sample_viewer.cpp:35
void destroy(OpenGlWrapper &open_gl) override
Definition sample_viewer.h:62
void setLinePositions()
Sets the line positions (y-values) of the waveform based on the current sample.
Definition sample_viewer.cpp:49
void resized() override
Handles component resizing. Adjusts waveform geometry.
Definition sample_viewer.cpp:77
void fileDragExit(const StringArray &files) override
Definition sample_viewer.h:99
Holds and manages a single sampled waveform, including stereo or mono data and multiple band-limited ...
Definition sample_source.h:25
A helper class to track the "status" of a particular Output as a poly_float value.
Definition synth_module.h:35
Declares the Sample and SampleSource classes for loading, managing, and playing back audio samples in...
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Defines the SynthModule class which extends ProcessorRouter to form a building block of the Vital syn...