From b233aa53195dd977e43b4d3530f6e90f06561c2a Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 23 Nov 2019 08:51:15 +0900 Subject: [PATCH] added signal for an edge changing that can ripple through the graph Useful for detecting when a graph needs recompiling, in tandem with the "InvalidateCache()" signal when necessary, this signal ripples through the nodes when any of the connections change which will likely need handling by the renderer. --- app/node/node.cpp | 48 ++++++++++++++++++++++--------- app/node/node.h | 2 ++ app/node/output/viewer/viewer.cpp | 13 +++++++++ app/node/output/viewer/viewer.h | 7 +++++ 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/app/node/node.cpp b/app/node/node.cpp index cdcd3a811..4380720b4 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -122,6 +122,24 @@ void Node::SendInvalidateCache(const rational &start_range, const rational &end_ } } +void Node::DependentEdgeChanged(NodeInput *from) +{ + Q_UNUSED(from) + + foreach (NodeParam* p, params_) { + if (p->type() == NodeParam::kOutput && p->IsConnected()) { + NodeOutput* out = static_cast(p); + + foreach (NodeEdgePtr edge, out->edges()) { + NodeInput* connected_input = edge->input(); + Node* connected_node = connected_input->parent(); + + connected_node->DependentEdgeChanged(connected_input); + } + } + } +} + void Node::LockUserInput() { user_input_lock_.lock(); @@ -177,26 +195,28 @@ void Node::DuplicateConnectionsBetweenLists(const QList &source, const Q Q_ASSERT(source.size() == destination.size()); for (int i=0;iparams_.size();j++) { - NodeParam* source_param = source_node->params_.at(j); + Q_ASSERT(source_input_node->id() == dest_input_node->id()); + + for (int j=0;jparams_.size();j++) { + NodeParam* source_param = source_input_node->params_.at(j); if (source_param->type() == NodeInput::kInput && source_param->IsConnected()) { NodeInput* source_input = static_cast(source_param); - NodeInput* dest_input = static_cast(dest_node->params_.at(j)); + NodeInput* dest_input = static_cast(dest_input_node->params_.at(j)); // Get this input's connected outputs - NodeOutput* connected_output = source_input->get_connected_output(); - Node* connected_node = connected_output->parent(); - - // Find index of connected output in source list - int connection_index = source.indexOf(connected_node); + NodeOutput* source_output = source_input->get_connected_output(); + Node* source_output_node = source_output->parent(); // Find equivalent in destination list - Node* dest_output_node = destination.at(connection_index); - NodeOutput* dest_output = static_cast(dest_output_node->params_.at(connected_output->index())); + Node* dest_output_node = destination.at(source.indexOf(source_output_node)); + + Q_ASSERT(dest_output_node->id() == source_output_node->id()); + + NodeOutput* dest_output = static_cast(dest_output_node->params_.at(source_output->index())); NodeParam::ConnectEdge(dest_output, dest_input); } @@ -252,7 +272,7 @@ const QList& Node::parameters() int Node::IndexOfParameter(NodeParam *param) { - return children().indexOf(param); + return params_.indexOf(param); } /** @@ -458,7 +478,7 @@ void Node::InputChanged(rational start, rational end) void Node::InputConnectionChanged(NodeEdgePtr edge) { - Q_UNUSED(edge) + DependentEdgeChanged(edge->input()); InvalidateCache(RATIONAL_MIN, RATIONAL_MAX, static_cast(sender())); } diff --git a/app/node/node.h b/app/node/node.h index 9cdfccf13..85a3b88e7 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -285,6 +285,8 @@ protected: void SendInvalidateCache(const rational& start_range, const rational& end_range); + virtual void DependentEdgeChanged(NodeInput* from); + public slots: signals: diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index 7bd95ef2c..f9a8ef6a7 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -117,3 +117,16 @@ rational ViewerOutput::Length() { return length_input_->get_realtime_value_of_connected_output().value(); } + +void ViewerOutput::DependentEdgeChanged(NodeInput *from) +{ + if (from == texture_input_) { + emit VideoGraphChanged(); + } else if (from == samples_input_) { + emit AudioGraphChanged(); + } + + // NOTE: This node technically has no outputs so default behavior is unnecessary, but if this node gets outputs some + // day this should be uncommented + //Node::DependentEdgeChanged(from); +} diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index 138962988..cc524fec1 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -57,6 +57,9 @@ public: rational Length(); +protected: + virtual void DependentEdgeChanged(NodeInput* from) override; + signals: void TimebaseChanged(const rational&); @@ -64,6 +67,10 @@ signals: void AudioChangedBetween(const rational&, const rational&); + void VideoGraphChanged(); + + void AudioGraphChanged(); + void LengthChanged(const rational& length); void SizeChanged(int width, int height);