OpenShot Library | libopenshot  0.2.5
ClipBase.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Source file for EffectBase class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #include "../include/ClipBase.h"
32 
33 using namespace openshot;
34 
35 // Generate Json::Value for this object
36 Json::Value ClipBase::JsonValue() const {
37 
38  // Create root json object
39  Json::Value root;
40  root["id"] = Id();
41  root["position"] = Position();
42  root["layer"] = Layer();
43  root["start"] = Start();
44  root["end"] = End();
45  root["duration"] = Duration();
46 
47  // return JsonValue
48  return root;
49 }
50 
51 // Load Json::Value into this object
52 void ClipBase::SetJsonValue(const Json::Value root) {
53 
54  // Set data from Json (if key is found)
55  if (!root["id"].isNull())
56  Id(root["id"].asString());
57  if (!root["position"].isNull())
58  Position(root["position"].asDouble());
59  if (!root["layer"].isNull())
60  Layer(root["layer"].asInt());
61  if (!root["start"].isNull())
62  Start(root["start"].asDouble());
63  if (!root["end"].isNull())
64  End(root["end"].asDouble());
65 }
66 
67 // Generate JSON for a property
68 Json::Value ClipBase::add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe* keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const {
69 
70  // Requested Point
71  const Point requested_point(requested_frame, requested_frame);
72 
73  // Create JSON Object
74  Json::Value prop = Json::Value(Json::objectValue);
75  prop["name"] = name;
76  prop["value"] = value;
77  prop["memo"] = memo;
78  prop["type"] = type;
79  prop["min"] = min_value;
80  prop["max"] = max_value;
81  if (keyframe) {
82  prop["keyframe"] = keyframe->Contains(requested_point);
83  prop["points"] = int(keyframe->GetCount());
84  Point closest_point = keyframe->GetClosestPoint(requested_point);
85  prop["interpolation"] = closest_point.interpolation;
86  prop["closest_point_x"] = closest_point.co.X;
87  prop["previous_point_x"] = keyframe->GetPreviousPoint(closest_point).co.X;
88  }
89  else {
90  prop["keyframe"] = false;
91  prop["points"] = 0;
92  prop["interpolation"] = CONSTANT;
93  prop["closest_point_x"] = -1;
94  prop["previous_point_x"] = -1;
95  }
96 
97  prop["readonly"] = readonly;
98  prop["choices"] = Json::Value(Json::arrayValue);
99 
100  // return JsonValue
101  return prop;
102 }
103 
104 Json::Value ClipBase::add_property_choice_json(std::string name, int value, int selected_value) const {
105 
106  // Create choice
107  Json::Value new_choice = Json::Value(Json::objectValue);
108  new_choice["name"] = name;
109  new_choice["value"] = value;
110  new_choice["selected"] = (value == selected_value);
111 
112  // return JsonValue
113  return new_choice;
114 }
float End() const
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:80
float Start() const
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:79
float Duration() const
Get the length of this clip (in seconds)
Definition: ClipBase.h:81
std::string Id() const
Get basic properties.
Definition: ClipBase.h:76
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: ClipBase.cpp:36
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
Definition: ClipBase.cpp:104
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:78
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: ClipBase.cpp:52
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:77
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
Definition: ClipBase.cpp:68
double X
The X value of the coordinate (usually representing the frame #)
Definition: Coordinate.h:57
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:64
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition: KeyFrame.cpp:188
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition: KeyFrame.cpp:230
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition: KeyFrame.cpp:510
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:225
A Point is the basic building block of a key-frame curve.
Definition: Point.h:82
Coordinate co
This is the primary coordinate.
Definition: Point.h:84
InterpolationType interpolation
This is the interpolation mode.
Definition: Point.h:87
This namespace is the default namespace for all code in the openshot library.
@ CONSTANT
Constant curves jump from their previous position to a new one (with no interpolation).
Definition: Point.h:49