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;
86 cerr << "+++ IO created with name = " << _name << endl;
89 IO::IO (Session& s, const XMLNode& node, DataType dt)
90 : SessionObject(s, "unnamed io")
95 pending_state_node = 0;
100 cerr << "+++ IO created from XML with name = " << _name << endl;
105 Glib::Mutex::Lock lm (io_lock);
107 BLOCK_PROCESS_CALLBACK ();
109 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
110 _session.engine().unregister_port (*i);
115 IO::silence (nframes_t nframes)
117 /* io_lock, not taken: function must be called from Session::process() calltree */
119 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
120 i->get_buffer(nframes).silence (nframes);
125 IO::check_bundles_connected ()
127 check_bundles (_bundles_connected, ports());
131 IO::check_bundles (std::vector<UserBundleInfo>& list, const PortSet& ports)
133 std::vector<UserBundleInfo> new_list;
135 for (std::vector<UserBundleInfo>::iterator i = list.begin(); i != list.end(); ++i) {
137 uint32_t const N = i->bundle->nchannels ();
139 if (_ports.num_ports (default_type()) < N) {
145 for (uint32_t j = 0; j < N; ++j) {
146 /* Every port on bundle channel j must be connected to our input j */
147 Bundle::PortList const pl = i->bundle->channel_ports (j);
148 for (uint32_t k = 0; k < pl.size(); ++k) {
149 if (ports.port(j)->connected_to (pl[k]) == false) {
161 new_list.push_back (*i);
163 i->changed.disconnect ();
172 IO::disconnect (Port* our_port, string other_port, void* src)
174 if (other_port.length() == 0 || our_port == 0) {
179 BLOCK_PROCESS_CALLBACK ();
182 Glib::Mutex::Lock lm (io_lock);
184 /* check that our_port is really one of ours */
186 if ( ! _ports.contains(our_port)) {
190 /* disconnect it from the source */
192 if (our_port->disconnect (other_port)) {
193 error << string_compose(_("IO: cannot disconnect port %1 from %2"), our_port->name(), other_port) << endmsg;
197 check_bundles_connected ();
201 changed (ConnectionsChanged, src); /* EMIT SIGNAL */
202 _session.set_dirty ();
208 IO::connect (Port* our_port, string other_port, void* src)
210 if (other_port.length() == 0 || our_port == 0) {
215 BLOCK_PROCESS_CALLBACK ();
218 Glib::Mutex::Lock lm (io_lock);
220 /* check that our_port is really one of ours */
222 if ( ! _ports.contains(our_port) ) {
226 /* connect it to the source */
228 if (our_port->connect (other_port)) {
234 changed (ConnectionsChanged, src); /* EMIT SIGNAL */
235 _session.set_dirty ();
240 IO::remove_port (Port* port, void* src)
242 IOChange change (NoChange);
245 BLOCK_PROCESS_CALLBACK ();
249 Glib::Mutex::Lock lm (io_lock);
251 if (_ports.remove(port)) {
252 change = IOChange (change|ConfigurationChanged);
254 if (port->connected()) {
255 change = IOChange (change|ConnectionsChanged);
258 _session.engine().unregister_port (*port);
259 check_bundles_connected ();
263 PortCountChanged (n_ports()); /* EMIT SIGNAL */
266 if (change == ConfigurationChanged) {
270 if (change != NoChange) {
271 changed (change, src);
272 _session.set_dirty ();
279 /** Add an output port.
281 * @param destination Name of input port to connect new port to.
282 * @param src Source for emitted ConfigurationChanged signal.
283 * @param type Data type of port. Default value (NIL) will use this IO's default type.
286 IO::add_port (string destination, void* src, DataType type)
290 if (type == DataType::NIL) {
291 type = _default_type;
295 BLOCK_PROCESS_CALLBACK ();
299 Glib::Mutex::Lock lm (io_lock);
301 /* Create a new output port */
303 string portname = build_legal_port_name (type);
305 if (_direction == Input) {
306 if ((our_port = _session.engine().register_input_port (type, portname)) == 0) {
307 error << string_compose(_("IO: cannot register input port %1"), portname) << endmsg;
311 if ((our_port = _session.engine().register_output_port (type, portname)) == 0) {
312 error << string_compose(_("IO: cannot register output port %1"), portname) << endmsg;
317 _ports.add (our_port);
320 PortCountChanged (n_ports()); /* EMIT SIGNAL */
323 if (destination.length()) {
324 if (our_port->connect (destination)) {
329 // pan_changed (src); /* EMIT SIGNAL */
330 changed (ConfigurationChanged, src); /* EMIT SIGNAL */
332 _session.set_dirty ();
338 IO::disconnect (void* src)
341 BLOCK_PROCESS_CALLBACK ();
344 Glib::Mutex::Lock lm (io_lock);
346 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
347 i->disconnect_all ();
350 check_bundles_connected ();
354 changed (ConnectionsChanged, src); /* EMIT SIGNAL */
360 IO::ensure_ports_locked (ChanCount count, bool clear, void* src)
363 bool changed = false;
365 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
367 const size_t n = count.get(*t);
369 /* remove unused ports */
370 for (size_t i = n_ports().get(*t); i > n; --i) {
371 port = _ports.port(*t, i-1);
375 _session.engine().unregister_port (*port);
380 /* create any necessary new ports */
381 while (n_ports().get(*t) < n) {
383 string portname = build_legal_port_name (*t);
387 if (_direction == Input) {
388 if ((port = _session.engine().register_input_port (*t, portname)) == 0) {
389 error << string_compose(_("IO: cannot register input port %1"), portname) << endmsg;
393 if ((port = _session.engine().register_output_port (*t, portname)) == 0) {
394 error << string_compose(_("IO: cannot register output port %1"), portname) << endmsg;
400 catch (AudioEngine::PortRegistrationFailure& err) {
402 throw AudioEngine::PortRegistrationFailure();
411 check_bundles_connected ();
412 PortCountChanged (n_ports()); /* EMIT SIGNAL */
413 _session.set_dirty ();
417 /* disconnect all existing ports so that we get a fresh start */
418 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
419 i->disconnect_all ();
428 IO::ensure_ports (ChanCount count, bool clear, bool lockit, void* src)
430 bool changed = false;
432 cerr << "Ensure that IO " << _name << '/' << (_direction == Input ? "input" : "output")
433 << " has " << count << endl;
435 if (count == n_ports() && !clear) {
436 cerr << "\talready has " << n_ports() << endl;
441 BLOCK_PROCESS_CALLBACK ();
442 Glib::Mutex::Lock im (io_lock);
443 changed = ensure_ports_locked (count, clear, src);
445 changed = ensure_ports_locked (count, clear, src);
449 this->changed (ConfigurationChanged, src); /* EMIT SIGNAL */
451 _session.set_dirty ();
454 cerr << "\t@" << this << " established with " << n_ports() << endl;
460 IO::ensure_io (ChanCount count, bool clear, void* src)
462 return ensure_ports (count, clear, true, src);
472 IO::state (bool full_state)
474 XMLNode* node = new XMLNode (state_node_name);
477 vector<string>::iterator ci;
479 LocaleGuard lg (X_("POSIX"));
480 Glib::Mutex::Lock lm (io_lock);
482 node->add_property("name", _name);
483 id().print (buf, sizeof (buf));
484 node->add_property("id", buf);
485 node->add_property ("direction", enum_2_string (_direction));
486 node->add_property ("default-type", _default_type.to_string());
488 for (std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) {
489 XMLNode* n = new XMLNode ("Bundle");
490 n->add_property ("name", i->bundle->name ());
491 node->add_child_nocopy (*n);
494 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
496 vector<string> connections;
498 XMLNode* pnode = new XMLNode (X_("Port"));
499 pnode->add_property (X_("type"), i->type().to_string());
501 if (i->get_connections (connections)) {
503 for (n = 0, ci = connections.begin(); ci != connections.end(); ++ci, ++n) {
505 /* if its a connection to our own port,
506 return only the port name, not the
507 whole thing. this allows connections
508 to be re-established even when our
509 client name is different.
512 pnode->add_property (X_("connection"), _session.engine().make_port_name_relative (*ci));
516 node->add_child_nocopy (*pnode);
523 IO::set_state (const XMLNode& node)
525 const XMLProperty* prop;
526 XMLNodeConstIterator iter;
527 LocaleGuard lg (X_("POSIX"));
529 /* force use of non-localized representation of decimal point,
530 since we use it a lot in XML files and so forth.
533 if (node.name() != state_node_name) {
534 error << string_compose(_("incorrect XML node \"%1\" passed to IO object"), node.name()) << endmsg;
538 if ((prop = node.property ("name")) != 0) {
539 set_name (prop->value());
542 if ((prop = node.property (X_("default-type"))) != 0) {
543 _default_type = DataType(prop->value());
544 assert(_default_type != DataType::NIL);
547 if ((prop = node.property ("id")) != 0) {
548 _id = prop->value ();
551 if ((prop = node.property ("direction")) != 0) {
552 _direction = (Direction) string_2_enum (prop->value(), _direction);
555 if (!connecting_legal) {
556 pending_state_node = new XMLNode (node);
559 if (create_ports (node)) {
563 if (connecting_legal) {
565 if (make_connections (node)) {
571 connection_legal_c = ConnectingLegal.connect (mem_fun (*this, &IO::connecting_became_legal));
579 IO::connecting_became_legal ()
583 assert (pending_state_node);
585 connection_legal_c.disconnect ();
587 ret = make_connections (*pending_state_node);
589 delete pending_state_node;
590 pending_state_node = 0;
595 boost::shared_ptr<Bundle>
596 IO::find_possible_bundle (const string &desired_name)
598 static const string digits = "0123456789";
599 const string &default_name = (_direction == Input ? _("in") : _("out"));
600 const string &bundle_type_name = (_direction == Input ? _("input") : _("output"));
602 boost::shared_ptr<Bundle> c = _session.bundle_by_name (desired_name);
605 int bundle_number, mask;
606 string possible_name;
608 string::size_type last_non_digit_pos;
610 error << string_compose(_("Unknown bundle \"%1\" listed for %2 of %3"), desired_name, bundle_type_name, _name)
613 // find numeric suffix of desired name
616 last_non_digit_pos = desired_name.find_last_not_of(digits);
618 if (last_non_digit_pos != string::npos) {
620 s << desired_name.substr(last_non_digit_pos);
624 // see if it's a stereo connection e.g. "in 3+4"
626 if (last_non_digit_pos > 1 && desired_name[last_non_digit_pos] == '+') {
627 int left_bundle_number = 0;
628 string::size_type left_last_non_digit_pos;
630 left_last_non_digit_pos = desired_name.find_last_not_of(digits, last_non_digit_pos-1);
632 if (left_last_non_digit_pos != string::npos) {
634 s << desired_name.substr(left_last_non_digit_pos, last_non_digit_pos-1);
635 s >> left_bundle_number;
637 if (left_bundle_number > 0 && left_bundle_number + 1 == bundle_number) {
648 // find highest set bit
650 while ((mask <= bundle_number) && (mask <<= 1)) {}
652 // "wrap" bundle number into largest possible power of 2
657 if (bundle_number & mask) {
658 bundle_number &= ~mask;
661 s << default_name << " " << bundle_number + 1;
664 s << "+" << bundle_number + 2;
667 possible_name = s.str();
669 if ((c = _session.bundle_by_name (possible_name)) != 0) {
676 info << string_compose (_("Bundle %1 was not available - \"%2\" used instead"), desired_name, possible_name)
679 error << string_compose(_("No %1 bundles available as a replacement"), bundle_type_name)
690 IO::get_port_counts (const XMLNode& node, ChanCount& n, boost::shared_ptr<Bundle>& c)
692 XMLProperty const * prop;
693 XMLNodeConstIterator iter;
694 uint32_t n_audio = 0;
700 if ((prop = node.property ("connection")) != 0) {
702 if ((c = find_possible_bundle (prop->value())) != 0) {
703 n = ChanCount::max (n, ChanCount(c->type(), c->nchannels()));
708 for (iter = node.children().begin(); iter != node.children().end(); ++iter) {
710 if ((*iter)->name() == X_("Bundle")) {
711 if ((c = find_possible_bundle (prop->value())) != 0) {
712 n = ChanCount::max (n, ChanCount(c->type(), c->nchannels()));
719 if ((*iter)->name() == X_("Port")) {
720 prop = (*iter)->property (X_("type"));
726 if (prop->value() == X_("audio")) {
727 cnt.set_audio (++n_audio);
728 } else if (prop->value() == X_("midi")) {
729 cnt.set_midi (++n_midi);
734 n = ChanCount::max (n, cnt);
739 IO::create_ports (const XMLNode& node)
742 boost::shared_ptr<Bundle> c;
744 get_port_counts (node, n, c);
746 cerr << _name << " got " << n << " from XML node" << endl;
748 if (ensure_ports (n, true, true, this)) {
749 error << string_compose(_("%1: cannot create I/O ports"), _name) << endmsg;
759 IO::make_connections (const XMLNode& node)
761 const XMLProperty* prop;
763 if ((prop = node.property ("connection")) != 0) {
764 boost::shared_ptr<Bundle> c = find_possible_bundle (prop->value());
770 if (n_ports().get(c->type()) == c->nchannels() && c->ports_are_outputs()) {
771 connect_ports_to_bundle (c, this);
779 for (XMLNodeConstIterator i = node.children().begin(); i != node.children().end(); ++i) {
781 if ((*i)->name() == "Bundle") {
782 XMLProperty const * prop = (*i)->property ("name");
784 boost::shared_ptr<Bundle> b = find_possible_bundle (prop->value());
786 connect_ports_to_bundle (b, this);
793 if ((*i)->name() == "Port") {
795 XMLProperty* prop = (*i)->property ("connection");
797 p->connect (prop->value());
806 IO::set_ports (const string& str)
808 vector<string> ports;
813 if ((nports = count (str.begin(), str.end(), '{')) == 0) {
818 if (ensure_ports (ChanCount(DataType::AUDIO, nports), true, true, this)) {
822 string::size_type start, end, ostart;
829 while ((start = str.find_first_of ('{', ostart)) != string::npos) {
832 if ((end = str.find_first_of ('}', start)) == string::npos) {
833 error << string_compose(_("IO: badly formed string in XML node for inputs \"%1\""), str) << endmsg;
837 if ((n = parse_io_string (str.substr (start, end - start), ports)) < 0) {
838 error << string_compose(_("bad input string in XML node \"%1\""), str) << endmsg;
844 for (int x = 0; x < n; ++x) {
845 connect (nth (i), ports[x], this);
857 IO::parse_io_string (const string& str, vector<string>& ports)
859 string::size_type pos, opos;
861 if (str.length() == 0) {
870 while ((pos = str.find_first_of (',', opos)) != string::npos) {
871 ports.push_back (str.substr (opos, pos - opos));
875 if (opos < str.length()) {
876 ports.push_back (str.substr(opos));
883 IO::parse_gain_string (const string& str, vector<string>& ports)
885 string::size_type pos, opos;
891 while ((pos = str.find_first_of (',', opos)) != string::npos) {
892 ports.push_back (str.substr (opos, pos - opos));
896 if (opos < str.length()) {
897 ports.push_back (str.substr(opos));
904 IO::set_name (const string& requested_name)
906 if (requested_name == _name) {
912 if ( (rt = dynamic_cast<Route *>(this))) {
913 name = Route::ensure_track_or_route_name(requested_name, _session);
915 name = requested_name;
919 /* replace all colons in the name. i wish we didn't have to do this */
921 if (replace_all (name, ":", "-")) {
922 warning << _("you cannot use colons to name objects with I/O connections") << endmsg;
925 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
926 string current_name = i->name();
927 current_name.replace (current_name.find (_name), _name.length(), name);
928 i->set_name (current_name);
931 bool const r = SessionObject::set_name(name);
939 IO::set_port_latency (nframes_t nframes)
941 Glib::Mutex::Lock lm (io_lock);
943 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
944 i->set_latency (nframes);
951 nframes_t max_latency;
956 /* io lock not taken - must be protected by other means */
958 for (PortSet::const_iterator i = _ports.begin(); i != _ports.end(); ++i) {
959 if ((latency = i->total_latency ()) > max_latency) {
960 max_latency = latency;
968 IO::update_port_total_latencies ()
970 /* io_lock, not taken: function must be called from Session::process() calltree */
972 for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
973 _session.engine().update_total_latency (*i);
978 IO::connect_ports_to_bundle (boost::shared_ptr<Bundle> c, void* src)
981 BLOCK_PROCESS_CALLBACK ();
982 Glib::Mutex::Lock lm2 (io_lock);
984 c->connect (_bundle, _session.engine());
986 /* If this is a UserBundle, make a note of what we've done */
988 boost::shared_ptr<UserBundle> ub = boost::dynamic_pointer_cast<UserBundle> (c);
991 /* See if we already know about this one */
992 std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin();
993 while (i != _bundles_connected.end() && i->bundle != ub) {
997 if (i == _bundles_connected.end()) {
998 /* We don't, so make a note */
999 _bundles_connected.push_back (UserBundleInfo (this, ub));
1004 changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */
1009 IO::disconnect_ports_from_bundle (boost::shared_ptr<Bundle> c, void* src)
1012 BLOCK_PROCESS_CALLBACK ();
1013 Glib::Mutex::Lock lm2 (io_lock);
1015 c->disconnect (_bundle, _session.engine());
1017 /* If this is a UserBundle, make a note of what we've done */
1019 boost::shared_ptr<UserBundle> ub = boost::dynamic_pointer_cast<UserBundle> (c);
1022 std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin();
1023 while (i != _bundles_connected.end() && i->bundle != ub) {
1027 if (i != _bundles_connected.end()) {
1028 _bundles_connected.erase (i);
1033 changed (IOChange (ConfigurationChanged|ConnectionsChanged), src); /* EMIT SIGNAL */
1039 IO::disable_connecting ()
1041 connecting_legal = false;
1046 IO::enable_connecting ()
1048 connecting_legal = true;
1049 return ConnectingLegal ();
1053 IO::bundle_changed (Bundle::Change c)
1056 // connect_input_ports_to_bundle (_input_bundle, this);
1061 IO::build_legal_port_name (DataType type)
1063 const int name_size = jack_port_name_size();
1067 if (type == DataType::AUDIO) {
1068 suffix = _("audio");
1069 } else if (type == DataType::MIDI) {
1072 throw unknown_type();
1075 if (_direction == Input) {
1078 suffix += _("_out");
1081 // allow up to 4 digits for the output port number, plus the slash, suffix and extra space
1083 limit = name_size - _session.engine().client_name().length() - (suffix.length() + 5);
1085 char buf1[name_size+1];
1086 char buf2[name_size+1];
1088 snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.c_str(), suffix.c_str());
1090 int port_number = find_port_hole (buf1);
1091 snprintf (buf2, name_size+1, "%s %d", buf1, port_number);
1093 return string (buf2);
1097 IO::find_port_hole (const char* base)
1099 /* CALLER MUST HOLD IO LOCK */
1103 if (_ports.empty()) {
1107 /* we only allow up to 4 characters for the port number
1110 for (n = 1; n < 9999; ++n) {
1111 char buf[jack_port_name_size()];
1112 PortSet::iterator i = _ports.begin();
1114 snprintf (buf, jack_port_name_size(), _("%s %u"), base, n);
1116 for ( ; i != _ports.end(); ++i) {
1117 if (i->name() == buf) {
1122 if (i == _ports.end()) {
1131 IO::audio(uint32_t n) const
1133 return _ports.nth_audio_port (n);
1138 IO::midi(uint32_t n) const
1140 return _ports.nth_midi_port (n);
1144 * Setup bundles that describe our inputs and outputs. Also creates bundles if necessary.
1148 IO::setup_bundles ()
1153 _bundle.reset (new Bundle (true));
1156 _bundle->suspend_signals ();
1158 _bundle->set_type (default_type ());
1160 _bundle->remove_channels ();
1162 if (_direction == Input) {
1163 snprintf(buf, sizeof (buf), _("%s in"), _name.c_str());
1165 snprintf(buf, sizeof (buf), _("%s out"), _name.c_str());
1167 _bundle->set_name (buf);
1168 uint32_t const ni = _ports.num_ports();
1169 for (uint32_t i = 0; i < ni; ++i) {
1170 _bundle->add_channel (bundle_channel_name (i, ni));
1171 _bundle->set_port (i, _session.engine().make_port_name_non_relative (_ports.port(i)->name()));
1174 _bundle->resume_signals ();
1177 /** @return Bundles connected to our ports */
1179 IO::bundles_connected ()
1184 for (std::vector<UserBundleInfo>::iterator i = _bundles_connected.begin(); i != _bundles_connected.end(); ++i) {
1185 bundles.push_back (i->bundle);
1188 /* Session bundles */
1189 boost::shared_ptr<ARDOUR::BundleList> b = _session.bundles ();
1190 for (ARDOUR::BundleList::iterator i = b->begin(); i != b->end(); ++i) {
1191 if ((*i)->connected_to (_bundle, _session.engine())) {
1192 bundles.push_back (*i);
1198 boost::shared_ptr<ARDOUR::RouteList> r = _session.get_routes ();
1200 if (_direction == Input) {
1201 for (ARDOUR::RouteList::iterator i = r->begin(); i != r->end(); ++i) {
1202 if ((*i)->output()->bundle()->connected_to (_bundle, _session.engine())) {
1203 bundles.push_back ((*i)->output()->bundle());
1207 for (ARDOUR::RouteList::iterator i = r->begin(); i != r->end(); ++i) {
1208 if ((*i)->input()->bundle()->connected_to (_bundle, _session.engine())) {
1209 bundles.push_back ((*i)->input()->bundle());
1218 IO::UserBundleInfo::UserBundleInfo (IO* io, boost::shared_ptr<UserBundle> b)
1221 changed = b->Changed.connect (
1222 sigc::mem_fun (*io, &IO::bundle_changed)
1227 IO::bundle_channel_name (uint32_t c, uint32_t n) const
1235 return c == 0 ? _("L") : _("R");
1237 snprintf (buf, sizeof(buf), _("%d"), (c + 1));
1245 IO::name_from_state (const XMLNode& node)
1247 const XMLProperty* prop;
1249 if ((prop = node.property ("name")) != 0) {
1250 return prop->value();
1257 IO::set_name_in_state (XMLNode& node, const string& new_name)
1259 const XMLProperty* prop;
1261 if ((prop = node.property ("name")) != 0) {
1262 node.add_property ("name", new_name);
1267 IO::connected_to (boost::shared_ptr<const IO> other) const
1269 assert (_direction != other->direction());
1272 uint32_t no = n_ports().n_total();
1273 uint32_t ni = other->n_ports ().n_total();
1275 for (i = 0; i < no; ++i) {
1276 for (j = 0; j < ni; ++j) {
1277 if (nth(i)->connected_to (other->nth(j)->name())) {
1287 IO::process_input (boost::shared_ptr<Processor> proc, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
1291 /* don't read the data into new buffers - just use the port buffers directly */
1293 bufs.attach_buffers (_ports, nframes, 0);
1294 proc->run_in_place (bufs, start_frame, end_frame, nframes);
1298 IO::collect_input (BufferSet& bufs, nframes_t nframes, ChanCount offset)
1300 assert(bufs.available() >= _ports.count());
1302 if (_ports.count() == ChanCount::ZERO) {
1306 bufs.set_count (_ports.count());
1308 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1309 PortSet::iterator i = _ports.begin(*t);
1310 BufferSet::iterator b = bufs.begin(*t);
1312 for (uint32_t off = 0; off < offset.get(*t); ++off, ++b) {
1313 if (b == bufs.end(*t)) {
1318 for ( ; i != _ports.end(*t); ++i, ++b) {
1319 Buffer& bb (i->get_buffer (nframes));
1320 b->read_from (bb, nframes);
1326 IO::copy_to_outputs (BufferSet& bufs, DataType type, nframes_t nframes, nframes_t offset)
1328 // Copy any buffers 1:1 to outputs
1330 PortSet::iterator o = _ports.begin(type);
1331 BufferSet::iterator i = bufs.begin(type);
1332 BufferSet::iterator prev = i;
1334 while (i != bufs.end(type) && o != _ports.end (type)) {
1335 Buffer& port_buffer (o->get_buffer (nframes));
1336 port_buffer.read_from (*i, nframes, offset);
1342 // Copy last buffer to any extra outputs
1344 while (o != _ports.end(type)) {
1345 Buffer& port_buffer (o->get_buffer (nframes));
1346 port_buffer.read_from (*prev, nframes, offset);