Vital
Loading...
Searching...
No Matches
WaveSourceKeyframe Class Reference

A keyframe that holds a single WaveFrame and supports various interpolation methods. More...

#include <wave_source.h>

Inheritance diagram for WaveSourceKeyframe:
WavetableKeyframe

Public Member Functions

 WaveSourceKeyframe ()
 Constructs a WaveSourceKeyframe with frequency-domain interpolation mode by default.
 
virtual ~WaveSourceKeyframe ()
 
vital::WaveFramewave_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.
 
- Public Member Functions inherited from WavetableKeyframe
 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.
 
WavetableComponentowner ()
 Gets the WavetableComponent that owns this keyframe.
 
void setOwner (WavetableComponent *owner)
 Sets the owner of this keyframe.
 

Protected Attributes

std::unique_ptr< vital::WaveFramewave_frame_
 The WaveFrame representing this keyframe’s waveform.
 
WaveSource::InterpolationMode interpolation_mode_
 The mode (time or frequency) used for this keyframe's interpolation.
 
- Protected Attributes inherited from WavetableKeyframe
int position_
 The position of this keyframe along the wavetable dimension.
 
WavetableComponentowner_
 The component that owns this keyframe.
 

Additional Inherited Members

- Static Public Member Functions inherited from WavetableKeyframe
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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ WaveSourceKeyframe()

WaveSourceKeyframe::WaveSourceKeyframe ( )
inline

Constructs a WaveSourceKeyframe with frequency-domain interpolation mode by default.

◆ ~WaveSourceKeyframe()

virtual WaveSourceKeyframe::~WaveSourceKeyframe ( )
inlinevirtual

Member Function Documentation

◆ copy()

void WaveSourceKeyframe::copy ( const WavetableKeyframe * keyframe)
overridevirtual

Copies the state from another keyframe of the same type.

Parameters
keyframeThe source keyframe to copy from.

Implements WavetableKeyframe.

◆ cubicFrequencyInterpolate()

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.

Parameters
prevThe previous WaveFrame.
fromThe starting WaveFrame.
toThe target WaveFrame.
nextThe next WaveFrame.
range_prevThe distance to prev.
rangeThe distance to to.
range_nextThe distance to next.
tThe interpolation factor [0,1].

◆ cubicTimeInterpolate()

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.

Parameters
prevThe previous WaveFrame.
fromThe starting WaveFrame.
toThe target WaveFrame.
nextThe next WaveFrame after 'to'.
range_prevThe distance (in keyframe positions) to prev.
rangeThe distance to to.
range_nextThe distance to next.
tThe interpolation factor [0,1].

◆ getInterpolationMode()

WaveSource::InterpolationMode WaveSourceKeyframe::getInterpolationMode ( ) const
inline

Gets the current interpolation mode for this keyframe.

Returns
The interpolation mode currently in use.

◆ interpolate()

void WaveSourceKeyframe::interpolate ( const WavetableKeyframe * from_keyframe,
const WavetableKeyframe * to_keyframe,
float t )
overridevirtual

Linearly interpolates between two keyframes.

Parameters
from_keyframeThe starting keyframe.
to_keyframeThe ending keyframe.
tThe interpolation factor [0,1].

Implements WavetableKeyframe.

◆ jsonToState()

void WaveSourceKeyframe::jsonToState ( json data)
overridevirtual

Restores the keyframe's state from a JSON object.

Parameters
dataThe JSON object containing the keyframe's state.

Reimplemented from WavetableKeyframe.

◆ linearFrequencyInterpolate()

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.

Parameters
fromThe starting WaveFrame.
toThe ending WaveFrame.
tThe interpolation factor [0,1].

◆ linearTimeInterpolate()

void WaveSourceKeyframe::linearTimeInterpolate ( const vital::WaveFrame * from,
const vital::WaveFrame * to,
float t )

Linearly interpolate two WaveFrames in the time domain.

Parameters
fromThe starting WaveFrame.
toThe ending WaveFrame.
tThe interpolation factor [0,1].

◆ render()

void WaveSourceKeyframe::render ( vital::WaveFrame * wave_frame)
inlineoverridevirtual

Renders the WaveFrame into the provided wave_frame without modification.

Parameters
wave_frameThe WaveFrame to copy into.

Implements WavetableKeyframe.

◆ setInterpolationMode()

void WaveSourceKeyframe::setInterpolationMode ( WaveSource::InterpolationMode mode)
inline

Sets the interpolation mode for this keyframe.

Parameters
modeThe interpolation mode (time or frequency).

◆ smoothInterpolate()

void WaveSourceKeyframe::smoothInterpolate ( const WavetableKeyframe * prev_keyframe,
const WavetableKeyframe * from_keyframe,
const WavetableKeyframe * to_keyframe,
const WavetableKeyframe * next_keyframe,
float t )
overridevirtual

Performs a smooth (cubic) interpolation using four keyframes for even smoother transitions.

By default does nothing. Subclasses can implement cubic interpolation if desired.

Parameters
prev_keyframeThe keyframe before from_keyframe.
from_keyframeThe starting keyframe.
to_keyframeThe ending keyframe.
next_keyframeThe keyframe after to_keyframe.
tThe interpolation factor [0,1].

Reimplemented from WavetableKeyframe.

◆ stateToJson()

json WaveSourceKeyframe::stateToJson ( )
overridevirtual

Serializes the state of this keyframe to a JSON object.

Returns
A JSON object representing the keyframe.

Reimplemented from WavetableKeyframe.

◆ wave_frame()

vital::WaveFrame * WaveSourceKeyframe::wave_frame ( )
inline

Provides direct access to the stored WaveFrame.

Returns
A pointer to the WaveFrame held by this keyframe.

Member Data Documentation

◆ interpolation_mode_

WaveSource::InterpolationMode WaveSourceKeyframe::interpolation_mode_
protected

The mode (time or frequency) used for this keyframe's interpolation.

◆ wave_frame_

std::unique_ptr<vital::WaveFrame> WaveSourceKeyframe::wave_frame_
protected

The WaveFrame representing this keyframe’s waveform.


The documentation for this class was generated from the following files: