Vital
Loading...
Searching...
No Matches
phase_modifier.h
Go to the documentation of this file.
1/*
2Summary:
3PhaseModifier manipulates the phase relationships among a wavetable’s harmonic components to achieve various timbral effects. By selecting a PhaseStyle and controlling parameters like phase offset and mix, it can produce harmonic shifts, alternate even/odd phase patterns, or clear all phase differences. Interpolating between keyframes allows for dynamic phase evolutions across the wavetable’s dimension.
4 */
5
6#pragma once
7
8#include "JuceHeader.h"
10
20 public:
33
42 public:
48
49 void copy(const WavetableKeyframe* keyframe) override;
50 void interpolate(const WavetableKeyframe* from_keyframe,
51 const WavetableKeyframe* to_keyframe, float t) override;
52 void render(vital::WaveFrame* wave_frame) override;
53 json stateToJson() override;
54 void jsonToState(json data) override;
55
61 float getPhase() { return phase_; }
62
68 float getMix() { return mix_; }
69
75 void setPhase(float phase) { phase_ = phase; }
76
82 void setMix(float mix) { mix_ = mix; }
83
89 void setPhaseStyle(PhaseStyle style) { phase_style_ = style; }
90
91 protected:
92 float phase_;
93 float mix_;
95
96 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PhaseModifierKeyframe)
97 };
98
103 virtual ~PhaseModifier() = default;
104
105 virtual WavetableKeyframe* createKeyframe(int position) override;
106 virtual void render(vital::WaveFrame* wave_frame, float position) override;
108 virtual json stateToJson() override;
109 virtual void jsonToState(json data) override;
110
118
124 void setPhaseStyle(PhaseStyle style) { phase_style_ = style; }
125
132
133 protected:
136
137 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PhaseModifier)
138};
139
A keyframe class holding parameters for phase modification at a given position.
Definition phase_modifier.h:41
float getMix()
Gets the mix ratio blending between original and modified phases.
Definition phase_modifier.h:68
void setMix(float mix)
Sets the mix ratio.
Definition phase_modifier.h:82
float getPhase()
Gets the phase offset applied to harmonics.
Definition phase_modifier.h:61
void jsonToState(json data) override
Restores the keyframe's state from a JSON object.
Definition phase_modifier.cpp:95
void copy(const WavetableKeyframe *keyframe) override
Copies the state from another keyframe of the same type.
Definition phase_modifier.cpp:27
PhaseModifierKeyframe()
Constructs a keyframe with default phase and mix values.
Definition phase_modifier.cpp:25
PhaseStyle phase_style_
Selected phase modification style.
Definition phase_modifier.h:94
json stateToJson() override
Serializes the state of this keyframe to a JSON object.
Definition phase_modifier.cpp:88
virtual ~PhaseModifierKeyframe()
Definition phase_modifier.h:47
void setPhase(float phase)
Sets the phase offset (in radians).
Definition phase_modifier.h:75
void interpolate(const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t) override
Linearly interpolates between two keyframes.
Definition phase_modifier.cpp:33
void setPhaseStyle(PhaseStyle style)
Sets the phase modification style.
Definition phase_modifier.h:89
void render(vital::WaveFrame *wave_frame) override
Renders the waveform of this keyframe into a WaveFrame.
Definition phase_modifier.cpp:43
float phase_
The phase offset in radians.
Definition phase_modifier.h:92
float mix_
The blend between original and modified harmonic phases.
Definition phase_modifier.h:93
A WavetableComponent that modifies the phase of frequency components in a wavetable frame.
Definition phase_modifier.h:19
PhaseModifier()
Constructs a PhaseModifier with a default normal phase style.
Definition phase_modifier.h:102
PhaseStyle phase_style_
The selected style of phase modification.
Definition phase_modifier.h:135
virtual WavetableKeyframe * createKeyframe(int position) override
Creates a new keyframe at a given position.
Definition phase_modifier.cpp:101
virtual WavetableComponentFactory::ComponentType getType() override
Returns the type of this WavetableComponent.
Definition phase_modifier.cpp:113
virtual ~PhaseModifier()=default
PhaseStyle getPhaseStyle() const
Gets the current phase modification style.
Definition phase_modifier.h:131
PhaseModifierKeyframe * getKeyframe(int index)
Retrieves a PhaseModifierKeyframe by index.
Definition phase_modifier.cpp:128
PhaseModifierKeyframe compute_frame_
A keyframe for intermediate computation.
Definition phase_modifier.h:134
virtual void render(vital::WaveFrame *wave_frame, float position) override
Renders the waveform at a given position into a WaveFrame.
Definition phase_modifier.cpp:107
virtual json stateToJson() override
Serializes the component’s state and all keyframes to a JSON object.
Definition phase_modifier.cpp:117
void setPhaseStyle(PhaseStyle style)
Sets the style of phase modification.
Definition phase_modifier.h:124
PhaseStyle
Various methods to modify harmonic phase.
Definition phase_modifier.h:25
@ kClear
Clear phase information, making all harmonics in phase.
Definition phase_modifier.h:30
@ kNumPhaseStyles
Definition phase_modifier.h:31
@ kHarmonicEvenOdd
Apply a harmonic-based shift with separate handling of even/odd harmonics.
Definition phase_modifier.h:29
@ kNormal
Apply a harmonic phase shift cumulatively up the harmonic series.
Definition phase_modifier.h:26
@ kEvenOdd
Apply different phase treatments to even and odd harmonics.
Definition phase_modifier.h:27
@ kHarmonic
Uniformly shift phase for all harmonics directly.
Definition phase_modifier.h:28
virtual void jsonToState(json data) override
Restores the component’s state from a JSON object.
Definition phase_modifier.cpp:123
ComponentType
Enumerates all known WavetableComponents, including sources and modifiers.
Definition wavetable_component_factory.h:28
A base class representing a component in a wavetable synthesis chain.
Definition wavetable_component.h:32
Represents a single state of a waveform at a specific position in a wavetable.
Definition wavetable_keyframe.h:35
Represents a single frame of a wavetable, containing both time-domain and frequency-domain data.
Definition wave_frame.h:16
nlohmann::json json
Definition line_generator.h:7