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

A WavetableComponent that applies nonlinear horizontal and vertical warping to a waveform. More...

#include <wave_warp_modifier.h>

Inheritance diagram for WaveWarpModifier:
WavetableComponent

Classes

class  WaveWarpModifierKeyframe
 A keyframe class holding horizontal and vertical warp parameters at a given position. More...
 

Public Member Functions

 WaveWarpModifier ()
 Constructs a WaveWarpModifier with symmetric warping by default.
 
virtual ~WaveWarpModifier ()=default
 
WavetableKeyframecreateKeyframe (int position) override
 Creates a new keyframe at a given position.
 
void render (vital::WaveFrame *wave_frame, float position) override
 Renders the waveform at a given position into a WaveFrame.
 
WavetableComponentFactory::ComponentType getType () override
 Returns the type of this WavetableComponent.
 
json stateToJson () override
 Serializes the component’s state and all keyframes to a JSON object.
 
void jsonToState (json data) override
 Restores the component’s state from a JSON object.
 
void setHorizontalAsymmetric (bool horizontal_asymmetric)
 Sets whether horizontal warping is asymmetric.
 
void setVerticalAsymmetric (bool vertical_asymmetric)
 Sets whether vertical warping is asymmetric.
 
bool getHorizontalAsymmetric () const
 Checks if horizontal warping is asymmetric.
 
bool getVerticalAsymmetric () const
 Checks if vertical warping is asymmetric.
 
WaveWarpModifierKeyframegetKeyframe (int index)
 Retrieves a WaveWarpModifierKeyframe by index.
 
- Public Member Functions inherited from WavetableComponent
 WavetableComponent ()
 Constructs a WavetableComponent with a default linear interpolation style.
 
virtual ~WavetableComponent ()
 
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

WaveWarpModifierKeyframe compute_frame_
 Keyframe used for intermediate computation.
 
bool horizontal_asymmetric_
 Controls horizontal warping symmetry.
 
bool vertical_asymmetric_
 Controls vertical warping symmetry.
 
- Protected Attributes inherited from WavetableComponent
std::vector< std::unique_ptr< WavetableKeyframe > > keyframes_
 The list of keyframes sorted by position.
 
InterpolationStyle interpolation_style_
 Current interpolation style (none, linear, cubic).
 

Additional Inherited Members

- Public Types inherited from WavetableComponent
enum  InterpolationStyle { kNone , kLinear , kCubic , kNumInterpolationStyles }
 Defines how interpolation is performed between keyframes. More...
 

Detailed Description

A WavetableComponent that applies nonlinear horizontal and vertical warping to a waveform.

WaveWarpModifier deforms the waveform’s time-domain shape by stretching or compressing the wave along both the horizontal (time) and vertical (amplitude) axes. It uses exponential-like mappings to create nonlinear transformations. Users can control two independent warp powers:

  • Horizontal power: adjusts how the sample positions are warped along the waveform cycle.
  • Vertical power: adjusts how the waveform amplitude is warped.

Furthermore, the warping can be symmetric or asymmetric:

  • Asymmetric warping: transforms only one side (e.g., positive or negative half) more strongly than the other.
  • Symmetric warping: applies a balanced transformation around a center point.

Constructor & Destructor Documentation

◆ WaveWarpModifier()

WaveWarpModifier::WaveWarpModifier ( )
inline

Constructs a WaveWarpModifier with symmetric warping by default.

◆ ~WaveWarpModifier()

virtual WaveWarpModifier::~WaveWarpModifier ( )
virtualdefault

Member Function Documentation

◆ createKeyframe()

WavetableKeyframe * WaveWarpModifier::createKeyframe ( int position)
overridevirtual

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.

Implements WavetableComponent.

◆ getHorizontalAsymmetric()

bool WaveWarpModifier::getHorizontalAsymmetric ( ) const
inline

Checks if horizontal warping is asymmetric.

Returns
True if horizontally asymmetric, false otherwise.

◆ getKeyframe()

WaveWarpModifier::WaveWarpModifierKeyframe * WaveWarpModifier::getKeyframe ( int index)

Retrieves a WaveWarpModifierKeyframe by index.

Parameters
indexThe index of the desired keyframe.
Returns
A pointer to the WaveWarpModifierKeyframe.

◆ getType()

WavetableComponentFactory::ComponentType WaveWarpModifier::getType ( )
overridevirtual

Returns the type of this WavetableComponent.

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

Returns
The component type enumerated in WavetableComponentFactory.

Implements WavetableComponent.

◆ getVerticalAsymmetric()

bool WaveWarpModifier::getVerticalAsymmetric ( ) const
inline

Checks if vertical warping is asymmetric.

Returns
True if vertically asymmetric, false otherwise.

◆ jsonToState()

void WaveWarpModifier::jsonToState ( json data)
overridevirtual

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 from WavetableComponent.

◆ render()

void WaveWarpModifier::render ( vital::WaveFrame * wave_frame,
float position )
overridevirtual

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].

Implements WavetableComponent.

◆ setHorizontalAsymmetric()

void WaveWarpModifier::setHorizontalAsymmetric ( bool horizontal_asymmetric)
inline

Sets whether horizontal warping is asymmetric.

Parameters
horizontal_asymmetricTrue for asymmetric, false for symmetric.

◆ setVerticalAsymmetric()

void WaveWarpModifier::setVerticalAsymmetric ( bool vertical_asymmetric)
inline

Sets whether vertical warping is asymmetric.

Parameters
vertical_asymmetricTrue for asymmetric, false for symmetric.

◆ stateToJson()

json WaveWarpModifier::stateToJson ( )
overridevirtual

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

Returns
A JSON object representing the entire state.

Reimplemented from WavetableComponent.

Member Data Documentation

◆ compute_frame_

WaveWarpModifierKeyframe WaveWarpModifier::compute_frame_
protected

Keyframe used for intermediate computation.

◆ horizontal_asymmetric_

bool WaveWarpModifier::horizontal_asymmetric_
protected

Controls horizontal warping symmetry.

◆ vertical_asymmetric_

bool WaveWarpModifier::vertical_asymmetric_
protected

Controls vertical warping symmetry.


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