Make Bundle::connected_to() optionally check for exclusivity
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Mon, 28 Aug 2017 10:18:02 +0000 (12:18 +0200)
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Mon, 28 Aug 2017 15:54:32 +0000 (17:54 +0200)
If the new optional argument is true, then the first bundle will also
check if it has other connections than to the given bundle.

libs/ardour/ardour/bundle.h
libs/ardour/bundle.cc

index 54d0e602b35d87acec27e9e41413eb6e464d5f3b..a84ae624f6e0f7062ba1b347f8b4267a6966cf31 100644 (file)
@@ -101,7 +101,8 @@ class LIBARDOUR_API Bundle : public PBD::ScopedConnectionList
                      bool allow_partial = false);
        void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
        bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &,
-                          DataType type = DataType::NIL);
+                          DataType type = DataType::NIL,
+                          bool exclusive = false);
        bool connected_to_anything (AudioEngine &);
        bool has_same_ports (boost::shared_ptr<Bundle>) const;
        uint32_t type_channel_to_overall (DataType, uint32_t) const;
index 33f71dcecd2149cca3341aca399cdc51bf0408f9..b12455b38b4c4215fa73d3bbe77f5e172eeaa01b 100644 (file)
@@ -434,8 +434,12 @@ Bundle::emit_changed (Change c)
        }
 }
 
-/* @return true if a Bundle is connected to another.
- * @param type: if not NIL, restrict the check to channels of that type. */
+/** This must not be called in code executed as a response to a backend event,
+ *  as it may query the backend in the same thread where it's waiting for us.
+ * @return true if a Bundle is connected to another.
+ * @param type: if not NIL, restrict the check to channels of that type.
+ * @param exclusive: if true, additionally check if the bundle is connected
+ *                   only to |other|, and return false if not. */
 bool
 Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine,
                       DataType type, bool exclusive)
@@ -446,7 +450,7 @@ Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine,
        if (type == DataType::NIL) {
                for (DataType::iterator t = DataType::begin();
                                        t != DataType::end(); ++t) {
-                       if (!connected_to(other, engine, *t))
+                       if (!connected_to(other, engine, *t, exclusive))
                                return false;
                }
                return true;
@@ -456,6 +460,8 @@ Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine,
        if (other->nchannels().n(type) != N)
                return false;
 
+       vector<string> port_connections;
+
        for (uint32_t i = 0; i < N; ++i) {
                Bundle::PortList const & our_ports =
                        channel_ports (type_channel_to_overall(type, i));
@@ -480,6 +486,13 @@ Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine,
                                        return false;
                                }
                        }
+
+                       if (exclusive && p) {
+                               port_connections.clear();
+                               p->get_connections(port_connections);
+                               if (port_connections.size() != other_ports.size())
+                                       return false;
+                       }
                }
        }