diff --git a/libs/ardour/ardour/bundle.h b/libs/ardour/ardour/bundle.h index fe0de29c76..704af61256 100644 --- a/libs/ardour/ardour/bundle.h +++ b/libs/ardour/ardour/bundle.h @@ -97,7 +97,8 @@ class LIBARDOUR_API Bundle : public PBD::ScopedConnectionList void remove_channel (uint32_t); void remove_channels (); void add_channels_from_bundle (boost::shared_ptr); - void connect (boost::shared_ptr, AudioEngine &); + 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_anything (AudioEngine &); diff --git a/libs/ardour/bundle.cc b/libs/ardour/bundle.cc index 5e57eb3e10..bdf2446077 100644 --- a/libs/ardour/bundle.cc +++ b/libs/ardour/bundle.cc @@ -322,20 +322,37 @@ Bundle::add_channels_from_bundle (boost::shared_ptr other) * with another bundle's channels. * @param other Other bundle. * @param engine AudioEngine to use to make the connections. + * @param allow_partial whether to allow leaving unconnected channels types, + * or require that the ChanCounts match exactly (default false). */ void -Bundle::connect (boost::shared_ptr other, AudioEngine & engine) +Bundle::connect (boost::shared_ptr other, AudioEngine & engine, + bool allow_partial) { - uint32_t const N = n_total(); - assert (N == other->n_total()); + ChanCount our_count = nchannels(); + ChanCount other_count = other->nchannels(); - for (uint32_t i = 0; i < N; ++i) { - Bundle::PortList const & our_ports = channel_ports (i); - Bundle::PortList const & other_ports = other->channel_ports (i); + if (!allow_partial && our_count != other_count) { + assert (our_count == other_count); + return; + } - for (Bundle::PortList::const_iterator j = our_ports.begin(); j != our_ports.end(); ++j) { - for (Bundle::PortList::const_iterator k = other_ports.begin(); k != other_ports.end(); ++k) { - engine.connect (*j, *k); + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + uint32_t N = our_count.n(*t); + if (N != other_count.n(*t)) + continue; + for (uint32_t i = 0; i < N; ++i) { + Bundle::PortList const & our_ports = + channel_ports (type_channel_to_overall(*t, i)); + Bundle::PortList const & other_ports = + other->channel_ports (other->type_channel_to_overall(*t, i)); + + for (Bundle::PortList::const_iterator j = our_ports.begin(); + j != our_ports.end(); ++j) { + for (Bundle::PortList::const_iterator k = other_ports.begin(); + k != other_ports.end(); ++k) { + engine.connect (*j, *k); + } } } }