@@ -91,7 +91,7 @@ void Keyframe::AddPoint(double x, double y, InterpolationType interpolate)
9191}
9292
9393// Get the index of a point by matching a coordinate
94- int64_t Keyframe::FindIndex (Point p) {
94+ int64_t Keyframe::FindIndex (Point p) const {
9595 // loop through points, and find a matching coordinate
9696 for (int64_t x = 0 ; x < Points.size (); x++) {
9797 // Get each point
@@ -109,7 +109,7 @@ int64_t Keyframe::FindIndex(Point p) {
109109}
110110
111111// Determine if point already exists
112- bool Keyframe::Contains (Point p) {
112+ bool Keyframe::Contains (Point p) const {
113113 // loop through points, and find a matching coordinate
114114 for (int64_t x = 0 ; x < Points.size (); x++) {
115115 // Get each point
@@ -127,7 +127,7 @@ bool Keyframe::Contains(Point p) {
127127}
128128
129129// Get current point (or closest point) from the X coordinate (i.e. the frame number)
130- Point Keyframe::GetClosestPoint (Point p, bool useLeft) {
130+ Point Keyframe::GetClosestPoint (Point p, bool useLeft) const {
131131 Point closest (-1 , -1 );
132132
133133 // loop through points, and find a matching coordinate
@@ -164,12 +164,12 @@ Point Keyframe::GetClosestPoint(Point p, bool useLeft) {
164164}
165165
166166// Get current point (or closest point to the right) from the X coordinate (i.e. the frame number)
167- Point Keyframe::GetClosestPoint (Point p) {
167+ Point Keyframe::GetClosestPoint (Point p) const {
168168 return GetClosestPoint (p, false );
169169}
170170
171171// Get previous point (if any)
172- Point Keyframe::GetPreviousPoint (Point p) {
172+ Point Keyframe::GetPreviousPoint (Point p) const {
173173
174174 // Lookup the index of this point
175175 try {
@@ -188,7 +188,7 @@ Point Keyframe::GetPreviousPoint(Point p) {
188188}
189189
190190// Get max point (by Y coordinate)
191- Point Keyframe::GetMaxPoint () {
191+ Point Keyframe::GetMaxPoint () const {
192192 Point maxPoint (-1 , -1 );
193193
194194 // loop through points, and find the largest Y value
@@ -207,12 +207,11 @@ Point Keyframe::GetMaxPoint() {
207207}
208208
209209// Get the value at a specific index
210- double Keyframe::GetValue (int64_t index)
211- {
210+ double Keyframe::GetValue (int64_t index) const {
212211 if (Points.empty ()) {
213212 return 0 ;
214213 }
215- std::vector<Point>::iterator candidate =
214+ std::vector<Point>::const_iterator candidate =
216215 std::lower_bound (begin (Points), end (Points), Point (index, -1 ), [](Point const & l, Point const & r) {
217216 return l.co .X < r.co .X ;
218217 });
@@ -229,7 +228,7 @@ double Keyframe::GetValue(int64_t index)
229228 // index is directly on a point
230229 return candidate->co .Y ;
231230 }
232- std::vector<Point>::iterator predecessor = candidate - 1 ;
231+ std::vector<Point>::const_iterator predecessor = candidate - 1 ;
233232 assert (predecessor->co .X < index);
234233 assert (index < candidate->co .X );
235234
@@ -284,19 +283,17 @@ double Keyframe::GetValue(int64_t index)
284283}
285284
286285// Get the rounded INT value at a specific index
287- int Keyframe::GetInt (int64_t index)
288- {
286+ int Keyframe::GetInt (int64_t index) const {
289287 return int (round (GetValue (index)));
290288}
291289
292290// Get the rounded INT value at a specific index
293- int64_t Keyframe::GetLong (int64_t index)
294- {
291+ int64_t Keyframe::GetLong (int64_t index) const {
295292 return long (round (GetValue (index)));
296293}
297294
298295// Get the direction of the curve at a specific index (increasing or decreasing)
299- bool Keyframe::IsIncreasing (int index)
296+ bool Keyframe::IsIncreasing (int index) const
300297{
301298 if (index < 1 || (index + 1 ) >= GetLength ()) {
302299 return true ;
@@ -312,14 +309,14 @@ bool Keyframe::IsIncreasing(int index)
312309}
313310
314311// Generate JSON string of this object
315- std::string Keyframe::Json () {
312+ std::string Keyframe::Json () const {
316313
317314 // Return formatted string
318315 return JsonValue ().toStyledString ();
319316}
320317
321318// Generate Json::JsonValue for this object
322- Json::Value Keyframe::JsonValue () {
319+ Json::Value Keyframe::JsonValue () const {
323320
324321 // Create root json object
325322 Json::Value root;
@@ -389,8 +386,7 @@ void Keyframe::SetJsonValue(Json::Value root) {
389386
390387// Get the fraction that represents how many times this value is repeated in the curve
391388// This is depreciated and will be removed soon.
392- Fraction Keyframe::GetRepeatFraction (int64_t index)
393- {
389+ Fraction Keyframe::GetRepeatFraction (int64_t index) const {
394390 // Is index a valid point?
395391 if (index >= 1 && (index + 1 ) < GetLength ()) {
396392 int64_t current_value = GetLong (index);
@@ -428,16 +424,15 @@ Fraction Keyframe::GetRepeatFraction(int64_t index)
428424}
429425
430426// Get the change in Y value (from the previous Y value)
431- double Keyframe::GetDelta (int64_t index)
432- {
427+ double Keyframe::GetDelta (int64_t index) const {
433428 if (index < 1 ) return 0 ;
434429 if (index == 1 && ! Points.empty ()) return Points[0 ].co .Y ;
435430 if (index >= GetLength ()) return 0 ;
436431 return GetLong (index) - GetLong (index - 1 );
437432}
438433
439434// Get a point at a specific index
440- Point const & Keyframe::GetPoint (int64_t index) {
435+ Point const & Keyframe::GetPoint (int64_t index) const {
441436 // Is index a valid point?
442437 if (index >= 0 && index < Points.size ())
443438 return Points[index];
@@ -447,14 +442,14 @@ Point const & Keyframe::GetPoint(int64_t index) {
447442}
448443
449444// Get the number of values (i.e. coordinates on the X axis)
450- int64_t Keyframe::GetLength () {
445+ int64_t Keyframe::GetLength () const {
451446 if (Points.empty ()) return 0 ;
452447 if (Points.size () == 1 ) return 1 ;
453448 return round (Points.back ().co .X ) + 1 ;
454449}
455450
456451// Get the number of points (i.e. # of points)
457- int64_t Keyframe::GetCount () {
452+ int64_t Keyframe::GetCount () const {
458453
459454 return Points.size ();
460455}
@@ -499,15 +494,15 @@ void Keyframe::UpdatePoint(int64_t index, Point p) {
499494 AddPoint (p);
500495}
501496
502- void Keyframe::PrintPoints () {
497+ void Keyframe::PrintPoints () const {
503498 cout << fixed << setprecision (4 );
504- for (std::vector<Point>::iterator it = Points.begin (); it != Points.end (); it++) {
499+ for (std::vector<Point>::const_iterator it = Points.begin (); it != Points.end (); it++) {
505500 Point p = *it;
506501 cout << p.co .X << " \t " << p.co .Y << endl;
507502 }
508503}
509504
510- void Keyframe::PrintValues () {
505+ void Keyframe::PrintValues () const {
511506 cout << fixed << setprecision (4 );
512507 cout << " Frame Number (X)\t Value (Y)\t Is Increasing\t Repeat Numerator\t Repeat Denominator\t Delta (Y Difference)\n " ;
513508
@@ -534,8 +529,7 @@ void Keyframe::ScalePoints(double scale)
534529}
535530
536531// Flip all the points in this openshot::Keyframe (useful for reversing an effect or transition, etc...)
537- void Keyframe::FlipPoints ()
538- {
532+ void Keyframe::FlipPoints () {
539533 for (int64_t point_index = 0 , reverse_index = Points.size () - 1 ; point_index < reverse_index; point_index++, reverse_index--) {
540534 // Flip the points
541535 using std::swap;
0 commit comments