Skip to content

Commit 0347ad2

Browse files
authored
Merge pull request #374 from musteresel/new-keyframe-implementation
New Keyframe implementation
2 parents c04dc94 + 89479bb commit 0347ad2

File tree

6 files changed

+506
-749
lines changed

6 files changed

+506
-749
lines changed

include/KeyFrame.h

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,12 @@ namespace openshot {
6363
*/
6464
class Keyframe {
6565
private:
66-
bool needs_update;
67-
double FactorialLookup[4];
68-
69-
/*
70-
* Because points can be added in any order, we need to reorder them
71-
* in ascending order based on the point.co.X value. This simplifies
72-
* processing the curve, due to all the points going from left to right.
73-
*/
74-
void ReorderPoints();
75-
76-
// Process an individual segment
77-
void ProcessSegment(int Segment, Point p1, Point p2);
78-
79-
// create lookup table for fast factorial calculation
80-
void CreateFactorialTable();
81-
82-
// Get a factorial for a coordinate
83-
double Factorial(int64_t n);
84-
85-
// Calculate the factorial function for Bernstein basis
86-
double Ni(int64_t n, int64_t i);
87-
88-
// Calculate Bernstein Basis
89-
double Bernstein(int64_t n, int64_t i, double t);
66+
std::vector<Point> Points; ///< Vector of all Points
9067

9168
public:
92-
std::vector<Point> Points; ///< Vector of all Points
93-
std::vector<Coordinate> Values; ///< Vector of all Values (i.e. the processed coordinates from the curve)
9469

9570
/// Default constructor for the Keyframe class
96-
Keyframe();
71+
Keyframe() = default;
9772

9873
/// Constructor which sets the default point & coordinate at X=1
9974
Keyframe(double value);
@@ -108,68 +83,60 @@ namespace openshot {
10883
void AddPoint(double x, double y, InterpolationType interpolate);
10984

11085
/// Does this keyframe contain a specific point
111-
bool Contains(Point p);
86+
bool Contains(Point p) const;
11287

11388
/// Flip all the points in this openshot::Keyframe (useful for reversing an effect or transition, etc...)
11489
void FlipPoints();
11590

11691
/// Get the index of a point by matching a coordinate
117-
int64_t FindIndex(Point p);
92+
int64_t FindIndex(Point p) const;
11893

11994
/// Get the value at a specific index
120-
double GetValue(int64_t index);
95+
double GetValue(int64_t index) const;
12196

12297
/// Get the rounded INT value at a specific index
123-
int GetInt(int64_t index);
98+
int GetInt(int64_t index) const;
12499

125100
/// Get the rounded LONG value at a specific index
126-
int64_t GetLong(int64_t index);
101+
int64_t GetLong(int64_t index) const;
127102

128103
/// Get the fraction that represents how many times this value is repeated in the curve
129-
Fraction GetRepeatFraction(int64_t index);
104+
Fraction GetRepeatFraction(int64_t index) const;
130105

131106
/// Get the change in Y value (from the previous Y value)
132-
double GetDelta(int64_t index);
107+
double GetDelta(int64_t index) const;
133108

134109
/// Get a point at a specific index
135-
Point& GetPoint(int64_t index);
110+
Point const & GetPoint(int64_t index) const;
136111

137112
/// Get current point (or closest point to the right) from the X coordinate (i.e. the frame number)
138-
Point GetClosestPoint(Point p);
113+
Point GetClosestPoint(Point p) const;
139114

140115
/// Get current point (or closest point) from the X coordinate (i.e. the frame number)
141116
/// Either use the closest left point, or right point
142-
Point GetClosestPoint(Point p, bool useLeft);
117+
Point GetClosestPoint(Point p, bool useLeft) const;
143118

144119
/// Get previous point (
145-
Point GetPreviousPoint(Point p);
120+
Point GetPreviousPoint(Point p) const;
146121

147122
/// Get max point (by Y coordinate)
148-
Point GetMaxPoint();
123+
Point GetMaxPoint() const;
149124

150125
// Get the number of values (i.e. coordinates on the X axis)
151-
int64_t GetLength();
126+
int64_t GetLength() const;
152127

153128
/// Get the number of points (i.e. # of points)
154-
int64_t GetCount();
129+
int64_t GetCount() const;
155130

156131
/// Get the direction of the curve at a specific index (increasing or decreasing)
157-
bool IsIncreasing(int index);
132+
bool IsIncreasing(int index) const;
158133

159134
/// Get and Set JSON methods
160-
std::string Json(); ///< Generate JSON string of this object
161-
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
135+
std::string Json() const; ///< Generate JSON string of this object
136+
Json::Value JsonValue() const; ///< Generate Json::JsonValue for this object
162137
void SetJson(std::string value); ///< Load JSON string into this object
163138
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
164139

165-
/**
166-
* @brief Calculate all of the values for this keyframe.
167-
*
168-
* This clears any existing data in the "values" vector. This method is automatically called
169-
* by AddPoint(), so you don't typically need to call this method.
170-
*/
171-
void Process();
172-
173140
/// Remove a point by matching a coordinate
174141
void RemovePoint(Point p);
175142

@@ -184,10 +151,10 @@ namespace openshot {
184151
void UpdatePoint(int64_t index, Point p);
185152

186153
/// Print a list of points
187-
void PrintPoints();
154+
void PrintPoints() const;
188155

189156
/// Print just the Y value of the point's primary coordinate
190-
void PrintValues();
157+
void PrintValues() const;
191158

192159
};
193160

src/Clip.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ void Clip::init_settings()
109109
// Init reader's rotation (if any)
110110
void Clip::init_reader_rotation() {
111111
// Only init rotation from reader when needed
112-
if (rotation.Points.size() > 1)
112+
if (rotation.GetCount() > 1)
113113
// Do nothing if more than 1 rotation Point
114114
return;
115-
else if (rotation.Points.size() == 1 && rotation.GetValue(1) != 0.0)
115+
else if (rotation.GetCount() == 1 && rotation.GetValue(1) != 0.0)
116116
// Do nothing if 1 Point, and it's not the default value
117117
return;
118118

@@ -273,7 +273,7 @@ void Clip::Close()
273273
float Clip::End()
274274
{
275275
// if a time curve is present, use its length
276-
if (time.Points.size() > 1)
276+
if (time.GetCount() > 1)
277277
{
278278
// Determine the FPS fo this clip
279279
float fps = 24.0;
@@ -314,8 +314,8 @@ std::shared_ptr<Frame> Clip::GetFrame(int64_t requested_frame)
314314
// Is a time map detected
315315
int64_t new_frame_number = requested_frame;
316316
int64_t time_mapped_number = adjust_frame_number_minimum(time.GetLong(requested_frame));
317-
if (time.Values.size() > 1)
318-
new_frame_number = time_mapped_number;
317+
if (time.GetLength() > 1)
318+
new_frame_number = time_mapped_number;
319319

320320
// Now that we have re-mapped what frame number is needed, go and get the frame pointer
321321
std::shared_ptr<Frame> original_frame;
@@ -397,7 +397,7 @@ void Clip::get_time_mapped_frame(std::shared_ptr<Frame> frame, int64_t frame_num
397397
throw ReaderClosed("No Reader has been initialized for this Clip. Call Reader(*reader) before calling this method.");
398398

399399
// Check for a valid time map curve
400-
if (time.Values.size() > 1)
400+
if (time.GetLength() > 1)
401401
{
402402
const GenericScopedLock<juce::CriticalSection> lock(getFrameCriticalSection);
403403

0 commit comments

Comments
 (0)