diff --git a/libs/ardour/ardour/bundle.h b/libs/ardour/ardour/bundle.h index 704af61256..54d0e602b3 100644 --- a/libs/ardour/ardour/bundle.h +++ b/libs/ardour/ardour/bundle.h @@ -100,7 +100,8 @@ class LIBARDOUR_API Bundle : public PBD::ScopedConnectionList void connect (boost::shared_ptr, AudioEngine &, bool allow_partial = false); void disconnect (boost::shared_ptr, AudioEngine &); - bool connected_to (boost::shared_ptr, AudioEngine &); + bool connected_to (boost::shared_ptr, AudioEngine &, + DataType type = DataType::NIL); bool connected_to_anything (AudioEngine &); bool has_same_ports (boost::shared_ptr) const; uint32_t type_channel_to_overall (DataType, uint32_t) const; diff --git a/libs/ardour/bundle.cc b/libs/ardour/bundle.cc index bdf2446077..33f71dcecd 100644 --- a/libs/ardour/bundle.cc +++ b/libs/ardour/bundle.cc @@ -434,30 +434,49 @@ 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. */ bool -Bundle::connected_to (boost::shared_ptr other, AudioEngine & engine) +Bundle::connected_to (boost::shared_ptr other, AudioEngine & engine, + DataType type, bool exclusive) { - if (_ports_are_inputs == other->_ports_are_inputs || nchannels() != other->nchannels()) { + if (_ports_are_inputs == other->_ports_are_inputs) return false; + + if (type == DataType::NIL) { + for (DataType::iterator t = DataType::begin(); + t != DataType::end(); ++t) { + if (!connected_to(other, engine, *t)) + return false; + } + return true; } - for (uint32_t i = 0; i < n_total(); ++i) { - Bundle::PortList const & A = channel_ports (i); - Bundle::PortList const & B = other->channel_ports (i); + uint32_t N = nchannels().n(type); + if (other->nchannels().n(type) != N) + return false; - for (uint32_t j = 0; j < A.size(); ++j) { - for (uint32_t k = 0; k < B.size(); ++k) { + for (uint32_t i = 0; i < N; ++i) { + Bundle::PortList const & our_ports = + channel_ports (type_channel_to_overall(type, i)); + Bundle::PortList const & other_ports = + other->channel_ports (other->type_channel_to_overall(type, i)); - boost::shared_ptr p = engine.get_port_by_name (A[j]); - boost::shared_ptr q = engine.get_port_by_name (B[k]); + for (Bundle::PortList::const_iterator j = our_ports.begin(); + j != our_ports.end(); ++j) { + boost::shared_ptr p = engine.get_port_by_name(*j); + + for (Bundle::PortList::const_iterator k = other_ports.begin(); + k != other_ports.end(); ++k) { + boost::shared_ptr q = engine.get_port_by_name(*k); if (!p && !q) { return false; } - if (p && !p->connected_to (B[k])) { + if (p && !p->connected_to (*k)) { return false; - } else if (q && !q->connected_to (A[j])) { + } else if (q && !q->connected_to (*j)) { return false; } }