Add connected_to ()
authorCarl Hetherington <carl@carlh.net>
Wed, 11 Feb 2009 02:13:15 +0000 (02:13 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 11 Feb 2009 02:13:15 +0000 (02:13 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@4527 d708f5d6-7413-0410-9779-e7cbd77b26cf

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

index 77d5e231960bfdb0cda7385094b3e99d2df1748b..98344e840681e51bb3c4d71233fa791b2cc98aaf 100644 (file)
@@ -88,6 +88,7 @@ class Bundle : public sigc::trackable
        void add_channels_from_bundle (boost::shared_ptr<Bundle>);
        void connect (boost::shared_ptr<Bundle>, AudioEngine &);
        void disconnect (boost::shared_ptr<Bundle>, AudioEngine &);
+       bool connected_to (boost::shared_ptr<Bundle>, AudioEngine &);
 
        /** Set the name.
         *  @param n New name.
index f90b84ff2512e321a7ea107836e21aac6ed93e5f..fc109c33a94ac91ae443d951e3d8be7999bdef5b 100644 (file)
@@ -23,6 +23,7 @@
 #include <ardour/ardour.h>
 #include <ardour/bundle.h>
 #include <ardour/audioengine.h>
+#include <ardour/port.h>
 #include <pbd/xml++.h>
 
 #include "i18n.h"
@@ -395,3 +396,38 @@ Bundle::emit_changed (Change c)
        }
 }
                
+bool
+Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine)
+{
+       if (_ports_are_inputs == other->_ports_are_inputs ||
+           _type != other->_type ||
+           nchannels() != other->nchannels ()) {
+
+               return false;
+       }
+
+       for (uint32_t i = 0; i < nchannels(); ++i) {
+               Bundle::PortList const & A = channel_ports (i);
+               Bundle::PortList const & B = other->channel_ports (i);
+               
+               for (uint32_t j = 0; j < A.size(); ++j) {
+                       for (uint32_t k = 0; k < B.size(); ++k) {
+
+                               Port* p = engine.get_port_by_name (A[j]);
+                               Port* q = engine.get_port_by_name (B[k]);
+
+                               if (!p && !q) {
+                                       return false;
+                               }
+
+                               if (p && !p->connected_to (B[k])) {
+                                       return false;
+                               } else if (q && !q->connected_to (A[j])) {
+                                       return false;
+                               }
+                       }
+               }
+       }
+
+       return true;
+}