OpenShot Library | libopenshot  0.3.3
KeyFrame.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_KEYFRAME_H
14 #define OPENSHOT_KEYFRAME_H
15 
16 #include <iostream>
17 #include <vector>
18 
19 #include "Point.h"
20 #include "Json.h"
21 
22 namespace openshot {
23 
25  bool IsPointBeforeX(Point const & p, double const x);
26 
28  double InterpolateLinearCurve(Point const & left, Point const & right, double const target);
29 
31  double InterpolateBezierCurve(Point const & left, Point const & right, double const target, double const allowed_error);
32 
34  double InterpolateBetween(Point const & left, Point const & right, double target, double allowed_error);
35 
53  class Keyframe {
54 
55 
56  private:
57  std::vector<Point> Points;
58 
59  public:
61  Keyframe() = default;
62 
64  Keyframe(double value);
65 
67  Keyframe(const std::vector<openshot::Point>& points);
68 
70  ~Keyframe();
71 
73  void AddPoint(Point p);
74 
76  void AddPoint(double x, double y, InterpolationType interpolate=BEZIER);
77 
79  bool Contains(Point p) const;
80 
82  void FlipPoints();
83 
85  int64_t FindIndex(Point p) const;
86 
88  double GetValue(int64_t index) const;
89 
91  int GetInt(int64_t index) const;
92 
94  int64_t GetLong(int64_t index) const;
95 
97  double GetDelta(int64_t index) const;
98 
100  Point const & GetPoint(int64_t index) const;
101 
103  Point GetClosestPoint(Point p) const;
104 
107  Point GetClosestPoint(Point p, bool useLeft) const;
108 
110  Point GetPreviousPoint(Point p) const;
111 
113  Point GetMaxPoint() const;
114 
115  // Get the number of values (i.e. coordinates on the X axis)
116  int64_t GetLength() const;
117 
119  int64_t GetCount() const;
120 
122  bool IsIncreasing(int index) const;
123 
124  // Get and Set JSON methods
125  std::string Json() const;
126  Json::Value JsonValue() const;
127  void SetJson(const std::string value);
128  void SetJsonValue(const Json::Value root);
129 
131  void RemovePoint(Point p);
132 
134  void RemovePoint(int64_t index);
135 
138  void ScalePoints(double scale);
139 
141  void UpdatePoint(int64_t index, Point p);
142 
144  void PrintPoints(std::ostream* out=&std::cout) const;
145 
147  void PrintValues(std::ostream* out=&std::cout) const;
148 
149  };
150 
151 }
152 
153 #endif
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
Point.h
Header file for Point class.
openshot::Keyframe::GetLong
int64_t GetLong(int64_t index) const
Get the rounded LONG value at a specific index.
Definition: KeyFrame.cpp:287
openshot::InterpolateLinearCurve
double InterpolateLinearCurve(Point const &left, Point const &right, double const target)
Linear interpolation between two points.
Definition: KeyFrame.cpp:36
openshot::Keyframe::Keyframe
Keyframe()=default
Default constructor for the Keyframe class.
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
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::Keyframe::Json
std::string Json() const
Generate JSON string of this object.
Definition: KeyFrame.cpp:332
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::GetMaxPoint
Point GetMaxPoint() const
Get max point (by Y coordinate)
Definition: KeyFrame.cpp:245
openshot::Keyframe::~Keyframe
~Keyframe()
Destructor.
Definition: KeyFrame.cpp:124
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::Keyframe::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: KeyFrame.cpp:372
openshot::Keyframe::Contains
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition: KeyFrame.cpp:184
openshot::Keyframe::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: KeyFrame.cpp:339
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
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
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::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::Keyframe::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: KeyFrame.cpp:355
openshot::Keyframe::PrintPoints
void PrintPoints(std::ostream *out=&std::cout) const
Print a list of points.
Definition: KeyFrame.cpp:470
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::UpdatePoint
void UpdatePoint(int64_t index, Point p)
Replace an existing point with a new point.
Definition: KeyFrame.cpp:462
openshot::Keyframe::GetPoint
const Point & GetPoint(int64_t index) const
Get a point at a specific index.
Definition: KeyFrame.cpp:407
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::Keyframe::GetLength
int64_t GetLength() const
Definition: KeyFrame.cpp:417
openshot::Keyframe::GetInt
int GetInt(int64_t index) const
Get the rounded INT value at a specific index.
Definition: KeyFrame.cpp:282
openshot::Keyframe::GetCount
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition: KeyFrame.cpp:424
openshot::Keyframe::ScalePoints
void ScalePoints(double scale)
Definition: KeyFrame.cpp:516
openshot::Keyframe::GetPreviousPoint
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition: KeyFrame.cpp:226
openshot::InterpolationType
InterpolationType
This controls how a Keyframe uses this point to interpolate between two points.
Definition: Point.h:28
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::BEZIER
@ BEZIER
Bezier curves are quadratic curves, which create a smooth curve.
Definition: Point.h:29
Json.h
Header file for JSON class.
openshot::Point
A Point is the basic building block of a key-frame curve.
Definition: Point.h:64
openshot::Keyframe::GetValue
double GetValue(int64_t index) const
Get the value at a specific index.
Definition: KeyFrame.cpp:258