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

A base class representing a component in a wavetable synthesis chain. More...

#include <wavetable_component.h>

Inheritance diagram for WavetableComponent:
FileSource FrequencyFilterModifier PhaseModifier SlewLimitModifier WaveFoldModifier WaveLineSource WaveSource WaveWarpModifier WaveWindowModifier

Public Types

enum  InterpolationStyle { kNone , kLinear , kCubic , kNumInterpolationStyles }
 Defines how interpolation is performed between keyframes. More...
 

Public Member Functions

 WavetableComponent ()
 Constructs a WavetableComponent with a default linear interpolation style.
 
virtual ~WavetableComponent ()
 
virtual WavetableKeyframecreateKeyframe (int position)=0
 Creates a new keyframe at a given position.
 
virtual void render (vital::WaveFrame *wave_frame, float position)=0
 Renders the waveform at a given position into a WaveFrame.
 
virtual WavetableComponentFactory::ComponentType getType ()=0
 Returns the type of this WavetableComponent.
 
virtual json stateToJson ()
 Serializes the component’s state and all keyframes to a JSON object.
 
virtual void jsonToState (json data)
 Restores the component’s state from a JSON object.
 
virtual void prerender ()
 Called before rendering to perform any needed precomputation.
 
virtual bool hasKeyframes ()
 Indicates whether this component relies on multiple keyframes.
 
void reset ()
 Clears all keyframes and inserts a default one at position 0.
 
void interpolate (WavetableKeyframe *dest, float position)
 Interpolates a destination keyframe at a given position.
 
WavetableKeyframeinsertNewKeyframe (int position)
 Inserts a new keyframe at the given position, creating and sorting it into the array.
 
void reposition (WavetableKeyframe *keyframe)
 Repositions a keyframe in the keyframe list after its position changed.
 
void remove (WavetableKeyframe *keyframe)
 Removes a specific keyframe from the component.
 
int numFrames () const
 Gets the number of keyframes.
 
int indexOf (WavetableKeyframe *keyframe) const
 Finds the index of a given keyframe.
 
WavetableKeyframegetFrameAt (int index) const
 Gets a keyframe by index.
 
int getIndexFromPosition (int position) const
 Finds the insertion index for a given position to keep keyframes sorted.
 
WavetableKeyframegetFrameAtPosition (int position)
 Gets a keyframe by position if one matches exactly, or nullptr otherwise.
 
int getLastKeyframePosition ()
 Gets the highest position among all keyframes.
 
void setInterpolationStyle (InterpolationStyle type)
 Sets the global interpolation style.
 
InterpolationStyle getInterpolationStyle () const
 Gets the current global interpolation style.
 

Protected Attributes

std::vector< std::unique_ptr< WavetableKeyframe > > keyframes_
 The list of keyframes sorted by position.
 
InterpolationStyle interpolation_style_
 Current interpolation style (none, linear, cubic).
 

Detailed Description

A base class representing a component in a wavetable synthesis chain.

WavetableComponent manages a collection of WavetableKeyframes, each representing a waveform configuration at a certain position (time/frame index). By interpolating between these keyframes, the component produces a smooth transition of waveform shapes across the wavetable dimension. WavetableComponents can represent sources of waveforms, or modifiers that apply transformations to existing waveforms.

Key functionalities include:

  • Creating and managing keyframes.
  • Interpolating between keyframes using linear or cubic styles.
  • Serialization to/from JSON for preset saving.

Member Enumeration Documentation

◆ InterpolationStyle

Defines how interpolation is performed between keyframes.

Enumerator
kNone 

No interpolation, just jumps between keyframes.

kLinear 

Linear interpolation between adjacent keyframes.

kCubic 

Cubic interpolation for smoother transitions.

kNumInterpolationStyles 

Constructor & Destructor Documentation

◆ WavetableComponent()

WavetableComponent::WavetableComponent ( )
inline

Constructs a WavetableComponent with a default linear interpolation style.

◆ ~WavetableComponent()

virtual WavetableComponent::~WavetableComponent ( )
inlinevirtual

Member Function Documentation

◆ createKeyframe()

virtual WavetableKeyframe * WavetableComponent::createKeyframe ( int position)
pure virtual

Creates a new keyframe at a given position.

Implemented by subclasses to produce a keyframe type suited to their functionality.

Parameters
positionThe wavetable frame index (0 to kNumOscillatorWaveFrames-1).
Returns
A pointer to the newly created WavetableKeyframe.

Implemented in FileSource, FrequencyFilterModifier, PhaseModifier, SlewLimitModifier, WaveFoldModifier, WaveLineSource, WaveSource, WaveWarpModifier, and WaveWindowModifier.

◆ getFrameAt()

WavetableKeyframe * WavetableComponent::getFrameAt ( int index) const
inline

Gets a keyframe by index.

Parameters
indexThe keyframe index.
Returns
The WavetableKeyframe at that index.

◆ getFrameAtPosition()

WavetableKeyframe * WavetableComponent::getFrameAtPosition ( int position)

Gets a keyframe by position if one matches exactly, or nullptr otherwise.

Parameters
positionThe position to search for.
Returns
The keyframe at that position or nullptr if none matches.

◆ getIndexFromPosition()

int WavetableComponent::getIndexFromPosition ( int position) const

Finds the insertion index for a given position to keep keyframes sorted.

Parameters
positionThe position along the wavetable.
Returns
The index where a keyframe with this position should be inserted.

◆ getInterpolationStyle()

InterpolationStyle WavetableComponent::getInterpolationStyle ( ) const
inline

Gets the current global interpolation style.

Returns
The InterpolationStyle currently used.

◆ getLastKeyframePosition()

int WavetableComponent::getLastKeyframePosition ( )

Gets the highest position among all keyframes.

If no keyframes exist, returns 0. If the component doesn't use keyframes, returns the last possible frame index.

Returns
The position of the last keyframe.

◆ getType()

virtual WavetableComponentFactory::ComponentType WavetableComponent::getType ( )
pure virtual

Returns the type of this WavetableComponent.

Used to identify the specific component for serialization and UI mapping.

Returns
The component type enumerated in WavetableComponentFactory.

Implemented in FileSource, FrequencyFilterModifier, PhaseModifier, ShepardToneSource, SlewLimitModifier, WaveFoldModifier, WaveLineSource, WaveSource, WaveWarpModifier, and WaveWindowModifier.

◆ hasKeyframes()

virtual bool WavetableComponent::hasKeyframes ( )
inlinevirtual

Indicates whether this component relies on multiple keyframes.

Returns
True by default, can be overridden by subclasses that do not use keyframes.

Reimplemented in ShepardToneSource.

◆ indexOf()

int WavetableComponent::indexOf ( WavetableKeyframe * keyframe) const
inline

Finds the index of a given keyframe.

Parameters
keyframeThe keyframe pointer to find.
Returns
The index of the keyframe or -1 if not found.

◆ insertNewKeyframe()

WavetableKeyframe * WavetableComponent::insertNewKeyframe ( int position)

Inserts a new keyframe at the given position, creating and sorting it into the array.

Parameters
positionThe position along the wavetable dimension.
Returns
The newly created WavetableKeyframe.

◆ interpolate()

void WavetableComponent::interpolate ( WavetableKeyframe * dest,
float position )

Interpolates a destination keyframe at a given position.

Uses the current interpolation style (none, linear, cubic) to populate dest with data interpolated from existing keyframes.

Parameters
destThe destination keyframe to fill.
positionThe position along the wavetable to interpolate at.

◆ jsonToState()

void WavetableComponent::jsonToState ( json data)
virtual

Restores the component’s state from a JSON object.

Clears existing keyframes and reconstructs them from the provided JSON data.

Parameters
dataThe JSON object containing saved state data.

Reimplemented in FileSource, FrequencyFilterModifier, PhaseModifier, WaveLineSource, WaveSource, WaveWarpModifier, and WaveWindowModifier.

◆ numFrames()

int WavetableComponent::numFrames ( ) const
inline

Gets the number of keyframes.

Returns
The number of keyframes.

◆ prerender()

virtual void WavetableComponent::prerender ( )
inlinevirtual

Called before rendering to perform any needed precomputation.

By default does nothing, can be overridden by subclasses.

◆ remove()

void WavetableComponent::remove ( WavetableKeyframe * keyframe)

Removes a specific keyframe from the component.

Parameters
keyframeThe keyframe to remove.

◆ render()

virtual void WavetableComponent::render ( vital::WaveFrame * wave_frame,
float position )
pure virtual

Renders the waveform at a given position into a WaveFrame.

Uses interpolation between keyframes based on the current interpolation style to produce a waveform for the given position.

Parameters
wave_frameThe WaveFrame to fill with the resulting waveform.
positionThe position along the wavetable dimension [0, kNumOscillatorWaveFrames-1].

Implemented in FileSource, FrequencyFilterModifier, PhaseModifier, ShepardToneSource, SlewLimitModifier, WaveFoldModifier, WaveLineSource, WaveSource, WaveWarpModifier, and WaveWindowModifier.

◆ reposition()

void WavetableComponent::reposition ( WavetableKeyframe * keyframe)

Repositions a keyframe in the keyframe list after its position changed.

Removes and re-inserts it in sorted order by position.

Parameters
keyframeThe keyframe to reposition.

◆ reset()

void WavetableComponent::reset ( )

Clears all keyframes and inserts a default one at position 0.

◆ setInterpolationStyle()

void WavetableComponent::setInterpolationStyle ( InterpolationStyle type)
inline

Sets the global interpolation style.

Parameters
typeThe InterpolationStyle (none, linear, cubic).

◆ stateToJson()

json WavetableComponent::stateToJson ( )
virtual

Serializes the component’s state and all keyframes to a JSON object.

Returns
A JSON object representing the entire state.

Reimplemented in FileSource, FrequencyFilterModifier, PhaseModifier, WaveLineSource, WaveSource, WaveWarpModifier, and WaveWindowModifier.

Member Data Documentation

◆ interpolation_style_

InterpolationStyle WavetableComponent::interpolation_style_
protected

Current interpolation style (none, linear, cubic).

◆ keyframes_

std::vector<std::unique_ptr<WavetableKeyframe> > WavetableComponent::keyframes_
protected

The list of keyframes sorted by position.


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