remove Glib::ustring from libardour; allow any characters except '/' and '\' in paths...
[ardour.git] / libs / ardour / io.cc
index 36cc25a31585b07f3e208f79e5354870680efd4c..ed2b23f7ee918348a97a11924466ee445c9a0543 100644 (file)
@@ -111,6 +111,10 @@ IO::check_bundles_connected ()
        check_bundles (_bundles_connected, ports());
 }
 
+/** Check the bundles in list to see which are connected to a given PortSet,
+ *  and update list with those that are connected such that every port on every
+ *  bundle channel x is connected to port x in ports.
+ */
 void
 IO::check_bundles (std::vector<UserBundleInfo*>& list, const PortSet& ports)
 {
@@ -118,9 +122,9 @@ IO::check_bundles (std::vector<UserBundleInfo*>& list, const PortSet& ports)
 
        for (std::vector<UserBundleInfo*>::iterator i = list.begin(); i != list.end(); ++i) {
 
-               uint32_t const N = (*i)->bundle->nchannels ();
+               uint32_t const N = (*i)->bundle->nchannels().n_total();
 
-               if (_ports.num_ports (default_type()) < N) {
+               if (_ports.num_ports() < N) {
                        continue;
                }
 
@@ -182,7 +186,7 @@ IO::disconnect (Port* our_port, string other_port, void* src)
                }
        }
 
-       changed (ConnectionsChanged, src); /* EMIT SIGNAL */
+       changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */
        _session.set_dirty ();
 
        return 0;
@@ -215,7 +219,7 @@ IO::connect (Port* our_port, string other_port, void* src)
                }
        }
 
-       changed (ConnectionsChanged, src); /* EMIT SIGNAL */
+       changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */
        _session.set_dirty ();
        return 0;
 }
@@ -223,20 +227,23 @@ IO::connect (Port* our_port, string other_port, void* src)
 int
 IO::remove_port (Port* port, void* src)
 {
-       IOChange change (NoChange);
+       IOChange change;
 
        {
                BLOCK_PROCESS_CALLBACK ();
 
-
                {
                        Glib::Mutex::Lock lm (io_lock);
 
+                       ChanCount before = _ports.count ();
+
                        if (_ports.remove(port)) {
-                               change = IOChange (change|ConfigurationChanged);
+                               change.type = IOChange::Type (change.type | IOChange::ConfigurationChanged);
+                               change.before = before;
+                               change.after = _ports.count ();
 
                                if (port->connected()) {
-                                       change = IOChange (change|ConnectionsChanged);
+                                       change.type = IOChange::Type (change.type | IOChange::ConnectionsChanged);
                                }
 
                                _session.engine().unregister_port (*port);
@@ -247,11 +254,11 @@ IO::remove_port (Port* port, void* src)
                PortCountChanged (n_ports()); /* EMIT SIGNAL */
        }
 
-       if (change & ConfigurationChanged) {
+       if (change.type & IOChange::ConfigurationChanged) {
                setup_bundle ();
        }
 
-       if (change != NoChange) {
+       if (change.type != IOChange::NoChange) {
                changed (change, src);
                _session.set_dirty ();
                return 0;
@@ -260,9 +267,9 @@ IO::remove_port (Port* port, void* src)
        return -1;
 }
 
-/** Add an output port.
+/** Add a port.
  *
- * @param destination Name of input port to connect new port to.
+ * @param destination Name of port to connect new port to.
  * @param src Source for emitted ConfigurationChanged signal.
  * @param type Data type of port.  Default value (NIL) will use this IO's default type.
  */
@@ -275,6 +282,8 @@ IO::add_port (string destination, void* src, DataType type)
                type = _default_type;
        }
 
+       IOChange change;
+
        {
                BLOCK_PROCESS_CALLBACK ();
 
@@ -282,7 +291,7 @@ IO::add_port (string destination, void* src, DataType type)
                {
                        Glib::Mutex::Lock lm (io_lock);
 
-                       /* Create a new output port */
+                       /* Create a new port */
 
                        string portname = build_legal_port_name (type);
 
@@ -298,6 +307,7 @@ IO::add_port (string destination, void* src, DataType type)
                                }
                        }
 
+                       change.before = _ports.count ();
                        _ports.add (our_port);
                }
 
@@ -311,7 +321,9 @@ IO::add_port (string destination, void* src, DataType type)
        }
 
        // pan_changed (src); /* EMIT SIGNAL */
-       changed (ConfigurationChanged, src); /* EMIT SIGNAL */
+       change.type = IOChange::ConfigurationChanged;
+       change.after = _ports.count ();
+       changed (change, src); /* EMIT SIGNAL */
        setup_bundle ();
        _session.set_dirty ();
 
@@ -335,7 +347,7 @@ IO::disconnect (void* src)
                }
        }
 
-       changed (ConnectionsChanged, src); /* EMIT SIGNAL */
+       changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */
 
        return 0;
 }
@@ -383,7 +395,7 @@ IO::ensure_ports_locked (ChanCount count, bool clear, void* /*src*/)
 
                        catch (AudioEngine::PortRegistrationFailure& err) {
                                /* pass it on */
-                               throw AudioEngine::PortRegistrationFailure();
+                               throw;
                        }
 
                        _ports.add (port);
@@ -417,6 +429,10 @@ IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src)
                return 0;
        }
 
+       IOChange change;
+
+       change.before = _ports.count ();
+       
        if (lockit) {
                BLOCK_PROCESS_CALLBACK ();
                Glib::Mutex::Lock im (io_lock);
@@ -426,7 +442,9 @@ IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src)
        }
 
        if (changed) {
-               this->changed (ConfigurationChanged, src); /* EMIT SIGNAL */
+               change.after = _ports.count ();
+               change.type = IOChange::ConfigurationChanged;
+               this->changed (change, src); /* EMIT SIGNAL */
                setup_bundle ();
                _session.set_dirty ();
        }
@@ -771,7 +789,7 @@ IO::get_port_counts (const XMLNode& node, int version, ChanCount& n, boost::shar
        if ((prop = node.property ("connection")) != 0) {
 
                if ((c = find_possible_bundle (prop->value())) != 0) {
-                       n = ChanCount::max (n, ChanCount(c->type(), c->nchannels()));
+                       n = ChanCount::max (n, c->nchannels());
                }
                return 0;
        }
@@ -780,7 +798,7 @@ IO::get_port_counts (const XMLNode& node, int version, ChanCount& n, boost::shar
 
                if ((*iter)->name() == X_("Bundle")) {
                        if ((c = find_possible_bundle (prop->value())) != 0) {
-                               n = ChanCount::max (n, ChanCount(c->type(), c->nchannels()));
+                               n = ChanCount::max (n, c->nchannels());
                                return 0;
                        } else {
                                return -1;
@@ -1166,7 +1184,7 @@ IO::connect_ports_to_bundle (boost::shared_ptr<Bundle> c, void* src)
                }
        }
 
-       changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */
+       changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */
        return 0;
 }
 
@@ -1196,7 +1214,7 @@ IO::disconnect_ports_from_bundle (boost::shared_ptr<Bundle> c, void* src)
                }
        }
 
-       changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */
+       changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */
        return 0;
 }
 
@@ -1328,8 +1346,6 @@ IO::setup_bundle ()
 
        _bundle->suspend_signals ();
 
-       _bundle->set_type (default_type ());
-
        _bundle->remove_channels ();
 
        if (_direction == Input) {
@@ -1338,10 +1354,17 @@ IO::setup_bundle ()
                snprintf(buf, sizeof (buf), _("%s out"), _name.val().c_str());
        }
         _bundle->set_name (buf);
-       uint32_t const ni = _ports.num_ports();
-       for (uint32_t i = 0; i < ni; ++i) {
-               _bundle->add_channel (bundle_channel_name (i, ni));
-               _bundle->set_port (i, _session.engine().make_port_name_non_relative (_ports.port(i)->name()));
+
+       int c = 0;
+       for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
+
+               uint32_t const N = _ports.count().get (*i);
+               for (uint32_t j = 0; j < N; ++j) {
+                       _bundle->add_channel (bundle_channel_name (j, N, *i), *i);
+                       _bundle->set_port (c, _session.engine().make_port_name_non_relative (_ports.port(*i, j)->name()));
+                       ++c;
+               }
+
        }
 
        _bundle->resume_signals ();
@@ -1395,18 +1418,27 @@ IO::UserBundleInfo::UserBundleInfo (IO* io, boost::shared_ptr<UserBundle> b)
 }
 
 std::string
-IO::bundle_channel_name (uint32_t c, uint32_t n) const
+IO::bundle_channel_name (uint32_t c, uint32_t n, DataType t) const
 {
        char buf[32];
 
-       switch (n) {
-       case 1:
-               return _("mono");
-       case 2:
-               return c == 0 ? _("L") : _("R");
-       default:
+       if (t == DataType::AUDIO) {
+
+               switch (n) {
+               case 1:
+                       return _("mono");
+               case 2:
+                       return c == 0 ? _("L") : _("R");
+               default:
+                       snprintf (buf, sizeof(buf), _("%d"), (c + 1));
+                       return buf;
+               }
+
+       } else {
+
                snprintf (buf, sizeof(buf), _("%d"), (c + 1));
                return buf;
+
        }
 
        return "";