2 * Copyright (C) 2007-2010 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "ardour/user_bundle.h"
22 #include "ardour/types_convert.h"
24 #include "pbd/compose.h"
25 #include "pbd/error.h"
26 #include "pbd/failed_constructor.h"
27 #include "pbd/xml++.h"
29 ARDOUR::UserBundle::UserBundle (std::string const & n)
35 ARDOUR::UserBundle::UserBundle (XMLNode const & node, bool i)
38 if (set_state (node, Stateful::loading_state_version)) {
39 throw failed_constructor ();
44 ARDOUR::UserBundle::set_state (XMLNode const & node, int /*version*/)
47 if (!node.get_property ("name", str)) {
48 PBD::error << _("Node for Bundle has no \"name\" property") << endmsg;
54 XMLNodeList const channels = node.children ();
57 for (XMLNodeConstIterator i = channels.begin(); i != channels.end(); ++i) {
59 if ((*i)->name() != "Channel") {
60 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*i)->name()) << endmsg;
64 if (!(*i)->get_property ("name", str)) {
65 PBD::error << _("Node for Channel has no \"name\" property") << endmsg;
69 DataType type(DataType::NIL);
70 if (!(*i)->get_property ("type", type)) {
71 PBD::error << _("Node for Channel has no \"type\" property") << endmsg;
75 add_channel (str, type);
77 XMLNodeList const ports = (*i)->children ();
79 for (XMLNodeConstIterator j = ports.begin(); j != ports.end(); ++j) {
80 if ((*j)->name() != "Port") {
81 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*j)->name()) << endmsg;
85 if (!(*j)->get_property ("name", str)) {
86 PBD::error << _("Node for Port has no \"name\" property") << endmsg;
90 add_port_to_channel (n, str);
100 ARDOUR::UserBundle::get_state ()
104 if (ports_are_inputs ()) {
105 node = new XMLNode ("InputBundle");
107 node = new XMLNode ("OutputBundle");
110 node->set_property ("name", name ());
113 Glib::Threads::Mutex::Lock lm (_channel_mutex);
115 for (std::vector<Channel>::iterator i = _channel.begin(); i != _channel.end(); ++i) {
116 XMLNode* c = new XMLNode ("Channel");
117 c->set_property ("name", i->name);
118 c->set_property ("type", i->type);
120 for (PortList::iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
121 XMLNode* p = new XMLNode ("Port");
122 p->set_property ("name", *j);
123 c->add_child_nocopy (*p);
126 node->add_child_nocopy (*c);