Vital
Loading...
Searching...
No Matches
wave_line_source.h
Go to the documentation of this file.
1/*
2Summary:
3WaveLineSource constructs wavetables using a line generator that defines a waveform through a set of points. By adjusting the points’ positions and power values, and optionally smoothing the line, it produces a custom waveform shape. Keyframes store configurations of these line-based shapes, and interpolation (including nonlinear “pull_power” effects) allows the waveform to evolve smoothly from one shape to another across the wavetable’s dimension.
4 */
5
6#pragma once
7
8#include "JuceHeader.h"
10
24public:
26 static constexpr int kDefaultLinePoints = 4;
27
37 public:
42 virtual ~WaveLineSourceKeyframe() = default;
43
44 void copy(const WavetableKeyframe* keyframe) override;
45 void interpolate(const WavetableKeyframe* from_keyframe,
46 const WavetableKeyframe* to_keyframe, float t) override;
47 void render(vital::WaveFrame* wave_frame) override;
48 json stateToJson() override;
49 void jsonToState(json data) override;
50
57 inline std::pair<float, float> getPoint(int index) const { return line_generator_.getPoint(index); }
58
67 inline float getPower(int index) const { return line_generator_.getPower(index); }
68
75 inline void setPoint(std::pair<float, float> point, int index) { line_generator_.setPoint(index, point); }
76
83 inline void setPower(float power, int index) { line_generator_.setPower(index, power); }
84
91
98
104 inline int getNumPoints() const { return line_generator_.getNumPoints(); }
105
113 inline void setSmooth(bool smooth) { line_generator_.setSmooth(smooth); }
114
120 void setPullPower(float power) { pull_power_ = power; }
121
127 float getPullPower() const { return pull_power_; }
128
135
142
143 protected:
146
147 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveLineSourceKeyframe)
148 };
149
154 virtual ~WaveLineSource() = default;
155
156 WavetableKeyframe* createKeyframe(int position) override;
157 void render(vital::WaveFrame* wave_frame, float position) override;
159 json stateToJson() override;
160 void jsonToState(json data) override;
161
167 void setNumPoints(int num_points);
168
174 int numPoints() { return num_points_; }
175
182 WaveLineSourceKeyframe* getKeyframe(int index);
183
184protected:
187
188 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveLineSource)
189};
A class for generating and storing a line shape, defined by a series of points and associated powers.
Definition line_generator.h:20
force_inline int getNumPoints() const
Returns the current number of points defining the line.
Definition line_generator.h:327
force_inline void setPower(int index, float power)
Sets the power for a specific point.
Definition line_generator.h:349
void addMiddlePoint(int index)
Inserts a point exactly between two existing points.
Definition line_generator.cpp:251
force_inline void setPoint(int index, std::pair< float, float > point)
Sets the position of a specific point.
Definition line_generator.h:337
void setSmooth(bool smooth)
Enables or disables smoothing behavior.
Definition line_generator.h:96
void removePoint(int index)
Removes the point at a specified index.
Definition line_generator.cpp:259
force_inline std::pair< float, float > getPoint(int index) const
Returns a point at the given index.
Definition line_generator.h:306
force_inline float getPower(int index) const
Returns the power at the given index.
Definition line_generator.h:317
A keyframe class that represents a particular line-based waveform configuration at a given position.
Definition wave_line_source.h:36
float getPower(int index) const
Retrieves the power value for a given point.
Definition wave_line_source.h:67
LineGenerator * getLineGenerator()
Provides access to the underlying LineGenerator for modification.
Definition wave_line_source.h:141
int getNumPoints() const
Gets the number of points defining the line.
Definition wave_line_source.h:104
void jsonToState(json data) override
Restores the keyframe's state from a JSON object.
Definition wave_line_source.cpp:76
void render(vital::WaveFrame *wave_frame) override
Renders the waveform of this keyframe into a WaveFrame.
Definition wave_line_source.cpp:60
float pull_power_
Controls nonlinear interpolation between keyframes.
Definition wave_line_source.h:145
WaveLineSourceKeyframe()
Constructs a WaveLineSourceKeyframe with default parameters.
Definition wave_line_source.cpp:14
void copy(const WavetableKeyframe *keyframe) override
Copies the state from another keyframe of the same type.
Definition wave_line_source.cpp:19
const LineGenerator * getLineGenerator() const
Provides const access to the underlying LineGenerator.
Definition wave_line_source.h:134
float getPullPower() const
Gets the current pull power value.
Definition wave_line_source.h:127
void removePoint(int index)
Removes a point from the line definition.
Definition wave_line_source.h:90
std::pair< float, float > getPoint(int index) const
Retrieves a point (x,y) by index.
Definition wave_line_source.h:57
void setSmooth(bool smooth)
Sets whether the line should be smoothed.
Definition wave_line_source.h:113
json stateToJson() override
Serializes the state of this keyframe to a JSON object.
Definition wave_line_source.cpp:69
void addMiddlePoint(int index)
Inserts a middle point between two existing points.
Definition wave_line_source.h:97
LineGenerator line_generator_
The generator producing the line-based waveform.
Definition wave_line_source.h:144
void interpolate(const WavetableKeyframe *from_keyframe, const WavetableKeyframe *to_keyframe, float t) override
Linearly interpolates between two keyframes.
Definition wave_line_source.cpp:31
void setPullPower(float power)
Sets the pull power, which influences how interpolation occurs between keyframes.
Definition wave_line_source.h:120
void setPoint(std::pair< float, float > point, int index)
Sets a point’s position.
Definition wave_line_source.h:75
void setPower(float power, int index)
Sets the power for a given point.
Definition wave_line_source.h:83
A WavetableComponent that generates waveforms from a series of line segments.
Definition wave_line_source.h:23
WaveLineSourceKeyframe * getKeyframe(int index)
Retrieves a WaveLineSourceKeyframe by index.
Definition wave_line_source.cpp:116
static constexpr int kDefaultLinePoints
The default number of line points used if none are specified.
Definition wave_line_source.h:26
int num_points_
The number of points defining the line-based waveform.
Definition wave_line_source.h:185
WavetableComponentFactory::ComponentType getType() override
Returns the type of this WavetableComponent.
Definition wave_line_source.cpp:97
WaveLineSource()
Constructs a WaveLineSource with a default number of points.
Definition wave_line_source.h:153
int numPoints()
Returns the current number of points in the line generator.
Definition wave_line_source.h:174
json stateToJson() override
Serializes the component’s state and all keyframes to a JSON object.
Definition wave_line_source.cpp:101
void jsonToState(json data) override
Restores the component’s state from a JSON object.
Definition wave_line_source.cpp:107
void setNumPoints(int num_points)
Sets the number of points used by the line generator.
Definition wave_line_source.cpp:112
WavetableKeyframe * createKeyframe(int position) override
Creates a new keyframe at a given position.
Definition wave_line_source.cpp:85
WaveLineSourceKeyframe compute_frame_
A keyframe for intermediate computations.
Definition wave_line_source.h:186
void render(vital::WaveFrame *wave_frame, float position) override
Renders the waveform at a given position into a WaveFrame.
Definition wave_line_source.cpp:91
virtual ~WaveLineSource()=default
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
int index()
Gets the index of this keyframe within its owner component.
Definition wavetable_keyframe.cpp:32
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