Vital
|
A keyframe that holds a single WaveFrame and supports various interpolation methods. More...
#include <wave_source.h>
Public Member Functions | |
WaveSourceKeyframe () | |
Constructs a WaveSourceKeyframe with frequency-domain interpolation mode by default. | |
virtual | ~WaveSourceKeyframe () |
vital::WaveFrame * | wave_frame () |
Provides direct access to the stored WaveFrame. | |
void | copy (const WavetableKeyframe *keyframe) override |
Copies the state from another keyframe of the same type. | |
void | linearTimeInterpolate (const vital::WaveFrame *from, const vital::WaveFrame *to, float t) |
Linearly interpolate two WaveFrames in the time domain. | |
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. | |
void | linearFrequencyInterpolate (const vital::WaveFrame *from, const vital::WaveFrame *to, float t) |
Linear interpolation in frequency domain. | |
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. | |
void | interpolate (const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t) override |
Linearly interpolates between two keyframes. | |
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. | |
void | render (vital::WaveFrame *wave_frame) override |
Renders the WaveFrame into the provided wave_frame without modification. | |
json | stateToJson () override |
Serializes the state of this keyframe to a JSON object. | |
void | jsonToState (json data) override |
Restores the keyframe's state from a JSON object. | |
void | setInterpolationMode (WaveSource::InterpolationMode mode) |
Sets the interpolation mode for this keyframe. | |
WaveSource::InterpolationMode | getInterpolationMode () const |
Gets the current interpolation mode for this keyframe. | |
![]() | |
WavetableKeyframe () | |
Constructs a WavetableKeyframe with a default position of 0 and no owner. | |
virtual | ~WavetableKeyframe () |
int | index () |
Gets the index of this keyframe within its owner component. | |
int | position () const |
Gets the wavetable frame position of this keyframe. | |
void | setPosition (int position) |
Sets the frame position of this keyframe. | |
WavetableComponent * | owner () |
Gets the WavetableComponent that owns this keyframe. | |
void | setOwner (WavetableComponent *owner) |
Sets the owner of this keyframe. | |
Protected Attributes | |
std::unique_ptr< vital::WaveFrame > | wave_frame_ |
The WaveFrame representing this keyframe’s waveform. | |
WaveSource::InterpolationMode | interpolation_mode_ |
The mode (time or frequency) used for this keyframe's interpolation. | |
![]() | |
int | position_ |
The position of this keyframe along the wavetable dimension. | |
WavetableComponent * | owner_ |
The component that owns this keyframe. | |
Additional Inherited Members | |
![]() | |
static float | linearTween (float point_from, float point_to, float t) |
Performs linear interpolation between two points. | |
static float | cubicTween (float point_prev, float point_from, float point_to, float point_next, float range_prev, float range, float range_next, float t) |
Performs cubic interpolation taking into account a previous and next point for smoother curves. | |
A keyframe that holds a single WaveFrame and supports various interpolation methods.
A WaveSourceKeyframe stores a WaveFrame that can represent a full cycle of a waveform in both time and frequency domains. It offers functions for linear and cubic interpolation in either time or frequency domains, enabling smooth transitions between different waveforms stored in other keyframes.
|
inline |
Constructs a WaveSourceKeyframe with frequency-domain interpolation mode by default.
|
inlinevirtual |
|
overridevirtual |
Copies the state from another keyframe of the same type.
keyframe | The source keyframe to copy from. |
Implements WavetableKeyframe.
void WaveSourceKeyframe::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.
Allows for very smooth harmonic transitions across multiple keyframes.
prev | The previous WaveFrame. |
from | The starting WaveFrame. |
to | The target WaveFrame. |
next | The next WaveFrame. |
range_prev | The distance to prev. |
range | The distance to to. |
range_next | The distance to next. |
t | The interpolation factor [0,1]. |
void WaveSourceKeyframe::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.
prev | The previous WaveFrame. |
from | The starting WaveFrame. |
to | The target WaveFrame. |
next | The next WaveFrame after 'to'. |
range_prev | The distance (in keyframe positions) to prev. |
range | The distance to to. |
range_next | The distance to next. |
t | The interpolation factor [0,1]. |
|
inline |
Gets the current interpolation mode for this keyframe.
|
overridevirtual |
Linearly interpolates between two keyframes.
from_keyframe | The starting keyframe. |
to_keyframe | The ending keyframe. |
t | The interpolation factor [0,1]. |
Implements WavetableKeyframe.
|
overridevirtual |
Restores the keyframe's state from a JSON object.
data | The JSON object containing the keyframe's state. |
Reimplemented from WavetableKeyframe.
void WaveSourceKeyframe::linearFrequencyInterpolate | ( | const vital::WaveFrame * | from, |
const vital::WaveFrame * | to, | ||
float | t ) |
Linear interpolation in frequency domain.
Interpolates amplitudes and phases of harmonics for a smoother spectral transition.
from | The starting WaveFrame. |
to | The ending WaveFrame. |
t | The interpolation factor [0,1]. |
void WaveSourceKeyframe::linearTimeInterpolate | ( | const vital::WaveFrame * | from, |
const vital::WaveFrame * | to, | ||
float | t ) |
Linearly interpolate two WaveFrames in the time domain.
from | The starting WaveFrame. |
to | The ending WaveFrame. |
t | The interpolation factor [0,1]. |
|
inlineoverridevirtual |
Renders the WaveFrame into the provided wave_frame without modification.
wave_frame | The WaveFrame to copy into. |
Implements WavetableKeyframe.
|
inline |
Sets the interpolation mode for this keyframe.
mode | The interpolation mode (time or frequency). |
|
overridevirtual |
Performs a smooth (cubic) interpolation using four keyframes for even smoother transitions.
By default does nothing. Subclasses can implement cubic interpolation if desired.
prev_keyframe | The keyframe before from_keyframe. |
from_keyframe | The starting keyframe. |
to_keyframe | The ending keyframe. |
next_keyframe | The keyframe after to_keyframe. |
t | The interpolation factor [0,1]. |
Reimplemented from WavetableKeyframe.
|
overridevirtual |
Serializes the state of this keyframe to a JSON object.
Reimplemented from WavetableKeyframe.
|
inline |
Provides direct access to the stored WaveFrame.
|
protected |
The mode (time or frequency) used for this keyframe's interpolation.
|
protected |
The WaveFrame representing this keyframe’s waveform.