OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
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
22namespace 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
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
Header file for JSON class.
Header file for Point class.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition KeyFrame.h:53
int64_t FindIndex(Point p) const
Get the index of a point by matching a coordinate.
Definition KeyFrame.cpp:166
void RemovePoint(Point p)
Remove a point by matching a coordinate.
Definition KeyFrame.cpp:430
void SetJson(const std::string value)
Load JSON string into this object.
Definition KeyFrame.cpp:355
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition KeyFrame.cpp:184
~Keyframe()
Destructor.
Definition KeyFrame.cpp:124
void PrintValues(std::ostream *out=&std::cout) const
Print just the Y value of the point's primary coordinate.
Definition KeyFrame.cpp:481
Point GetMaxPoint() const
Get max point (by Y coordinate)
Definition KeyFrame.cpp:245
int GetInt(int64_t index) const
Get the rounded INT value at a specific index.
Definition KeyFrame.cpp:282
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition KeyFrame.cpp:372
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
double GetDelta(int64_t index) const
Get the change in Y value (from the previous Y value)
Definition KeyFrame.cpp:399
Point const & GetPoint(int64_t index) const
Get a point at a specific index.
Definition KeyFrame.cpp:407
int64_t GetLength() const
Definition KeyFrame.cpp:417
void PrintPoints(std::ostream *out=&std::cout) const
Print a list of points.
Definition KeyFrame.cpp:470
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition KeyFrame.cpp:226
int64_t GetLong(int64_t index) const
Get the rounded LONG value at a specific index.
Definition KeyFrame.cpp:287
void UpdatePoint(int64_t index, Point p)
Replace an existing point with a new point.
Definition KeyFrame.cpp:462
void ScalePoints(double scale)
Definition KeyFrame.cpp:516
std::string Json() const
Generate JSON string of this object.
Definition KeyFrame.cpp:332
double GetValue(int64_t index) const
Get the value at a specific index.
Definition KeyFrame.cpp:258
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition KeyFrame.cpp:339
void FlipPoints()
Flip all the points in this openshot::Keyframe (useful for reversing an effect or transition,...
Definition KeyFrame.cpp:530
Keyframe()=default
Default constructor for the Keyframe class.
bool IsIncreasing(int index) const
Get the direction of the curve at a specific index (increasing or decreasing)
Definition KeyFrame.cpp:292
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition KeyFrame.cpp:424
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
A Point is the basic building block of a key-frame curve.
Definition Point.h:64
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
double InterpolateLinearCurve(Point const &left, Point const &right, double const target)
Linear interpolation between two points.
Definition KeyFrame.cpp:36
double InterpolateBezierCurve(Point const &left, Point const &right, double const target, double const allowed_error)
Bezier interpolation between two points.
Definition KeyFrame.cpp:44
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
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
InterpolationType
This controls how a Keyframe uses this point to interpolate between two points.
Definition Point.h:28
@ BEZIER
Bezier curves are quadratic curves, which create a smooth curve.
Definition Point.h:29