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