Vital
Loading...
Searching...
No Matches
wave_source.h
Go to the documentation of this file.
1/*
2Summary:
3WaveSource and WaveSourceKeyframe provide a direct representation of wavetables via WaveFrames. By storing entire waveforms and supporting time or frequency domain interpolation (including cubic methods for smoothness), they enable flexible and sophisticated transitions between keyframes. This results in dynamic and evolving sounds that can be tailored by controlling interpolation modes and parameters.
4 */
5
6#pragma once
7
8#include "JuceHeader.h"
10#include "wave_frame.h"
11
13
26 public:
35
39 WaveSource();
40 virtual ~WaveSource();
41
42 WavetableKeyframe* createKeyframe(int position) override;
43 void render(vital::WaveFrame* wave_frame, float position) override;
45 json stateToJson() override;
46 void jsonToState(json data) override;
47
55
63
70
77
78protected:
79 std::unique_ptr<WaveSourceKeyframe> compute_frame_;
81
82 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveSource)
83};
84
93public:
98 wave_frame_ = std::make_unique<vital::WaveFrame>();
99 }
101
108
109 void copy(const WavetableKeyframe* keyframe) override;
110
118 void linearTimeInterpolate(const vital::WaveFrame* from, const vital::WaveFrame* to, float t);
119
132 void cubicTimeInterpolate(const vital::WaveFrame* prev, const vital::WaveFrame* from,
133 const vital::WaveFrame* to, const vital::WaveFrame* next,
134 float range_prev, float range, float range_next, float t);
135
145 void linearFrequencyInterpolate(const vital::WaveFrame* from, const vital::WaveFrame* to, float t);
146
161 void cubicFrequencyInterpolate(const vital::WaveFrame* prev, const vital::WaveFrame* from,
162 const vital::WaveFrame* to, const vital::WaveFrame* next,
163 float range_prev, float range, float range_next, float t);
164
165 void interpolate(const WavetableKeyframe* from_keyframe, const WavetableKeyframe* to_keyframe, float t) override;
166 void smoothInterpolate(const WavetableKeyframe* prev_keyframe,
167 const WavetableKeyframe* from_keyframe,
168 const WavetableKeyframe* to_keyframe,
169 const WavetableKeyframe* next_keyframe, float t) override;
170
178 }
179
180 json stateToJson() override;
181 void jsonToState(json data) override;
182
189
196
197protected:
198 std::unique_ptr<vital::WaveFrame> wave_frame_;
200
201 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveSourceKeyframe)
202};
A WavetableComponent that acts as a direct source of waveforms.
Definition wave_source.h:25
json stateToJson() override
Serializes the component’s state and all keyframes to a JSON object.
Definition wave_source.cpp:35
std::unique_ptr< WaveSourceKeyframe > compute_frame_
A keyframe for intermediate interpolation computations.
Definition wave_source.h:79
virtual ~WaveSource()
Definition wave_source.cpp:15
void setInterpolationMode(InterpolationMode mode)
Sets the interpolation mode for morphing between keyframes.
Definition wave_source.h:69
InterpolationMode interpolation_mode_
The mode of interpolation.
Definition wave_source.h:80
void jsonToState(json data) override
Restores the component’s state from a JSON object.
Definition wave_source.cpp:41
vital::WaveFrame * getWaveFrame(int index)
Gets a WaveFrame from a specified keyframe index.
Definition wave_source.cpp:47
void render(vital::WaveFrame *wave_frame, float position) override
Renders the waveform at a given position into a WaveFrame.
Definition wave_source.cpp:24
WaveSourceKeyframe * getKeyframe(int index)
Retrieves a WaveSourceKeyframe by index.
Definition wave_source.cpp:51
InterpolationMode getInterpolationMode() const
Gets the current interpolation mode.
Definition wave_source.h:76
WavetableKeyframe * createKeyframe(int position) override
Creates a new keyframe at a given position.
Definition wave_source.cpp:17
InterpolationMode
Defines how keyframes should be interpolated.
Definition wave_source.h:31
@ kTime
Interpolate directly in time domain.
Definition wave_source.h:32
@ kFrequency
Interpolate in frequency domain.
Definition wave_source.h:33
WaveSource()
Constructs a WaveSource with a default frequency-domain interpolation mode.
Definition wave_source.cpp:10
WavetableComponentFactory::ComponentType getType() override
Returns the type of this WavetableComponent.
Definition wave_source.cpp:31
A keyframe that holds a single WaveFrame and supports various interpolation methods.
Definition wave_source.h:92
WaveSourceKeyframe()
Constructs a WaveSourceKeyframe with frequency-domain interpolation mode by default.
Definition wave_source.h:97
WaveSource::InterpolationMode interpolation_mode_
The mode (time or frequency) used for this keyframe's interpolation.
Definition wave_source.h:199
void copy(const WavetableKeyframe *keyframe) override
Copies the state from another keyframe of the same type.
Definition wave_source.cpp:56
void smoothInterpolate(const WavetableKeyframe *prev_keyframe, const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, const WavetableKeyframe *next_keyframe, float t) override
Performs a smooth (cubic) interpolation using four keyframes for even smoother transitions.
Definition wave_source.cpp:173
virtual ~WaveSourceKeyframe()
Definition wave_source.h:100
void cubicTimeInterpolate(const vital::WaveFrame *prev, const vital::WaveFrame *from, const vital::WaveFrame *to, const vital::WaveFrame *next, float range_prev, float range, float range_next, float t)
Cubic interpolation in time domain using four WaveFrames for smooth transitions.
Definition wave_source.cpp:69
void linearFrequencyInterpolate(const vital::WaveFrame *from, const vital::WaveFrame *to, float t)
Linear interpolation in frequency domain.
Definition wave_source.cpp:82
json stateToJson() override
Serializes the state of this keyframe to a JSON object.
Definition wave_source.cpp:193
void setInterpolationMode(WaveSource::InterpolationMode mode)
Sets the interpolation mode for this keyframe.
Definition wave_source.h:188
void jsonToState(json data) override
Restores the keyframe's state from a JSON object.
Definition wave_source.cpp:201
void linearTimeInterpolate(const vital::WaveFrame *from, const vital::WaveFrame *to, float t)
Linearly interpolate two WaveFrames in the time domain.
Definition wave_source.cpp:62
std::unique_ptr< vital::WaveFrame > wave_frame_
The WaveFrame representing this keyframe’s waveform.
Definition wave_source.h:198
WaveSource::InterpolationMode getInterpolationMode() const
Gets the current interpolation mode for this keyframe.
Definition wave_source.h:195
vital::WaveFrame * wave_frame()
Provides direct access to the stored WaveFrame.
Definition wave_source.h:107
void cubicFrequencyInterpolate(const vital::WaveFrame *prev, const vital::WaveFrame *from, const vital::WaveFrame *to, const vital::WaveFrame *next, float range_prev, float range, float range_next, float t)
Cubic interpolation in frequency domain using four WaveFrames.
Definition wave_source.cpp:112
void render(vital::WaveFrame *wave_frame) override
Renders the WaveFrame into the provided wave_frame without modification.
Definition wave_source.h:176
void interpolate(const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t) override
Linearly interpolates between two keyframes.
Definition wave_source.cpp:162
ComponentType
Enumerates all known WavetableComponents, including sources and modifiers.
Definition wavetable_component_factory.h:28
A base class representing a component in a wavetable synthesis chain.
Definition wavetable_component.h:32
Represents a single state of a waveform at a specific position in a wavetable.
Definition wavetable_keyframe.h:35
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
Definition wave_frame.h:16
void copy(const WaveFrame *other)
Copies another WaveFrame's time and frequency domain data into this one.
Definition wave_frame.cpp:57
nlohmann::json json
Definition line_generator.h:7