Skip to content

Commit fd88a60

Browse files
committed
Updated variable names
Updated "attached_id" to "parentObjectId", "attachedObject" to "parentTrackedObject", and "attachedClip" to "parentClipObject"
1 parent 3f11361 commit fd88a60

File tree

2 files changed

+137
-102
lines changed

2 files changed

+137
-102
lines changed

src/Clip.cpp

Lines changed: 127 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void Clip::init_settings()
5858
mixing = VOLUME_MIX_NONE;
5959
waveform = false;
6060
previous_properties = "";
61-
attached_id = "";
61+
parentObjectId = "";
6262

6363
// Init scale curves
6464
scale_x = Keyframe(1.0);
@@ -101,8 +101,8 @@ void Clip::init_settings()
101101
has_video = Keyframe(-1.0);
102102

103103
// Initialize the attached object and attached clip as null pointers
104-
attachedObject = nullptr;
105-
attachedClip = NULL;
104+
parentTrackedObject = nullptr;
105+
parentClipObject = NULL;
106106

107107
// Init reader info struct and cache size
108108
init_reader_settings();
@@ -272,13 +272,13 @@ void Clip::AttachToObject(std::string object_id)
272272

273273
// Set the pointer to the trackedObject this clip is attached to
274274
void Clip::SetAttachedObject(std::shared_ptr<openshot::TrackedObjectBase> trackedObject){
275-
attachedObject = trackedObject;
275+
parentTrackedObject = trackedObject;
276276
return;
277277
}
278278

279279
// Set the pointer to the clip this clip is attached to
280280
void Clip::SetAttachedClip(Clip* clipObject){
281-
attachedClip = clipObject;
281+
parentClipObject = clipObject;
282282
return;
283283
}
284284

@@ -800,10 +800,10 @@ std::string Clip::PropertiesJSON(int64_t requested_frame) const {
800800
root["display"] = add_property_json("Frame Number", display, "int", "", NULL, 0, 3, false, requested_frame);
801801
root["mixing"] = add_property_json("Volume Mixing", mixing, "int", "", NULL, 0, 2, false, requested_frame);
802802
root["waveform"] = add_property_json("Waveform", waveform, "int", "", NULL, 0, 1, false, requested_frame);
803-
if (!attached_id.empty()) {
804-
root["attached_id"] = add_property_json("Attached ID", 0.0, "string", attached_id, NULL, -1, -1, false, requested_frame);
803+
if (!parentObjectId.empty()) {
804+
root["parentObjectId"] = add_property_json("Parent Object ID", 0.0, "string", parentObjectId, NULL, -1, -1, false, requested_frame);
805805
} else {
806-
root["attached_id"] = add_property_json("Attached ID", 0.0, "string", "None", NULL, -1, -1, false, requested_frame);
806+
root["parentObjectId"] = add_property_json("Parent Object ID", 0.0, "string", "None", NULL, -1, -1, false, requested_frame);
807807
}
808808
// Add gravity choices (dropdown style)
809809
root["gravity"]["choices"].append(add_property_choice_json("Top Left", GRAVITY_TOP_LEFT, gravity));
@@ -837,49 +837,76 @@ std::string Clip::PropertiesJSON(int64_t requested_frame) const {
837837
root["waveform"]["choices"].append(add_property_choice_json("Yes", true, waveform));
838838
root["waveform"]["choices"].append(add_property_choice_json("No", false, waveform));
839839

840-
if (attachedObject){
841-
840+
// Add the parentTrackedObject's properties
841+
if (parentTrackedObject)
842+
{
842843
// Convert Clip's frame position to Timeline's frame position
843844
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
844845
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
845846
double timeline_frame_number = requested_frame + clip_start_position - clip_start_frame;
846847

847848
// Get attached object's parent clip properties
848-
std::map< std::string, float > attached_clip_properties = attachedObject->GetParentClipProperties(timeline_frame_number);
849-
double attached_frame_number = attached_clip_properties["frame_number"];
850-
849+
std::map< std::string, float > trackedObjectParentClipProperties = parentTrackedObject->GetParentClipProperties(timeline_frame_number);
850+
double parentObject_frame_number = trackedObjectParentClipProperties["frame_number"];
851851
// Get attached object properties
852-
std::map< std::string, float > attached_properties = attachedObject->GetBoxValues(attached_frame_number);
853-
854-
// Compose attachedObject's properties with it's parent clip's properties
855-
float attached_location_x = attached_properties["cx"] - 0.5 + attached_clip_properties["cx"];
856-
float attached_location_y = attached_properties["cy"] - 0.5 + attached_clip_properties["cy"];
857-
float attached_scale_x = attached_properties["w"]*attached_properties["sx"];
858-
float attached_scale_y = attached_properties["h"]*attached_properties["sy"];
859-
float attached_rotation = attached_properties["r"] + attached_clip_properties["r"];
860-
861-
// Set JSON properties with composed attached object's properties
862-
root["location_x"] = add_property_json("Location X", attached_location_x, "float", "", &location_x, -1.0, 1.0, false, requested_frame);
863-
root["location_y"] = add_property_json("Location Y", attached_location_y, "float", "", &location_y, -1.0, 1.0, false, requested_frame);
864-
root["scale_x"] = add_property_json("Scale X", attached_scale_x, "float", "", &scale_x, 0.0, 1.0, false, requested_frame);
865-
root["scale_y"] = add_property_json("Scale Y", attached_scale_y, "float", "", &scale_y, 0.0, 1.0, false, requested_frame);
866-
root["rotation"] = add_property_json("Rotation", attached_rotation, "float", "", &rotation, -360, 360, false, requested_frame);
867-
868-
} else {
852+
std::map< std::string, float > trackedObjectProperties = parentTrackedObject->GetBoxValues(parentObject_frame_number);
869853

870-
// Set JSON properties with clip's properties
854+
// Correct the parent Tracked Object properties by the clip's reference system
855+
float parentObject_location_x = trackedObjectProperties["cx"] - 0.5 + trackedObjectParentClipProperties["cx"];
856+
float parentObject_location_y = trackedObjectProperties["cy"] - 0.5 + trackedObjectParentClipProperties["cy"];
857+
float parentObject_scale_x = trackedObjectProperties["w"]*trackedObjectProperties["sx"];
858+
float parentObject_scale_y = trackedObjectProperties["h"]*trackedObjectProperties["sy"];
859+
float parentObject_rotation = trackedObjectProperties["r"] + trackedObjectParentClipProperties["r"];
860+
861+
// Add the parent Tracked Object properties to JSON
862+
root["location_x"] = add_property_json("Location X", parentObject_location_x, "float", "", &location_x, -1.0, 1.0, false, requested_frame);
863+
root["location_y"] = add_property_json("Location Y", parentObject_location_y, "float", "", &location_y, -1.0, 1.0, false, requested_frame);
864+
root["scale_x"] = add_property_json("Scale X", parentObject_scale_x, "float", "", &scale_x, 0.0, 1.0, false, requested_frame);
865+
root["scale_y"] = add_property_json("Scale Y", parentObject_scale_y, "float", "", &scale_y, 0.0, 1.0, false, requested_frame);
866+
root["rotation"] = add_property_json("Rotation", parentObject_rotation, "float", "", &rotation, -360, 360, false, requested_frame);
867+
root["shear_x"] = add_property_json("Shear X", shear_x.GetValue(requested_frame), "float", "", &shear_x, -1.0, 1.0, false, requested_frame);
868+
root["shear_y"] = add_property_json("Shear Y", shear_y.GetValue(requested_frame), "float", "", &shear_y, -1.0, 1.0, false, requested_frame);
869+
}
870+
// Add the parentClipObject's properties
871+
else if (parentClipObject)
872+
{
873+
// Convert Clip's frame position to Timeline's frame position
874+
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
875+
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
876+
double timeline_frame_number = requested_frame + clip_start_position - clip_start_frame;
877+
878+
// Correct the parent Clip Object properties by the clip's reference system
879+
float parentObject_location_x = parentClipObject->location_x.GetValue(timeline_frame_number);
880+
float parentObject_location_y = parentClipObject->location_y.GetValue(timeline_frame_number);
881+
float parentObject_scale_x = parentClipObject->scale_x.GetValue(timeline_frame_number);
882+
float parentObject_scale_y = parentClipObject->scale_y.GetValue(timeline_frame_number);
883+
float parentObject_shear_x = parentClipObject->shear_x.GetValue(timeline_frame_number);
884+
float parentObject_shear_y = parentClipObject->shear_y.GetValue(timeline_frame_number);
885+
float parentObject_rotation = parentClipObject->rotation.GetValue(timeline_frame_number);
886+
887+
// Add the parent Clip Object properties to JSON
888+
root["location_x"] = add_property_json("Location X", parentObject_location_x, "float", "", &location_x, -1.0, 1.0, false, requested_frame);
889+
root["location_y"] = add_property_json("Location Y", parentObject_location_y, "float", "", &location_y, -1.0, 1.0, false, requested_frame);
890+
root["scale_x"] = add_property_json("Scale X", parentObject_scale_x, "float", "", &scale_x, 0.0, 1.0, false, requested_frame);
891+
root["scale_y"] = add_property_json("Scale Y", parentObject_scale_y, "float", "", &scale_y, 0.0, 1.0, false, requested_frame);
892+
root["rotation"] = add_property_json("Rotation", parentObject_rotation, "float", "", &rotation, -360, 360, false, requested_frame);
893+
root["shear_x"] = add_property_json("Shear X", parentObject_shear_x, "float", "", &shear_x, -1.0, 1.0, false, requested_frame);
894+
root["shear_y"] = add_property_json("Shear Y", parentObject_shear_y, "float", "", &shear_y, -1.0, 1.0, false, requested_frame);
895+
}
896+
else
897+
{
898+
// Add this own clip's properties to JSON
871899
root["location_x"] = add_property_json("Location X", location_x.GetValue(requested_frame), "float", "", &location_x, -1.0, 1.0, false, requested_frame);
872900
root["location_y"] = add_property_json("Location Y", location_y.GetValue(requested_frame), "float", "", &location_y, -1.0, 1.0, false, requested_frame);
873901
root["scale_x"] = add_property_json("Scale X", scale_x.GetValue(requested_frame), "float", "", &scale_x, 0.0, 1.0, false, requested_frame);
874902
root["scale_y"] = add_property_json("Scale Y", scale_y.GetValue(requested_frame), "float", "", &scale_y, 0.0, 1.0, false, requested_frame);
875903
root["rotation"] = add_property_json("Rotation", rotation.GetValue(requested_frame), "float", "", &rotation, -360, 360, false, requested_frame);
876-
904+
root["shear_x"] = add_property_json("Shear X", shear_x.GetValue(requested_frame), "float", "", &shear_x, -1.0, 1.0, false, requested_frame);
905+
root["shear_y"] = add_property_json("Shear Y", shear_y.GetValue(requested_frame), "float", "", &shear_y, -1.0, 1.0, false, requested_frame);
877906
}
878907

879908
// Keyframes
880909
root["alpha"] = add_property_json("Alpha", alpha.GetValue(requested_frame), "float", "", &alpha, 0.0, 1.0, false, requested_frame);
881-
root["shear_x"] = add_property_json("Shear X", shear_x.GetValue(requested_frame), "float", "", &shear_x, -1.0, 1.0, false, requested_frame);
882-
root["shear_y"] = add_property_json("Shear Y", shear_y.GetValue(requested_frame), "float", "", &shear_y, -1.0, 1.0, false, requested_frame);
883910
root["origin_x"] = add_property_json("Origin X", origin_x.GetValue(requested_frame), "float", "", &origin_x, 0.0, 1.0, false, requested_frame);
884911
root["origin_y"] = add_property_json("Origin Y", origin_y.GetValue(requested_frame), "float", "", &origin_y, 0.0, 1.0, false, requested_frame);
885912
root["volume"] = add_property_json("Volume", volume.GetValue(requested_frame), "float", "", &volume, 0.0, 1.0, false, requested_frame);
@@ -912,7 +939,7 @@ Json::Value Clip::JsonValue() const {
912939

913940
// Create root json object
914941
Json::Value root = ClipBase::JsonValue(); // get parent properties
915-
root["attached_id"] = attached_id;
942+
root["parentObjectId"] = parentObjectId;
916943
root["gravity"] = gravity;
917944
root["scale"] = scale;
918945
root["anchor"] = anchor;
@@ -990,13 +1017,13 @@ void Clip::SetJsonValue(const Json::Value root) {
9901017
cache.Clear();
9911018

9921019
// Set data from Json (if key is found)
993-
if (!root["attached_id"].isNull()){
994-
attached_id = root["attached_id"].asString();
995-
if (attached_id.size() > 0 && attached_id != "None"){
996-
AttachToObject(attached_id);
1020+
if (!root["parentObjectId"].isNull()){
1021+
parentObjectId = root["parentObjectId"].asString();
1022+
if (parentObjectId.size() > 0 && parentObjectId != "None"){
1023+
AttachToObject(parentObjectId);
9971024
} else{
998-
attachedObject = nullptr;
999-
attachedClip = NULL;
1025+
parentTrackedObject = nullptr;
1026+
parentClipObject = NULL;
10001027
}
10011028
}
10021029
if (!root["gravity"].isNull())
@@ -1288,7 +1315,7 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
12881315
QSize source_size = source_image->size();
12891316

12901317
// Apply stretch scale to correctly fit the bounding-box
1291-
if (attachedObject){
1318+
if (parentTrackedObject){
12921319
scale = SCALE_STRETCH;
12931320
}
12941321

@@ -1329,63 +1356,71 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
13291356
}
13301357
}
13311358

1332-
// Initialize attached object's properties values
1333-
float attached_location_x = 0.0;
1334-
float attached_location_y = 0.0;
1335-
float attached_scale_x = 1.0;
1336-
float attached_scale_y = 1.0;
1337-
float attached_rotation = 0.0;
1359+
// Initialize parent object's properties (Clip or Tracked Object)
1360+
float parentObject_location_x = 0.0;
1361+
float parentObject_location_y = 0.0;
1362+
float parentObject_scale_x = 1.0;
1363+
float parentObject_scale_y = 1.0;
1364+
float parentObject_shear_x = 0.0;
1365+
float parentObject_shear_y = 0.0;
1366+
float parentObject_rotation = 0.0;
13381367

1339-
if (attachedClip){
1368+
// Get the parentClipObject properties
1369+
if (parentClipObject){
13401370

13411371
// Convert Clip's frame position to Timeline's frame position
13421372
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
13431373
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
13441374
double timeline_frame_number = frame->number + clip_start_position - clip_start_frame;
13451375

1346-
attached_location_x = attachedClip->location_x.GetValue(timeline_frame_number);
1347-
attached_location_y = attachedClip->location_y.GetValue(timeline_frame_number);
1348-
attached_scale_x = attachedClip->scale_x.GetValue(timeline_frame_number);
1349-
attached_scale_y = attachedClip->scale_y.GetValue(timeline_frame_number);
1350-
attached_rotation = attachedClip->rotation.GetValue(timeline_frame_number);
1376+
// Get parent object's properties (Clip)
1377+
parentObject_location_x = parentClipObject->location_x.GetValue(timeline_frame_number);
1378+
parentObject_location_y = parentClipObject->location_y.GetValue(timeline_frame_number);
1379+
parentObject_scale_x = parentClipObject->scale_x.GetValue(timeline_frame_number);
1380+
parentObject_scale_y = parentClipObject->scale_y.GetValue(timeline_frame_number);
1381+
parentObject_shear_x = parentClipObject->shear_x.GetValue(timeline_frame_number);
1382+
parentObject_shear_y = parentClipObject->shear_y.GetValue(timeline_frame_number);
1383+
parentObject_rotation = parentClipObject->rotation.GetValue(timeline_frame_number);
13511384
}
13521385

1353-
/* TRANSFORM CLIP TO ATTACHED OBJECT'S POSITION AND DIMENSION */
1354-
if (attachedObject){
1386+
// Get the parentTrackedObject properties
1387+
if (parentTrackedObject){
13551388

13561389
// Convert Clip's frame position to Timeline's frame position
13571390
long clip_start_position = round(Position() * info.fps.ToDouble()) + 1;
13581391
long clip_start_frame = (Start() * info.fps.ToDouble()) + 1;
13591392
double timeline_frame_number = frame->number + clip_start_position - clip_start_frame;
13601393

1361-
// Get attached object's parent clip properties
1362-
std::map< std::string, float > attached_clip_properties = attachedObject->GetParentClipProperties(timeline_frame_number);
1363-
1364-
// Get attachedObject's properties and compose with attachedObject's parent clip properties
1365-
if (!attached_clip_properties.empty()){
1366-
1367-
// Get attachedObject's parent clip frame number
1368-
double attached_frame_number = attached_clip_properties["frame_number"];
1369-
1370-
// Get attachedObject's properties values
1371-
std::map< std::string, float > attached_properties = attachedObject->GetBoxValues(attached_frame_number);
1372-
1373-
attached_location_x = attached_properties["cx"] - 0.5 + attached_clip_properties["cx"];
1374-
attached_location_y = attached_properties["cy"] - 0.5 + attached_clip_properties["cy"];
1375-
attached_scale_x = attached_properties["w"]*attached_properties["sx"];
1376-
attached_scale_y = attached_properties["h"]*attached_properties["sy"];
1377-
attached_rotation = attached_properties["r"] + attached_clip_properties["r"];
1378-
1379-
} else {
1380-
// Get attachedObject's properties values
1381-
std::map< std::string, float > attached_properties = attachedObject->GetBoxValues(timeline_frame_number);
1382-
1383-
attached_location_x = attached_properties["cx"] - 0.5;
1384-
attached_location_y = attached_properties["cy"] - 0.5;
1385-
attached_scale_x = attached_properties["w"]*attached_properties["sx"];
1386-
attached_scale_y = attached_properties["h"]*attached_properties["sy"];
1387-
attached_rotation = attached_properties["r"];
1394+
// Get parentTrackedObject's parent clip's properties
1395+
std::map<std::string, float> trackedObjectParentClipProperties = parentTrackedObject->GetParentClipProperties(timeline_frame_number);
13881396

1397+
// Get the attached object's parent clip's properties
1398+
if (!trackedObjectParentClipProperties.empty())
1399+
{
1400+
// Get parent object's properties (Tracked Object)
1401+
float parentObject_frame_number = trackedObjectParentClipProperties["frame_number"];
1402+
1403+
// Access the parentTrackedObject's properties
1404+
std::map<std::string, float> trackedObjectProperties = parentTrackedObject->GetBoxValues(parentObject_frame_number);
1405+
1406+
// Get the Tracked Object's properties and correct them by the clip's reference system
1407+
parentObject_location_x = trackedObjectProperties["cx"] - 0.5 + trackedObjectParentClipProperties["location_x"];
1408+
parentObject_location_y = trackedObjectProperties["cy"] - 0.5 + trackedObjectParentClipProperties["location_y"];
1409+
parentObject_scale_x = trackedObjectProperties["w"]*trackedObjectProperties["sx"];
1410+
parentObject_scale_y = trackedObjectProperties["h"]*trackedObjectProperties["sy"];
1411+
parentObject_rotation = trackedObjectProperties["r"] + trackedObjectParentClipProperties["rotation"];
1412+
}
1413+
else
1414+
{
1415+
// Access the parentTrackedObject's properties
1416+
std::map<std::string, float> trackedObjectProperties = parentTrackedObject->GetBoxValues(timeline_frame_number);
1417+
1418+
// Get the Tracked Object's properties and correct them by the clip's reference system
1419+
parentObject_location_x = trackedObjectProperties["cx"] - 0.5;
1420+
parentObject_location_y = trackedObjectProperties["cy"] - 0.5;
1421+
parentObject_scale_x = trackedObjectProperties["w"]*trackedObjectProperties["sx"];
1422+
parentObject_scale_y = trackedObjectProperties["h"]*trackedObjectProperties["sy"];
1423+
parentObject_rotation = trackedObjectProperties["r"];
13891424
}
13901425
}
13911426

@@ -1397,10 +1432,10 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
13971432
float sx = scale_x.GetValue(frame->number); // percentage X scale
13981433
float sy = scale_y.GetValue(frame->number); // percentage Y scale
13991434

1400-
// Compose clip's scale to attachedObject's scale
1401-
if(attached_scale_x != 0.0 && attached_scale_y != 0.0){
1402-
sx*= attached_scale_x;
1403-
sy*= attached_scale_y;
1435+
// Change clip's scale to parentObject's scale
1436+
if(parentObject_scale_x != 0.0 && parentObject_scale_y != 0.0){
1437+
sx*= parentObject_scale_x;
1438+
sy*= parentObject_scale_y;
14041439
}
14051440

14061441
float scaled_source_width = source_size.width() * sx;
@@ -1447,11 +1482,11 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, int width, int height)
14471482
QTransform transform;
14481483

14491484
/* LOCATION, ROTATION, AND SCALE */
1450-
float r = rotation.GetValue(frame->number) + attached_rotation; // rotate in degrees
1451-
x += ( width * (location_x.GetValue(frame->number) + attached_location_x) ); // move in percentage of final width
1452-
y += ( height * (location_y.GetValue(frame->number) + attached_location_y) ); // move in percentage of final height
1453-
float shear_x_value = shear_x.GetValue(frame->number);
1454-
float shear_y_value = shear_y.GetValue(frame->number);
1485+
float r = rotation.GetValue(frame->number) + parentObject_rotation; // rotate in degrees
1486+
x += (width * (location_x.GetValue(frame->number) + parentObject_location_x )); // move in percentage of final width
1487+
y += (height * (location_y.GetValue(frame->number) + parentObject_location_y )); // move in percentage of final height
1488+
float shear_x_value = shear_x.GetValue(frame->number) + parentObject_shear_x;
1489+
float shear_y_value = shear_y.GetValue(frame->number) + parentObject_shear_y;
14551490
float origin_x_value = origin_x.GetValue(frame->number);
14561491
float origin_y_value = origin_y.GetValue(frame->number);
14571492

0 commit comments

Comments
 (0)