OpenShot Library | libopenshot  0.1.2
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 <tr1/memory>
37 #include <sstream>
38 #include "Exceptions.h"
39 #include "Point.h"
40 #include "Json.h"
41 
42 using namespace std;
43 
44 namespace openshot {
45 
46  /**
47  * @brief This abstract class is the base class, used by all clips in libopenshot.
48  *
49  * Clips are objects that attach to the timeline and can be layered and positioned
50  * together. There are 2 primary types of clips: Effects and Video/Audio Clips.
51  */
52  class ClipBase {
53  protected:
54  string id; ///< ID Property for all derived Clip and Effect classes.
55  float position; ///< The position on the timeline where this clip should start playing
56  int layer; ///< The layer this clip is on. Lower clips are covered up by higher clips.
57  float start; ///< The position in seconds to start playing (used to trim the beginning of a clip)
58  float end; ///< The position in seconds to end playing (used to trim the ending of a clip)
59  string previous_properties; ///< This string contains the previous JSON properties
60 
61  /// Generate JSON for a property
62  Json::Value add_property_json(string name, float value, string type, string memo, bool contains_point, int number_of_points, float min_value, float max_value, InterpolationType intepolation, int closest_point_x, bool readonly);
63 
64  /// Generate JSON choice for a property (dropdown properties)
65  Json::Value add_property_choice_json(string name, int value, int selected_value);
66 
67  public:
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  string Id() { return id; } ///< Get the Id of this clip object
77  float Position() { return position; } ///< Get position on timeline (in seconds)
78  int Layer() { return layer; } ///< Get layer of clip on timeline (lower number is covered by higher numbers)
79  float Start() { return start; } ///< Get start position (in seconds) of clip (trim start of video)
80  float End() { return end; } ///< Get end position (in seconds) of clip (trim end of video)
81  float Duration() { return end - start; } ///< Get the length of this clip (in seconds)
82 
83  /// Set basic properties
84  void Id(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 string Json() = 0; ///< Generate JSON string of this object
92  virtual void SetJson(string value) throw(InvalidJSON) = 0; ///< Load JSON string into this object
93  virtual Json::Value JsonValue() = 0; ///< Generate Json::JsonValue for this object
94  virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::JsonValue 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 string PropertiesJSON(long int requested_frame) = 0;
99 
100  };
101 
102 
103 }
104 
105 #endif
void Layer(int value)
Set layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:86
string previous_properties
This string contains the previous JSON properties.
Definition: ClipBase.h:59
void Start(float value)
Set start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:87
Header file for Point class.
float position
The position on the timeline where this clip should start playing.
Definition: ClipBase.h:55
float End()
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:80
int Layer()
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:78
int layer
The layer this clip is on. Lower clips are covered up by higher clips.
Definition: ClipBase.h:56
Header file for all Exception classes.
string Id()
Get basic properties.
Definition: ClipBase.h:76
float Position()
Get position on timeline (in seconds)
Definition: ClipBase.h:77
Header file for JSON class.
void Position(float value)
Set the Id of this clip object
Definition: ClipBase.h:85
string id
ID Property for all derived Clip and Effect classes.
Definition: ClipBase.h:54
float start
The position in seconds to start playing (used to trim the beginning of a clip)
Definition: ClipBase.h:57
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:52
void Id(string value)
Set basic properties.
Definition: ClipBase.h:84
void End(float value)
Set end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:88
float end
The position in seconds to end playing (used to trim the ending of a clip)
Definition: ClipBase.h:58
InterpolationType
This controls how a Keyframe uses this point to interpolate between two points.
Definition: Point.h:45
This namespace is the default namespace for all code in the openshot library.
Exception for invalid JSON.
Definition: Exceptions.h:152
float Duration()
Get the length of this clip (in seconds)
Definition: ClipBase.h:81
float Start()
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:79