OpenShot Library | libopenshot  0.2.2
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 // Constrain a color value from 0 to 255
62 int EffectBase::constrain(int color_value)
63 {
64  // Constrain new color from 0 to 255
65  if (color_value < 0)
66  color_value = 0;
67  else if (color_value > 255)
68  color_value = 255;
69 
70  return color_value;
71 }
72 
73 // Generate JSON string of this object
74 string EffectBase::Json() {
75 
76  // Return formatted string
77  return JsonValue().toStyledString();
78 }
79 
80 // Generate Json::JsonValue for this object
81 Json::Value EffectBase::JsonValue() {
82 
83  // Create root json object
84  Json::Value root = ClipBase::JsonValue(); // get parent properties
85  root["name"] = info.name;
86  root["class_name"] = info.class_name;
87  root["short_name"] = info.short_name;
88  root["description"] = info.description;
89  root["has_video"] = info.has_video;
90  root["has_audio"] = info.has_audio;
91  root["order"] = Order();
92 
93  // return JsonValue
94  return root;
95 }
96 
97 // Load JSON string into this object
98 void EffectBase::SetJson(string value) {
99 
100  // Parse JSON string into JSON objects
101  Json::Value root;
102  Json::Reader reader;
103  bool success = reader.parse( value, root );
104  if (!success)
105  // Raise exception
106  throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
107 
108  try
109  {
110  // Set all values that match
111  SetJsonValue(root);
112  }
113  catch (exception e)
114  {
115  // Error parsing JSON (or missing keys)
116  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
117  }
118 }
119 
120 // Load Json::JsonValue into this object
121 void EffectBase::SetJsonValue(Json::Value root) {
122 
123  // Set parent data
125 
126  // Set data from Json (if key is found)
127  if (!root["order"].isNull())
128  Order(root["order"].asInt());
129 }
130 
131 // Generate Json::JsonValue for this object
132 Json::Value EffectBase::JsonInfo() {
133 
134  // Create root json object
135  Json::Value root;
136  root["name"] = info.name;
137  root["class_name"] = info.class_name;
138  root["short_name"] = info.short_name;
139  root["description"] = info.description;
140  root["has_video"] = info.has_video;
141  root["has_audio"] = info.has_audio;
142 
143  // return JsonValue
144  return root;
145 }
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:98
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:132
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Definition: EffectBase.cpp:81
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:121
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
int constrain(int color_value)
Constrain a color value from 0 to 255.
Definition: EffectBase.cpp:62
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:104
virtual string Json()=0
Get and Set JSON methods.
Definition: EffectBase.cpp:74
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