2 #include <pbd/failed_constructor.h>
3 #include <pbd/compose.h>
5 #include "ardour/user_bundle.h"
6 #include "ardour/port_set.h"
8 #include "ardour/session.h"
9 #include "ardour/audioengine.h"
12 ARDOUR::UserBundle::UserBundle (std::string const & n)
18 ARDOUR::UserBundle::UserBundle (XMLNode const & x, bool i)
22 throw failed_constructor ();
27 ARDOUR::UserBundle::nchannels () const
29 Glib::Mutex::Lock lm (_ports_mutex);
30 return ChanCount (type(), _ports.size ());
33 const ARDOUR::PortList&
34 ARDOUR::UserBundle::channel_ports (uint32_t n) const
36 assert (n < nchannels ().get (type()));
38 Glib::Mutex::Lock lm (_ports_mutex);
43 ARDOUR::UserBundle::add_port_to_channel (uint32_t c, std::string const & p)
45 assert (c < nchannels ().get (type()));
50 Glib::Mutex::Lock lm (_ports_mutex);
51 _ports[c].push_back (p);
58 ARDOUR::UserBundle::remove_port_from_channel (uint32_t c, std::string const & p)
60 assert (c < nchannels ().get (type()));
65 Glib::Mutex::Lock lm (_ports_mutex);
66 PortList::iterator i = std::find (_ports[c].begin(), _ports[c].end(), p);
67 if (i != _ports[c].end()) {
76 ARDOUR::UserBundle::port_attached_to_channel (uint32_t c, std::string const & p) const
78 assert (c < nchannels ().get (type()));
80 Glib::Mutex::Lock lm (_ports_mutex);
81 return std::find (_ports[c].begin(), _ports[c].end(), p) != _ports[c].end();
85 ARDOUR::UserBundle::add_channel ()
87 ConfigurationWillChange ();
90 Glib::Mutex::Lock lm (_ports_mutex);
91 _ports.resize (_ports.size() + 1);
94 ConfigurationHasChanged ();
98 ARDOUR::UserBundle::set_channels (uint32_t n)
100 ConfigurationWillChange ();
103 Glib::Mutex::Lock lm (_ports_mutex);
107 ConfigurationHasChanged ();
111 ARDOUR::UserBundle::remove_channel (uint32_t r)
113 assert (r < nchannels ().get (type()));
115 ConfigurationWillChange ();
118 Glib::Mutex::Lock lm (_ports_mutex);
119 _ports.erase (_ports.begin() + r, _ports.begin() + r + 1);
122 ConfigurationHasChanged ();
126 ARDOUR::UserBundle::set_state (XMLNode const & node)
128 XMLProperty const * name;
130 if ((name = node.property ("name")) == 0) {
131 PBD::error << _("Node for Bundle has no \"name\" property") << endmsg;
135 set_name (name->value ());
137 XMLNodeList const channels = node.children ();
140 for (XMLNodeConstIterator i = channels.begin(); i != channels.end(); ++i) {
142 if ((*i)->name() != "Channel") {
143 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*i)->name()) << endmsg;
149 XMLNodeList const ports = (*i)->children ();
151 for (XMLNodeConstIterator j = ports.begin(); j != ports.end(); ++j) {
152 if ((*j)->name() != "Port") {
153 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*j)->name()) << endmsg;
157 if ((name = (*j)->property ("name")) == 0) {
158 PBD::error << _("Node for Port has no \"name\" property") << endmsg;
162 add_port_to_channel (n, name->value ());
172 ARDOUR::UserBundle::get_state ()
176 if (ports_are_inputs ()) {
177 node = new XMLNode ("InputBundle");
179 node = new XMLNode ("OutputBundle");
182 node->add_property ("name", name ());
184 for (std::vector<PortList>::iterator i = _ports.begin(); i != _ports.end(); ++i) {
186 XMLNode* c = new XMLNode ("Channel");
188 for (PortList::iterator j = i->begin(); j != i->end(); ++j) {
189 XMLNode* p = new XMLNode ("Port");
190 p->add_property ("name", *j);
191 c->add_child_nocopy (*p);
194 node->add_child_nocopy (*c);