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