OpenShot Library | libopenshot  0.2.5
ClipBase.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for ClipBase 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_CLIPBASE_H
32 #define OPENSHOT_CLIPBASE_H
33 
34 #include <memory>
35 #include <sstream>
36 #include "Exceptions.h"
37 #include "Point.h"
38 #include "KeyFrame.h"
39 #include "Json.h"
40 
41 namespace openshot {
42 
43  /**
44  * @brief This abstract class is the base class, used by all clips in libopenshot.
45  *
46  * Clips are objects that attach to the timeline and can be layered and positioned
47  * together. There are 2 primary types of clips: Effects and Video/Audio Clips.
48  */
49  class ClipBase {
50  protected:
51  std::string id; ///< ID Property for all derived Clip and Effect classes.
52  float position; ///< The position on the timeline where this clip should start playing
53  int layer; ///< The layer this clip is on. Lower clips are covered up by higher clips.
54  float start; ///< The position in seconds to start playing (used to trim the beginning of a clip)
55  float end; ///< The position in seconds to end playing (used to trim the ending of a clip)
56  std::string previous_properties; ///< This string contains the previous JSON properties
57 
58  /// Generate JSON for a property
59  Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe* keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const;
60 
61  /// Generate JSON choice for a property (dropdown properties)
62  Json::Value add_property_choice_json(std::string name, int value, int selected_value) const;
63 
64  public:
65 
66  /// Constructor for the base clip
67  ClipBase() { };
68 
69  // Compare a clip using the Position() property
70  bool operator< ( ClipBase& a) { return (Position() < a.Position()); }
71  bool operator<= ( ClipBase& a) { return (Position() <= a.Position()); }
72  bool operator> ( ClipBase& a) { return (Position() > a.Position()); }
73  bool operator>= ( ClipBase& a) { return (Position() >= a.Position()); }
74 
75  /// Get basic properties
76  std::string Id() const { return id; } ///< Get the Id of this clip object
77  float Position() const { return position; } ///< Get position on timeline (in seconds)
78  int Layer() const { return layer; } ///< Get layer of clip on timeline (lower number is covered by higher numbers)
79  float Start() const { return start; } ///< Get start position (in seconds) of clip (trim start of video)
80  float End() const { return end; } ///< Get end position (in seconds) of clip (trim end of video)
81  float Duration() const { return end - start; } ///< Get the length of this clip (in seconds)
82 
83  /// Set basic properties
84  void Id(std::string value) { id = value; } ///> Set the Id of this clip object
85  void Position(float value) { position = value; } ///< Set position on timeline (in seconds)
86  void Layer(int value) { layer = value; } ///< Set layer of clip on timeline (lower number is covered by higher numbers)
87  void Start(float value) { start = value; } ///< Set start position (in seconds) of clip (trim start of video)
88  void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video)
89 
90  /// Get and Set JSON methods
91  virtual std::string Json() const = 0; ///< Generate JSON string of this object
92  virtual void SetJson(const std::string value) = 0; ///< Load JSON string into this object
93  virtual Json::Value JsonValue() const = 0; ///< Generate Json::Value for this object
94  virtual void SetJsonValue(const Json::Value root) = 0; ///< Load Json::Value into this object
95 
96  /// Get all properties for a specific frame (perfect for a UI to display the current state
97  /// of all properties at any time)
98  virtual std::string PropertiesJSON(int64_t requested_frame) const = 0;
99 
100  virtual ~ClipBase() = default;
101  };
102 
103 
104 }
105 
106 #endif
Header file for all Exception classes.
Header file for JSON class.
Header file for the Keyframe class.
Header file for Point class.
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:49
float End() const
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:80
float Start() const
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:79
float start
The position in seconds to start playing (used to trim the beginning of a clip)
Definition: ClipBase.h:54
float Duration() const
Get the length of this clip (in seconds)
Definition: ClipBase.h:81
virtual std::string Json() const =0
Get and Set JSON methods.
virtual std::string PropertiesJSON(int64_t requested_frame) const =0
bool operator>=(ClipBase &a)
Definition: ClipBase.h:73
std::string Id() const
Get basic properties.
Definition: ClipBase.h:76
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: ClipBase.cpp:36
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
Definition: ClipBase.cpp:104
void Id(std::string value)
Set basic properties.
Definition: ClipBase.h:84
bool operator<=(ClipBase &a)
Definition: ClipBase.h:71
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:78
ClipBase()
Constructor for the base clip.
Definition: ClipBase.h:67
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: ClipBase.cpp:52
int layer
The layer this clip is on. Lower clips are covered up by higher clips.
Definition: ClipBase.h:53
void Start(float value)
Set start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:87
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:77
bool operator>(ClipBase &a)
Definition: ClipBase.h:72
std::string id
ID Property for all derived Clip and Effect classes.
Definition: ClipBase.h:51
void Layer(int value)
Set layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:86
float position
The position on the timeline where this clip should start playing.
Definition: ClipBase.h:52
virtual void SetJson(const std::string value)=0
Load JSON string into this object.
float end
The position in seconds to end playing (used to trim the ending of a clip)
Definition: ClipBase.h:55
void Position(float value)
Set the Id of this clip object
Definition: ClipBase.h:85
bool operator<(ClipBase &a)
Definition: ClipBase.h:70
void End(float value)
Set end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:88
virtual ~ClipBase()=default
std::string previous_properties
This string contains the previous JSON properties.
Definition: ClipBase.h:56
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
Definition: ClipBase.cpp:68
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:64
This namespace is the default namespace for all code in the openshot library.