Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[ardour.git] / libs / ardour / user_bundle.cc
1 #include <cassert>
2 #include "pbd/failed_constructor.h"
3 #include "pbd/compose.h"
4 #include "pbd/xml++.h"
5 #include "ardour/user_bundle.h"
6 #include "ardour/port_set.h"
7 #include "ardour/io.h"
8 #include "ardour/session.h"
9 #include "ardour/audioengine.h"
10 #include "i18n.h"
11
12 ARDOUR::UserBundle::UserBundle (std::string const & n)
13         : Bundle (n)
14 {
15
16 }
17
18 ARDOUR::UserBundle::UserBundle (XMLNode const & x, bool i)
19         : Bundle (i)
20 {
21         if (set_state (x)) {
22                 throw failed_constructor ();
23         }
24 }
25
26 int
27 ARDOUR::UserBundle::set_state (XMLNode const & node)
28 {
29         XMLProperty const * name;
30
31         if ((name = node.property ("name")) == 0) {
32                 PBD::error << _("Node for Bundle has no \"name\" property") << endmsg;
33                 return -1;
34         }
35
36         set_name (name->value ());
37
38         XMLNodeList const channels = node.children ();
39
40         int n = 0;
41         for (XMLNodeConstIterator i = channels.begin(); i != channels.end(); ++i) {
42
43                 if ((*i)->name() != "Channel") {
44                         PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*i)->name()) << endmsg;
45                         return -1;
46                 }
47
48                 if ((name = (*i)->property ("name")) == 0) {
49                         PBD::error << _("Node for Channel has no \"name\" property") << endmsg;
50                         return -1;
51                 }
52
53                 add_channel (name->value ());
54
55                 XMLNodeList const ports = (*i)->children ();
56
57                 for (XMLNodeConstIterator j = ports.begin(); j != ports.end(); ++j) {
58                         if ((*j)->name() != "Port") {
59                                 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*j)->name()) << endmsg;
60                                 return -1;
61                         }
62
63                         if ((name = (*j)->property ("name")) == 0) {
64                                 PBD::error << _("Node for Port has no \"name\" property") << endmsg;
65                                 return -1;
66                         }
67
68                         add_port_to_channel (n, name->value ());
69                 }
70
71                 ++n;
72         }
73
74         return 0;
75 }
76
77 XMLNode&
78 ARDOUR::UserBundle::get_state ()
79 {
80         XMLNode *node;
81
82         if (ports_are_inputs ()) {
83                 node = new XMLNode ("InputBundle");
84         } else {
85                 node = new XMLNode ("OutputBundle");
86         }
87
88         node->add_property ("name", name ());
89
90         {
91                 Glib::Mutex::Lock lm (_channel_mutex);
92
93                 for (std::vector<Channel>::iterator i = _channel.begin(); i != _channel.end(); ++i) {
94                         XMLNode* c = new XMLNode ("Channel");
95                         c->add_property ("name", i->name);
96
97                         for (PortList::iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
98                                 XMLNode* p = new XMLNode ("Port");
99                                 p->add_property ("name", *j);
100                                 c->add_child_nocopy (*p);
101                         }
102
103                         node->add_child_nocopy (*c);
104                 }
105         }
106
107         return *node;
108 }