X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fio.cc;h=d6b5b1e7db3d5afea189c18d7bbe693582067140;hb=ad547e53fc168410b22628a8cb125e8d4da4b293;hp=4a762c8eb73237cb48c121b9d4b3381a27df742b;hpb=d1e7733a4a2eda4ce39dfd60d6410fb28ec69479;p=ardour.git diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 4a762c8eb7..d6b5b1e7db 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2006 Paul Davis + Copyright (C) 2000-2006 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,12 +18,12 @@ #include #include +#include + #include #include #include -#include - #include #include @@ -41,7 +41,6 @@ #include "ardour/midi_port.h" #include "ardour/session.h" #include "ardour/cycle_timer.h" -#include "ardour/panner.h" #include "ardour/buffer_set.h" #include "ardour/meter.h" #include "ardour/amp.h" @@ -49,19 +48,7 @@ #include "i18n.h" -#include - -/* - A bug in OS X's cmath that causes isnan() and isinf() to be - "undeclared". the following works around that -*/ - -#if defined(__APPLE__) && defined(__MACH__) -extern "C" int isnan (double); -extern "C" int isinf (double); -#endif - -#define BLOCK_PROCESS_CALLBACK() Glib::Mutex::Lock em (_session.engine().process_lock()) +#define BLOCK_PROCESS_CALLBACK() Glib::Mutex::Lock em (AudioEngine::instance()->process_lock()) using namespace std; using namespace ARDOUR; @@ -69,8 +56,8 @@ using namespace PBD; const string IO::state_node_name = "IO"; bool IO::connecting_legal = false; -sigc::signal IO::ConnectingLegal; -sigc::signal IO::PortCountChanged; +PBD::Signal0 IO::ConnectingLegal; +PBD::Signal1 IO::PortCountChanged; /** @param default_type The type of port that will be created by ensure_io * and friends if no type is explicitly requested (to avoid breakage). @@ -82,8 +69,7 @@ IO::IO (Session& s, const string& name, Direction dir, DataType default_type) { _active = true; pending_state_node = 0; - setup_bundles (); - cerr << "+++ IO created with name = " << _name << endl; + setup_bundle (); } IO::IO (Session& s, const XMLNode& node, DataType dt) @@ -94,10 +80,8 @@ IO::IO (Session& s, const XMLNode& node, DataType dt) _active = true; pending_state_node = 0; - set_state (node); - - setup_bundles (); - cerr << "+++ IO created from XML with name = " << _name << endl; + set_state (node, Stateful::loading_state_version); + setup_bundle (); } IO::~IO () @@ -127,16 +111,20 @@ 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& list, const PortSet& ports) +IO::check_bundles (std::vector& list, const PortSet& ports) { - std::vector new_list; - - for (std::vector::iterator i = list.begin(); i != list.end(); ++i) { + std::vector new_list; + + for (std::vector::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; } @@ -144,7 +132,7 @@ IO::check_bundles (std::vector& list, const PortSet& ports) for (uint32_t j = 0; j < N; ++j) { /* Every port on bundle channel j must be connected to our input j */ - Bundle::PortList const pl = i->bundle->channel_ports (j); + Bundle::PortList const pl = (*i)->bundle->channel_ports (j); for (uint32_t k = 0; k < pl.size(); ++k) { if (ports.port(j)->connected_to (pl[k]) == false) { ok = false; @@ -160,7 +148,7 @@ IO::check_bundles (std::vector& list, const PortSet& ports) if (ok) { new_list.push_back (*i); } else { - i->changed.disconnect (); + delete *i; } } @@ -175,20 +163,20 @@ IO::disconnect (Port* our_port, string other_port, void* src) return 0; } - { + { BLOCK_PROCESS_CALLBACK (); - + { Glib::Mutex::Lock lm (io_lock); - + /* check that our_port is really one of ours */ - + if ( ! _ports.contains(our_port)) { return -1; } - + /* disconnect it from the source */ - + if (our_port->disconnect (other_port)) { error << string_compose(_("IO: cannot disconnect port %1 from %2"), our_port->name(), other_port) << endmsg; return -1; @@ -198,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; @@ -213,16 +201,16 @@ IO::connect (Port* our_port, string other_port, void* src) { BLOCK_PROCESS_CALLBACK (); - + { Glib::Mutex::Lock lm (io_lock); - + /* check that our_port is really one of ours */ - + if ( ! _ports.contains(our_port) ) { return -1; } - + /* connect it to the source */ if (our_port->connect (other_port)) { @@ -231,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; } @@ -239,21 +227,24 @@ 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); check_bundles_connected (); @@ -263,11 +254,11 @@ IO::remove_port (Port* port, void* src) PortCountChanged (n_ports()); /* EMIT SIGNAL */ } - if (change == ConfigurationChanged) { - setup_bundles (); + if (change.type & IOChange::ConfigurationChanged) { + setup_bundle (); } - if (change != NoChange) { + if (change.type != IOChange::NoChange) { changed (change, src); _session.set_dirty (); return 0; @@ -291,15 +282,17 @@ IO::add_port (string destination, void* src, DataType type) type = _default_type; } + IOChange change; + { BLOCK_PROCESS_CALLBACK (); - - { + + { Glib::Mutex::Lock lm (io_lock); - + /* Create a new output port */ - + string portname = build_legal_port_name (type); if (_direction == Input) { @@ -314,6 +307,7 @@ IO::add_port (string destination, void* src, DataType type) } } + change.before = _ports.count (); _ports.add (our_port); } @@ -325,10 +319,12 @@ IO::add_port (string destination, void* src, DataType type) return -1; } } - + // pan_changed (src); /* EMIT SIGNAL */ - changed (ConfigurationChanged, src); /* EMIT SIGNAL */ - setup_bundles (); + change.type = IOChange::ConfigurationChanged; + change.after = _ports.count (); + changed (change, src); /* EMIT SIGNAL */ + setup_bundle (); _session.set_dirty (); return 0; @@ -337,12 +333,12 @@ IO::add_port (string destination, void* src, DataType type) int IO::disconnect (void* src) { - { + { BLOCK_PROCESS_CALLBACK (); - + { Glib::Mutex::Lock lm (io_lock); - + for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) { i->disconnect_all (); } @@ -350,26 +346,26 @@ IO::disconnect (void* src) check_bundles_connected (); } } - - changed (ConnectionsChanged, src); /* EMIT SIGNAL */ - + + changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */ + return 0; } bool -IO::ensure_ports_locked (ChanCount count, bool clear, void* src) +IO::ensure_ports_locked (ChanCount count, bool clear, void* /*src*/) { Port* port = 0; bool changed = false; - + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { - + const size_t n = count.get(*t); - + /* remove unused ports */ for (size_t i = n_ports().get(*t); i > n; --i) { port = _ports.port(*t, i-1); - + assert(port); _ports.remove(port); _session.engine().unregister_port (*port); @@ -399,20 +395,20 @@ IO::ensure_ports_locked (ChanCount count, bool clear, void* src) catch (AudioEngine::PortRegistrationFailure& err) { /* pass it on */ - throw AudioEngine::PortRegistrationFailure(); + throw; } _ports.add (port); changed = true; } } - + if (changed) { check_bundles_connected (); PortCountChanged (n_ports()); /* EMIT SIGNAL */ _session.set_dirty (); } - + if (clear) { /* disconnect all existing ports so that we get a fresh start */ for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) { @@ -429,14 +425,14 @@ IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src) { bool changed = false; - cerr << "Ensure that IO " << _name << '/' << (_direction == Input ? "input" : "output") - << " has " << count << endl; - if (count == n_ports() && !clear) { - cerr << "\talready has " << n_ports() << endl; return 0; } + IOChange change; + + change.before = _ports.count (); + if (lockit) { BLOCK_PROCESS_CALLBACK (); Glib::Mutex::Lock im (io_lock); @@ -446,13 +442,13 @@ IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src) } if (changed) { - this->changed (ConfigurationChanged, src); /* EMIT SIGNAL */ - setup_bundles (); + change.after = _ports.count (); + change.type = IOChange::ConfigurationChanged; + this->changed (change, src); /* EMIT SIGNAL */ + setup_bundle (); _session.set_dirty (); } - cerr << "\t@" << this << " established with " << n_ports() << endl; - return 0; } @@ -469,7 +465,7 @@ IO::get_state (void) } XMLNode& -IO::state (bool full_state) +IO::state (bool /*full_state*/) { XMLNode* node = new XMLNode (state_node_name); char buf[64]; @@ -485,18 +481,19 @@ IO::state (bool full_state) node->add_property ("direction", enum_2_string (_direction)); node->add_property ("default-type", _default_type.to_string()); - for (std::vector::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) { + for (std::vector::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) { XMLNode* n = new XMLNode ("Bundle"); - n->add_property ("name", i->bundle->name ()); + n->add_property ("name", (*i)->bundle->name ()); node->add_child_nocopy (*n); } for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) { - + vector connections; XMLNode* pnode = new XMLNode (X_("Port")); pnode->add_property (X_("type"), i->type().to_string()); + pnode->add_property (X_("name"), i->name()); if (i->get_connections (connections)) { @@ -508,11 +505,14 @@ IO::state (bool full_state) to be re-established even when our client name is different. */ - - pnode->add_property (X_("connection"), _session.engine().make_port_name_relative (*ci)); - } + + XMLNode* cnode = new XMLNode (X_("Connection")); + + cnode->add_property (X_("other"), _session.engine().make_port_name_relative (*ci)); + pnode->add_child_nocopy (*cnode); + } } - + node->add_child_nocopy (*pnode); } @@ -520,8 +520,14 @@ IO::state (bool full_state) } int -IO::set_state (const XMLNode& node) +IO::set_state (const XMLNode& node, int version) { + /* callers for version < 3000 need to call set_state_2X directly, as A3 IOs + * are input OR output, not both, so the direction needs to be specified + * by the caller. + */ + assert (version >= 3000); + const XMLProperty* prop; XMLNodeConstIterator iter; LocaleGuard lg (X_("POSIX")); @@ -534,7 +540,7 @@ IO::set_state (const XMLNode& node) error << string_compose(_("incorrect XML node \"%1\" passed to IO object"), node.name()) << endmsg; return -1; } - + if ((prop = node.property ("name")) != 0) { set_name (prop->value()); } @@ -552,25 +558,76 @@ IO::set_state (const XMLNode& node) _direction = (Direction) string_2_enum (prop->value(), _direction); } - if (!connecting_legal) { + if (create_ports (node, version)) { + return -1; + } + + if (connecting_legal) { + + if (make_connections (node, version, false)) { + return -1; + } + + } else { + pending_state_node = new XMLNode (node); - } + pending_state_node_version = version; + pending_state_node_in = false; + ConnectingLegal.connect_same_thread (connection_legal_c, boost::bind (&IO::connecting_became_legal, this)); + } - if (create_ports (node)) { + + return 0; +} + +int +IO::set_state_2X (const XMLNode& node, int version, bool in) +{ + const XMLProperty* prop; + XMLNodeConstIterator iter; + LocaleGuard lg (X_("POSIX")); + + /* force use of non-localized representation of decimal point, + since we use it a lot in XML files and so forth. + */ + + if (node.name() != state_node_name) { + error << string_compose(_("incorrect XML node \"%1\" passed to IO object"), node.name()) << endmsg; + return -1; + } + + if ((prop = node.property ("name")) != 0) { + set_name (prop->value()); + } + + if ((prop = node.property (X_("default-type"))) != 0) { + _default_type = DataType(prop->value()); + assert(_default_type != DataType::NIL); + } + + if ((prop = node.property ("id")) != 0) { + _id = prop->value (); + } + + _direction = in ? Input : Output; + + if (create_ports (node, version)) { return -1; } if (connecting_legal) { - - if (make_connections (node)) { + + if (make_connections_2X (node, version, in)) { return -1; } } else { - - connection_legal_c = ConnectingLegal.connect (mem_fun (*this, &IO::connecting_became_legal)); - } + pending_state_node = new XMLNode (node); + pending_state_node_version = version; + pending_state_node_in = in; + ConnectingLegal.connect_same_thread (connection_legal_c, boost::bind (&IO::connecting_became_legal, this)); + } return 0; } @@ -584,8 +641,8 @@ IO::connecting_became_legal () connection_legal_c.disconnect (); - ret = make_connections (*pending_state_node); - + ret = make_connections (*pending_state_node, pending_state_node_version, pending_state_node_in); + delete pending_state_node; pending_state_node = 0; @@ -598,7 +655,7 @@ IO::find_possible_bundle (const string &desired_name) static const string digits = "0123456789"; const string &default_name = (_direction == Input ? _("in") : _("out")); const string &bundle_type_name = (_direction == Input ? _("input") : _("output")); - + boost::shared_ptr c = _session.bundle_by_name (desired_name); if (!c) { @@ -612,7 +669,7 @@ IO::find_possible_bundle (const string &desired_name) // find numeric suffix of desired name bundle_number = 0; - + last_non_digit_pos = desired_name.find_last_not_of(digits); if (last_non_digit_pos != string::npos) { @@ -620,16 +677,16 @@ IO::find_possible_bundle (const string &desired_name) s << desired_name.substr(last_non_digit_pos); s >> bundle_number; } - + // see if it's a stereo connection e.g. "in 3+4" if (last_non_digit_pos > 1 && desired_name[last_non_digit_pos] == '+') { - int left_bundle_number = 0; string::size_type left_last_non_digit_pos; left_last_non_digit_pos = desired_name.find_last_not_of(digits, last_non_digit_pos-1); if (left_last_non_digit_pos != string::npos) { + int left_bundle_number = 0; stringstream s; s << desired_name.substr(left_last_non_digit_pos, last_non_digit_pos-1); s >> left_bundle_number; @@ -648,22 +705,22 @@ IO::find_possible_bundle (const string &desired_name) // find highest set bit mask = 1; while ((mask <= bundle_number) && (mask <<= 1)) {} - - // "wrap" bundle number into largest possible power of 2 + + // "wrap" bundle number into largest possible power of 2 // that works... while (mask) { if (bundle_number & mask) { bundle_number &= ~mask; - + stringstream s; s << default_name << " " << bundle_number + 1; if (stereo) { s << "+" << bundle_number + 2; } - + possible_name = s.str(); if ((c = _session.bundle_by_name (possible_name)) != 0) { @@ -687,8 +744,40 @@ IO::find_possible_bundle (const string &desired_name) } int -IO::get_port_counts (const XMLNode& node, ChanCount& n, boost::shared_ptr& c) +IO::get_port_counts_2X (XMLNode const & node, int /*version*/, ChanCount& n, boost::shared_ptr& /*c*/) { + XMLProperty const * prop; + XMLNodeList children = node.children (); + + uint32_t n_audio = 0; + + for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) { + + if ((prop = node.property ("inputs")) != 0 && _direction == Input) { + n_audio = count (prop->value().begin(), prop->value().end(), '{'); + } else if ((prop = node.property ("input-connection")) != 0 && _direction == Input) { + n_audio = 1; + } else if ((prop = node.property ("outputs")) != 0 && _direction == Output) { + n_audio = count (prop->value().begin(), prop->value().end(), '{'); + } else if ((prop = node.property ("output-connection")) != 0 && _direction == Output) { + n_audio = 2; + } + } + + ChanCount cnt; + cnt.set_audio (n_audio); + n = ChanCount::max (n, cnt); + + return 0; +} + +int +IO::get_port_counts (const XMLNode& node, int version, ChanCount& n, boost::shared_ptr& c) +{ + if (version < 3000) { + return get_port_counts_2X (node, version, n, c); + } + XMLProperty const * prop; XMLNodeConstIterator iter; uint32_t n_audio = 0; @@ -700,16 +789,16 @@ IO::get_port_counts (const XMLNode& node, ChanCount& n, boost::shared_ptrvalue())) != 0) { - n = ChanCount::max (n, ChanCount(c->type(), c->nchannels())); + n = ChanCount::max (n, c->nchannels()); } return 0; } - + for (iter = node.children().begin(); iter != node.children().end(); ++iter) { 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; @@ -730,20 +819,18 @@ IO::get_port_counts (const XMLNode& node, ChanCount& n, boost::shared_ptr c; - - get_port_counts (node, n, c); - - cerr << _name << " got " << n << " from XML node" << endl; + + get_port_counts (node, version, n, c); if (ensure_ports (n, true, true, this)) { error << string_compose(_("%1: cannot create I/O ports"), _name) << endmsg; @@ -756,25 +843,13 @@ IO::create_ports (const XMLNode& node) } int -IO::make_connections (const XMLNode& node) +IO::make_connections (const XMLNode& node, int version, bool in) { - const XMLProperty* prop; - - if ((prop = node.property ("connection")) != 0) { - boost::shared_ptr c = find_possible_bundle (prop->value()); - - if (!c) { - return -1; - } - - if (n_ports().get(c->type()) == c->nchannels() && c->ports_are_outputs()) { - connect_ports_to_bundle (c, this); - } - - return 0; - } + if (version < 3000) { + return make_connections_2X (node, version, in); + } - uint32_t n = 0; + const XMLProperty* prop; for (XMLNodeConstIterator i = node.children().begin(); i != node.children().end(); ++i) { @@ -791,14 +866,131 @@ IO::make_connections (const XMLNode& node) } if ((*i)->name() == "Port") { - Port* p = nth (n++); - XMLProperty* prop = (*i)->property ("connection"); - if (p && prop) { - p->connect (prop->value()); + + prop = (*i)->property (X_("name")); + + if (!prop) { + continue; } + + Port* p = port_by_name (prop->value()); + + if (p) { + for (XMLNodeConstIterator c = (*i)->children().begin(); c != (*i)->children().end(); ++c) { + + XMLNode* cnode = (*c); + + if (cnode->name() != X_("Connection")) { + continue; + } + + if ((prop = cnode->property (X_("other"))) == 0) { + continue; + } + + if (prop) { + p->connect (prop->value()); + } + } + } } } - + + return 0; +} + + +int +IO::make_connections_2X (const XMLNode& node, int /*version*/, bool in) +{ + const XMLProperty* prop; + + /* XXX: bundles ("connections" as was) */ + + if ((prop = node.property ("inputs")) != 0 && in) { + + string::size_type ostart = 0; + string::size_type start = 0; + string::size_type end = 0; + int i = 0; + int n; + vector ports; + + string const str = prop->value (); + + while ((start = str.find_first_of ('{', ostart)) != string::npos) { + start += 1; + + if ((end = str.find_first_of ('}', start)) == string::npos) { + error << string_compose(_("IO: badly formed string in XML node for inputs \"%1\""), str) << endmsg; + return -1; + } + + if ((n = parse_io_string (str.substr (start, end - start), ports)) < 0) { + error << string_compose(_("bad input string in XML node \"%1\""), str) << endmsg; + + return -1; + + } else if (n > 0) { + + + for (int x = 0; x < n; ++x) { + /* XXX: this is a bit of a hack; need to check if it's always valid */ + string::size_type const p = ports[x].find ("/out"); + if (p != string::npos) { + ports[x].replace (p, 4, "/audio_out"); + } + nth(i)->connect (ports[x]); + } + } + + ostart = end+1; + i++; + } + + } + + if ((prop = node.property ("outputs")) != 0 && !in) { + + string::size_type ostart = 0; + string::size_type start = 0; + string::size_type end = 0; + int i = 0; + int n; + vector ports; + + string const str = prop->value (); + + while ((start = str.find_first_of ('{', ostart)) != string::npos) { + start += 1; + + if ((end = str.find_first_of ('}', start)) == string::npos) { + error << string_compose(_("IO: badly formed string in XML node for outputs \"%1\""), str) << endmsg; + return -1; + } + + if ((n = parse_io_string (str.substr (start, end - start), ports)) < 0) { + error << string_compose(_("IO: bad output string in XML node \"%1\""), str) << endmsg; + + return -1; + + } else if (n > 0) { + + for (int x = 0; x < n; ++x) { + /* XXX: this is a bit of a hack; need to check if it's always valid */ + string::size_type const p = ports[x].find ("/in"); + if (p != string::npos) { + ports[x].replace (p, 3, "/audio_in"); + } + nth(i)->connect (ports[x]); + } + } + + ostart = end+1; + i++; + } + } + return 0; } @@ -809,7 +1001,7 @@ IO::set_ports (const string& str) int i; int n; uint32_t nports; - + if ((nports = count (str.begin(), str.end(), '{')) == 0) { return 0; } @@ -838,7 +1030,7 @@ IO::set_ports (const string& str) error << string_compose(_("bad input string in XML node \"%1\""), str) << endmsg; return -1; - + } else if (n > 0) { for (int x = 0; x < n; ++x) { @@ -871,7 +1063,7 @@ IO::parse_io_string (const string& str, vector& ports) ports.push_back (str.substr (opos, pos - opos)); opos = pos + 1; } - + if (opos < str.length()) { ports.push_back (str.substr(opos)); } @@ -892,7 +1084,7 @@ IO::parse_gain_string (const string& str, vector& ports) ports.push_back (str.substr (opos, pos - opos)); opos = pos + 1; } - + if (opos < str.length()) { ports.push_back (str.substr(opos)); } @@ -903,34 +1095,25 @@ IO::parse_gain_string (const string& str, vector& ports) bool IO::set_name (const string& requested_name) { - if (requested_name == _name) { + string name = requested_name; + + if (_name == name) { return true; } - - string name; - Route *rt; - if ( (rt = dynamic_cast(this))) { - name = Route::ensure_track_or_route_name(requested_name, _session); - } else { - name = requested_name; - } - /* replace all colons in the name. i wish we didn't have to do this */ - if (replace_all (name, ":", "-")) { - warning << _("you cannot use colons to name objects with I/O connections") << endmsg; - } + replace_all (name, ":", "-"); for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) { string current_name = i->name(); - current_name.replace (current_name.find (_name), _name.length(), name); + current_name.replace (current_name.find (_name), _name.val().length(), name); i->set_name (current_name); } - bool const r = SessionObject::set_name(name); + bool const r = SessionObject::set_name (name); - setup_bundles (); + setup_bundle (); return r; } @@ -958,7 +1141,7 @@ IO::latency () const for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) { if ((latency = i->total_latency ()) > max_latency) { max_latency = latency; - } + } } return max_latency; @@ -989,19 +1172,19 @@ IO::connect_ports_to_bundle (boost::shared_ptr c, void* src) if (ub) { /* See if we already know about this one */ - std::vector::iterator i = _bundles_connected.begin(); - while (i != _bundles_connected.end() && i->bundle != ub) { + std::vector::iterator i = _bundles_connected.begin(); + while (i != _bundles_connected.end() && (*i)->bundle != ub) { ++i; } if (i == _bundles_connected.end()) { /* We don't, so make a note */ - _bundles_connected.push_back (UserBundleInfo (this, ub)); + _bundles_connected.push_back (new UserBundleInfo (this, ub)); } } } - changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */ + changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */ return 0; } @@ -1013,24 +1196,25 @@ IO::disconnect_ports_from_bundle (boost::shared_ptr c, void* src) Glib::Mutex::Lock lm2 (io_lock); c->disconnect (_bundle, _session.engine()); - + /* If this is a UserBundle, make a note of what we've done */ boost::shared_ptr ub = boost::dynamic_pointer_cast (c); if (ub) { - std::vector::iterator i = _bundles_connected.begin(); - while (i != _bundles_connected.end() && i->bundle != ub) { + std::vector::iterator i = _bundles_connected.begin(); + while (i != _bundles_connected.end() && (*i)->bundle != ub) { ++i; } if (i != _bundles_connected.end()) { + delete *i; _bundles_connected.erase (i); } } } - changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */ + changed (IOChange (IOChange::ConnectionsChanged), src); /* EMIT SIGNAL */ return 0; } @@ -1046,11 +1230,12 @@ int IO::enable_connecting () { connecting_legal = true; - return ConnectingLegal (); + boost::optional r = ConnectingLegal (); + return r.get_value_or (0); } void -IO::bundle_changed (Bundle::Change c) +IO::bundle_changed (Bundle::Change /*c*/) { //XXX // connect_input_ports_to_bundle (_input_bundle, this); @@ -1071,11 +1256,17 @@ IO::build_legal_port_name (DataType type) } else { throw unknown_type(); } - + + /* note that if "in" or "out" are translated it will break a session + across locale switches because a port's connection list will + show (old) translated names, but the current port name will + use the (new) translated name. + */ + if (_direction == Input) { - suffix += _("_in"); + suffix += X_("_in"); } else { - suffix += _("_out"); + suffix += X_("_out"); } // allow up to 4 digits for the output port number, plus the slash, suffix and extra space @@ -1084,9 +1275,9 @@ IO::build_legal_port_name (DataType type) char buf1[name_size+1]; char buf2[name_size+1]; - - snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.c_str(), suffix.c_str()); - + + snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.val().c_str(), suffix.c_str()); + int port_number = find_port_hole (buf1); snprintf (buf2, name_size+1, "%s %d", buf1, port_number); @@ -1141,34 +1332,39 @@ IO::midi(uint32_t n) const } /** - * Setup bundles that describe our inputs and outputs. Also creates bundles if necessary. + * Setup a bundle that describe our inputs or outputs. Also creates the bundle if necessary. */ void -IO::setup_bundles () +IO::setup_bundle () { char buf[32]; if (!_bundle) { - _bundle.reset (new Bundle (true)); + _bundle.reset (new Bundle (_direction == Input)); } _bundle->suspend_signals (); - _bundle->set_type (default_type ()); - _bundle->remove_channels (); if (_direction == Input) { - snprintf(buf, sizeof (buf), _("%s in"), _name.c_str()); + snprintf(buf, sizeof (buf), _("%s in"), _name.val().c_str()); } else { - snprintf(buf, sizeof (buf), _("%s out"), _name.c_str()); + 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 (); @@ -1179,10 +1375,10 @@ BundleList IO::bundles_connected () { BundleList bundles; - + /* User bundles */ - for (std::vector::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) { - bundles.push_back (i->bundle); + for (std::vector::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) { + bundles.push_back ((*i)->bundle); } /* Session bundles */ @@ -1210,7 +1406,7 @@ IO::bundles_connected () } } } - + return bundles; } @@ -1218,24 +1414,31 @@ IO::bundles_connected () IO::UserBundleInfo::UserBundleInfo (IO* io, boost::shared_ptr b) { bundle = b; - changed = b->Changed.connect ( - sigc::mem_fun (*io, &IO::bundle_changed) - ); + b->Changed.connect_same_thread (changed, boost::bind (&IO::bundle_changed, io, _1)); } 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 ""; @@ -1245,11 +1448,11 @@ string IO::name_from_state (const XMLNode& node) { const XMLProperty* prop; - + if ((prop = node.property ("name")) != 0) { return prop->value(); - } - + } + return string(); } @@ -1257,21 +1460,39 @@ void IO::set_name_in_state (XMLNode& node, const string& new_name) { const XMLProperty* prop; - + if ((prop = node.property ("name")) != 0) { node.add_property ("name", new_name); - } + } +} + +bool +IO::connected () const +{ + /* do we have any connections at all? */ + + for (PortSet::const_iterator p = _ports.begin(); p != _ports.end(); ++p) { + if (p->connected()) { + return true; + } + } + + return false; } bool IO::connected_to (boost::shared_ptr other) const { + if (!other) { + return connected (); + } + assert (_direction != other->direction()); uint32_t i, j; uint32_t no = n_ports().n_total(); uint32_t ni = other->n_ports ().n_total(); - + for (i = 0; i < no; ++i) { for (j = 0; j < ni; ++j) { if (nth(i)->connected_to (other->nth(j)->name())) { @@ -1291,14 +1512,14 @@ IO::process_input (boost::shared_ptr proc, sframes_t start_frame, sfr /* don't read the data into new buffers - just use the port buffers directly */ bufs.attach_buffers (_ports, nframes, 0); - proc->run_in_place (bufs, start_frame, end_frame, nframes); + proc->run (bufs, start_frame, end_frame, nframes, true); } void IO::collect_input (BufferSet& bufs, nframes_t nframes, ChanCount offset) { assert(bufs.available() >= _ports.count()); - + if (_ports.count() == ChanCount::ZERO) { return; } @@ -1326,7 +1547,7 @@ void IO::copy_to_outputs (BufferSet& bufs, DataType type, nframes_t nframes, nframes_t offset) { // Copy any buffers 1:1 to outputs - + PortSet::iterator o = _ports.begin(type); BufferSet::iterator i = bufs.begin(type); BufferSet::iterator prev = i; @@ -1338,7 +1559,7 @@ IO::copy_to_outputs (BufferSet& bufs, DataType type, nframes_t nframes, nframes_ ++i; ++o; } - + // Copy last buffer to any extra outputs while (o != _ports.end(type)) { @@ -1347,3 +1568,32 @@ IO::copy_to_outputs (BufferSet& bufs, DataType type, nframes_t nframes, nframes_ ++o; } } + +Port* +IO::port_by_name (const std::string& str) const +{ + /* to be called only from ::set_state() - no locking */ + + for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) { + + const Port& p(*i); + + if (p.name() == str) { + return const_cast(&p); + } + } + + return 0; +} + +bool +IO::physically_connected () const +{ + for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) { + if (i->physically_connected()) { + return true; + } + } + + return false; +}