2 Copyright (C) 2012 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.
20 #include "ardour/user_bundle.h"
21 #include "ardour/types_convert.h"
23 #include "pbd/compose.h"
24 #include "pbd/error.h"
25 #include "pbd/failed_constructor.h"
26 #include "pbd/xml++.h"
28 ARDOUR::UserBundle::UserBundle (std::string const & n)
34 ARDOUR::UserBundle::UserBundle (XMLNode const & node, bool i)
37 if (set_state (node, Stateful::loading_state_version)) {
38 throw failed_constructor ();
43 ARDOUR::UserBundle::set_state (XMLNode const & node, int /*version*/)
46 if (!node.get_property ("name", str)) {
47 PBD::error << _("Node for Bundle has no \"name\" property") << endmsg;
53 XMLNodeList const channels = node.children ();
56 for (XMLNodeConstIterator i = channels.begin(); i != channels.end(); ++i) {
58 if ((*i)->name() != "Channel") {
59 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*i)->name()) << endmsg;
63 if (!(*i)->get_property ("name", str)) {
64 PBD::error << _("Node for Channel has no \"name\" property") << endmsg;
68 DataType type(DataType::NIL);
69 if (!(*i)->get_property ("type", type)) {
70 PBD::error << _("Node for Channel has no \"type\" property") << endmsg;
74 add_channel (str, type);
76 XMLNodeList const ports = (*i)->children ();
78 for (XMLNodeConstIterator j = ports.begin(); j != ports.end(); ++j) {
79 if ((*j)->name() != "Port") {
80 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*j)->name()) << endmsg;
84 if (!(*j)->get_property ("name", str)) {
85 PBD::error << _("Node for Port has no \"name\" property") << endmsg;
89 add_port_to_channel (n, str);
99 ARDOUR::UserBundle::get_state ()
103 if (ports_are_inputs ()) {
104 node = new XMLNode ("InputBundle");
106 node = new XMLNode ("OutputBundle");
109 node->set_property ("name", name ());
112 Glib::Threads::Mutex::Lock lm (_channel_mutex);
114 for (std::vector<Channel>::iterator i = _channel.begin(); i != _channel.end(); ++i) {
115 XMLNode* c = new XMLNode ("Channel");
116 c->set_property ("name", i->name);
117 c->set_property ("type", i->type);
119 for (PortList::iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
120 XMLNode* p = new XMLNode ("Port");
121 p->set_property ("name", *j);
122 c->add_child_nocopy (*p);
125 node->add_child_nocopy (*c);