OpenShot Library | libopenshot  0.1.9
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["name"] = info.name;
74  root["class_name"] = info.class_name;
75  root["short_name"] = info.short_name;
76  root["description"] = info.description;
77  root["has_video"] = info.has_video;
78  root["has_audio"] = info.has_audio;
79  root["order"] = Order();
80 
81  // return JsonValue
82  return root;
83 }
84 
85 // Load JSON string into this object
86 void EffectBase::SetJson(string value) {
87 
88  // Parse JSON string into JSON objects
89  Json::Value root;
90  Json::Reader reader;
91  bool success = reader.parse( value, root );
92  if (!success)
93  // Raise exception
94  throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
95 
96  try
97  {
98  // Set all values that match
99  SetJsonValue(root);
100  }
101  catch (exception e)
102  {
103  // Error parsing JSON (or missing keys)
104  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
105  }
106 }
107 
108 // Load Json::JsonValue into this object
109 void EffectBase::SetJsonValue(Json::Value root) {
110 
111  // Set parent data
113 
114  // Set data from Json (if key is found)
115  if (!root["order"].isNull())
116  Order(root["order"].asInt());
117 }
118 
119 // Generate Json::JsonValue for this object
120 Json::Value EffectBase::JsonInfo() {
121 
122  // Create root json object
123  Json::Value root;
124  root["name"] = info.name;
125  root["class_name"] = info.class_name;
126  root["short_name"] = info.short_name;
127  root["description"] = info.description;
128  root["has_video"] = info.has_video;
129  root["has_audio"] = info.has_audio;
130 
131  // return JsonValue
132  return root;
133 }
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:86
float End()
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:86
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:84
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:120
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:83
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:109
This namespace is the default namespace for all code in the openshot library.
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:85
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:73