OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
ClipBase.cpp
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#include "ClipBase.h"
14#include "Timeline.h"
15
16using namespace openshot;
17
18// Set position on timeline (in seconds)
19void ClipBase::Position(float value) {
20
21 position = value;
22
23 if (ParentTimeline()) {
24 // Resort timeline items (internal clips/effects arrays)
25 Timeline *parentTimeline = (Timeline *) ParentTimeline();
26 parentTimeline->SortTimeline();
27 }
28}
29
30// Set layer of clip on timeline (lower number is covered by higher numbers)
31void ClipBase::Layer(int value) {
32 layer = value;
33
34 if (ParentTimeline()) {
35 // Resort timeline items (internal clips/effects arrays)
36 Timeline *parentTimeline = (Timeline *) ParentTimeline();
37 parentTimeline->SortTimeline();
38 }
39}
40
41// Set start position (in seconds) of clip (trim start of video)
42void ClipBase::Start(float value) {
43 start = value;
44
45 if (ParentTimeline()) {
46 // Resort timeline items (internal clips/effects arrays)
47 Timeline *parentTimeline = (Timeline *) ParentTimeline();
48 parentTimeline->SortTimeline();
49 }
50}
51
52// Set end position (in seconds) of clip (trim end of video)
53void ClipBase::End(float value) {
54 end = value;
55
56 if (ParentTimeline()) {
57 // Resort timeline items (internal clips/effects arrays)
58 Timeline *parentTimeline = (Timeline *) ParentTimeline();
59 parentTimeline->SortTimeline();
60 }
61}
62
63// Generate Json::Value for this object
64Json::Value ClipBase::JsonValue() const {
65
66 // Create root json object
67 Json::Value root;
68 root["id"] = Id();
69 root["position"] = Position();
70 root["layer"] = Layer();
71 root["start"] = Start();
72 root["end"] = End();
73 root["duration"] = Duration();
74
75 // return JsonValue
76 return root;
77}
78
79// Load Json::Value into this object
80void ClipBase::SetJsonValue(const Json::Value root) {
81
82 // Set data from Json (if key is found)
83 if (!root["id"].isNull())
84 Id(root["id"].asString());
85 if (!root["position"].isNull())
86 Position(root["position"].asDouble());
87 if (!root["layer"].isNull())
88 Layer(root["layer"].asInt());
89 if (!root["start"].isNull())
90 Start(root["start"].asDouble());
91 if (!root["end"].isNull())
92 End(root["end"].asDouble());
93}
94
95// Generate JSON for a property
96Json::Value ClipBase::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 {
97
98 // Requested Point
99 const Point requested_point(requested_frame, requested_frame);
100
101 // Create JSON Object
102 Json::Value prop = Json::Value(Json::objectValue);
103 prop["name"] = name;
104 prop["value"] = value;
105 prop["memo"] = memo;
106 prop["type"] = type;
107 prop["min"] = min_value;
108 prop["max"] = max_value;
109 if (keyframe) {
110 prop["keyframe"] = keyframe->Contains(requested_point);
111 prop["points"] = int(keyframe->GetCount());
112 Point closest_point = keyframe->GetClosestPoint(requested_point);
113 prop["interpolation"] = closest_point.interpolation;
114 prop["closest_point_x"] = closest_point.co.X;
115 prop["previous_point_x"] = keyframe->GetPreviousPoint(closest_point).co.X;
116 }
117 else {
118 prop["keyframe"] = false;
119 prop["points"] = 0;
120 prop["interpolation"] = CONSTANT;
121 prop["closest_point_x"] = -1;
122 prop["previous_point_x"] = -1;
123 }
124
125 prop["readonly"] = readonly;
126 prop["choices"] = Json::Value(Json::arrayValue);
127
128 // return JsonValue
129 return prop;
130}
131
132Json::Value ClipBase::add_property_choice_json(std::string name, int value, int selected_value) const {
133
134 // Create choice
135 Json::Value new_choice = Json::Value(Json::objectValue);
136 new_choice["name"] = name;
137 new_choice["value"] = value;
138 new_choice["selected"] = (value == selected_value);
139
140 // return JsonValue
141 return new_choice;
142}
Header file for ClipBase class.
Header file for Timeline class.
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
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
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Definition ClipBase.h:87
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition ClipBase.cpp:80
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
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
float end
The position in seconds to end playing (used to trim the ending of a clip)
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:96
double X
The X value of the coordinate (usually representing the frame #)
Definition Coordinate.h:40
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition KeyFrame.h:53
bool Contains(Point p) const
Does this keyframe contain a specific point.
Definition KeyFrame.cpp:184
Point GetPreviousPoint(Point p) const
Get previous point (.
Definition KeyFrame.cpp:226
int64_t GetCount() const
Get the number of points (i.e. # of points)
Definition KeyFrame.cpp:424
Point GetClosestPoint(Point p) const
Get current point (or closest point to the right) from the X coordinate (i.e. the frame number)
Definition KeyFrame.cpp:221
A Point is the basic building block of a key-frame curve.
Definition Point.h:64
Coordinate co
This is the primary coordinate.
Definition Point.h:66
InterpolationType interpolation
This is the interpolation mode.
Definition Point.h:69
This class represents a timeline.
Definition Timeline.h:148
void SortTimeline()
Sort all clips and effects on timeline - which affects the internal order of clips and effects arrays...
Definition Timeline.h:354
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
@ CONSTANT
Constant curves jump from their previous position to a new one (with no interpolation).
Definition Point.h:31