diff --git a/src/Clip.cpp b/src/Clip.cpp index b6c968a27..1f52fd9ba 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -248,19 +248,21 @@ Clip::~Clip() void Clip::AttachToTracker(std::string tracked_id) { // Search for the tracked object on the timeline - Timeline *parentTimeline = (Timeline *) ParentTimeline(); + Timeline* parentTimeline = (Timeline *) ParentTimeline(); - // Create a smart pointer to the tracked object from the timeline - std::shared_ptr trackedObject = parentTimeline->GetTrackedObject(tracked_id); - - // Check for valid tracked object - if (trackedObject){ - SetAttachedObject(trackedObject); - return; - } - else{ - return; + // Check if the clip has a parent timeline + if (parentTimeline){ + + // Create a smart pointer to the tracked object from the timeline + std::shared_ptr trackedObject = parentTimeline->GetTrackedObject(tracked_id); + + // Check for valid tracked object + if (trackedObject){ + SetAttachedObject(trackedObject); + } + } + return; } // Set the pointer to the trackedObject this clip is attached to @@ -1138,17 +1140,22 @@ void Clip::AddEffect(EffectBase* effect) Timeline* parentTimeline = (Timeline *) ParentTimeline(); - // Downcast effect as Tracker - Tracker* tracker = (Tracker *) effect; + // Check if this clip has a parent timeline + if (parentTimeline){ - // Get tracked data from the Tracker effect - std::shared_ptr trackedData = tracker->trackedData; + // Downcast effect as Tracker + Tracker* tracker = (Tracker *) effect; - // Set tracked data parent clip to this - trackedData->ParentClip(this); + // Get tracked data from the Tracker effect + std::shared_ptr trackedData = tracker->trackedData; - // Add tracked data to the timeline - parentTimeline->AddTrackedObject(trackedData); + // Set tracked data parent clip to this + trackedData->ParentClip(this); + + // Add tracked data to the timeline + parentTimeline->AddTrackedObject(trackedData); + + } } // Clear cache diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 8cbfeb843..de69bcce8 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -1071,6 +1071,13 @@ void Timeline::SetJsonValue(const Json::Value root) { // Create Clip Clip *c = new Clip(); + // When a clip is attached to an object, it searches for the object + // on it's parent timeline. Setting the parent timeline of the clip here + // allows attaching it to an object when exporting the project (because) + // the exporter script initializes the clip and it's effects + // before setting it's parent timeline. + c->ParentTimeline(this); + // Load Json into Clip c->SetJsonValue(existing_clip); diff --git a/src/TrackedObjectBBox.cpp b/src/TrackedObjectBBox.cpp index 119ec0839..b926d4487 100644 --- a/src/TrackedObjectBBox.cpp +++ b/src/TrackedObjectBBox.cpp @@ -475,7 +475,7 @@ std::map TrackedObjectBBox::GetParentClipProperties(int64_t // Calculate parentClip's frame number long parentClip_start_position = round( parentClip->Position() * parentClip->info.fps.ToDouble() ) + 1; long parentClip_start_frame = ( parentClip->Start() * parentClip->info.fps.ToDouble() ) + 1; - float parentClip_frame_number = frame_number - parentClip_start_position + parentClip_start_frame; + float parentClip_frame_number = round(frame_number - parentClip_start_position) + parentClip_start_frame; // Get parentClip's Keyframes float parentClip_location_x = parentClip->location_x.GetValue(parentClip_frame_number); diff --git a/src/TrackedObjectBBox.h b/src/TrackedObjectBBox.h index 3e05529de..d7903b734 100644 --- a/src/TrackedObjectBBox.h +++ b/src/TrackedObjectBBox.h @@ -214,10 +214,10 @@ namespace openshot void clear(); /// Get and Set JSON methods - std::string Json() const; ///< Generate JSON string of this object - Json::Value JsonValue() const; ///< Generate Json::Value for this object - void SetJson(const std::string value); ///< Load JSON string into this object - void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object + std::string Json() const override; ///< Generate JSON string of this object + Json::Value JsonValue() const override; ///< Generate Json::Value for this object + void SetJson(const std::string value) override; ///< Load JSON string into this object + void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object /// Get all properties for a specific frame (perfect for a UI to display the current state /// of all properties at any time)