diff --git a/app/node/node.cpp b/app/node/node.cpp index 12b92d665..6e02dc68e 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -2002,6 +2002,50 @@ void Node::SetValueAtTime(const NodeInput &input, const rational &time, const QV } } +void FindPathInternal(std::list &vec, Node *to, int &path_index) +{ + Node *from = vec.back(); + + for (auto it=from->input_connections().cbegin(); it!=from->input_connections().cend(); it++) { + vec.push_back(it->second); + if (it->second == to) { + // Found a path, determine if it's the one we want + if (path_index == 0) { + // It is! + break; + } else { + path_index--; + } + } + + // Recurse to see if we can find it here + FindPathInternal(vec, to, path_index); + if (vec.back() == to) { + // Found through recursion + break; + } else { + // Must not be available through this path + vec.pop_back(); + } + } +} + +std::list Node::FindPath(Node *from, Node *to, int path_index) +{ + std::list v; + + v.push_back(from); + + FindPathInternal(v, to, path_index); + + if (v.size() == 1) { + // Failed to find path, return empty list + v.pop_back(); + } + + return v; +} + Project *Node::ArrayInsertCommand::GetRelevantProject() const { return node_->project(); diff --git a/app/node/node.h b/app/node/node.h index 106448c1c..98fcd8e27 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -956,6 +956,8 @@ public: static void SetValueAtTime(const NodeInput &input, const rational &time, const QVariant &value, int track, MultiUndoCommand *command, bool insert_on_all_tracks_if_no_key); + static std::list FindPath(Node *from, Node *to, int path_index = 0); + static const QString kEnabledInput; protected: