OpenShot Library | libopenshot  0.2.7
EffectBase.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for EffectBase class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_EFFECT_BASE_H
32 #define OPENSHOT_EFFECT_BASE_H
33 
34 #include "ClipBase.h"
35 
36 #include "Json.h"
37 #include "TrackedObjectBase.h"
38 
39 #include <memory>
40 #include <map>
41 #include <string>
42 
43 namespace openshot
44 {
45  /**
46  * @brief This struct contains info about an effect, such as the name, video or audio effect, etc...
47  *
48  * Each derived class of EffectBase is responsible for updating this struct to reflect accurate information
49  * about the underlying effect. Derived classes of EffectBase should call the InitEffectInfo() method to initialize the
50  * default values of this struct.
51  */
53  {
54  std::string class_name; ///< The class name of the effect
55  std::string name; ///< The name of the effect
56  std::string description; ///< The description of this effect and what it does
57  std::string parent_effect_id; ///< Id of the parent effect (if there is one)
58  bool has_video; ///< Determines if this effect manipulates the image of a frame
59  bool has_audio; ///< Determines if this effect manipulates the audio of a frame
60  bool has_tracked_object; ///< Determines if this effect track objects through the clip
61  };
62 
63  /**
64  * @brief This abstract class is the base class, used by all effects in libopenshot.
65  *
66  * Effects are types of classes that manipulate the image or audio data of an openshot::Frame object.
67  * The only requirements for an 'effect', is to derive from this base class, implement the Apply()
68  * method, and call the InitEffectInfo() method.
69  */
70  class EffectBase : public ClipBase
71  {
72  private:
73  int order; ///< The order to evaluate this effect. Effects are processed in this order (when more than one overlap).
74 
75  protected:
76  openshot::ClipBase* clip; ///< Pointer to the parent clip instance (if any)
77 
78  public:
79 
80  /// Parent effect (which properties will set this effect properties)
82 
83  /// Map of Tracked Object's by their indices (used by Effects that track objects on clips)
84  std::map<int, std::shared_ptr<openshot::TrackedObjectBase> > trackedObjects;
85 
86  /// Information about the current effect
88 
89  /// Display effect information in the standard output stream (stdout)
90  void DisplayInfo();
91 
92  /// Constrain a color value from 0 to 255
93  int constrain(int color_value);
94 
95  /// Initialize the values of the EffectInfo struct. It is important for derived classes to call
96  /// this method, or the EffectInfo struct values will not be initialized.
97  void InitEffectInfo();
98 
99  /// Parent clip object of this effect (which can be unparented and NULL)
101 
102  /// Set parent clip object of this effect
103  void ParentClip(openshot::ClipBase* new_clip);
104 
105  /// Set the parent effect from which this properties will be set to
106  void SetParentEffect(std::string parentEffect_id);
107 
108  /// Return the ID of this effect's parent clip
109  std::string ParentClipId() const;
110 
111  /// Get the indexes and IDs of all visible objects in the given frame
112  virtual std::string GetVisibleObjects(int64_t frame_number) const {return {}; };
113 
114  // Get and Set JSON methods
115  virtual std::string Json() const; ///< Generate JSON string of this object
116  virtual void SetJson(const std::string value); ///< Load JSON string into this object
117  virtual Json::Value JsonValue() const; ///< Generate Json::Value for this object
118  virtual void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
119 
120  virtual std::string Json(int64_t requested_frame) const{
121  return "";
122  };
123  virtual void SetJson(int64_t requested_frame, const std::string value) {
124  return;
125  };
126 
127  Json::Value JsonInfo() const; ///< Generate JSON object of meta data / info
128 
129  /// Get the order that this effect should be executed.
130  int Order() const { return order; }
131 
132  /// Set the order that this effect should be executed.
133  void Order(int new_order) { order = new_order; }
134 
135  virtual ~EffectBase() = default;
136  };
137 
138 }
139 
140 #endif
Header file for ClipBase class.
Header file for JSON class.
Header file for the TrackedObjectBase class.
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:51
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:71
void DisplayInfo()
Display effect information in the standard output stream (stdout)
Definition: EffectBase.cpp:60
virtual void SetJson(const std::string value)
Load JSON string into this object.
Definition: EffectBase.cpp:110
EffectBase * parentEffect
Parent effect (which properties will set this effect properties)
Definition: EffectBase.h:81
virtual std::string Json(int64_t requested_frame) const
Definition: EffectBase.h:120
Json::Value JsonInfo() const
Generate JSON object of meta data / info.
Definition: EffectBase.cpp:173
virtual void SetJson(int64_t requested_frame, const std::string value)
Definition: EffectBase.h:123
std::string ParentClipId() const
Return the ID of this effect's parent clip.
Definition: EffectBase.cpp:223
void SetParentEffect(std::string parentEffect_id)
Set the parent effect from which this properties will be set to.
Definition: EffectBase.cpp:198
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: EffectBase.cpp:92
virtual ~EffectBase()=default
openshot::ClipBase * ParentClip()
Parent clip object of this effect (which can be unparented and NULL)
Definition: EffectBase.cpp:188
int constrain(int color_value)
Constrain a color value from 0 to 255.
Definition: EffectBase.cpp:73
virtual std::string Json() const
Generate JSON string of this object.
Definition: EffectBase.cpp:85
virtual std::string GetVisibleObjects(int64_t frame_number) const
Get the indexes and IDs of all visible objects in the given frame.
Definition: EffectBase.h:112
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: EffectBase.cpp:127
int Order() const
Get the order that this effect should be executed.
Definition: EffectBase.h:130
void Order(int new_order)
Set the order that this effect should be executed.
Definition: EffectBase.h:133
openshot::ClipBase * clip
Pointer to the parent clip instance (if any)
Definition: EffectBase.h:76
EffectInfoStruct info
Information about the current effect.
Definition: EffectBase.h:87
std::map< int, std::shared_ptr< openshot::TrackedObjectBase > > trackedObjects
Map of Tracked Object's by their indices (used by Effects that track objects on clips)
Definition: EffectBase.h:84
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47
This struct contains info about an effect, such as the name, video or audio effect,...
Definition: EffectBase.h:53
bool has_video
Determines if this effect manipulates the image of a frame.
Definition: EffectBase.h:58
std::string parent_effect_id
Id of the parent effect (if there is one)
Definition: EffectBase.h:57
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition: EffectBase.h:59
std::string class_name
The class name of the effect.
Definition: EffectBase.h:54
std::string name
The name of the effect.
Definition: EffectBase.h:55
std::string description
The description of this effect and what it does.
Definition: EffectBase.h:56
bool has_tracked_object
Determines if this effect track objects through the clip.
Definition: EffectBase.h:60