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

A WavetableComponent that modifies the phase of frequency components in a wavetable frame. More...

#include <phase_modifier.h>

Inheritance diagram for PhaseModifier:
WavetableComponent

Classes

class  PhaseModifierKeyframe
 A keyframe class holding parameters for phase modification at a given position. More...
 

Public Types

enum  PhaseStyle {
  kNormal , kEvenOdd , kHarmonic , kHarmonicEvenOdd ,
  kClear , kNumPhaseStyles
}
 Various methods to modify harmonic phase. More...
 
- Public Types inherited from WavetableComponent
enum  InterpolationStyle { kNone , kLinear , kCubic , kNumInterpolationStyles }
 Defines how interpolation is performed between keyframes. More...
 

Public Member Functions

 PhaseModifier ()
 Constructs a PhaseModifier with a default normal phase style.
 
virtual ~PhaseModifier ()=default
 
virtual WavetableKeyframecreateKeyframe (int position) override
 Creates a new keyframe at a given position.
 
virtual void render (vital::WaveFrame *wave_frame, float position) override
 Renders the waveform at a given position into a WaveFrame.
 
virtual WavetableComponentFactory::ComponentType getType () override
 Returns the type of this WavetableComponent.
 
virtual json stateToJson () override
 Serializes the component’s state and all keyframes to a JSON object.
 
virtual void jsonToState (json data) override
 Restores the component’s state from a JSON object.
 
PhaseModifierKeyframegetKeyframe (int index)
 Retrieves a PhaseModifierKeyframe by index.
 
void setPhaseStyle (PhaseStyle style)
 Sets the style of phase modification.
 
PhaseStyle getPhaseStyle () const
 Gets the current phase modification style.
 
- 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

PhaseModifierKeyframe compute_frame_
 A keyframe for intermediate computation.
 
PhaseStyle phase_style_
 The selected style of phase modification.
 
- 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).
 

Detailed Description

A WavetableComponent that modifies the phase of frequency components in a wavetable frame.

PhaseModifier adjusts the phase relationships between harmonic components of a wave. Different phase styles can produce effects such as shifting all harmonics uniformly, applying alternate phase shifts to even/odd harmonics, or completely clearing phase information. It allows partial blending of the phase modification using a mix parameter.

Member Enumeration Documentation

◆ PhaseStyle

Various methods to modify harmonic phase.

Enumerator
kNormal 

Apply a harmonic phase shift cumulatively up the harmonic series.

kEvenOdd 

Apply different phase treatments to even and odd harmonics.

kHarmonic 

Uniformly shift phase for all harmonics directly.

kHarmonicEvenOdd 

Apply a harmonic-based shift with separate handling of even/odd harmonics.

kClear 

Clear phase information, making all harmonics in phase.

kNumPhaseStyles 

Constructor & Destructor Documentation

◆ PhaseModifier()

PhaseModifier::PhaseModifier ( )
inline

Constructs a PhaseModifier with a default normal phase style.

◆ ~PhaseModifier()

virtual PhaseModifier::~PhaseModifier ( )
virtualdefault

Member Function Documentation

◆ createKeyframe()

WavetableKeyframe * PhaseModifier::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.

◆ getKeyframe()

PhaseModifier::PhaseModifierKeyframe * PhaseModifier::getKeyframe ( int index)

Retrieves a PhaseModifierKeyframe by index.

Parameters
indexThe index of the desired keyframe.
Returns
Pointer to the PhaseModifierKeyframe.

◆ getPhaseStyle()

PhaseStyle PhaseModifier::getPhaseStyle ( ) const
inline

Gets the current phase modification style.

Returns
The current PhaseStyle.

◆ getType()

WavetableComponentFactory::ComponentType PhaseModifier::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.

◆ jsonToState()

void PhaseModifier::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 PhaseModifier::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.

◆ setPhaseStyle()

void PhaseModifier::setPhaseStyle ( PhaseStyle style)
inline

Sets the style of phase modification.

Parameters
styleThe chosen PhaseStyle.

◆ stateToJson()

json PhaseModifier::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_

PhaseModifierKeyframe PhaseModifier::compute_frame_
protected

A keyframe for intermediate computation.

◆ phase_style_

PhaseStyle PhaseModifier::phase_style_
protected

The selected style of phase modification.


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