OpenShot Library | libopenshot  0.3.3
ClipBase.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_CLIPBASE_H
14 #define OPENSHOT_CLIPBASE_H
15 
16 #include <memory>
17 #include <sstream>
18 #include "CacheMemory.h"
19 #include "Frame.h"
20 #include "Point.h"
21 #include "KeyFrame.h"
22 #include "Json.h"
23 #include "TimelineBase.h"
24 
25 
26 namespace openshot {
33  class ClipBase {
34  protected:
35  std::string id;
36  float position;
37  int layer;
38  float start;
39  float end;
40  std::string previous_properties;
42 
44  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;
45 
47  Json::Value add_property_choice_json(std::string name, int value, int selected_value) const;
48 
49  public:
52  position(0.0),
53  layer(0),
54  start(0.0),
55  end(0.0),
57  timeline(nullptr) {}
58 
59  // Compare a clip using the Position() property
60  bool operator< ( ClipBase& a) { return (Position() < a.Position()); }
61  bool operator<= ( ClipBase& a) { return (Position() <= a.Position()); }
62  bool operator> ( ClipBase& a) { return (Position() > a.Position()); }
63  bool operator>= ( ClipBase& a) { return (Position() >= a.Position()); }
64 
71  virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) = 0;
72 
82  virtual std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) = 0;
83 
84  // Get basic properties
85  std::string Id() const { return id; }
86  float Position() const { return position; }
87  int Layer() const { return layer; }
88  float Start() const { return start; }
89  virtual float End() const { return end; }
90  float Duration() const { return end - start; }
92 
93  // Set basic properties
94  void Id(std::string value) { id = value; }
95  void Position(float value);
96  void Layer(int value);
97  void Start(float value);
98  virtual void End(float value);
99  virtual void ParentTimeline(openshot::TimelineBase* new_timeline) { timeline = new_timeline; }
100 
101  // Get and Set JSON methods
102  virtual std::string Json() const = 0;
103  virtual void SetJson(const std::string value) = 0;
104  virtual Json::Value JsonValue() const = 0;
105  virtual void SetJsonValue(const Json::Value root) = 0;
106 
109  virtual std::string PropertiesJSON(int64_t requested_frame) const = 0;
110 
111  virtual ~ClipBase() = default;
112  };
113 
114 
115 }
116 
117 #endif
Header file for CacheMemory class.
Header file for Frame class.
Header file for JSON class.
Header file for the Keyframe class.
Header file for Point class.
Header file for Timeline class.
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:33
float Start() const
Get start position (in seconds) of clip (trim start of video)
Definition: ClipBase.h:88
float start
The position in seconds to start playing (used to trim the beginning of a clip)
Definition: ClipBase.h:38
float Duration() const
Get the length of this clip (in seconds)
Definition: ClipBase.h:90
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
Definition: ClipBase.h:89
virtual std::string Json() const =0
Generate JSON string of this object.
virtual std::string PropertiesJSON(int64_t requested_frame) const =0
bool operator>=(ClipBase &a)
Definition: ClipBase.h:63
virtual std::shared_ptr< openshot::Frame > GetFrame(std::shared_ptr< openshot::Frame > frame, int64_t frame_number)=0
This method is required for all derived classes of ClipBase, and returns a modified openshot::Frame o...
std::string Id() const
Get the Id of this clip object.
Definition: ClipBase.h:85
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: ClipBase.cpp:64
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:132
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number)=0
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
void Id(std::string value)
Definition: ClipBase.h:94
bool operator<=(ClipBase &a)
Definition: ClipBase.h:61
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.h:87
ClipBase()
Constructor for the base clip.
Definition: ClipBase.h:51
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: ClipBase.cpp:80
openshot::TimelineBase * timeline
Pointer to the parent timeline instance (if any)
Definition: ClipBase.h:41
int layer
The layer this clip is on. Lower clips are covered up by higher clips.
Definition: ClipBase.h:37
float Position() const
Get position on timeline (in seconds)
Definition: ClipBase.h:86
bool operator>(ClipBase &a)
Definition: ClipBase.h:62
std::string id
ID Property for all derived Clip and Effect classes.
Definition: ClipBase.h:35
virtual void ParentTimeline(openshot::TimelineBase *new_timeline)
Set associated Timeline pointer.
Definition: ClipBase.h:99
virtual openshot::TimelineBase * ParentTimeline()
Get the associated Timeline pointer (if any)
Definition: ClipBase.h:91
float position
The position on the timeline where this clip should start playing.
Definition: ClipBase.h:36
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:39
bool operator<(ClipBase &a)
Definition: ClipBase.h:60
virtual ~ClipBase()=default
std::string previous_properties
This string contains the previous JSON properties.
Definition: ClipBase.h:40
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:96
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
This class represents a timeline (used for building generic timeline implementations)
Definition: TimelineBase.h:41
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:29