2 Copyright (C) 2000-2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <sigc++/bind.h>
28 #include <glibmm/thread.h>
30 #include "pbd/xml++.h"
31 #include "pbd/replace_all.h"
32 #include "pbd/unknown_type.h"
33 #include "pbd/enumwriter.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/buffer.h"
37 #include "ardour/io.h"
38 #include "ardour/route.h"
39 #include "ardour/port.h"
40 #include "ardour/audio_port.h"
41 #include "ardour/midi_port.h"
42 #include "ardour/session.h"
43 #include "ardour/cycle_timer.h"
44 #include "ardour/panner.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/meter.h"
47 #include "ardour/amp.h"
48 #include "ardour/user_bundle.h"
55 A bug in OS X's cmath that causes isnan() and isinf() to be
56 "undeclared". the following works around that
59 #if defined(__APPLE__) && defined(__MACH__)
60 extern "C" int isnan (double);
61 extern "C" int isinf (double);
64 #define BLOCK_PROCESS_CALLBACK() Glib::Mutex::Lock em (_session.engine().process_lock())
67 using namespace ARDOUR;
70 const string IO::state_node_name = "IO";
71 bool IO::connecting_legal = false;
72 sigc::signal<int> IO::ConnectingLegal;
73 sigc::signal<void,ChanCount> IO::PortCountChanged;
75 /** @param default_type The type of port that will be created by ensure_io
76 * and friends if no type is explicitly requested (to avoid breakage).
78 IO::IO (Session& s, const string& name, Direction dir, DataType default_type)
79 : SessionObject (s, name)
81 , _default_type (default_type)
84 pending_state_node = 0;
88 IO::IO (Session& s, const XMLNode& node, DataType dt)
89 : SessionObject(s, "unnamed io")
94 pending_state_node = 0;
102 Glib::Mutex::Lock lm (io_lock);
104 BLOCK_PROCESS_CALLBACK ();
106 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
107 _session.engine().unregister_port (*i);
112 IO::silence (nframes_t nframes)
114 /* io_lock, not taken: function must be called from Session::process() calltree */
116 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
117 i->get_buffer(nframes).silence (nframes);
122 IO::check_bundles_connected ()
124 check_bundles (_bundles_connected, ports());
128 IO::check_bundles (std::vector<UserBundleInfo>& list, const PortSet& ports)
130 std::vector<UserBundleInfo> new_list;
132 for (std::vector<UserBundleInfo>::iterator i = list.begin(); i != list.end(); ++i) {
134 uint32_t const N = i->bundle->nchannels ();
136 if (_ports.num_ports (default_type()) < N) {
142 for (uint32_t j = 0; j < N; ++j) {
143 /* Every port on bundle channel j must be connected to our input j */
144 Bundle::PortList const pl = i->bundle->channel_ports (j);
145 for (uint32_t k = 0; k < pl.size(); ++k) {
146 if (ports.port(j)->connected_to (pl[k]) == false) {
158 new_list.push_back (*i);
160 i->changed.disconnect ();
169 IO::disconnect (Port* our_port, string other_port, void* src)
171 if (other_port.length() == 0 || our_port == 0) {
176 BLOCK_PROCESS_CALLBACK ();
179 Glib::Mutex::Lock lm (io_lock);
181 /* check that our_port is really one of ours */
183 if ( ! _ports.contains(our_port)) {
187 /* disconnect it from the source */
189 if (our_port->disconnect (other_port)) {
190 error << string_compose(_("IO: cannot disconnect port %1 from %2"), our_port->name(), other_port) << endmsg;
194 check_bundles_connected ();
198 changed (ConnectionsChanged, src); /* EMIT SIGNAL */
199 _session.set_dirty ();
205 IO::connect (Port* our_port, string other_port, void* src)
207 if (other_port.length() == 0 || our_port == 0) {
212 BLOCK_PROCESS_CALLBACK ();
215 Glib::Mutex::Lock lm (io_lock);
217 /* check that our_port is really one of ours */
219 if ( ! _ports.contains(our_port) ) {
223 /* connect it to the source */
225 if (our_port->connect (other_port)) {
231 changed (ConnectionsChanged, src); /* EMIT SIGNAL */
232 _session.set_dirty ();
237 IO::remove_port (Port* port, void* src)
239 IOChange change (NoChange);
242 BLOCK_PROCESS_CALLBACK ();
246 Glib::Mutex::Lock lm (io_lock);
248 if (_ports.remove(port)) {
249 change = IOChange (change|ConfigurationChanged);
251 if (port->connected()) {
252 change = IOChange (change|ConnectionsChanged);
255 _session.engine().unregister_port (*port);
256 check_bundles_connected ();
260 PortCountChanged (n_ports()); /* EMIT SIGNAL */
263 if (change == ConfigurationChanged) {
267 if (change != NoChange) {
268 changed (change, src);
269 _session.set_dirty ();
276 /** Add an output port.
278 * @param destination Name of input port to connect new port to.
279 * @param src Source for emitted ConfigurationChanged signal.
280 * @param type Data type of port. Default value (NIL) will use this IO's default type.
283 IO::add_port (string destination, void* src, DataType type)
287 if (type == DataType::NIL) {
288 type = _default_type;
292 BLOCK_PROCESS_CALLBACK ();
296 Glib::Mutex::Lock lm (io_lock);
298 /* Create a new output port */
300 string portname = build_legal_port_name (type);
302 if (_direction == Input) {
303 if ((our_port = _session.engine().register_input_port (type, portname)) == 0) {
304 error << string_compose(_("IO: cannot register input port %1"), portname) << endmsg;
308 if ((our_port = _session.engine().register_output_port (type, portname)) == 0) {
309 error << string_compose(_("IO: cannot register output port %1"), portname) << endmsg;
314 _ports.add (our_port);
317 PortCountChanged (n_ports()); /* EMIT SIGNAL */
320 if (destination.length()) {
321 if (our_port->connect (destination)) {
326 // pan_changed (src); /* EMIT SIGNAL */
327 changed (ConfigurationChanged, src); /* EMIT SIGNAL */
329 _session.set_dirty ();
335 IO::disconnect (void* src)
338 BLOCK_PROCESS_CALLBACK ();
341 Glib::Mutex::Lock lm (io_lock);
343 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
344 i->disconnect_all ();
347 check_bundles_connected ();
351 changed (ConnectionsChanged, src); /* EMIT SIGNAL */
357 IO::ensure_ports_locked (ChanCount count, bool clear, void* src)
360 bool changed = false;
362 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
364 const size_t n = count.get(*t);
366 /* remove unused ports */
367 for (size_t i = n_ports().get(*t); i > n; --i) {
368 port = _ports.port(*t, i-1);
372 _session.engine().unregister_port (*port);
377 /* create any necessary new ports */
378 while (n_ports().get(*t) < n) {
380 string portname = build_legal_port_name (*t);
384 if (_direction == Input) {
385 if ((port = _session.engine().register_input_port (*t, portname)) == 0) {
386 error << string_compose(_("IO: cannot register input port %1"), portname) << endmsg;
390 if ((port = _session.engine().register_output_port (*t, portname)) == 0) {
391 error << string_compose(_("IO: cannot register output port %1"), portname) << endmsg;
397 catch (AudioEngine::PortRegistrationFailure& err) {
399 throw AudioEngine::PortRegistrationFailure();
408 check_bundles_connected ();
409 PortCountChanged (n_ports()); /* EMIT SIGNAL */
410 _session.set_dirty ();
414 /* disconnect all existing ports so that we get a fresh start */
415 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
416 i->disconnect_all ();
425 IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src)
427 bool changed = false;
429 if (count == n_ports() && !clear) {
434 BLOCK_PROCESS_CALLBACK ();
435 Glib::Mutex::Lock im (io_lock);
436 changed = ensure_ports_locked (count, clear, src);
438 changed = ensure_ports_locked (count, clear, src);
442 this->changed (ConfigurationChanged, src); /* EMIT SIGNAL */
444 _session.set_dirty ();
451 IO::ensure_io (ChanCount count, bool clear, void* src)
453 return ensure_ports (count, clear, true, src);
463 IO::state (bool full_state)
465 XMLNode* node = new XMLNode (state_node_name);
468 vector<string>::iterator ci;
470 LocaleGuard lg (X_("POSIX"));
471 Glib::Mutex::Lock lm (io_lock);
473 node->add_property("name", _name);
474 id().print (buf, sizeof (buf));
475 node->add_property("id", buf);
476 node->add_property ("direction", enum_2_string (_direction));
477 node->add_property ("default-type", _default_type.to_string());
479 for (std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) {
480 XMLNode* n = new XMLNode ("Bundle");
481 n->add_property ("name", i->bundle->name ());
482 node->add_child_nocopy (*n);
485 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
487 vector<string> connections;
489 XMLNode* pnode = new XMLNode (X_("Port"));
490 pnode->add_property (X_("type"), i->type().to_string());
491 pnode->add_property (X_("name"), i->name());
493 if (i->get_connections (connections)) {
495 for (n = 0, ci = connections.begin(); ci != connections.end(); ++ci, ++n) {
497 /* if its a connection to our own port,
498 return only the port name, not the
499 whole thing. this allows connections
500 to be re-established even when our
501 client name is different.
504 XMLNode* cnode = new XMLNode (X_("Connection"));
506 cnode->add_property (X_("other"), _session.engine().make_port_name_relative (*ci));
507 pnode->add_child_nocopy (*cnode);
511 node->add_child_nocopy (*pnode);
518 IO::set_state (const XMLNode& node)
520 const XMLProperty* prop;
521 XMLNodeConstIterator iter;
522 LocaleGuard lg (X_("POSIX"));
524 /* force use of non-localized representation of decimal point,
525 since we use it a lot in XML files and so forth.
528 if (node.name() != state_node_name) {
529 error << string_compose(_("incorrect XML node \"%1\" passed to IO object"), node.name()) << endmsg;
533 if ((prop = node.property ("name")) != 0) {
534 set_name (prop->value());
537 if ((prop = node.property (X_("default-type"))) != 0) {
538 _default_type = DataType(prop->value());
539 assert(_default_type != DataType::NIL);
542 if ((prop = node.property ("id")) != 0) {
543 _id = prop->value ();
546 if ((prop = node.property ("direction")) != 0) {
547 _direction = (Direction) string_2_enum (prop->value(), _direction);
550 if (create_ports (node)) {
554 if (connecting_legal) {
556 if (make_connections (node)) {
562 pending_state_node = new XMLNode (node);
563 connection_legal_c = ConnectingLegal.connect (mem_fun (*this, &IO::connecting_became_legal));
571 IO::connecting_became_legal ()
575 assert (pending_state_node);
577 connection_legal_c.disconnect ();
579 ret = make_connections (*pending_state_node);
581 delete pending_state_node;
582 pending_state_node = 0;
587 boost::shared_ptr<Bundle>
588 IO::find_possible_bundle (const string &desired_name)
590 static const string digits = "0123456789";
591 const string &default_name = (_direction == Input ? _("in") : _("out"));
592 const string &bundle_type_name = (_direction == Input ? _("input") : _("output"));
594 boost::shared_ptr<Bundle> c = _session.bundle_by_name (desired_name);
597 int bundle_number, mask;
598 string possible_name;
600 string::size_type last_non_digit_pos;
602 error << string_compose(_("Unknown bundle \"%1\" listed for %2 of %3"), desired_name, bundle_type_name, _name)
605 // find numeric suffix of desired name
608 last_non_digit_pos = desired_name.find_last_not_of(digits);
610 if (last_non_digit_pos != string::npos) {
612 s << desired_name.substr(last_non_digit_pos);
616 // see if it's a stereo connection e.g. "in 3+4"
618 if (last_non_digit_pos > 1 && desired_name[last_non_digit_pos] == '+') {
619 int left_bundle_number = 0;
620 string::size_type left_last_non_digit_pos;
622 left_last_non_digit_pos = desired_name.find_last_not_of(digits, last_non_digit_pos-1);
624 if (left_last_non_digit_pos != string::npos) {
626 s << desired_name.substr(left_last_non_digit_pos, last_non_digit_pos-1);
627 s >> left_bundle_number;
629 if (left_bundle_number > 0 && left_bundle_number + 1 == bundle_number) {
640 // find highest set bit
642 while ((mask <= bundle_number) && (mask <<= 1)) {}
644 // "wrap" bundle number into largest possible power of 2
649 if (bundle_number & mask) {
650 bundle_number &= ~mask;
653 s << default_name << " " << bundle_number + 1;
656 s << "+" << bundle_number + 2;
659 possible_name = s.str();
661 if ((c = _session.bundle_by_name (possible_name)) != 0) {
668 info << string_compose (_("Bundle %1 was not available - \"%2\" used instead"), desired_name, possible_name)
671 error << string_compose(_("No %1 bundles available as a replacement"), bundle_type_name)
682 IO::get_port_counts (const XMLNode& node, ChanCount& n, boost::shared_ptr<Bundle>& c)
684 XMLProperty const * prop;
685 XMLNodeConstIterator iter;
686 uint32_t n_audio = 0;
692 if ((prop = node.property ("connection")) != 0) {
694 if ((c = find_possible_bundle (prop->value())) != 0) {
695 n = ChanCount::max (n, ChanCount(c->type(), c->nchannels()));
700 for (iter = node.children().begin(); iter != node.children().end(); ++iter) {
702 if ((*iter)->name() == X_("Bundle")) {
703 if ((c = find_possible_bundle (prop->value())) != 0) {
704 n = ChanCount::max (n, ChanCount(c->type(), c->nchannels()));
711 if ((*iter)->name() == X_("Port")) {
712 prop = (*iter)->property (X_("type"));
718 if (prop->value() == X_("audio")) {
719 cnt.set_audio (++n_audio);
720 } else if (prop->value() == X_("midi")) {
721 cnt.set_midi (++n_midi);
726 n = ChanCount::max (n, cnt);
731 IO::create_ports (const XMLNode& node)
734 boost::shared_ptr<Bundle> c;
736 get_port_counts (node, n, c);
738 if (ensure_ports (n, true, true, this)) {
739 error << string_compose(_("%1: cannot create I/O ports"), _name) << endmsg;
749 IO::make_connections (const XMLNode& node)
751 const XMLProperty* prop;
753 for (XMLNodeConstIterator i = node.children().begin(); i != node.children().end(); ++i) {
755 if ((*i)->name() == "Bundle") {
756 XMLProperty const * prop = (*i)->property ("name");
758 boost::shared_ptr<Bundle> b = find_possible_bundle (prop->value());
760 connect_ports_to_bundle (b, this);
767 if ((*i)->name() == "Port") {
769 prop = (*i)->property (X_("name"));
775 Port* p = port_by_name (prop->value());
778 for (XMLNodeConstIterator c = (*i)->children().begin(); c != (*i)->children().end(); ++c) {
780 XMLNode* cnode = (*c);
782 if (cnode->name() != X_("Connection")) {
786 if ((prop = cnode->property (X_("other"))) == 0) {
791 p->connect (prop->value());
802 IO::set_ports (const string& str)
804 vector<string> ports;
809 if ((nports = count (str.begin(), str.end(), '{')) == 0) {
814 if (ensure_ports (ChanCount(DataType::AUDIO, nports), true, true, this)) {
818 string::size_type start, end, ostart;
825 while ((start = str.find_first_of ('{', ostart)) != string::npos) {
828 if ((end = str.find_first_of ('}', start)) == string::npos) {
829 error << string_compose(_("IO: badly formed string in XML node for inputs \"%1\""), str) << endmsg;
833 if ((n = parse_io_string (str.substr (start, end - start), ports)) < 0) {
834 error << string_compose(_("bad input string in XML node \"%1\""), str) << endmsg;
840 for (int x = 0; x < n; ++x) {
841 connect (nth (i), ports[x], this);
853 IO::parse_io_string (const string& str, vector<string>& ports)
855 string::size_type pos, opos;
857 if (str.length() == 0) {
866 while ((pos = str.find_first_of (',', opos)) != string::npos) {
867 ports.push_back (str.substr (opos, pos - opos));
871 if (opos < str.length()) {
872 ports.push_back (str.substr(opos));
879 IO::parse_gain_string (const string& str, vector<string>& ports)
881 string::size_type pos, opos;
887 while ((pos = str.find_first_of (',', opos)) != string::npos) {
888 ports.push_back (str.substr (opos, pos - opos));
892 if (opos < str.length()) {
893 ports.push_back (str.substr(opos));
900 IO::set_name (const string& requested_name)
902 if (requested_name == _name) {
908 if ( (rt = dynamic_cast<Route *>(this))) {
909 name = Route::ensure_track_or_route_name(requested_name, _session);
911 name = requested_name;
915 /* replace all colons in the name. i wish we didn't have to do this */
917 if (replace_all (name, ":", "-")) {
918 warning << _("you cannot use colons to name objects with I/O connections") << endmsg;
921 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
922 string current_name = i->name();
923 current_name.replace (current_name.find (_name), _name.length(), name);
924 i->set_name (current_name);
927 bool const r = SessionObject::set_name(name);
935 IO::set_port_latency (nframes_t nframes)
937 Glib::Mutex::Lock lm (io_lock);
939 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
940 i->set_latency (nframes);
947 nframes_t max_latency;
952 /* io lock not taken - must be protected by other means */
954 for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) {
955 if ((latency = i->total_latency ()) > max_latency) {
956 max_latency = latency;
964 IO::update_port_total_latencies ()
966 /* io_lock, not taken: function must be called from Session::process() calltree */
968 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
969 _session.engine().update_total_latency (*i);
974 IO::connect_ports_to_bundle (boost::shared_ptr<Bundle> c, void* src)
977 BLOCK_PROCESS_CALLBACK ();
978 Glib::Mutex::Lock lm2 (io_lock);
980 c->connect (_bundle, _session.engine());
982 /* If this is a UserBundle, make a note of what we've done */
984 boost::shared_ptr<UserBundle> ub = boost::dynamic_pointer_cast<UserBundle> (c);
987 /* See if we already know about this one */
988 std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin();
989 while (i != _bundles_connected.end() && i->bundle != ub) {
993 if (i == _bundles_connected.end()) {
994 /* We don't, so make a note */
995 _bundles_connected.push_back (UserBundleInfo (this, ub));
1000 changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */
1005 IO::disconnect_ports_from_bundle (boost::shared_ptr<Bundle> c, void* src)
1008 BLOCK_PROCESS_CALLBACK ();
1009 Glib::Mutex::Lock lm2 (io_lock);
1011 c->disconnect (_bundle, _session.engine());
1013 /* If this is a UserBundle, make a note of what we've done */
1015 boost::shared_ptr<UserBundle> ub = boost::dynamic_pointer_cast<UserBundle> (c);
1018 std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin();
1019 while (i != _bundles_connected.end() && i->bundle != ub) {
1023 if (i != _bundles_connected.end()) {
1024 _bundles_connected.erase (i);
1029 changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */
1035 IO::disable_connecting ()
1037 connecting_legal = false;
1042 IO::enable_connecting ()
1044 connecting_legal = true;
1045 return ConnectingLegal ();
1049 IO::bundle_changed (Bundle::Change c)
1052 // connect_input_ports_to_bundle (_input_bundle, this);
1057 IO::build_legal_port_name (DataType type)
1059 const int name_size = jack_port_name_size();
1063 if (type == DataType::AUDIO) {
1064 suffix = _("audio");
1065 } else if (type == DataType::MIDI) {
1068 throw unknown_type();
1071 if (_direction == Input) {
1074 suffix += _("_out");
1077 // allow up to 4 digits for the output port number, plus the slash, suffix and extra space
1079 limit = name_size - _session.engine().client_name().length() - (suffix.length() + 5);
1081 char buf1[name_size+1];
1082 char buf2[name_size+1];
1084 snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.c_str(), suffix.c_str());
1086 int port_number = find_port_hole (buf1);
1087 snprintf (buf2, name_size+1, "%s %d", buf1, port_number);
1089 return string (buf2);
1093 IO::find_port_hole (const char* base)
1095 /* CALLER MUST HOLD IO LOCK */
1099 if (_ports.empty()) {
1103 /* we only allow up to 4 characters for the port number
1106 for (n = 1; n < 9999; ++n) {
1107 char buf[jack_port_name_size()];
1108 PortSet::iterator i = _ports.begin();
1110 snprintf (buf, jack_port_name_size(), _("%s %u"), base, n);
1112 for ( ; i != _ports.end(); ++i) {
1113 if (i->name() == buf) {
1118 if (i == _ports.end()) {
1127 IO::audio(uint32_t n) const
1129 return _ports.nth_audio_port (n);
1134 IO::midi(uint32_t n) const
1136 return _ports.nth_midi_port (n);
1140 * Setup bundles that describe our inputs and outputs. Also creates bundles if necessary.
1144 IO::setup_bundles ()
1149 _bundle.reset (new Bundle (true));
1152 _bundle->suspend_signals ();
1154 _bundle->set_type (default_type ());
1156 _bundle->remove_channels ();
1158 if (_direction == Input) {
1159 snprintf(buf, sizeof (buf), _("%s in"), _name.c_str());
1161 snprintf(buf, sizeof (buf), _("%s out"), _name.c_str());
1163 _bundle->set_name (buf);
1164 uint32_t const ni = _ports.num_ports();
1165 for (uint32_t i = 0; i < ni; ++i) {
1166 _bundle->add_channel (bundle_channel_name (i, ni));
1167 _bundle->set_port (i, _session.engine().make_port_name_non_relative (_ports.port(i)->name()));
1170 _bundle->resume_signals ();
1173 /** @return Bundles connected to our ports */
1175 IO::bundles_connected ()
1180 for (std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) {
1181 bundles.push_back (i->bundle);
1184 /* Session bundles */
1185 boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
1186 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1187 if ((*i)->connected_to (_bundle, _session.engine())) {
1188 bundles.push_back (*i);
1194 boost::shared_ptr<ARDOUR::RouteList> r = _session.get_routes ();
1196 if (_direction == Input) {
1197 for (ARDOUR::RouteList::iterator i = r->begin(); i != r->end(); ++i) {
1198 if ((*i)->output()->bundle()->connected_to (_bundle, _session.engine())) {
1199 bundles.push_back ((*i)->output()->bundle());
1203 for (ARDOUR::RouteList::iterator i = r->begin(); i != r->end(); ++i) {
1204 if ((*i)->input()->bundle()->connected_to (_bundle, _session.engine())) {
1205 bundles.push_back ((*i)->input()->bundle());
1214 IO::UserBundleInfo::UserBundleInfo (IO* io, boost::shared_ptr<UserBundle> b)
1217 changed = b->Changed.connect (
1218 sigc::mem_fun (*io, &IO::bundle_changed)
1223 IO::bundle_channel_name (uint32_t c, uint32_t n) const
1231 return c == 0 ? _("L") : _("R");
1233 snprintf (buf, sizeof(buf), _("%d"), (c + 1));
1241 IO::name_from_state (const XMLNode& node)
1243 const XMLProperty* prop;
1245 if ((prop = node.property ("name")) != 0) {
1246 return prop->value();
1253 IO::set_name_in_state (XMLNode& node, const string& new_name)
1255 const XMLProperty* prop;
1257 if ((prop = node.property ("name")) != 0) {
1258 node.add_property ("name", new_name);
1263 IO::connected_to (boost::shared_ptr<const IO> other) const
1265 assert (_direction != other->direction());
1268 uint32_t no = n_ports().n_total();
1269 uint32_t ni = other->n_ports ().n_total();
1271 for (i = 0; i < no; ++i) {
1272 for (j = 0; j < ni; ++j) {
1273 if (nth(i)->connected_to (other->nth(j)->name())) {
1283 IO::process_input (boost::shared_ptr<Processor> proc, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
1287 /* don't read the data into new buffers - just use the port buffers directly */
1289 bufs.attach_buffers (_ports, nframes, 0);
1290 proc->run (bufs, start_frame, end_frame, nframes);
1294 IO::collect_input (BufferSet& bufs, nframes_t nframes, ChanCount offset)
1296 assert(bufs.available() >= _ports.count());
1298 if (_ports.count() == ChanCount::ZERO) {
1302 bufs.set_count (_ports.count());
1304 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1305 PortSet::iterator i = _ports.begin(*t);
1306 BufferSet::iterator b = bufs.begin(*t);
1308 for (uint32_t off = 0; off < offset.get(*t); ++off, ++b) {
1309 if (b == bufs.end(*t)) {
1314 for ( ; i != _ports.end(*t); ++i, ++b) {
1315 Buffer& bb (i->get_buffer (nframes));
1316 b->read_from (bb, nframes);
1322 IO::copy_to_outputs (BufferSet& bufs, DataType type, nframes_t nframes, nframes_t offset)
1324 // Copy any buffers 1:1 to outputs
1326 PortSet::iterator o = _ports.begin(type);
1327 BufferSet::iterator i = bufs.begin(type);
1328 BufferSet::iterator prev = i;
1330 while (i != bufs.end(type) && o != _ports.end (type)) {
1331 Buffer& port_buffer (o->get_buffer (nframes));
1332 port_buffer.read_from (*i, nframes, offset);
1338 // Copy last buffer to any extra outputs
1340 while (o != _ports.end(type)) {
1341 Buffer& port_buffer (o->get_buffer (nframes));
1342 port_buffer.read_from (*prev, nframes, offset);
1348 IO::port_by_name (const std::string& str) const
1350 /* to be called only from ::set_state() - no locking */
1352 for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) {
1356 if (p.name() == str) {
1357 return const_cast<Port*>(&p);