From 351d4a246e978dbd86f1a80cc07c71b74de2bb6b Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 6 Dec 2019 20:34:19 +1100 Subject: [PATCH] use NodeInputArray for tracks as well These were introduced for the new Block system and make just as much sense for the Track system. They've now been implemented for both. --- app/node/input.cpp | 2 +- app/node/inputarray.cpp | 12 +- app/node/inputarray.h | 4 +- app/node/node.cpp | 4 +- app/node/output/timeline/timeline.cpp | 10 +- app/node/output/timeline/tracklist.cpp | 173 ++++++++++--------------- app/node/output/timeline/tracklist.h | 66 +++++----- app/node/output/track/track.cpp | 38 +----- app/node/output/track/track.h | 9 -- app/project/item/sequence/sequence.cpp | 24 +--- app/project/item/sequence/sequence.h | 2 - 11 files changed, 133 insertions(+), 211 deletions(-) diff --git a/app/node/input.cpp b/app/node/input.cpp index eb9c79ee1..1c7ed085d 100644 --- a/app/node/input.cpp +++ b/app/node/input.cpp @@ -306,7 +306,7 @@ void NodeInput::CopyValues(NodeInput *source, NodeInput *dest, bool include_conn dst_array->SetSize(src_array->GetSize()); for (int i=0;iGetSize();i++) { - CopyValues(src_array->ParamAt(i), dst_array->ParamAt(i), include_connections); + CopyValues(src_array->At(i), dst_array->At(i), include_connections); } } } diff --git a/app/node/inputarray.cpp b/app/node/inputarray.cpp index 5e19e3693..d86a39a4f 100644 --- a/app/node/inputarray.cpp +++ b/app/node/inputarray.cpp @@ -65,11 +65,21 @@ int NodeInputArray::IndexOfSubParameter(NodeInput *input) const return sub_params_.indexOf(input); } -NodeInput *NodeInputArray::ParamAt(int index) const +NodeInput *NodeInputArray::At(int index) const { return sub_params_.at(index); } +NodeInput *NodeInputArray::First() const +{ + return sub_params_.first(); +} + +NodeInput *NodeInputArray::Last() const +{ + return sub_params_.last(); +} + const QVector &NodeInputArray::sub_params() { return sub_params_; diff --git a/app/node/inputarray.h b/app/node/inputarray.h index 756d8e86a..faf29f2de 100644 --- a/app/node/inputarray.h +++ b/app/node/inputarray.h @@ -22,7 +22,9 @@ public: int IndexOfSubParameter(NodeInput* input) const; - NodeInput* ParamAt(int index) const; + NodeInput* First() const; + NodeInput* Last() const; + NodeInput* At(int index) const; const QVector& sub_params(); diff --git a/app/node/node.cpp b/app/node/node.cpp index cec2712fa..4f35c6f52 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -214,7 +214,7 @@ void DuplicateConnectionsBetweenListsInternal(const QList &source, const NodeInputArray* dest_array = static_cast(dest_input); for (int i=0;iGetSize();i++) { - DuplicateConnectionsBetweenListsInternal(source, destination, source_array->ParamAt(i), dest_array->ParamAt(i)); + DuplicateConnectionsBetweenListsInternal(source, destination, source_array->At(i), dest_array->At(i)); } } } @@ -287,7 +287,7 @@ void Node::TraverseInputInternal(QList& list, NodeInput* input, bool trav NodeInputArray* input_array = static_cast(input); for (int i=0;iGetSize();i++) { - TraverseInputInternal(list, input_array->ParamAt(i), traverse); + TraverseInputInternal(list, input_array->At(i), traverse); } } } diff --git a/app/node/output/timeline/timeline.cpp b/app/node/output/timeline/timeline.cpp index 0d3becb43..91e4204c0 100644 --- a/app/node/output/timeline/timeline.cpp +++ b/app/node/output/timeline/timeline.cpp @@ -34,7 +34,7 @@ TimelineOutput::TimelineOutput() for (int i=0;iTracks()); + QVector track_list = list->Tracks(); + + foreach (TrackOutput* track, track_list) { + if (track) { + track_cache_.append(list->Tracks()); + } + } } } diff --git a/app/node/output/timeline/tracklist.cpp b/app/node/output/timeline/tracklist.cpp index b452867e3..30d86754b 100644 --- a/app/node/output/timeline/tracklist.cpp +++ b/app/node/output/timeline/tracklist.cpp @@ -28,67 +28,9 @@ TrackList::TrackList(TimelineOutput* parent, const enum TrackType &type, NodeInp track_input_(track_input), type_(type) { - connect(parent, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackConnectionAdded(NodeEdgePtr))); - connect(parent, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackConnectionRemoved(NodeEdgePtr))); -} - -TrackOutput *TrackList::attached_track() -{ - return dynamic_cast(track_input_->get_connected_node()); -} - -void TrackList::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*))); - connect(current_track, SIGNAL(TrackLengthChanged()), this, SLOT(UpdateTotalLength())); - - current_track->SetIndex(track_cache_.size()); - current_track->set_track_type(type_); - - track_cache_.append(current_track); - emit TrackListChanged(); - - // This function must be called after the track is added to track_cache_, since it uses track_cache_ to determine - // the track's index - emit TrackAdded(current_track); - - current_track = current_track->next_track(); - } - - UpdateTotalLength(); -} - -void TrackList::DetachTrack(TrackOutput *track) -{ - TrackOutput* current_track = track; - - // Traverse through Tracks uncaching and disconnecting them - while (current_track != nullptr) { - emit TrackRemoved(current_track); - - current_track->SetIndex(-1); - current_track->set_track_type(kTrackTypeNone); - - 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*))); - disconnect(current_track, SIGNAL(Refreshed()), this, SLOT(UpdateTotalLength())); - - track_cache_.removeAll(current_track); - emit TrackListChanged(); - - current_track = current_track->next_track(); - } - - UpdateTotalLength(); + connect(track_input, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(TrackConnected(NodeEdgePtr))); + connect(track_input, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(TrackDisconnected(NodeEdgePtr))); + connect(track_input, SIGNAL(SizeChanged(int)), this, SLOT(TrackListSizeChanged(int))); } void TrackList::TrackAddedBlock(Block *block) @@ -101,6 +43,18 @@ void TrackList::TrackRemovedBlock(Block *block) emit BlockRemoved(block); } +void TrackList::TrackListSizeChanged(int size) +{ + int old_size = track_cache_.size(); + + track_cache_.resize(size); + + // Fill new slots with nullptr + for (int i=old_size;i &TrackList::Tracks() { return track_cache_; @@ -125,20 +79,20 @@ const enum TrackType &TrackList::TrackType() return type_; } -void TrackList::AddTrack() +TrackOutput* TrackList::AddTrack() { TrackOutput* track = new TrackOutput(); GetParentGraph()->AddNode(track); track_input_->Append(); - NodeInput* assoc_input = track_input_->ParamAt(track_input_->GetSize() - 1); + NodeInput* assoc_input = track_input_->At(track_input_->GetSize() - 1); // Connect this track directly to this output NodeParam::ConnectEdge(track->output(), assoc_input); // FIXME: Test code only - if (track_input_->GetSize() > 1) { + /*if (track_input_->GetSize() > 1) { if (current_last_track->output()->IsConnected()) { AlphaOverBlend* blend = new AlphaOverBlend(); GetParentGraph()->AddNode(blend); @@ -147,19 +101,13 @@ void TrackList::AddTrack() NodeParam::ConnectEdge(current_last_track->output(), blend->base_input()); NodeParam::ConnectEdge(blend->output(), current_last_track->output()->edges().first()->input()); } - } + }*/ // End test code - if (track_cache_.isEmpty()) { + // Connect this track to the current last track + NodeParam::ConnectEdge(track->output(), assoc_input); - } else { - TrackOutput* current_last_track = track_cache_.last(); - - // Connect this track to the current last track - NodeParam::ConnectEdge(track->output(), current_last_track->track_input()); - - - } + return track; } void TrackList::RemoveTrack() @@ -175,52 +123,61 @@ void TrackList::RemoveTrack() delete track; } -void TrackList::TrackConnectionAdded(NodeEdgePtr edge) +void TrackList::TrackConnected(NodeEdgePtr edge) { - if (edge->input() != track_input_) { - return; - } + int track_index = track_input_->IndexOfSubParameter(edge->input()); - AttachTrack(attached_track()); -} + Q_ASSERT(track_index >= 0); -void TrackList::TrackConnectionRemoved(NodeEdgePtr edge) -{ - if (edge->input() != track_input_) { - return; - } + Node* connected_node = edge->output()->parentNode(); - TrackOutput* track = dynamic_cast(edge->output()->parentNode()); + if (connected_node->IsTrack()) { + TrackOutput* connected_track = static_cast(connected_node);// Traverse through Tracks caching and connecting them - if (track) - DetachTrack(track); -} + track_cache_.replace(track_index, connected_track); -void TrackList::TrackEdgeAdded(NodeEdgePtr edge) -{ - // Assume this signal was sent from a TrackOutput - TrackOutput* track = static_cast(sender()); + connect(connected_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*))); + connect(connected_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*))); + connect(connected_track, SIGNAL(TrackLengthChanged()), this, SLOT(UpdateTotalLength())); - // 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 = dynamic_cast(edge->output()->parentNode()); + connected_track->SetIndex(track_index); + connected_track->set_track_type(type_); + + emit TrackListChanged(); + + // This function must be called after the track is added to track_cache_, since it uses track_cache_ to determine + // the track's index + emit TrackAdded(connected_track); + + UpdateTotalLength(); - if (added_track) - AttachTrack(added_track); } } -void TrackList::TrackEdgeRemoved(NodeEdgePtr edge) +void TrackList::TrackDisconnected(NodeEdgePtr edge) { - // Assume this signal was sent from a TrackOutput - TrackOutput* track = static_cast(sender()); + int track_index = track_input_->IndexOfSubParameter(edge->input()); - // 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 = dynamic_cast(edge->output()->parentNode()); + Q_ASSERT(track_index >= 0); - if (added_track) - DetachTrack(added_track); + TrackOutput* track = track_cache_.at(track_index); + + if (track) { + track_cache_.replace(track_index, nullptr); + + // Traverse through Tracks uncaching and disconnecting them + emit TrackRemoved(track); + + track->SetIndex(-1); + track->set_track_type(kTrackTypeNone); + + disconnect(track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*))); + disconnect(track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*))); + disconnect(track, SIGNAL(TrackLengthChanged()), this, SLOT(UpdateTotalLength())); + + emit TrackListChanged(); + + UpdateTotalLength(); } } @@ -234,7 +191,9 @@ void TrackList::UpdateTotalLength() total_length_ = 0; foreach (TrackOutput* track, track_cache_) { - total_length_ = qMax(total_length_, track->track_length()); + if (track) { + total_length_ = qMax(total_length_, track->track_length()); + } } emit LengthChanged(total_length_); diff --git a/app/node/output/timeline/tracklist.h b/app/node/output/timeline/tracklist.h index 68e2723b2..ec3fed10c 100644 --- a/app/node/output/timeline/tracklist.h +++ b/app/node/output/timeline/tracklist.h @@ -34,17 +34,11 @@ class TrackList : public QObject { public: TrackList(TimelineOutput *parent, const enum TrackType& type, NodeInputArray* track_input); - TrackOutput* attached_track(); - - void AttachTrack(TrackOutput *track); - - void DetachTrack(TrackOutput* track); - const QVector& Tracks(); TrackOutput* TrackAt(int index); - void AddTrack(); + TrackOutput *AddTrack(); void RemoveTrack(); @@ -52,36 +46,6 @@ public: const enum TrackType& TrackType(); -public slots:/** - * @brief Slot for when the track connection is added - */ - void TrackConnectionAdded(NodeEdgePtr edge); - - /** - * @brief Slot for when the track connection is removed - */ - void TrackConnectionRemoved(NodeEdgePtr edge); - - /** - * @brief Slot for when a connected Track has added a Block so we can update the UI - */ - void TrackAddedBlock(Block* block); - - /** - * @brief Slot for when a connected Track has added a Block so we can update the UI - */ - 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); - signals: void BlockAdded(Block* block, int index); @@ -110,6 +74,34 @@ private: enum TrackType type_; private slots: + /** + * @brief Slot for when the track connection is added + */ + void TrackConnected(NodeEdgePtr edge); + + /** + * @brief Slot for when the track connection is removed + */ + void TrackDisconnected(NodeEdgePtr edge); + + /** + * @brief Slot for when a connected Track has added a Block so we can update the UI + */ + void TrackAddedBlock(Block* block); + + /** + * @brief Slot for when a connected Track has added a Block so we can update the UI + */ + void TrackRemovedBlock(Block* block); + + /** + * @brief Slot for when the count of tracks in the track input changes + */ + void TrackListSizeChanged(int size); + + /** + * @brief Slot for when any of the track's length changes so we can update the length of the tracklist + */ void UpdateTotalLength(); }; diff --git a/app/node/output/track/track.cpp b/app/node/output/track/track.cpp index 9e0dbee30..5c44649ed 100644 --- a/app/node/output/track/track.cpp +++ b/app/node/output/track/track.cpp @@ -27,8 +27,6 @@ TrackOutput::TrackOutput() : track_type_(kTrackTypeNone), - previous_track_(nullptr), - next_track_(nullptr), block_invalidate_cache_stack_(0), index_(-1) { @@ -95,26 +93,6 @@ void TrackOutput::SetIndex(const int &index) index_ = index; } -void TrackOutput::set_previous_track(TrackOutput *previous) -{ - previous_track_ = previous; -} - -void TrackOutput::set_next_track(TrackOutput *next) -{ - next_track_ = next; -} - -TrackOutput *TrackOutput::previous_track() const -{ - return previous_track_; -} - -TrackOutput *TrackOutput::next_track() const -{ - return next_track_; -} - Block *TrackOutput::BlockContainingTime(const rational &time) const { foreach (Block* block, block_cache_) { @@ -224,7 +202,7 @@ void TrackOutput::InsertBlockAtIndex(Block *block, int index) block_input_->InsertAt(index); NodeParam::ConnectEdge(block->output(), - block_input_->ParamAt(index)); + block_input_->At(index)); } void TrackOutput::AppendBlock(Block *block) @@ -236,7 +214,7 @@ void TrackOutput::AppendBlock(Block *block) int last_index = block_input_->GetSize(); block_input_->Append(); NodeParam::ConnectEdge(block->output(), - block_input_->ParamAt(last_index)); + block_input_->At(last_index)); UnblockInvalidateCache(); @@ -297,10 +275,10 @@ void TrackOutput::ReplaceBlock(Block *old, Block *replace) int index_of_old_block = block_cache_.indexOf(old); NodeParam::DisconnectEdge(old->output(), - block_input_->ParamAt(index_of_old_block)); + block_input_->At(index_of_old_block)); NodeParam::ConnectEdge(replace->output(), - block_input_->ParamAt(index_of_old_block)); + block_input_->At(index_of_old_block)); UnblockInvalidateCache(); @@ -462,11 +440,9 @@ void TrackOutput::BlockListSizeChanged(int size) block_cache_.resize(size); - if (size > old_size) { - // Fill new slots with nullptr - for (int i=old_size;iSetCanBeDeleted(false); AddNode(viewer_output_); - video_track_output_ = new TrackOutput(); - video_track_output_->SetCanBeDeleted(false); - AddNode(video_track_output_); - - audio_track_output_ = new TrackOutput(); - audio_track_output_->SetCanBeDeleted(false); - AddNode(audio_track_output_); - - // Connect tracks to viewer - NodeParam::ConnectEdge(video_track_output_->output(), viewer_output_->texture_input()); - NodeParam::ConnectEdge(audio_track_output_->output(), viewer_output_->samples_input()); - // Connect timeline length to viewer NodeParam::ConnectEdge(timeline_output_->output(), viewer_output_->length_input()); - // Connect track to timeline - NodeParam::ConnectEdge(video_track_output_->output(), timeline_output_->track_input(kTrackTypeVideo)); - NodeParam::ConnectEdge(audio_track_output_->output(), timeline_output_->track_input(kTrackTypeAudio)); + // Create tracks and connect them to the viewer + Node* video_track_output = timeline_output_->track_list(TrackType::kTrackTypeVideo)->AddTrack(); + Node* audio_track_output = timeline_output_->track_list(TrackType::kTrackTypeAudio)->AddTrack(); + NodeParam::ConnectEdge(video_track_output->output(), viewer_output_->texture_input()); + NodeParam::ConnectEdge(audio_track_output->output(), viewer_output_->samples_input()); // Update the timebase on these nodes set_video_params(video_params_); diff --git a/app/project/item/sequence/sequence.h b/app/project/item/sequence/sequence.h index 4c6e8c264..208ca53c4 100644 --- a/app/project/item/sequence/sequence.h +++ b/app/project/item/sequence/sequence.h @@ -64,8 +64,6 @@ public: private: TimelineOutput* timeline_output_; ViewerOutput* viewer_output_; - TrackOutput* video_track_output_; - TrackOutput* audio_track_output_; VideoParams video_params_;