OpenShot Library | libopenshot  0.1.2
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  * @section LICENSE
7  *
8  * Copyright (c) 2008-2014 OpenShot Studios, LLC
9  * <http://www.openshotstudios.com/>. This file is part of
10  * OpenShot Library (libopenshot), an open-source project dedicated to
11  * delivering high quality video editing and animation solutions to the
12  * world. For more information visit <http://www.openshot.org/>.
13  *
14  * OpenShot Library (libopenshot) is free software: you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public License
16  * as published by the Free Software Foundation, either version 3 of the
17  * License, or (at your option) any later version.
18  *
19  * OpenShot Library (libopenshot) is distributed in the hope that it will be
20  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #include "../include/ClipBase.h"
29 
30 using namespace openshot;
31 
32 // Generate Json::JsonValue for this object
33 Json::Value ClipBase::JsonValue() {
34 
35  // Create root json object
36  Json::Value root;
37  root["id"] = Id();
38  root["position"] = Position();
39  root["layer"] = Layer();
40  root["start"] = Start();
41  root["end"] = End();
42  root["duration"] = Duration();
43 
44  // return JsonValue
45  return root;
46 }
47 
48 // Load Json::JsonValue into this object
49 void ClipBase::SetJsonValue(Json::Value root) {
50 
51  // Set data from Json (if key is found)
52  if (!root["id"].isNull())
53  Id(root["id"].asString());
54  if (!root["position"].isNull())
55  Position(root["position"].asDouble());
56  if (!root["layer"].isNull())
57  Layer(root["layer"].asInt());
58  if (!root["start"].isNull())
59  Start(root["start"].asDouble());
60  if (!root["end"].isNull())
61  End(root["end"].asDouble());
62 }
63 
64 // Generate JSON for a property
65 Json::Value ClipBase::add_property_json(string name, float value, string type, string memo, bool contains_point, int number_of_points, float min_value, float max_value, InterpolationType intepolation, int closest_point_x, bool readonly) {
66 
67  // Create JSON Object
68  Json::Value prop = Json::Value(Json::objectValue);
69  prop["name"] = name;
70  prop["value"] = value;
71  prop["memo"] = memo;
72  prop["type"] = type;
73  prop["min"] = min_value;
74  prop["max"] = max_value;
75  prop["keyframe"] = contains_point;
76  prop["points"] = number_of_points;
77  prop["readonly"] = readonly;
78  prop["interpolation"] = intepolation;
79  prop["closest_point_x"] = closest_point_x;
80  prop["choices"] = Json::Value(Json::arrayValue);
81 
82  // return JsonValue
83  return prop;
84 }
85 
86 Json::Value ClipBase::add_property_choice_json(string name, int value, int selected_value) {
87 
88  // Create choice
89  Json::Value new_choice = Json::Value(Json::objectValue);
90  new_choice["name"] = name;
91  new_choice["value"] = value;
92  new_choice["selected"] = (value == selected_value);
93 
94  // return JsonValue
95  return new_choice;
96 }
float End()
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:80
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:78
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Definition: ClipBase.cpp:49
Json::Value add_property_choice_json(string name, int value, int selected_value)
Generate JSON choice for a property (dropdown properties)
Definition: ClipBase.cpp:86
Json::Value add_property_json(string name, float value, string type, string memo, bool contains_point, int number_of_points, float min_value, float max_value, InterpolationType intepolation, int closest_point_x, bool readonly)
Generate JSON for a property.
Definition: ClipBase.cpp:65
string Id()
Get basic properties.
Definition: ClipBase.h:76
float Position()
Get position on timeline (in seconds)
Definition: ClipBase.h:77
InterpolationType
This controls how a Keyframe uses this point to interpolate between two points.
Definition: Point.h:45
This namespace is the default namespace for all code in the openshot library.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Definition: ClipBase.cpp:33
float Duration()
Get the length of this clip (in seconds)
Definition: ClipBase.h:81
float Start()
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:79