diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/bundle.h | 20 | ||||
-rw-r--r-- | libs/ardour/bundle.cc | 98 | ||||
-rw-r--r-- | libs/ardour/io.cc | 16 | ||||
-rw-r--r-- | libs/ardour/session.cc | 12 | ||||
-rw-r--r-- | libs/ardour/user_bundle.cc | 9 |
5 files changed, 71 insertions, 84 deletions
diff --git a/libs/ardour/ardour/bundle.h b/libs/ardour/ardour/bundle.h index cc2ee19155..39c58ed318 100644 --- a/libs/ardour/ardour/bundle.h +++ b/libs/ardour/ardour/bundle.h @@ -28,13 +28,14 @@ #include "pbd/signals.h" #include "ardour/data_type.h" +#include "ardour/chan_count.h" namespace ARDOUR { class AudioEngine; /** A set of `channels', each of which is associated with 0 or more ports. - * Each channel has a name which can be anything useful. + * Each channel has a name which can be anything useful, and a data type. * Intended for grouping things like, for example, a buss' outputs. * `Channel' is a rather overloaded term but I can't think of a better * one right now. @@ -49,33 +50,34 @@ class Bundle : public PBD::ScopedConnectionList typedef std::vector<std::string> PortList; struct Channel { - Channel (std::string n) : name (n) {} + Channel (std::string n, DataType t) : name (n), type (t) {} bool operator== (Channel const &o) const { - return name == o.name && ports == o.ports; + return name == o.name && type == o.type && ports == o.ports; } std::string name; + DataType type; PortList ports; }; Bundle (bool i = true); Bundle (std::string const &, bool i = true); - Bundle (std::string const &, DataType, bool i = true); Bundle (boost::shared_ptr<Bundle>); virtual ~Bundle() {} /** @return Number of channels that this Bundle has */ - uint32_t nchannels () const; + ChanCount nchannels () const; /** @param Channel index. * @return Ports associated with this channel. */ PortList const & channel_ports (uint32_t) const; - void add_channel (std::string const &); + void add_channel (std::string const &, DataType); std::string channel_name (uint32_t) const; + DataType channel_type (uint32_t) const; void set_channel_name (uint32_t, std::string const &); void add_port_to_channel (uint32_t, std::string); void set_port (uint32_t, std::string); @@ -98,11 +100,6 @@ class Bundle : public PBD::ScopedConnectionList /** @return Bundle name */ std::string name () const { return _name; } - void set_type (DataType); - - /** @return Type of the ports in this Bundle. */ - DataType type () const { return _type; } - void set_ports_are_inputs (); void set_ports_are_outputs (); bool ports_are_inputs () const { return _ports_are_inputs; } @@ -135,7 +132,6 @@ class Bundle : public PBD::ScopedConnectionList void emit_changed (Change); std::string _name; - DataType _type; bool _ports_are_inputs; bool _signals_suspended; diff --git a/libs/ardour/bundle.cc b/libs/ardour/bundle.cc index f409e0beee..9878437ff8 100644 --- a/libs/ardour/bundle.cc +++ b/libs/ardour/bundle.cc @@ -36,8 +36,7 @@ using namespace PBD; * @param i true if ports are inputs, otherwise false. */ Bundle::Bundle (bool i) - : _type (DataType::AUDIO), - _ports_are_inputs (i), + : _ports_are_inputs (i), _signals_suspended (false), _pending_change (Change (0)) { @@ -51,23 +50,6 @@ Bundle::Bundle (bool i) */ Bundle::Bundle (std::string const & n, bool i) : _name (n), - _type (DataType::AUDIO), - _ports_are_inputs (i), - _signals_suspended (false), - _pending_change (Change (0)) -{ - -} - - -/** Construct a bundle. - * @param n Name. - * @param t Type. - * @param i true if ports are inputs, otherwise false. - */ -Bundle::Bundle (std::string const & n, DataType t, bool i) - : _name (n), - _type (t), _ports_are_inputs (i), _signals_suspended (false), _pending_change (Change (0)) @@ -75,11 +57,9 @@ Bundle::Bundle (std::string const & n, DataType t, bool i) } - Bundle::Bundle (boost::shared_ptr<Bundle> other) : _channel (other->_channel), _name (other->_name), - _type (other->_type), _ports_are_inputs (other->_ports_are_inputs), _signals_suspended (other->_signals_suspended), _pending_change (other->_pending_change) @@ -87,17 +67,23 @@ Bundle::Bundle (boost::shared_ptr<Bundle> other) } -uint32_t +ChanCount Bundle::nchannels () const { Glib::Mutex::Lock lm (_channel_mutex); - return _channel.size (); + + ChanCount c; + for (vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) { + c.set (i->type, c.get (i->type) + 1); + } + + return c; } Bundle::PortList const & Bundle::channel_ports (uint32_t c) const { - assert (c < nchannels()); + assert (c < nchannels().n_total()); Glib::Mutex::Lock lm (_channel_mutex); return _channel[c].ports; @@ -110,7 +96,7 @@ Bundle::channel_ports (uint32_t c) const void Bundle::add_port_to_channel (uint32_t ch, string portname) { - assert (ch < nchannels()); + assert (ch < nchannels().n_total()); assert (portname.find_first_of (':') != string::npos); { @@ -128,7 +114,7 @@ Bundle::add_port_to_channel (uint32_t ch, string portname) void Bundle::remove_port_from_channel (uint32_t ch, string portname) { - assert (ch < nchannels()); + assert (ch < nchannels().n_total()); bool changed = false; @@ -155,7 +141,7 @@ Bundle::remove_port_from_channel (uint32_t ch, string portname) void Bundle::set_port (uint32_t ch, string portname) { - assert (ch < nchannels()); + assert (ch < nchannels().n_total()); assert (portname.find_first_of (':') != string::npos); { @@ -169,11 +155,11 @@ Bundle::set_port (uint32_t ch, string portname) /** @param n Channel name */ void -Bundle::add_channel (std::string const & n) +Bundle::add_channel (std::string const & n, DataType t) { { Glib::Mutex::Lock lm (_channel_mutex); - _channel.push_back (Channel (n)); + _channel.push_back (Channel (n, t)); } emit_changed (ConfigurationChanged); @@ -182,7 +168,7 @@ Bundle::add_channel (std::string const & n) bool Bundle::port_attached_to_channel (uint32_t ch, std::string portname) { - assert (ch < nchannels()); + assert (ch < nchannels().n_total()); Glib::Mutex::Lock lm (_channel_mutex); return (std::find (_channel[ch].ports.begin (), _channel[ch].ports.end (), portname) != _channel[ch].ports.end ()); @@ -194,7 +180,7 @@ Bundle::port_attached_to_channel (uint32_t ch, std::string portname) void Bundle::remove_channel (uint32_t ch) { - assert (ch < nchannels ()); + assert (ch < nchannels().n_total()); Glib::Mutex::Lock lm (_channel_mutex); _channel.erase (_channel.begin () + ch); @@ -252,7 +238,7 @@ Bundle::offers_port_alone (std::string p) const std::string Bundle::channel_name (uint32_t ch) const { - assert (ch < nchannels()); + assert (ch < nchannels().n_total()); Glib::Mutex::Lock lm (_channel_mutex); return _channel[ch].name; @@ -265,7 +251,7 @@ Bundle::channel_name (uint32_t ch) const void Bundle::set_channel_name (uint32_t ch, std::string const & n) { - assert (ch < nchannels()); + assert (ch < nchannels().n_total()); { Glib::Mutex::Lock lm (_channel_mutex); @@ -282,14 +268,14 @@ Bundle::set_channel_name (uint32_t ch, std::string const & n) void Bundle::add_channels_from_bundle (boost::shared_ptr<Bundle> other) { - uint32_t const ch = nchannels (); + uint32_t const ch = nchannels().n_total(); - for (uint32_t i = 0; i < other->nchannels(); ++i) { + for (uint32_t i = 0; i < other->nchannels().n_total(); ++i) { std::stringstream s; s << other->name() << " " << other->channel_name(i); - add_channel (s.str()); + add_channel (s.str(), other->channel_type(i)); PortList const& pl = other->channel_ports (i); for (uint32_t j = 0; j < pl.size(); ++j) { @@ -306,8 +292,8 @@ Bundle::add_channels_from_bundle (boost::shared_ptr<Bundle> other) void Bundle::connect (boost::shared_ptr<Bundle> other, AudioEngine & engine) { - uint32_t const N = nchannels (); - assert (N == other->nchannels ()); + uint32_t const N = nchannels().n_total(); + assert (N == other->nchannels().n_total()); for (uint32_t i = 0; i < N; ++i) { Bundle::PortList const & our_ports = channel_ports (i); @@ -324,8 +310,8 @@ Bundle::connect (boost::shared_ptr<Bundle> other, AudioEngine & engine) void Bundle::disconnect (boost::shared_ptr<Bundle> other, AudioEngine & engine) { - uint32_t const N = nchannels (); - assert (N == other->nchannels ()); + uint32_t const N = nchannels().n_total(); + assert (N == other->nchannels().n_total()); for (uint32_t i = 0; i < N; ++i) { Bundle::PortList const & our_ports = channel_ports (i); @@ -360,7 +346,7 @@ Bundle::remove_ports_from_channels () void Bundle::remove_ports_from_channel (uint32_t ch) { - assert (ch < nchannels ()); + assert (ch < nchannels().n_total()); { Glib::Mutex::Lock lm (_channel_mutex); @@ -400,14 +386,11 @@ Bundle::emit_changed (Change c) bool Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine) { - if (_ports_are_inputs == other->_ports_are_inputs || - _type != other->_type || - nchannels() != other->nchannels ()) { - + if (_ports_are_inputs == other->_ports_are_inputs || nchannels() != other->nchannels()) { return false; } - for (uint32_t i = 0; i < nchannels(); ++i) { + for (uint32_t i = 0; i < nchannels().n_total(); ++i) { Bundle::PortList const & A = channel_ports (i); Bundle::PortList const & B = other->channel_ports (i); @@ -433,16 +416,6 @@ Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine) return true; } -/** Set the type of the ports in this Bundle. - * @param t New type. - */ -void -Bundle::set_type (DataType t) -{ - _type = t; - emit_changed (TypeChanged); -} - void Bundle::set_ports_are_inputs () { @@ -473,9 +446,9 @@ Bundle::set_name (string const & n) bool Bundle::has_same_ports (boost::shared_ptr<Bundle> b) const { - uint32_t const N = nchannels (); + uint32_t const N = nchannels().n_total(); - if (b->nchannels() != N) { + if (b->nchannels().n_total() != N) { return false; } @@ -489,3 +462,12 @@ Bundle::has_same_ports (boost::shared_ptr<Bundle> b) const return true; } + +DataType +Bundle::channel_type (uint32_t c) const +{ + assert (c < nchannels().n_total()); + + Glib::Mutex::Lock lm (_channel_mutex); + return _channel[c].type; +} diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index f40cbafb2d..0cc61e1044 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -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; } @@ -771,7 +775,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 +784,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; @@ -1328,8 +1332,6 @@ IO::setup_bundle () _bundle->suspend_signals (); - _bundle->set_type (default_type ()); - _bundle->remove_channels (); if (_direction == Input) { @@ -1340,7 +1342,7 @@ IO::setup_bundle () _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->add_channel (bundle_channel_name (i, ni), _ports.port(i)->type()); _bundle->set_port (i, _session.engine().make_port_name_non_relative (_ports.port(i)->name())); } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 423cc8cb9a..675cd9acfe 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -441,7 +441,7 @@ Session::when_engine_running () snprintf (buf, sizeof (buf), _("out %" PRIu32), np+1); shared_ptr<Bundle> c (new Bundle (buf, true)); - c->add_channel (_("mono")); + c->add_channel (_("mono"), DataType::AUDIO); c->set_port (0, _engine.get_nth_physical_output (DataType::AUDIO, np)); add_bundle (c); @@ -454,9 +454,9 @@ Session::when_engine_running () char buf[32]; snprintf (buf, sizeof(buf), _("out %" PRIu32 "+%" PRIu32), np + 1, np + 2); shared_ptr<Bundle> c (new Bundle (buf, true)); - c->add_channel (_("L")); + c->add_channel (_("L"), DataType::AUDIO); c->set_port (0, _engine.get_nth_physical_output (DataType::AUDIO, np)); - c->add_channel (_("R")); + c->add_channel (_("R"), DataType::AUDIO); c->set_port (1, _engine.get_nth_physical_output (DataType::AUDIO, np + 1)); add_bundle (c); @@ -470,7 +470,7 @@ Session::when_engine_running () snprintf (buf, sizeof (buf), _("in %" PRIu32), np+1); shared_ptr<Bundle> c (new Bundle (buf, false)); - c->add_channel (_("mono")); + c->add_channel (_("mono"), DataType::AUDIO); c->set_port (0, _engine.get_nth_physical_input (DataType::AUDIO, np)); add_bundle (c); @@ -484,9 +484,9 @@ Session::when_engine_running () snprintf (buf, sizeof(buf), _("in %" PRIu32 "+%" PRIu32), np + 1, np + 2); shared_ptr<Bundle> c (new Bundle (buf, false)); - c->add_channel (_("L")); + c->add_channel (_("L"), DataType::AUDIO); c->set_port (0, _engine.get_nth_physical_input (DataType::AUDIO, np)); - c->add_channel (_("R")); + c->add_channel (_("R"), DataType::AUDIO); c->set_port (1, _engine.get_nth_physical_input (DataType::AUDIO, np + 1)); add_bundle (c); diff --git a/libs/ardour/user_bundle.cc b/libs/ardour/user_bundle.cc index 4c39c5f5ff..b6c38e0eed 100644 --- a/libs/ardour/user_bundle.cc +++ b/libs/ardour/user_bundle.cc @@ -50,7 +50,13 @@ ARDOUR::UserBundle::set_state (XMLNode const & node, int /*version*/) return -1; } - add_channel (name->value ()); + XMLProperty const * type; + if ((type = (*i)->property ("type")) == 0) { + PBD::error << _("Node for Channel has no \"type\" property") << endmsg; + return -1; + } + + add_channel (name->value (), DataType (type->value())); XMLNodeList const ports = (*i)->children (); @@ -93,6 +99,7 @@ ARDOUR::UserBundle::get_state () for (std::vector<Channel>::iterator i = _channel.begin(); i != _channel.end(); ++i) { XMLNode* c = new XMLNode ("Channel"); c->add_property ("name", i->name); + c->add_property ("type", i->type.to_string()); for (PortList::iterator j = i->ports.begin(); j != i->ports.end(); ++j) { XMLNode* p = new XMLNode ("Port"); |