diff --git a/app/node/output/timeline/timeline.cpp b/app/node/output/timeline/timeline.cpp index 1eb1aaf24..1cf8a3a53 100644 --- a/app/node/output/timeline/timeline.cpp +++ b/app/node/output/timeline/timeline.cpp @@ -118,25 +118,53 @@ TrackOutput *TimelineOutput::attached_track() return ValueToPtr(track_input_->get_value(0)); } +void TimelineOutput::AttachTrack(TrackOutput *track) +{ + TrackOutput* current_track = track; + + // Traverse through Tracks caching and connecting them + while (current_track != nullptr) { + connect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr))); + connect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr))); + connect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*))); + connect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*))); + + track_cache_.append(current_track); + + // This function must be called after the track is added to track_cache_, since it uses track_cache_ to determine + // the track's index + current_track->GenerateBlockWidgets(); + + current_track = current_track->next_track(); + } +} + +void TimelineOutput::DetachTrack(TrackOutput *track) +{ + TrackOutput* current_track = track; + + // Traverse through Tracks uncaching and disconnecting them + while (current_track != nullptr) { + current_track->DestroyBlockWidgets(); + + disconnect(current_track, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackEdgeAdded(NodeEdgePtr))); + disconnect(current_track, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackEdgeRemoved(NodeEdgePtr))); + disconnect(current_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*))); + disconnect(current_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*))); + + track_cache_.removeAll(current_track); + + current_track = current_track->next_track(); + } +} + void TimelineOutput::TrackConnectionAdded(NodeEdgePtr edge) { if (edge->input() != track_input()) { return; } - TrackOutput* track = attached_track(); - - // Traverse through Tracks caching and connecting them - while (track != nullptr) { - track_cache_.append(track); - - connect(track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*))); - connect(track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*))); - - track->GenerateBlockWidgets(); - - track = track->next_track(); - } + AttachTrack(attached_track()); // FIXME: TEST CODE ONLY if (attached_timeline_ != nullptr) { @@ -151,12 +179,7 @@ void TimelineOutput::TrackConnectionRemoved(NodeEdgePtr edge) return; } - foreach (TrackOutput* track, track_cache_) { - disconnect(track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*))); - disconnect(track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*))); - } - - track_cache_.clear(); + DetachTrack(ValueToPtr(edge->output()->get_value(0))); if (attached_timeline_ != nullptr) { attached_timeline_->Clear(); @@ -178,3 +201,29 @@ void TimelineOutput::TrackRemovedBlock(Block *block) attached_timeline_->view()->RemoveBlock(block); } } + +void TimelineOutput::TrackEdgeAdded(NodeEdgePtr edge) +{ + // Assume this signal was sent from a TrackOutput + TrackOutput* track = static_cast(sender()); + + // If this edge pertains to the track's track input, all the tracks just added need attaching + if (edge->input() == track->track_input()) { + TrackOutput* added_track = ValueToPtr(edge->output()->get_value(0)); + + AttachTrack(added_track); + } +} + +void TimelineOutput::TrackEdgeRemoved(NodeEdgePtr edge) +{ + // Assume this signal was sent from a TrackOutput + TrackOutput* track = static_cast(sender()); + + // If this edge pertains to the track's track input, all the tracks just added need attaching + if (edge->input() == track->track_input()) { + TrackOutput* added_track = ValueToPtr(edge->output()->get_value(0)); + + DetachTrack(added_track); + } +} diff --git a/app/node/output/timeline/timeline.h b/app/node/output/timeline/timeline.h index 38ee873ab..8d54554b4 100644 --- a/app/node/output/timeline/timeline.h +++ b/app/node/output/timeline/timeline.h @@ -53,6 +53,10 @@ private: TrackOutput* attached_track(); + void AttachTrack(TrackOutput *track); + + void DetachTrack(TrackOutput* track); + TimelinePanel* attached_timeline_; NodeInput* track_input_; @@ -83,6 +87,16 @@ private slots: */ void TrackRemovedBlock(Block* block); + /** + * @brief Slot for when an attached Track has an edge added + */ + void TrackEdgeAdded(NodeEdgePtr edge); + + /** + * @brief Slot for when an attached Track has an edge added + */ + void TrackEdgeRemoved(NodeEdgePtr edge); + }; #endif // TIMELINEOUTPUT_H diff --git a/app/node/output/track/track.cpp b/app/node/output/track/track.cpp index fef20c61b..6833f9f90 100644 --- a/app/node/output/track/track.cpp +++ b/app/node/output/track/track.cpp @@ -106,6 +106,13 @@ void TrackOutput::GenerateBlockWidgets() } } +void TrackOutput::DestroyBlockWidgets() +{ + foreach (Block* block, block_cache_) { + emit BlockRemoved(block); + } +} + TrackOutput *TrackOutput::next_track() { return ValueToPtr(track_input_->get_value(0)); diff --git a/app/node/output/track/track.h b/app/node/output/track/track.h index fa30489c7..ab802cb9c 100644 --- a/app/node/output/track/track.h +++ b/app/node/output/track/track.h @@ -48,6 +48,8 @@ public: void GenerateBlockWidgets(); + void DestroyBlockWidgets(); + TrackOutput* next_track(); NodeInput* track_input(); diff --git a/app/widget/timelineview/timelineview.h b/app/widget/timelineview/timelineview.h index 3ad8ec9df..a4f563f11 100644 --- a/app/widget/timelineview/timelineview.h +++ b/app/widget/timelineview/timelineview.h @@ -47,6 +47,8 @@ public: void RemoveBlock(Block* block); + void RemoveBlocksOfTrack(Block* block); + void SetScale(const double& scale); void SetTimebase(const rational& timebase);