Add an API to traverse the process graph downstream
authorRobin Gareus <robin@gareus.org>
Wed, 6 Apr 2016 00:00:17 +0000 (02:00 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 6 Apr 2016 00:00:17 +0000 (02:00 +0200)
libs/ardour/ardour/route_graph.h
libs/ardour/route_graph.cc

index e1e1049cd6562d01b20d892ba53c85a9601d9041..aae2ba019db5fc1b8f6b32ed1073f35f8fb61d53 100644 (file)
@@ -44,6 +44,7 @@ public:
 
        void add (GraphVertex from, GraphVertex to, bool via_sends_only);
        bool has (GraphVertex from, GraphVertex to, bool* via_sends_only);
+       bool feeds (GraphVertex from, GraphVertex to);
        std::set<GraphVertex> from (GraphVertex r) const;
        void remove (GraphVertex from, GraphVertex to);
        bool has_none_to (GraphVertex to) const;
@@ -56,6 +57,7 @@ private:
        typedef std::multimap<GraphVertex, std::pair<GraphVertex, bool> > EdgeMapWithSends;
 
        EdgeMapWithSends::iterator find_in_from_to_with_sends (GraphVertex, GraphVertex);
+       EdgeMapWithSends::iterator find_recursively_in_from_to_with_sends (GraphVertex, GraphVertex);
 
        /** map of edges with from as `first' and to as `second' */
        EdgeMap _from_to;
index ab88a0d839c5b45f676531e3216006597fdc43a3..910141a44029c901343c43a8720d5f5d45d839d7 100644 (file)
@@ -59,6 +59,24 @@ GraphEdges::find_in_from_to_with_sends (GraphVertex from, GraphVertex to)
        return _from_to_with_sends.end ();
 }
 
+GraphEdges::EdgeMapWithSends::iterator
+GraphEdges::find_recursively_in_from_to_with_sends (GraphVertex from, GraphVertex to)
+{
+       typedef EdgeMapWithSends::iterator Iter;
+       pair<Iter, Iter> r = _from_to_with_sends.equal_range (from);
+       for (Iter i = r.first; i != r.second; ++i) {
+               if (i->second.first == to) {
+                       return i;
+               }
+               GraphEdges::EdgeMapWithSends::iterator t = find_recursively_in_from_to_with_sends (i->second.first, to);
+               if (t != _from_to_with_sends.end ()) {
+                       return t;
+               }
+       }
+
+       return _from_to_with_sends.end ();
+}
+
 /** @param via_sends_only if non-0, filled in with true if the edge is a
  *  path via a send only.
  *  @return true if the given edge is present.
@@ -78,6 +96,16 @@ GraphEdges::has (GraphVertex from, GraphVertex to, bool* via_sends_only)
        return true;
 }
 
+bool
+GraphEdges::feeds (GraphVertex from, GraphVertex to)
+{
+       EdgeMapWithSends::iterator i = find_recursively_in_from_to_with_sends (from, to);
+       if (i == _from_to_with_sends.end ()) {
+               return false;
+       }
+       return true;
+}
+
 /** @return the vertices that are fed from `r' */
 set<GraphVertex>
 GraphEdges::from (GraphVertex r) const