Make Bundle::disconnect() more robust
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Tue, 29 Aug 2017 08:33:53 +0000 (10:33 +0200)
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Tue, 29 Aug 2017 08:53:41 +0000 (10:53 +0200)
Instead of asserting or crashing if the number of channels of both
bundles don't match, just try to disconnect as much as possible.

libs/ardour/bundle.cc

index b12455b38b4c4215fa73d3bbe77f5e172eeaa01b..081d790b6c170621f17445d85ebbd309af742b3d 100644 (file)
@@ -361,16 +361,23 @@ Bundle::connect (boost::shared_ptr<Bundle> other, AudioEngine & engine,
 void
 Bundle::disconnect (boost::shared_ptr<Bundle> other, AudioEngine & engine)
 {
-       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);
+       for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
+               uint32_t N = min(our_count.n(*t), other_count.n(*t));
+               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.disconnect (*j, *k);
+                       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.disconnect (*j, *k);
+                               }
                        }
                }
        }