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.
This commit is contained in:
itsmattkc
2019-12-06 20:34:19 +11:00
parent 9140479940
commit 351d4a246e
11 changed files with 133 additions and 211 deletions
+1 -1
View File
@@ -306,7 +306,7 @@ void NodeInput::CopyValues(NodeInput *source, NodeInput *dest, bool include_conn
dst_array->SetSize(src_array->GetSize());
for (int i=0;i<dst_array->GetSize();i++) {
CopyValues(src_array->ParamAt(i), dst_array->ParamAt(i), include_connections);
CopyValues(src_array->At(i), dst_array->At(i), include_connections);
}
}
}
+11 -1
View File
@@ -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<NodeInput *> &NodeInputArray::sub_params()
{
return sub_params_;
+3 -1
View File
@@ -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<NodeInput*>& sub_params();
+2 -2
View File
@@ -214,7 +214,7 @@ void DuplicateConnectionsBetweenListsInternal(const QList<Node *> &source, const
NodeInputArray* dest_array = static_cast<NodeInputArray*>(dest_input);
for (int i=0;i<source_array->GetSize();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<Node*>& list, NodeInput* input, bool trav
NodeInputArray* input_array = static_cast<NodeInputArray*>(input);
for (int i=0;i<input_array->GetSize();i++) {
TraverseInputInternal(list, input_array->ParamAt(i), traverse);
TraverseInputInternal(list, input_array->At(i), traverse);
}
}
}
+8 -2
View File
@@ -34,7 +34,7 @@ TimelineOutput::TimelineOutput()
for (int i=0;i<kTrackTypeCount;i++) {
// Create track input
NodeInput* track_input = new NodeInput(QString("track_in_%1").arg(i));
NodeInputArray* track_input = new NodeInputArray(QStringLiteral("track_in_%1").arg(i));
AddInput(track_input);
track_inputs_.replace(i, track_input);
@@ -106,7 +106,13 @@ void TimelineOutput::UpdateTrackCache()
track_cache_.clear();
foreach (TrackList* list, track_lists_) {
track_cache_.append(list->Tracks());
QVector<TrackOutput*> track_list = list->Tracks();
foreach (TrackOutput* track, track_list) {
if (track) {
track_cache_.append(list->Tracks());
}
}
}
}
+66 -107
View File
@@ -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<TrackOutput*>(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<size;i++) {
track_cache_.replace(i, nullptr);
}
}
const QVector<TrackOutput *> &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<TrackOutput*>(edge->output()->parentNode());
if (connected_node->IsTrack()) {
TrackOutput* connected_track = static_cast<TrackOutput*>(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<TrackOutput*>(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<TrackOutput*>(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<TrackOutput*>(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<TrackOutput*>(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_);
+29 -37
View File
@@ -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<TrackOutput*>& 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();
};
+7 -31
View File
@@ -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;i<size;i++) {
block_cache_.replace(i, nullptr);
}
// Fill new slots with nullptr
for (int i=old_size;i<size;i++) {
block_cache_.replace(i, nullptr);
}
}
-9
View File
@@ -50,11 +50,6 @@ public:
const int& Index();
void SetIndex(const int& index);
void set_previous_track(TrackOutput* previous);
void set_next_track(TrackOutput* next);
TrackOutput* previous_track() const;
TrackOutput* next_track() const;
Block* BlockContainingTime(const rational& time) const;
Block* NearestBlockBefore(const rational& time) const;
@@ -163,10 +158,6 @@ private:
rational track_length_;
TrackOutput* previous_track_;
TrackOutput* next_track_;
int block_invalidate_cache_stack_;
int index_;
+6 -18
View File
@@ -32,9 +32,7 @@
Sequence::Sequence() :
timeline_output_(nullptr),
viewer_output_(nullptr),
video_track_output_(nullptr),
audio_track_output_(nullptr)
viewer_output_(nullptr)
{
}
@@ -64,24 +62,14 @@ void Sequence::add_default_nodes()
viewer_output_->SetCanBeDeleted(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_);
-2
View File
@@ -64,8 +64,6 @@ public:
private:
TimelineOutput* timeline_output_;
ViewerOutput* viewer_output_;
TrackOutput* video_track_output_;
TrackOutput* audio_track_output_;
VideoParams video_params_;