timeline gets updated when tracks are added and removed

This commit is contained in:
itsmattkc
2019-08-18 18:29:35 +10:00
parent c68e879d47
commit 9ccf2610c8
5 changed files with 93 additions and 19 deletions
+68 -19
View File
@@ -118,25 +118,53 @@ TrackOutput *TimelineOutput::attached_track()
return ValueToPtr<TrackOutput>(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<TrackOutput>(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<TrackOutput*>(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<TrackOutput>(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<TrackOutput*>(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<TrackOutput>(edge->output()->get_value(0));
DetachTrack(added_track);
}
}
+14
View File
@@ -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
+7
View File
@@ -106,6 +106,13 @@ void TrackOutput::GenerateBlockWidgets()
}
}
void TrackOutput::DestroyBlockWidgets()
{
foreach (Block* block, block_cache_) {
emit BlockRemoved(block);
}
}
TrackOutput *TrackOutput::next_track()
{
return ValueToPtr<TrackOutput>(track_input_->get_value(0));
+2
View File
@@ -48,6 +48,8 @@ public:
void GenerateBlockWidgets();
void DestroyBlockWidgets();
TrackOutput* next_track();
NodeInput* track_input();
+2
View File
@@ -47,6 +47,8 @@ public:
void RemoveBlock(Block* block);
void RemoveBlocksOfTrack(Block* block);
void SetScale(const double& scale);
void SetTimebase(const rational& timebase);