OpenShot Library | libopenshot 1.1.1
Loading...
Searching...
No Matches
ClipBase.h
Go to the documentation of this file.
1
8
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 "KeyFrame.h"
20#include "IdGenerator.h"
21#include "Json.h"
22#include "TimelineBase.h"
23
24
25namespace 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 void SetBaseJsonValue(const Json::Value& root);
44
46 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;
47
49 Json::Value add_property_choice_json(std::string name, int value, int selected_value) const;
50
51 public:
54 id(IdGenerator::Generate()),
55 position(0.0),
56 layer(0),
57 start(0.0),
58 end(0.0),
60 timeline(nullptr) {}
61
62 // Compare a clip using the Position() property
63 bool operator< ( ClipBase& a) { return (Position() < a.Position()); }
64 bool operator<= ( ClipBase& a) { return (Position() <= a.Position()); }
65 bool operator> ( ClipBase& a) { return (Position() > a.Position()); }
66 bool operator>= ( ClipBase& a) { return (Position() >= a.Position()); }
67
74 virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) = 0;
75
85 virtual std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) = 0;
86
87 // Get basic properties
88 std::string Id() const { return id; }
89 float Position() const { return position; }
90 int Layer() const { return layer; }
91 float Start() const { return start; }
92 virtual float End() const { return end; }
93 float Duration() const { return end - start; }
95
96 // Set basic properties
97 void Id(std::string value) { id = value; }
98 void Position(float value);
99 void Layer(int value);
100 void Start(float value);
101 virtual void End(float value);
102 virtual void ParentTimeline(openshot::TimelineBase* new_timeline) { timeline = new_timeline; }
103
104 // Get and Set JSON methods
105 virtual std::string Json() const = 0;
106 virtual void SetJson(const std::string value) = 0;
107 virtual Json::Value JsonValue() const = 0;
108 virtual void SetJsonValue(const Json::Value root) = 0;
109
112 virtual std::string PropertiesJSON(int64_t requested_frame) const = 0;
113
114 virtual ~ClipBase() = default;
115 };
116
117
118}
119
120#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 Timeline class.
void SetBaseJsonValue(const Json::Value &root)
Load common clip fields without copying derived animation data.
Definition ClipBase.cpp:84
float Start() const
Get start position (in seconds) of clip (trim start of video).
Definition ClipBase.h:91
float start
The position in seconds to start playing (used to trim the beginning of a clip).
Definition ClipBase.h:37
float Duration() const
Get the length of this clip (in seconds).
Definition ClipBase.h:93
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...
virtual float End() const
Get end position (in seconds) of clip (trim end of video).
Definition ClipBase.h:92
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:66
std::string Id() const
Get the Id of this clip object.
Definition ClipBase.h:88
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:136
void Id(std::string value)
Definition ClipBase.h:97
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...
bool operator<=(ClipBase &a)
Definition ClipBase.h:64
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers).
Definition ClipBase.h:90
ClipBase()
Constructor for the base clip.
Definition ClipBase.h:53
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:40
int layer
The layer this clip is on. Lower clips are covered up by higher clips.
Definition ClipBase.h:36
float Position() const
Get position on timeline (in seconds).
Definition ClipBase.h:89
virtual openshot::TimelineBase * ParentTimeline()
Get the associated Timeline pointer (if any).
Definition ClipBase.h:94
bool operator>(ClipBase &a)
Definition ClipBase.h:65
std::string id
ID Property for all derived Clip and Effect classes.
Definition ClipBase.h:34
virtual void ParentTimeline(openshot::TimelineBase *new_timeline)
Set associated Timeline pointer.
Definition ClipBase.h:102
float position
The position on the timeline where this clip should start playing.
Definition ClipBase.h:35
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:38
bool operator<(ClipBase &a)
Definition ClipBase.h:63
virtual ~ClipBase()=default
std::string previous_properties
This string contains the previous JSON properties.
Definition ClipBase.h:39
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:100
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).
This namespace is the default namespace for all code in the openshot library.