From 963607b7d33a292700cd9e49f82577f2a42cd37d Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu, 21 Oct 2021 11:52:01 -0700 Subject: [PATCH] clip: retrieve any connected viewer on invalidate --- app/node/block/clip/clip.cpp | 12 ++++++++- app/node/block/clip/clip.h | 9 +++++++ app/node/node.h | 48 ++++++++++++++++++++++++++++++------ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/app/node/block/clip/clip.cpp b/app/node/block/clip/clip.cpp index efb9c9040..d966098a0 100644 --- a/app/node/block/clip/clip.cpp +++ b/app/node/block/clip/clip.cpp @@ -21,6 +21,7 @@ #include "clip.h" #include "node/output/track/track.h" +#include "node/output/viewer/viewer.h" #include "widget/slider/floatslider.h" #include "widget/slider/rationalslider.h" @@ -35,7 +36,8 @@ const QString ClipBlock::kReverseInput = QStringLiteral("reverse_in"); ClipBlock::ClipBlock() : in_transition_(nullptr), - out_transition_(nullptr) + out_transition_(nullptr), + connected_viewer_(nullptr) { AddInput(kMediaInInput, NodeValue::kRational, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable)); SetInputProperty(kMediaInInput, QStringLiteral("view"), RationalSlider::kTime); @@ -189,6 +191,14 @@ void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int adj = TimeRange(MediaToSequenceTime(range.in()), MediaToSequenceTime(range.out())); } + // Find connected viewer node + auto viewers = FindInputNodesConnectedToInput(NodeInput(this, kBufferIn)); + if (viewers.isEmpty()) { + connected_viewer_ = nullptr; + } else { + connected_viewer_ = viewers.first(); + } + super::InvalidateCache(adj, from, element, options); } else { // Otherwise, pass signal along normally diff --git a/app/node/block/clip/clip.h b/app/node/block/clip/clip.h index 9ff1bc1ec..ee8eef2e8 100644 --- a/app/node/block/clip/clip.h +++ b/app/node/block/clip/clip.h @@ -26,6 +26,8 @@ namespace olive { +class ViewerOutput; + /** * @brief Node that represents a block of Media */ @@ -99,6 +101,11 @@ public: return waveform_; } + ViewerOutput *connected_viewer() const + { + return connected_viewer_; + } + static const QString kBufferIn; static const QString kMediaInInput; static const QString kSpeedInput; @@ -121,6 +128,8 @@ private: TransitionBlock* in_transition_; TransitionBlock* out_transition_; + ViewerOutput *connected_viewer_; + private: AudioVisualWaveform waveform_; diff --git a/app/node/node.h b/app/node/node.h index 27e938467..b22af3fff 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -644,6 +644,12 @@ public: template QVector FindInputNodes() const; + /** + * @brief Find nodes of a certain type that this Node takes inputs from + */ + template + static QVector FindInputNodesConnectedToInput(const NodeInput &input); + template /** * @brief Find a node of a certain type that this Node outputs to @@ -1169,6 +1175,12 @@ private: */ int GetInternalInputArraySize(const QString& input); + /** + * @brief Find nodes of a certain type that this Node takes inputs from + */ + template + static void FindInputNodesConnectedToInputInternal(const NodeInput &input, QVector& list); + template static void FindInputNodeInternal(const Node* n, QVector& list); @@ -1274,18 +1286,38 @@ private slots: }; +template +void Node::FindInputNodesConnectedToInputInternal(const NodeInput &input, QVector &list) +{ + Node* edge = input.GetConnectedOutput(); + if (!edge) { + return; + } + + T* cast_test = dynamic_cast(edge); + + if (cast_test) { + list.append(cast_test); + } + + FindInputNodeInternal(edge, list); +} + +template +QVector Node::FindInputNodesConnectedToInput(const NodeInput &input) +{ + QVector list; + + FindInputNodesConnectedToInputInternal(input, list); + + return list; +} + template void Node::FindInputNodeInternal(const Node* n, QVector &list) { for (auto it=n->input_connections_.cbegin(); it!=n->input_connections_.cend(); it++) { - Node* edge = it->second; - T* cast_test = dynamic_cast(edge); - - if (cast_test) { - list.append(cast_test); - } - - FindInputNodeInternal(edge, list); + FindInputNodesConnectedToInputInternal(it->first, list); } }