diff --git a/app/node/node.cpp b/app/node/node.cpp index 623b06330..12a8184bc 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -87,17 +87,35 @@ int Node::IndexOfParameter(NodeParam *param) return children().indexOf(param); } -QList Node::GetDependencies() -{ - QList params = parameters(); +/** + * @brief Recursively collects dependencies of Node `n` and appends them to QList `list` + */ +void GetDependenciesInternal(Node* n, QList& list) { + QList params = n->parameters(); foreach (NodeParam* p, params) { if (p->type() == NodeParam::kInput) { + QVector param_edges = p->edges(); + foreach (NodeEdgePtr edge, param_edges) { + Node* connected_node = edge->output()->parent(); + + list.append(connected_node); + GetDependenciesInternal(connected_node, list); + } } } } +QList Node::GetDependencies() +{ + QList node_list; + + GetDependenciesInternal(this, node_list); + + return node_list; +} + QVariant Node::PtrToValue(void *ptr) { return reinterpret_cast(ptr); diff --git a/app/node/node.h b/app/node/node.h index bca105b1c..f6503711f 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -109,7 +109,7 @@ public: int IndexOfParameter(NodeParam* param); /** - * @brief Return a list of all Nodes that this Node's inputs are connected to + * @brief Return a list of all Nodes that this Node's inputs are connected to (does not include this Node) */ QList GetDependencies(); diff --git a/app/node/output/timeline/timeline.cpp b/app/node/output/timeline/timeline.cpp index f8e819d7f..eae91d000 100644 --- a/app/node/output/timeline/timeline.cpp +++ b/app/node/output/timeline/timeline.cpp @@ -174,31 +174,39 @@ void TimelineOutput::InsertBlock(Block *block, int index) NodeGraph* graph = static_cast(parent()); graph->AddNode(block); - // FIXME: We'll probably want to add more nodes than this? + // Add all of Block's dependencies + QList block_dependencies = block->GetDependencies(); + foreach (Node* dep, block_dependencies) { + graph->AddNode(dep); + } if (block_cache_.isEmpty()) { + // If there are no blocks connected, the index doesn't matter. Just connect it. Block::ConnectBlocks(block, this); } else if (index == 0) { - // Prepend block before all others + // If the index is 0, it goes at the very beginning Block::ConnectBlocks(block, block_cache_.first()); } else { - // Insert block between + // Otherwise, the block goes between two other blocks somehow Block* before; Block* after; if (index < block_cache_.size()) { + // The block goes somewhere in between some set of two blocks before = block_cache_.at(index - 1); after = block_cache_.at(index); } else { + // The block goes at the very end before = block_cache_.last(); after = this; } + // Connect blocks correctly Block::DisconnectBlocks(before, after); Block::ConnectBlocks(before, block); Block::ConnectBlocks(block, after); diff --git a/app/widget/timelineview/tool/import.cpp b/app/widget/timelineview/tool/import.cpp index 841962b4e..5b8b0852e 100644 --- a/app/widget/timelineview/tool/import.cpp +++ b/app/widget/timelineview/tool/import.cpp @@ -22,6 +22,8 @@ #include +#include "node/input/media/media.h" + TimelineView::ImportTool::ImportTool(TimelineView *parent) : Tool(parent) { @@ -103,9 +105,15 @@ void TimelineView::ImportTool::DragDrop(QDropEvent *event) if (parent()->HasGhosts()) { foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { ClipBlock* clip = new ClipBlock(); + MediaInput* media = new MediaInput(); clip->set_length(ghost->Out() - ghost->In()); + media->SetFootage(ghost->stream()->footage()); + NodeParam::ConnectEdge(media->texture_output(), clip->texture_input()); + + // FIXME: If this doesn't have a TimelineOutput node attached, this is a memory leak. Maybe switching nodes to + // shared ptrs would be a better idea. emit parent()->RequestInsertBlock(clip, 0); }