Vital
Loading...
Searching...
No Matches
WavetableKeyframe Class Referenceabstract

Represents a single state of a waveform at a specific position in a wavetable. More...

#include <wavetable_keyframe.h>

Inheritance diagram for WavetableKeyframe:
FileSource::FileSourceKeyframe FrequencyFilterModifier::FrequencyFilterModifierKeyframe PhaseModifier::PhaseModifierKeyframe SlewLimitModifier::SlewLimitModifierKeyframe WaveFoldModifier::WaveFoldModifierKeyframe WaveLineSource::WaveLineSourceKeyframe WaveSourceKeyframe WaveWarpModifier::WaveWarpModifierKeyframe WaveWindowModifier::WaveWindowModifierKeyframe

Public Member Functions

 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.
 
virtual void copy (const WavetableKeyframe *keyframe)=0
 Copies the state from another keyframe of the same type.
 
virtual void interpolate (const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t)=0
 Linearly interpolates between two keyframes.
 
virtual void smoothInterpolate (const WavetableKeyframe *prev_keyframe, const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, const WavetableKeyframe *next_keyframe, float t)
 Performs a smooth (cubic) interpolation using four keyframes for even smoother transitions.
 
virtual void render (vital::WaveFrame *wave_frame)=0
 Renders the waveform of this keyframe into a WaveFrame.
 
virtual json stateToJson ()
 Serializes the state of this keyframe to a JSON object.
 
virtual void jsonToState (json data)
 Restores the keyframe's state from a JSON object.
 
WavetableComponentowner ()
 Gets the WavetableComponent that owns this keyframe.
 
void setOwner (WavetableComponent *owner)
 Sets the owner of this keyframe.
 

Static Public Member Functions

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.
 

Protected Attributes

int position_
 The position of this keyframe along the wavetable dimension.
 
WavetableComponentowner_
 The component that owns this keyframe.
 

Detailed Description

Represents a single state of a waveform at a specific position in a wavetable.

WavetableKeyframe acts as a snapshot of a waveform configuration at a particular frame index. Wavetable components typically have multiple keyframes spaced across the wavetable dimension. Interpolating between these keyframes produces smooth changes in the waveform over the course of the table.

Each keyframe stores:

  • A position within the wavetable (0 to kNumOscillatorWaveFrames-1).
  • A reference to its owning component.

Subclasses define how the keyframe’s waveform data is stored and how interpolation and rendering are performed.

Constructor & Destructor Documentation

◆ WavetableKeyframe()

WavetableKeyframe::WavetableKeyframe ( )
inline

Constructs a WavetableKeyframe with a default position of 0 and no owner.

◆ ~WavetableKeyframe()

virtual WavetableKeyframe::~WavetableKeyframe ( )
inlinevirtual

Member Function Documentation

◆ copy()

◆ cubicTween()

float WavetableKeyframe::cubicTween ( float point_prev,
float point_from,
float point_to,
float point_next,
float range_prev,
float range,
float range_next,
float t )
static

Performs cubic interpolation taking into account a previous and next point for smoother curves.

Parameters
point_prevThe value before the start.
point_fromThe starting value.
point_toThe ending value.
point_nextThe value after the end.
range_prevThe horizontal distance to point_prev.
rangeThe horizontal distance between point_from and point_to.
range_nextThe horizontal distance to point_next.
tThe interpolation factor [0,1].
Returns
The smoothly interpolated value.

◆ index()

int WavetableKeyframe::index ( )

Gets the index of this keyframe within its owner component.

Returns
The index of the keyframe or -1 if not found.

◆ interpolate()

virtual void WavetableKeyframe::interpolate ( const WavetableKeyframe * from_keyframe,
const WavetableKeyframe * to_keyframe,
float t )
pure virtual

◆ jsonToState()

◆ linearTween()

float WavetableKeyframe::linearTween ( float point_from,
float point_to,
float t )
static

Performs linear interpolation between two points.

Parameters
point_fromThe starting value.
point_toThe ending value.
tThe interpolation factor [0,1].
Returns
The interpolated value.

◆ owner()

WavetableComponent * WavetableKeyframe::owner ( )
inline

Gets the WavetableComponent that owns this keyframe.

Returns
A pointer to the owner component.

◆ position()

int WavetableKeyframe::position ( ) const
inline

Gets the wavetable frame position of this keyframe.

Returns
The frame position (0 to kNumOscillatorWaveFrames-1).

◆ render()

◆ setOwner()

void WavetableKeyframe::setOwner ( WavetableComponent * owner)
inline

Sets the owner of this keyframe.

Parameters
ownerThe WavetableComponent that owns this keyframe.

◆ setPosition()

void WavetableKeyframe::setPosition ( int position)
inline

Sets the frame position of this keyframe.

Parameters
positionThe new frame position.

◆ smoothInterpolate()

virtual void WavetableKeyframe::smoothInterpolate ( const WavetableKeyframe * prev_keyframe,
const WavetableKeyframe * from_keyframe,
const WavetableKeyframe * to_keyframe,
const WavetableKeyframe * next_keyframe,
float t )
inlinevirtual

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 in WaveSourceKeyframe.

◆ stateToJson()

Member Data Documentation

◆ owner_

WavetableComponent* WavetableKeyframe::owner_
protected

The component that owns this keyframe.

◆ position_

int WavetableKeyframe::position_
protected

The position of this keyframe along the wavetable dimension.


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