Vital
Loading...
Searching...
No Matches
wave_window_modifier.h
Go to the documentation of this file.
1/*
2Summary:
3WaveWindowModifier applies a chosen windowing function to the beginning and end of a waveform, tapering its amplitude based on left_position_ and right_position_. Different window shapes (cosine, half-sine, linear, square, wiggle) produce various slopes and transitions. By interpolating between keyframes, users can animate the window size and shape over the wavetable, influencing how the waveform’s amplitude envelope evolves dynamically.
4 */
5
6#pragma once
7
8#include "JuceHeader.h"
10
20public:
33
41 static float applyWindow(WindowShape window_shape, float t);
42
52 public:
58
59 void copy(const WavetableKeyframe* keyframe) override;
60 void interpolate(const WavetableKeyframe* from_keyframe,
61 const WavetableKeyframe* to_keyframe, float t) override;
62 void render(vital::WaveFrame* wave_frame) override;
63 json stateToJson() override;
64 void jsonToState(json data) override;
65
73 void setLeft(float left) { left_position_ = left; }
74
82 void setRight(float right) { right_position_ = right; }
83
89 float getLeft() { return left_position_; }
90
96 float getRight() { return right_position_; }
97
103 void setWindowShape(WindowShape window_shape) { window_shape_ = window_shape; }
104
105 protected:
112 inline float applyWindow(float t) { return WaveWindowModifier::applyWindow(window_shape_, t); }
113
117
118 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveWindowModifierKeyframe)
119 };
120
126
127 WavetableKeyframe* createKeyframe(int position) override;
128 void render(vital::WaveFrame* wave_frame, float position) override;
130 json stateToJson() override;
131 void jsonToState(json data) override;
132
139 WaveWindowModifierKeyframe* getKeyframe(int index);
140
146 void setWindowShape(WindowShape window_shape) { window_shape_ = window_shape; }
147
154
155protected:
158
159 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveWindowModifier)
160};
A keyframe class that stores the window shape and positions at a given table position.
Definition wave_window_modifier.h:51
void setRight(float right)
Sets the right position of the window (0 to 1).
Definition wave_window_modifier.h:82
json stateToJson() override
Serializes the state of this keyframe to a JSON object.
Definition wave_window_modifier.cpp:71
WaveWindowModifierKeyframe()
Constructs a WaveWindowModifierKeyframe with a default window shape and positions.
Definition wave_window_modifier.cpp:24
void render(vital::WaveFrame *wave_frame) override
Renders the waveform of this keyframe into a WaveFrame.
Definition wave_window_modifier.cpp:49
WindowShape window_shape_
The chosen window shape for this keyframe.
Definition wave_window_modifier.h:116
float getLeft()
Gets the left window position.
Definition wave_window_modifier.h:89
float right_position_
The right boundary of the windowing region.
Definition wave_window_modifier.h:115
float left_position_
The left boundary of the windowing region.
Definition wave_window_modifier.h:114
virtual ~WaveWindowModifierKeyframe()
Definition wave_window_modifier.h:57
void setWindowShape(WindowShape window_shape)
Sets the window shape for this keyframe.
Definition wave_window_modifier.h:103
void jsonToState(json data) override
Restores the keyframe's state from a JSON object.
Definition wave_window_modifier.cpp:78
void setLeft(float left)
Sets the left position of the window (0 to 1).
Definition wave_window_modifier.h:73
void interpolate(const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t) override
Linearly interpolates between two keyframes.
Definition wave_window_modifier.cpp:39
float applyWindow(float t)
Applies the currently selected window shape at a given normalized time t.
Definition wave_window_modifier.h:112
float getRight()
Gets the right window position.
Definition wave_window_modifier.h:96
void copy(const WavetableKeyframe *keyframe) override
Copies the state from another keyframe of the same type.
Definition wave_window_modifier.cpp:32
A WavetableComponent that applies a windowing function to a waveform’s head and tail.
Definition wave_window_modifier.h:19
WindowShape getWindowShape()
Gets the current window shape.
Definition wave_window_modifier.h:153
json stateToJson() override
Serializes the component’s state and all keyframes to a JSON object.
Definition wave_window_modifier.cpp:101
void render(vital::WaveFrame *wave_frame, float position) override
Renders the waveform at a given position into a WaveFrame.
Definition wave_window_modifier.cpp:90
static float applyWindow(WindowShape window_shape, float t)
Applies the chosen window shape to a given normalized position.
Definition wave_window_modifier.cpp:10
WaveWindowModifierKeyframe compute_frame_
A keyframe for intermediate computations.
Definition wave_window_modifier.h:156
WaveWindowModifierKeyframe * getKeyframe(int index)
Retrieves a WaveWindowModifierKeyframe by index.
Definition wave_window_modifier.cpp:112
WindowShape window_shape_
The global window shape used.
Definition wave_window_modifier.h:157
virtual ~WaveWindowModifier()
Definition wave_window_modifier.h:125
void jsonToState(json data) override
Restores the component’s state from a JSON object.
Definition wave_window_modifier.cpp:107
WavetableComponentFactory::ComponentType getType() override
Returns the type of this WavetableComponent.
Definition wave_window_modifier.cpp:97
WavetableKeyframe * createKeyframe(int position) override
Creates a new keyframe at a given position.
Definition wave_window_modifier.cpp:84
WindowShape
Defines different windowing curves.
Definition wave_window_modifier.h:25
@ kNumWindowShapes
Definition wave_window_modifier.h:31
@ kLinear
A linear ramp window.
Definition wave_window_modifier.h:28
@ kWiggle
A more complex wiggle-based shape.
Definition wave_window_modifier.h:30
@ kCos
A cosine-based window (smooth rise/fall).
Definition wave_window_modifier.h:26
@ kHalfSin
A half-sine window shape.
Definition wave_window_modifier.h:27
@ kSquare
A sudden step (square) window.
Definition wave_window_modifier.h:29
WaveWindowModifier()
Constructs a WaveWindowModifier with a default cosine window shape.
Definition wave_window_modifier.h:124
void setWindowShape(WindowShape window_shape)
Sets the window shape used by this modifier.
Definition wave_window_modifier.h:146
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