From 149f3fa907f53f7fa37dd496aa373a994b567d9d Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 11 Aug 2019 21:01:37 +1000 Subject: [PATCH] timelineview is now a true view of the blocks at all times --- app/core.cpp | 4 +- app/node/block/block.cpp | 13 +++ app/node/block/block.h | 19 +++- app/node/node.cpp | 11 ++ app/node/node.h | 5 + app/node/output/timeline/timeline.cpp | 135 +++++++++++------------ app/node/output/timeline/timeline.h | 20 ++-- app/node/param.cpp | 4 +- app/panel/timeline/timeline.cpp | 5 + app/panel/timeline/timeline.h | 2 + app/widget/nodeview/nodeview.cpp | 2 + app/widget/nodeview/nodeviewitem.cpp | 2 + app/widget/timelineview/timelineview.cpp | 5 + 13 files changed, 141 insertions(+), 86 deletions(-) diff --git a/app/core.cpp b/app/core.cpp index 4ab51d6dd..80fc12315 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -295,10 +295,10 @@ void Core::CreateNewSequence() NodeParam::ConnectEdge(sg->texture_output(), cb1->texture_input()); NodeParam::ConnectEdge(ii->texture_output(), cb2->texture_input()); Block::ConnectBlocks(cb1, cb2); - NodeParam::ConnectEdge(cb2->block_output(), tb->block_input()); + Block::ConnectBlocks(cb2, tb); NodeParam::ConnectEdge(tb->texture_output(), vo->texture_input()); - tb->Refresh(); + //tb->Refresh(); tb->AttachTimeline(olive::panel_focus_manager->MostRecentlyFocused()); olive::panel_focus_manager->MostRecentlyFocused()->SetGraph(new_sequence.get()); diff --git a/app/node/block/block.cpp b/app/node/block/block.cpp index 4c5d89d5c..005183345 100644 --- a/app/node/block/block.cpp +++ b/app/node/block/block.cpp @@ -20,6 +20,8 @@ #include "block.h" +#include + Block::Block() { previous_input_ = new NodeInput(); @@ -37,6 +39,9 @@ Block::Block() texture_output_ = new NodeOutput(); texture_output_->set_data_type(NodeParam::kTexture); AddParameter(texture_output_); + + connect(this, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(BlockOrderChanged(NodeEdgePtr))); + connect(this, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(BlockOrderChanged(NodeEdgePtr))); } QString Block::Category() @@ -115,6 +120,14 @@ void Block::RefreshFollowing() } } +void Block::BlockOrderChanged(NodeEdgePtr edge) +{ + if (edge->input() == previous_input() || edge->input() == next_input()) { + // The blocks surrounding this one have changed, we need to Refresh() + RefreshFollowing(); + } +} + NodeOutput *Block::texture_output() { return texture_output_; diff --git a/app/node/block/block.h b/app/node/block/block.h index f131dd065..42cb48baa 100644 --- a/app/node/block/block.h +++ b/app/node/block/block.h @@ -37,7 +37,8 @@ public: enum Type { kClip, - kGap + kGap, + kEnd }; virtual Type type() = 0; @@ -78,16 +79,24 @@ public slots: * Blocks before it are accurate and up to date. You may need to traverse through the Block list (using previous()) * and run Refresh() on all Blocks sequentially. */ - void Refresh(); + virtual void Refresh(); + /** + * @brief Calls Refresh() on this block and all blocks connected after it (but not before it) + */ void RefreshFollowing(); signals: + /** + * @brief Signal emitted when this Block is refreshed + * + * Can be used as essentially a "changed" signal for UI widgets to know when to update their views + */ void Refreshed(); protected: -private: +private: NodeInput* previous_input_; NodeInput* next_input_; NodeOutput* block_output_; @@ -96,6 +105,10 @@ private: rational in_point_; rational out_point_; + +private slots: + void BlockOrderChanged(NodeEdgePtr edge); + }; #endif // BLOCK_H diff --git a/app/node/node.cpp b/app/node/node.cpp index 9122a93d9..623b06330 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -87,6 +87,17 @@ int Node::IndexOfParameter(NodeParam *param) return children().indexOf(param); } +QList Node::GetDependencies() +{ + QList params = parameters(); + + foreach (NodeParam* p, params) { + if (p->type() == NodeParam::kInput) { + + } + } +} + QVariant Node::PtrToValue(void *ptr) { return reinterpret_cast(ptr); diff --git a/app/node/node.h b/app/node/node.h index 5cea5dfee..bca105b1c 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -108,6 +108,11 @@ public: */ int IndexOfParameter(NodeParam* param); + /** + * @brief Return a list of all Nodes that this Node's inputs are connected to + */ + QList GetDependencies(); + /** * @brief Convert a pointer to a value that can be sent between NodeParams */ diff --git a/app/node/output/timeline/timeline.cpp b/app/node/output/timeline/timeline.cpp index 80b62b2d7..f8e819d7f 100644 --- a/app/node/output/timeline/timeline.cpp +++ b/app/node/output/timeline/timeline.cpp @@ -20,20 +20,17 @@ #include "timeline.h" -#include TimelineOutput::TimelineOutput() : first_block_(nullptr), - current_block_(nullptr), + current_block_(this), attached_timeline_(nullptr) { - block_input_ = new NodeInput(); - block_input_->add_data_input(NodeInput::kBlock); - AddParameter(block_input_); +} - texture_output_ = new NodeOutput(); - texture_output_->set_data_type(NodeOutput::kTexture); - AddParameter(texture_output_); +Block::Type TimelineOutput::type() +{ + return kEnd; } QString TimelineOutput::Name() @@ -93,50 +90,55 @@ void TimelineOutput::AttachTimeline(TimelinePanel *timeline) } } -NodeInput *TimelineOutput::block_input() +rational TimelineOutput::length() { - return block_input_; -} - -NodeOutput *TimelineOutput::texture_output() -{ - return texture_output_; + return 0; } void TimelineOutput::Refresh() { + QVector detect_attached_blocks; + Block* previous = attached_block(); - - first_block_ = nullptr; - - // Find first block while (previous != nullptr) { + detect_attached_blocks.prepend(previous); - // Cache block in "first", if this is indeed the first, its previous will be nullptr thus breaking the loop - first_block_ = previous; + if (attached_timeline_ != nullptr && !block_cache_.contains(previous)) { + // FIXME: Remove the need to cast this + attached_timeline_->AddClip(static_cast(previous)); + } previous = previous->previous(); } - if (first_block_ != nullptr) { - first_block_->RefreshFollowing(); + if (attached_timeline_ != nullptr) { + foreach (Block* b, block_cache_) { + if (!detect_attached_blocks.contains(b)) { + attached_timeline_->RemoveClip(static_cast(b)); + } + } } + + block_cache_ = detect_attached_blocks; + + Block::Refresh(); } void TimelineOutput::Process(const rational &time) { - // This node is intended to connect to the end of the timeline, so being beyond its out point is considered the end - // of the sequence - if (attached_block() == nullptr || time >= attached_block()->out()) { - texture_output_->set_value(0); - current_block_ = nullptr; + // Run default node processing + Block::Process(time); + + // This node representso the end of the timeline, so being beyond its in point is considered the end of the sequence + if (time >= in()) { + texture_output()->set_value(0); + current_block_ = this; return; } // If we're here, we need to find the current clip to display - if (current_block_ == nullptr) { - current_block_ = attached_block(); - } + // attached_block() is guaranteed to not be nullptr if we didn't return before + current_block_ = attached_block(); // If the time requested is an earlier Block, traverse earlier until we find it while (time < current_block_->in()) { @@ -149,12 +151,21 @@ void TimelineOutput::Process(const rational &time) } // At this point, we must have found the correct block so we use its texture output to produce the image - texture_output_->set_value(current_block_->texture_output()->get_value(time)); + texture_output()->set_value(current_block_->texture_output()->get_value(time)); +} + +Block *TimelineOutput::first_block() +{ + if (block_cache_.isEmpty()) { + return nullptr; + } + + return block_cache_.first(); } Block *TimelineOutput::attached_block() { - return ValueToPtr(block_input_->get_value(0)); + return ValueToPtr(previous_input()->get_value(0)); } void TimelineOutput::InsertBlock(Block *block, int index) @@ -165,48 +176,32 @@ void TimelineOutput::InsertBlock(Block *block, int index) // FIXME: We'll probably want to add more nodes than this? - Block* block_before = nullptr; - Block* block_after = first_block_; + if (block_cache_.isEmpty()) { - for (int i=0;inext(); + } else if (index == 0) { - if (block_after == nullptr) { - break; - } - } + // Prepend block before all others + Block::ConnectBlocks(block, block_cache_.first()); - if (block_before != nullptr && block_after != nullptr) { - // If neither blocks are null, we're inserting this block between them - - // Disconnect existing blocks - Block::DisconnectBlocks(block_before, block_after); - Block::ConnectBlocks(block_before, block); - Block::ConnectBlocks(block, block_after); - } else if (block_before != nullptr) { - // We're at the end of the Sequence - - // Disconnect previous ending clip from this one - NodeParam::DisconnectEdge(block_before->block_output(), block_input_); - NodeParam::ConnectEdge(block->block_output(), block_input_); - - // Connect both blocks together - Block::ConnectBlocks(block_before, block); - } else if (block_after != nullptr) { - // We're at the start of the Sequence - - // Connect both blocks together - Block::ConnectBlocks(block, block_after); } else { - // Sequence is empty - NodeParam::ConnectEdge(block->block_output(), block_input_); - } - if (attached_timeline_ != nullptr) { - attached_timeline_->AddClip(static_cast(block)); - } + // Insert block between + Block* before; + Block* after; - Refresh(); + if (index < block_cache_.size()) { + before = block_cache_.at(index - 1); + after = block_cache_.at(index); + } else { + before = block_cache_.last(); + after = this; + } + + Block::DisconnectBlocks(before, after); + Block::ConnectBlocks(before, block); + Block::ConnectBlocks(block, after); + + } } diff --git a/app/node/output/timeline/timeline.h b/app/node/output/timeline/timeline.h index 1705664bf..a4533e60b 100644 --- a/app/node/output/timeline/timeline.h +++ b/app/node/output/timeline/timeline.h @@ -21,18 +21,20 @@ #ifndef TIMELINEOUTPUT_H #define TIMELINEOUTPUT_H -#include "node/node.h" +#include "node/block/block.h" #include "panel/timeline/timeline.h" /** * @brief Node that represents the end of the Timeline as well as a time traversal Node */ -class TimelineOutput : public Node +class TimelineOutput : public Block { Q_OBJECT public: TimelineOutput(); + virtual Type type() override; + virtual QString Name() override; virtual QString id() override; virtual QString Category() override; @@ -40,23 +42,23 @@ public: void AttachTimeline(TimelinePanel* timeline); - NodeInput* block_input(); - NodeOutput* texture_output(); + virtual rational length() override; + + virtual void Refresh() override; public slots: - void Refresh(); - virtual void Process(const rational &time) override; private: + QVector block_cache_; + + Block* first_block(); + Block* attached_block(); Block* first_block_; Block* current_block_; - NodeInput* block_input_; - NodeOutput* texture_output_; - TimelinePanel* attached_timeline_; private slots: diff --git a/app/node/param.cpp b/app/node/param.cpp index a8f294fca..98a62c131 100644 --- a/app/node/param.cpp +++ b/app/node/param.cpp @@ -128,7 +128,7 @@ NodeEdgePtr NodeParam::ConnectEdge(NodeOutput *output, NodeInput *input) input->edges_.append(edge); // Emit a signal than an edge was added (only one signal needs emitting) - emit output->EdgeAdded(edge); + emit input->EdgeAdded(edge); return edge; } @@ -141,7 +141,7 @@ void NodeParam::DisconnectEdge(NodeEdgePtr edge) output->edges_.removeAll(edge); input->edges_.removeAll(edge); - emit output->EdgeRemoved(edge); + emit input->EdgeRemoved(edge); } void NodeParam::DisconnectEdge(NodeOutput *output, NodeInput *input) diff --git a/app/panel/timeline/timeline.cpp b/app/panel/timeline/timeline.cpp index e398b3383..c44cec8ff 100644 --- a/app/panel/timeline/timeline.cpp +++ b/app/panel/timeline/timeline.cpp @@ -63,6 +63,11 @@ void TimelinePanel::AddClip(ClipBlock *clip) view_->AddClip(clip); } +void TimelinePanel::RemoveClip(ClipBlock *clip) +{ + view_->RemoveClip(clip); +} + void TimelinePanel::SetTimebase(const rational &timebase) { ruler_->SetTimebase(timebase); diff --git a/app/panel/timeline/timeline.h b/app/panel/timeline/timeline.h index 6b3f0e124..94b95c958 100644 --- a/app/panel/timeline/timeline.h +++ b/app/panel/timeline/timeline.h @@ -35,6 +35,8 @@ public: void AddClip(ClipBlock* clip); + void RemoveClip(ClipBlock* clip); + void SetTimebase(const rational& timebase); protected: diff --git a/app/widget/nodeview/nodeview.cpp b/app/widget/nodeview/nodeview.cpp index d17e326a8..b391a24fe 100644 --- a/app/widget/nodeview/nodeview.cpp +++ b/app/widget/nodeview/nodeview.cpp @@ -35,6 +35,8 @@ NodeView::NodeView(QWidget *parent) : void NodeView::SetGraph(NodeGraph *graph) { if (graph_ != nullptr) { + disconnect(graph_, SIGNAL(NodeAdded(Node*)), this, SLOT(AddNode(Node*))); + disconnect(graph_, SIGNAL(NodeRemoved(Node*)), this, SLOT(RemoveNode(Node*))); disconnect(graph_, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(AddEdge(NodeEdgePtr))); disconnect(graph_, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(RemoveEdge(NodeEdgePtr))); } diff --git a/app/widget/nodeview/nodeviewitem.cpp b/app/widget/nodeview/nodeviewitem.cpp index d73716587..9b847a4a6 100644 --- a/app/widget/nodeview/nodeviewitem.cpp +++ b/app/widget/nodeview/nodeviewitem.cpp @@ -257,6 +257,8 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti } } +#include "node/block/block.h" + void NodeViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { // We override standard mouse behavior in some cases. In these cases, we don't want the standard "move" and "release" diff --git a/app/widget/timelineview/timelineview.cpp b/app/widget/timelineview/timelineview.cpp index 025aec17d..9b0b104df 100644 --- a/app/widget/timelineview/timelineview.cpp +++ b/app/widget/timelineview/timelineview.cpp @@ -67,6 +67,11 @@ void TimelineView::AddClip(ClipBlock *clip) connect(clip, SIGNAL(Refreshed()), this, SLOT(BlockChanged())); } +void TimelineView::RemoveClip(ClipBlock *clip) +{ + delete clip_items_[clip]; +} + void TimelineView::SetScale(const double &scale) { scale_ = scale;