OpenShot Library | libopenshot  0.1.1
EffectBase.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/EffectBase.h"
29 
30 using namespace openshot;
31 
32 // Initialize the values of the FileInfo struct
34 {
35  // Init clip settings
36  Position(0.0);
37  Layer(0);
38  Start(0.0);
39  End(0.0);
40  Order(0);
41 
42  info.has_video = false;
43  info.has_audio = false;
44  info.name = "";
45  info.description = "";
46 }
47 
48 // Display file information
50  cout << fixed << setprecision(2) << boolalpha;
51  cout << "----------------------------" << endl;
52  cout << "----- Effect Information -----" << endl;
53  cout << "----------------------------" << endl;
54  cout << "--> Name: " << info.name << endl;
55  cout << "--> Description: " << info.description << endl;
56  cout << "--> Has Video: " << info.has_video << endl;
57  cout << "--> Has Audio: " << info.has_audio << endl;
58  cout << "----------------------------" << endl;
59 }
60 
61 // Generate JSON string of this object
62 string EffectBase::Json() {
63 
64  // Return formatted string
65  return JsonValue().toStyledString();
66 }
67 
68 // Generate Json::JsonValue for this object
69 Json::Value EffectBase::JsonValue() {
70 
71  // Create root json object
72  Json::Value root = ClipBase::JsonValue(); // get parent properties
73  root["order"] = Order();
74 
75  // return JsonValue
76  return root;
77 }
78 
79 // Load JSON string into this object
80 void EffectBase::SetJson(string value) throw(InvalidJSON) {
81 
82  // Parse JSON string into JSON objects
83  Json::Value root;
84  Json::Reader reader;
85  bool success = reader.parse( value, root );
86  if (!success)
87  // Raise exception
88  throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
89 
90  try
91  {
92  // Set all values that match
93  SetJsonValue(root);
94  }
95  catch (exception e)
96  {
97  // Error parsing JSON (or missing keys)
98  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
99  }
100 }
101 
102 // Load Json::JsonValue into this object
103 void EffectBase::SetJsonValue(Json::Value root) {
104 
105  // Set parent data
107 
108  // Set data from Json (if key is found)
109  if (!root["order"].isNull())
110  Order(root["order"].asInt());
111 }
112 
113 // Generate Json::JsonValue for this object
114 Json::Value EffectBase::JsonInfo() {
115 
116  // Create root json object
117  Json::Value root;
118  root["name"] = info.name;
119  root["class_name"] = info.class_name;
120  root["short_name"] = info.short_name;
121  root["description"] = info.description;
122  root["has_video"] = info.has_video;
123  root["has_audio"] = info.has_audio;
124 
125  // return JsonValue
126  return root;
127 }
void DisplayInfo()
Display effect information in the standard output stream (stdout)
Definition: EffectBase.cpp:49
virtual void SetJson(string value)=0
Load JSON string into this object.
Definition: EffectBase.cpp:80
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
string class_name
The class name of the effect.
Definition: EffectBase.h:51
Json::Value JsonInfo()
Generate JSON object of meta data / info.
Definition: EffectBase.cpp:114
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Definition: EffectBase.cpp:69
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:56
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Definition: ClipBase.cpp:49
float Position()
Get position on timeline (in seconds)
Definition: ClipBase.h:77
string name
The name of the effect.
Definition: EffectBase.h:53
string description
The description of this effect and what it does.
Definition: EffectBase.h:54
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Definition: EffectBase.cpp:103
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:55
Exception for invalid JSON.
Definition: Exceptions.h:152
string short_name
A short name of the effect, commonly used for icon names, etc...
Definition: EffectBase.h:52
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Definition: ClipBase.cpp:33
int Order()
Get the order that this effect should be executed.
Definition: EffectBase.h:101
virtual string Json()=0
Get and Set JSON methods.
Definition: EffectBase.cpp:62
float Start()
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:79
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:73