Loading...
Searching...
No Matches
KeyFrame.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_KEYFRAME_H
#define OPENSHOT_KEYFRAME_H
#include <iostream>
#include <vector>
#include "Point.h"
#include "Json.h"
namespace openshot {
bool IsPointBeforeX(Point const & p, double const x);
double InterpolateLinearCurve(Point const & left, Point const & right, double const target);
double InterpolateBezierCurve(Point const & left, Point const & right, double const target, double const allowed_error);
double InterpolateBetween(Point const & left, Point const & right, double target, double allowed_error);
class Keyframe {
private:
std::vector<Point> Points;
public:
Keyframe() = default;
Keyframe(double value);
Keyframe(const std::vector<openshot::Point>& points);
~Keyframe();
void AddPoint(Point p);
void AddPoint(double x, double y, InterpolationType interpolate=BEZIER);
bool Contains(Point p) const;
void FlipPoints();
int64_t FindIndex(Point p) const;
double GetValue(int64_t index) const;
int GetInt(int64_t index) const;
int64_t GetLong(int64_t index) const;
double GetDelta(int64_t index) const;
Point const & GetPoint(int64_t index) const;
Point GetClosestPoint(Point p) const;
Point GetClosestPoint(Point p, bool useLeft) const;
Point GetPreviousPoint(Point p) const;
Point GetMaxPoint() const;
// Get the number of values (i.e. coordinates on the X axis)
int64_t GetLength() const;
int64_t GetCount() const;
bool IsIncreasing(int index) const;
// Get and Set JSON methods
std::string Json() const;
Json::Value JsonValue() const;
void SetJson(const std::string value);
void SetJsonValue(const Json::Value root);
void RemovePoint(Point p);
void RemovePoint(int64_t index);
void ScalePoints(double scale);
void UpdatePoint(int64_t index, Point p);
void PrintPoints(std::ostream* out=&std::cout) const;
void PrintValues(std::ostream* out=&std::cout) const;
};
}
#endif
Json.h
Header file for JSON class.
Point.h
Header file for Point class.
openshot::Keyframe
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition KeyFrame.h:53
openshot::Keyframe::FindIndex
int64_t FindIndex(Point p) const
Get the index of a point by matching a coordinate.
Definition KeyFrame.cpp:166
openshot::Keyframe::RemovePoint
void RemovePoint(Point p)
Remove a point by matching a coordinate.
Definition KeyFrame.cpp:430
openshot::Keyframe::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition KeyFrame.cpp:355
openshot::Keyframe::Contains
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition KeyFrame.cpp:184
openshot::Keyframe::~Keyframe
~Keyframe()
Destructor.
Definition KeyFrame.cpp:124
openshot::Keyframe::PrintValues
void PrintValues(std::ostream *out=&std::cout) const
Print just the Y value of the point's primary coordinate.
Definition KeyFrame.cpp:481
openshot::Keyframe::GetMaxPoint
Point GetMaxPoint() const
Get max point (by Y coordinate)
Definition KeyFrame.cpp:245
openshot::Keyframe::GetInt
int GetInt(int64_t index) const
Get the rounded INT value at a specific index.
Definition KeyFrame.cpp:282
openshot::Keyframe::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition KeyFrame.cpp:372
openshot::Keyframe::AddPoint
void AddPoint(Point p)
Add a new point on the key-frame. Each point has a primary coordinate, a left handle,...
Definition KeyFrame.cpp:131
openshot::Keyframe::GetDelta
double GetDelta(int64_t index) const
Get the change in Y value (from the previous Y value)
Definition KeyFrame.cpp:399
openshot::Keyframe::GetPoint
Point const & GetPoint(int64_t index) const
Get a point at a specific index.
Definition KeyFrame.cpp:407
openshot::Keyframe::GetLength
int64_t GetLength() const
Definition KeyFrame.cpp:417
openshot::Keyframe::PrintPoints
void PrintPoints(std::ostream *out=&std::cout) const
Print a list of points.
Definition KeyFrame.cpp:470
openshot::Keyframe::GetPreviousPoint
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition KeyFrame.cpp:226
openshot::Keyframe::GetLong
int64_t GetLong(int64_t index) const
Get the rounded LONG value at a specific index.
Definition KeyFrame.cpp:287
openshot::Keyframe::UpdatePoint
void UpdatePoint(int64_t index, Point p)
Replace an existing point with a new point.
Definition KeyFrame.cpp:462
openshot::Keyframe::ScalePoints
void ScalePoints(double scale)
Definition KeyFrame.cpp:516
openshot::Keyframe::Json
std::string Json() const
Generate JSON string of this object.
Definition KeyFrame.cpp:332
openshot::Keyframe::GetValue
double GetValue(int64_t index) const
Get the value at a specific index.
Definition KeyFrame.cpp:258
openshot::Keyframe::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition KeyFrame.cpp:339
openshot::Keyframe::FlipPoints
void FlipPoints()
Flip all the points in this openshot::Keyframe (useful for reversing an effect or transition,...
Definition KeyFrame.cpp:530
openshot::Keyframe::Keyframe
Keyframe()=default
Default constructor for the Keyframe class.
openshot::Keyframe::IsIncreasing
bool IsIncreasing(int index) const
Get the direction of the curve at a specific index (increasing or decreasing)
Definition KeyFrame.cpp:292
openshot::Keyframe::GetCount
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition KeyFrame.cpp:424
openshot::Keyframe::GetClosestPoint
Point GetClosestPoint(Point p) const
Get current point (or closest point to the right) from the X coordinate (i.e. the frame number)
Definition KeyFrame.cpp:221
openshot::Point
A Point is the basic building block of a key-frame curve.
Definition Point.h:64
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::InterpolateLinearCurve
double InterpolateLinearCurve(Point const &left, Point const &right, double const target)
Linear interpolation between two points.
Definition KeyFrame.cpp:36
openshot::InterpolateBezierCurve
double InterpolateBezierCurve(Point const &left, Point const &right, double const target, double const allowed_error)
Bezier interpolation between two points.
Definition KeyFrame.cpp:44
openshot::IsPointBeforeX
bool IsPointBeforeX(Point const &p, double const x)
Check if the X coordinate of a given Point is lower than a given value.
Definition KeyFrame.cpp:31
openshot::InterpolateBetween
double InterpolateBetween(Point const &left, Point const &right, double target, double allowed_error)
Interpolate two points using the right Point's interpolation method.
Definition KeyFrame.cpp:80
openshot::InterpolationType
InterpolationType
This controls how a Keyframe uses this point to interpolate between two points.
Definition Point.h:28
openshot::BEZIER
@ BEZIER
Bezier curves are quadratic curves, which create a smooth curve.
Definition Point.h:29