OpenShot Library | libopenshot  0.1.9
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, Keyframe* keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) {
66 
67  // Requested Point
68  Point requested_point(requested_frame, requested_frame);
69 
70  // Create JSON Object
71  Json::Value prop = Json::Value(Json::objectValue);
72  prop["name"] = name;
73  prop["value"] = value;
74  prop["memo"] = memo;
75  prop["type"] = type;
76  prop["min"] = min_value;
77  prop["max"] = max_value;
78  if (keyframe) {
79  prop["keyframe"] = keyframe->Contains(requested_point);
80  prop["points"] = int(keyframe->GetCount());
81  Point closest_point = keyframe->GetClosestPoint(requested_point);
82  prop["interpolation"] = closest_point.interpolation;
83  prop["closest_point_x"] = closest_point.co.X;
84  prop["previous_point_x"] = keyframe->GetPreviousPoint(closest_point).co.X;
85  }
86  else {
87  prop["keyframe"] = false;
88  prop["points"] = 0;
89  prop["interpolation"] = CONSTANT;
90  prop["closest_point_x"] = -1;
91  prop["previous_point_x"] = -1;
92  }
93 
94  prop["readonly"] = readonly;
95  prop["choices"] = Json::Value(Json::arrayValue);
96 
97  // return JsonValue
98  return prop;
99 }
100 
101 Json::Value ClipBase::add_property_choice_json(string name, int value, int selected_value) {
102 
103  // Create choice
104  Json::Value new_choice = Json::Value(Json::objectValue);
105  new_choice["name"] = name;
106  new_choice["value"] = value;
107  new_choice["selected"] = (value == selected_value);
108 
109  // return JsonValue
110  return new_choice;
111 }
int64_t GetCount()
Get the number of points (i.e. # of points)
Definition: KeyFrame.cpp:452
InterpolationType interpolation
This is the interpolation mode.
Definition: Point.h:86
bool Contains(Point p)
Does this keyframe contain a specific point.
Definition: KeyFrame.cpp:128
float End()
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:86
A Point is the basic building block of a key-frame curve.
Definition: Point.h:81
Json::Value add_property_json(string name, float value, string type, string memo, Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame)
Generate JSON for a property.
Definition: ClipBase.cpp:65
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:84
Point GetPreviousPoint(Point p)
Get previous point (.
Definition: KeyFrame.cpp:188
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:101
string Id()
Get basic properties.
Definition: ClipBase.h:82
float Position()
Get position on timeline (in seconds)
Definition: ClipBase.h:83
double X
The X value of the coordinate (usually representing the frame #)
Definition: Coordinate.h:61
Point GetClosestPoint(Point p)
Get current point (or closest point to the right) from the X coordinate (i.e. the frame number) ...
Definition: KeyFrame.cpp:183
This namespace is the default namespace for all code in the openshot library.
Coordinate co
This is the primary coordinate.
Definition: Point.h:83
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Definition: ClipBase.cpp:33
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
Definition: KeyFrame.h:64
float Duration()
Get the length of this clip (in seconds)
Definition: ClipBase.h:87
Constant curves jump from their previous position to a new one (with no interpolation).
Definition: Point.h:48
float Start()
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:85