OpenShot Library | libopenshot  0.4.0
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 "CacheMemory.h"
18 #include "Frame.h"
19 #include "Point.h"
20 #include "KeyFrame.h"
21 #include "Json.h"
22 #include "TimelineBase.h"
23 
24 
25 namespace openshot {
32  class ClipBase {
33  protected:
34  std::string id;
35  float position;
36  int layer;
37  float start;
38  float end;
39  std::string previous_properties;
41 
43  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;
44 
46  Json::Value add_property_choice_json(std::string name, int value, int selected_value) const;
47 
48  public:
51  position(0.0),
52  layer(0),
53  start(0.0),
54  end(0.0),
56  timeline(nullptr) {}
57 
58  // Compare a clip using the Position() property
59  bool operator< ( ClipBase& a) { return (Position() < a.Position()); }
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 
70  virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) = 0;
71 
81  virtual std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) = 0;
82 
83  // Get basic properties
84  std::string Id() const { return id; }
85  float Position() const { return position; }
86  int Layer() const { return layer; }
87  float Start() const { return start; }
88  virtual float End() const { return end; }
89  float Duration() const { return end - start; }
90  virtual openshot::TimelineBase* ParentTimeline() { return timeline; }
91 
92  // Set basic properties
93  void Id(std::string value) { id = value; }
94  void Position(float value);
95  void Layer(int value);
96  void Start(float value);
97  virtual void End(float value);
98  virtual void ParentTimeline(openshot::TimelineBase* new_timeline) { timeline = new_timeline; }
99 
100  // Get and Set JSON methods
101  virtual std::string Json() const = 0;
102  virtual void SetJson(const std::string value) = 0;
103  virtual Json::Value JsonValue() const = 0;
104  virtual void SetJsonValue(const Json::Value root) = 0;
105 
108  virtual std::string PropertiesJSON(int64_t requested_frame) const = 0;
109 
110  virtual ~ClipBase() = default;
111  };
112 
113 
114 }
115 
116 #endif
openshot::ClipBase::add_property_json
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
TimelineBase.h
Header file for Timeline class.
openshot::ClipBase::~ClipBase
virtual ~ClipBase()=default
openshot::ClipBase::timeline
openshot::TimelineBase * timeline
Pointer to the parent timeline instance (if any)
Definition: ClipBase.h:40
Point.h
Header file for Point class.
openshot::ClipBase::End
virtual void End(float value)
Set end position (in seconds) of clip (trim end of video)
Definition: ClipBase.cpp:53
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::ClipBase::add_property_choice_json
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
openshot::ClipBase::Json
virtual std::string Json() const =0
Generate JSON string of this object.
openshot::ClipBase::operator>
bool operator>(ClipBase &a)
Definition: ClipBase.h:61
openshot::ClipBase::Position
void Position(float value)
Set the Id of this clip object
Definition: ClipBase.cpp:19
KeyFrame.h
Header file for the Keyframe class.
openshot::ClipBase::SetJson
virtual void SetJson(const std::string value)=0
Load JSON string into this object.
openshot::ClipBase::SetJsonValue
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: ClipBase.cpp:80
openshot::ClipBase::JsonValue
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: ClipBase.cpp:64
openshot::ClipBase::position
float position
The position on the timeline where this clip should start playing.
Definition: ClipBase.h:35
openshot::ClipBase::ClipBase
ClipBase()
Constructor for the base clip.
Definition: ClipBase.h:50
openshot::ClipBase::operator<
bool operator<(ClipBase &a)
Definition: ClipBase.h:59
openshot::Keyframe
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
CacheMemory.h
Header file for CacheMemory class.
openshot::ClipBase::operator<=
bool operator<=(ClipBase &a)
Definition: ClipBase.h:60
openshot::ClipBase::end
float end
The position in seconds to end playing (used to trim the ending of a clip)
Definition: ClipBase.h:38
openshot::ClipBase::Start
void Start(float value)
Set start position (in seconds) of clip (trim start of video)
Definition: ClipBase.cpp:42
Frame.h
Header file for Frame class.
openshot::ClipBase::start
float start
The position in seconds to start playing (used to trim the beginning of a clip)
Definition: ClipBase.h:37
openshot::ClipBase::id
std::string id
ID Property for all derived Clip and Effect classes.
Definition: ClipBase.h:34
openshot::ClipBase::layer
int layer
The layer this clip is on. Lower clips are covered up by higher clips.
Definition: ClipBase.h:36
openshot::ClipBase::PropertiesJSON
virtual std::string PropertiesJSON(int64_t requested_frame) const =0
openshot::ClipBase::Id
void Id(std::string value)
Definition: ClipBase.h:93
openshot::TimelineBase
This class represents a timeline (used for building generic timeline implementations)
Definition: TimelineBase.h:41
openshot::ClipBase::previous_properties
std::string previous_properties
This string contains the previous JSON properties.
Definition: ClipBase.h:39
openshot::ClipBase::GetFrame
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...
Json.h
Header file for JSON class.
openshot::ClipBase
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:32
openshot::ClipBase::Layer
void Layer(int value)
Set layer of clip on timeline (lower number is covered by higher numbers)
Definition: ClipBase.cpp:31
openshot::ClipBase::operator>=
bool operator>=(ClipBase &a)
Definition: ClipBase.h:62