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; }
91  virtual openshot::TimelineBase* ParentTimeline() { return timeline; }
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
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:41
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:62
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:36
openshot::ClipBase::ClipBase
ClipBase()
Constructor for the base clip.
Definition: ClipBase.h:51
openshot::ClipBase::operator<
bool operator<(ClipBase &a)
Definition: ClipBase.h:60
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:61
openshot::ClipBase::end
float end
The position in seconds to end playing (used to trim the ending of a clip)
Definition: ClipBase.h:39
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:38
openshot::ClipBase::id
std::string id
ID Property for all derived Clip and Effect classes.
Definition: ClipBase.h:35
openshot::ClipBase::layer
int layer
The layer this clip is on. Lower clips are covered up by higher clips.
Definition: ClipBase.h:37
openshot::ClipBase::PropertiesJSON
virtual std::string PropertiesJSON(int64_t requested_frame) const =0
openshot::ClipBase::Id
void Id(std::string value)
Definition: ClipBase.h:94
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:40
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:33
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:63