2013-09-12 17:52:10 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
2013-09-12 23:41:49 -05:00
|
|
|
* @brief Header file for the Keyframe class
|
2013-09-12 17:52:10 -05:00
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-12 17:52:10 -05:00
|
|
|
*/
|
|
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
#ifndef OPENSHOT_KEYFRAME_H
|
|
|
|
|
#define OPENSHOT_KEYFRAME_H
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2015-06-01 00:20:14 -07:00
|
|
|
#include <iomanip>
|
2011-10-11 08:44:27 -05:00
|
|
|
#include <math.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include "Exceptions.h"
|
2012-10-19 22:11:22 -05:00
|
|
|
#include "Fraction.h"
|
2011-10-11 08:44:27 -05:00
|
|
|
#include "Coordinate.h"
|
|
|
|
|
#include "Point.h"
|
2013-12-03 00:13:25 -06:00
|
|
|
#include "Json.h"
|
2011-10-11 08:44:27 -05:00
|
|
|
|
|
|
|
|
namespace openshot {
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
|
2011-10-11 08:44:27 -05:00
|
|
|
*
|
|
|
|
|
* Keyframes are used to animate and interpolate values of properties over time. For example, a single property
|
|
|
|
|
* can use a Keyframe instead of a constant value. Assume you want to slide an image (from left to right) over
|
|
|
|
|
* a video. You can create a Keyframe which will adjust the X value of the image over 100 frames (or however many
|
|
|
|
|
* frames the animation needs to last) from the value of 0 to 640.
|
|
|
|
|
*
|
|
|
|
|
* Please see the following <b>Example Code</b>:
|
|
|
|
|
* \code
|
|
|
|
|
* Keyframe k1;
|
|
|
|
|
* k1.AddPoint(Point(1,0));
|
|
|
|
|
* k1.AddPoint(Point(100,640));
|
|
|
|
|
*
|
|
|
|
|
* kf.PrintValues();
|
|
|
|
|
* \endcode
|
|
|
|
|
*/
|
|
|
|
|
class Keyframe {
|
|
|
|
|
private:
|
2019-11-19 23:43:28 +01:00
|
|
|
std::vector<Point> Points; ///< Vector of all Points
|
2011-10-11 08:44:27 -05:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// Default constructor for the Keyframe class
|
|
|
|
|
Keyframe();
|
|
|
|
|
|
2019-11-02 18:01:59 +02:00
|
|
|
/// Constructor which sets the default point & coordinate at X=1
|
2017-01-24 18:39:17 -06:00
|
|
|
Keyframe(double value);
|
2012-10-03 01:55:24 -05:00
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
/// Add a new point on the key-frame. Each point has a primary coordinate, a left handle, and a right handle.
|
|
|
|
|
void AddPoint(Point p);
|
|
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
/// Add a new point on the key-frame, with some defaults set (BEZIER)
|
2017-01-24 18:39:17 -06:00
|
|
|
void AddPoint(double x, double y);
|
2012-10-04 15:07:29 -05:00
|
|
|
|
2012-10-10 17:27:46 -05:00
|
|
|
/// Add a new point on the key-frame, with a specific interpolation type
|
2017-01-24 18:39:17 -06:00
|
|
|
void AddPoint(double x, double y, InterpolationType interpolate);
|
2012-10-10 17:27:46 -05:00
|
|
|
|
2015-02-09 22:41:42 -06:00
|
|
|
/// Does this keyframe contain a specific point
|
|
|
|
|
bool Contains(Point p);
|
|
|
|
|
|
2015-03-13 23:19:55 -05:00
|
|
|
/// Flip all the points in this openshot::Keyframe (useful for reversing an effect or transition, etc...)
|
|
|
|
|
void FlipPoints();
|
|
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
/// Get the index of a point by matching a coordinate
|
2017-10-26 18:44:35 -05:00
|
|
|
int64_t FindIndex(Point p);
|
2011-10-11 08:44:27 -05:00
|
|
|
|
|
|
|
|
/// Get the value at a specific index
|
2017-09-28 16:03:01 -05:00
|
|
|
double GetValue(int64_t index);
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2012-10-19 16:53:18 -05:00
|
|
|
/// Get the rounded INT value at a specific index
|
2017-09-28 16:03:01 -05:00
|
|
|
int GetInt(int64_t index);
|
2015-08-24 01:05:48 -05:00
|
|
|
|
|
|
|
|
/// Get the rounded LONG value at a specific index
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t GetLong(int64_t index);
|
2012-10-19 16:53:18 -05:00
|
|
|
|
2012-10-19 22:11:22 -05:00
|
|
|
/// Get the fraction that represents how many times this value is repeated in the curve
|
2017-09-28 16:03:01 -05:00
|
|
|
Fraction GetRepeatFraction(int64_t index);
|
2012-10-19 22:11:22 -05:00
|
|
|
|
2012-10-19 22:24:54 -05:00
|
|
|
/// Get the change in Y value (from the previous Y value)
|
2017-09-28 16:03:01 -05:00
|
|
|
double GetDelta(int64_t index);
|
2012-10-19 22:24:54 -05:00
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
/// Get a point at a specific index
|
2019-11-22 00:36:52 +01:00
|
|
|
Point const & GetPoint(int64_t index);
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
/// Get current point (or closest point to the right) from the X coordinate (i.e. the frame number)
|
2015-02-21 03:10:38 -06:00
|
|
|
Point GetClosestPoint(Point p);
|
|
|
|
|
|
2016-10-19 02:19:07 -05:00
|
|
|
/// Get current point (or closest point) from the X coordinate (i.e. the frame number)
|
|
|
|
|
/// Either use the closest left point, or right point
|
|
|
|
|
Point GetClosestPoint(Point p, bool useLeft);
|
|
|
|
|
|
|
|
|
|
/// Get previous point (
|
|
|
|
|
Point GetPreviousPoint(Point p);
|
|
|
|
|
|
2016-09-17 17:14:27 -05:00
|
|
|
/// Get max point (by Y coordinate)
|
|
|
|
|
Point GetMaxPoint();
|
|
|
|
|
|
2012-10-21 05:29:29 -05:00
|
|
|
// Get the number of values (i.e. coordinates on the X axis)
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t GetLength();
|
2012-10-21 05:29:29 -05:00
|
|
|
|
2015-02-22 01:04:54 -06:00
|
|
|
/// Get the number of points (i.e. # of points)
|
2017-09-28 16:03:01 -05:00
|
|
|
int64_t GetCount();
|
2015-02-22 01:04:54 -06:00
|
|
|
|
2013-12-03 00:13:25 -06:00
|
|
|
/// Get the direction of the curve at a specific index (increasing or decreasing)
|
|
|
|
|
bool IsIncreasing(int index);
|
|
|
|
|
|
2013-12-06 00:40:26 -06:00
|
|
|
/// Get and Set JSON methods
|
2019-08-04 22:54:06 -04:00
|
|
|
std::string Json(); ///< Generate JSON string of this object
|
2013-12-06 00:40:26 -06:00
|
|
|
Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
|
2019-08-04 22:54:06 -04:00
|
|
|
void SetJson(std::string value); ///< Load JSON string into this object
|
2013-12-07 21:09:55 -06:00
|
|
|
void SetJsonValue(Json::Value root); ///< Load Json::JsonValue into this object
|
2013-12-03 00:13:25 -06:00
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
/// Remove a point by matching a coordinate
|
2017-10-26 18:44:35 -05:00
|
|
|
void RemovePoint(Point p);
|
2011-10-11 08:44:27 -05:00
|
|
|
|
|
|
|
|
/// Remove a point by index
|
2017-10-26 18:44:35 -05:00
|
|
|
void RemovePoint(int64_t index);
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2015-03-13 23:19:55 -05:00
|
|
|
/// Scale all points by a percentage (good for evenly lengthening or shortening an openshot::Keyframe)
|
|
|
|
|
/// 1.0 = same size, 1.05 = 5% increase, etc...
|
2017-01-24 18:39:17 -06:00
|
|
|
void ScalePoints(double scale);
|
2015-03-13 23:19:55 -05:00
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
/// Replace an existing point with a new point
|
2017-09-28 16:03:01 -05:00
|
|
|
void UpdatePoint(int64_t index, Point p);
|
2011-10-11 08:44:27 -05:00
|
|
|
|
|
|
|
|
/// Print a list of points
|
|
|
|
|
void PrintPoints();
|
|
|
|
|
|
|
|
|
|
/// Print just the Y value of the point's primary coordinate
|
|
|
|
|
void PrintValues();
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|