7using json = nlohmann::json;
50 return 0.5f * sinf((t - 0.5f) *
vital::kPi) + 0.5f;
215 void addPoint(
int index, std::pair<float, float> position);
361 VITAL_ASSERT(num_points <= kMaxPoints && num_points >= 0);
A class for generating and storing a line shape, defined by a series of points and associated powers.
Definition line_generator.h:20
std::string name_
The name of the line shape.
Definition line_generator.h:374
void setLastBrowsedFile(const std::string &path)
Stores the last browsed file path associated with this line.
Definition line_generator.h:86
int render_count_
Count of how many times render() was called.
Definition line_generator.h:385
std::pair< float, float > lastPoint() const
Returns the last point in the line.
Definition line_generator.h:252
void initSin()
Initializes the line as a sine-like shape.
Definition line_generator.cpp:54
void setName(const std::string &name)
Sets a name identifier for the line.
Definition line_generator.h:79
void setLoop(bool loop)
Sets whether the line should loop at the end.
Definition line_generator.h:72
std::string last_browsed_file_
The last browsed file path for saving/loading this line.
Definition line_generator.h:375
force_inline bool smooth() const
Indicates whether smoothing is enabled.
Definition line_generator.h:280
float valueAtPhase(float phase)
Gets the line value at a given normalized phase.
Definition line_generator.cpp:199
bool loop_
Whether the line loops at the end.
Definition line_generator.h:382
int getRenderCount() const
Gets the number of times the line has been rendered since initialization.
Definition line_generator.h:371
void render()
Renders the line into the internal buffer based on the current points and settings.
Definition line_generator.cpp:149
std::string getLastBrowsedFile() const
Gets the last browsed file path associated with this line.
Definition line_generator.h:205
std::string getName() const
Gets the current name of the line.
Definition line_generator.h:198
float lastPower() const
Returns the power (interpolation shape factor) of the last point.
Definition line_generator.h:259
virtual ~LineGenerator()
Virtual destructor.
Definition line_generator.h:63
void checkLineIsLinear()
Checks if the line is the default linear shape.
Definition line_generator.cpp:205
LineGenerator(int resolution=kDefaultResolution)
Constructs a LineGenerator with a given resolution.
Definition line_generator.cpp:5
force_inline int getNumPoints() const
Returns the current number of points defining the line.
Definition line_generator.h:327
float powers_[kMaxPoints]
Powers controlling interpolation shape between points.
Definition line_generator.h:377
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
float getValueBetweenPoints(float x, int index_from, int index_to)
Interpolates a value between two points at a given x position.
Definition line_generator.cpp:211
force_inline void setPoint(int index, std::pair< float, float > point)
Sets the position of a specific point.
Definition line_generator.h:337
int num_points_
Current number of points.
Definition line_generator.h:378
static bool isValidJson(json data)
Checks if a given JSON object contains valid line data.
Definition line_generator.cpp:116
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
void flipHorizontal()
Flips the line horizontally around the x=0.5 vertical axis.
Definition line_generator.cpp:268
force_inline vital::mono_float * getBuffer() const
Gets a pointer to the internal buffer used for interpolation.
Definition line_generator.h:289
void initTriangle()
Initializes the line as a triangle shape.
Definition line_generator.cpp:23
force_inline int resolution() const
Gets the resolution of the line's internal buffer.
Definition line_generator.h:266
force_inline bool linear() const
Indicates whether the line is currently a simple linear shape.
Definition line_generator.h:273
std::pair< float, float > points_[kMaxPoints]
Array of points defining the line shape.
Definition line_generator.h:376
std::unique_ptr< vital::mono_float[]> buffer_
Internal buffer holding the rendered line values.
Definition line_generator.h:381
static force_inline float smoothTransition(float t)
Smooth transition function for smoothing between points.
Definition line_generator.h:49
float getValueAtPhase(float phase)
Returns the value of the line at a given phase by searching through the points.
Definition line_generator.cpp:230
void jsonToState(json data)
Restores the line state from a given JSON object.
Definition line_generator.cpp:125
force_inline void setNumPoints(int num_points)
Sets the number of points currently in use.
Definition line_generator.h:360
void initSawDown()
Initializes the line as a "saw down" shape.
Definition line_generator.cpp:82
static constexpr int kMaxPoints
Maximum number of points that can define the line.
Definition line_generator.h:25
void initSquare()
Initializes the line as a square shape.
Definition line_generator.cpp:37
json stateToJson()
Converts the current state of the line into a JSON object.
Definition line_generator.cpp:96
force_inline std::pair< float, float > getPoint(int index) const
Returns a point at the given index.
Definition line_generator.h:306
void initLinear()
Initializes the line to a simple linear shape (from 1.0 at x=0 to 0.0 at x=1).
Definition line_generator.cpp:11
force_inline vital::mono_float * getCubicInterpolationBuffer() const
Gets a pointer to the buffer used for cubic interpolation.
Definition line_generator.h:298
bool linear_
Whether the line is the simple linear shape.
Definition line_generator.h:384
force_inline float getPower(int index) const
Returns the power at the given index.
Definition line_generator.h:317
bool smooth_
Whether to apply smoothing between points.
Definition line_generator.h:383
static constexpr int kExtraValues
Extra buffer values used for interpolation outside the main range.
Definition line_generator.h:39
void addPoint(int index, std::pair< float, float > position)
Inserts a new point into the line at a specified index.
Definition line_generator.cpp:239
void flipVertical()
Flips the line vertically around y=0.5.
Definition line_generator.cpp:286
void initSawUp()
Initializes the line as a "saw up" shape.
Definition line_generator.cpp:68
static constexpr int kDefaultResolution
Default resolution of the rendered line buffer.
Definition line_generator.h:32
int resolution_
Resolution of the internal buffer.
Definition line_generator.h:379
#define VITAL_ASSERT(x)
Definition common.h:11
#define force_inline
Definition common.h:23
nlohmann::json json
Definition line_generator.h:7
constexpr mono_float kPi
Pi constant.
Definition common.h:36
float mono_float
Definition common.h:33