radically rethink export/bounce/freeze code design. probably not 100% done by freeze...
[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 & node, bool i)
19         : Bundle (i)
20 {
21         if (set_state (node, Stateful::loading_state_version)) {
22                 throw failed_constructor ();
23         }
24 }
25
26 int
27 ARDOUR::UserBundle::set_state (XMLNode const & node, int /*version*/)
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                 XMLProperty const * type;
54                 if ((type = (*i)->property ("type")) == 0) {
55                         PBD::error << _("Node for Channel has no \"type\" property") << endmsg;
56                         return -1;
57                 }
58
59                 add_channel (name->value (), DataType (type->value()));
60
61                 XMLNodeList const ports = (*i)->children ();
62
63                 for (XMLNodeConstIterator j = ports.begin(); j != ports.end(); ++j) {
64                         if ((*j)->name() != "Port") {
65                                 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*j)->name()) << endmsg;
66                                 return -1;
67                         }
68
69                         if ((name = (*j)->property ("name")) == 0) {
70                                 PBD::error << _("Node for Port has no \"name\" property") << endmsg;
71                                 return -1;
72                         }
73
74                         add_port_to_channel (n, name->value ());
75                 }
76
77                 ++n;
78         }
79
80         return 0;
81 }
82
83 XMLNode&
84 ARDOUR::UserBundle::get_state ()
85 {
86         XMLNode *node;
87
88         if (ports_are_inputs ()) {
89                 node = new XMLNode ("InputBundle");
90         } else {
91                 node = new XMLNode ("OutputBundle");
92         }
93
94         node->add_property ("name", name ());
95
96         {
97                 Glib::Mutex::Lock lm (_channel_mutex);
98
99                 for (std::vector<Channel>::iterator i = _channel.begin(); i != _channel.end(); ++i) {
100                         XMLNode* c = new XMLNode ("Channel");
101                         c->add_property ("name", i->name);
102                         c->add_property ("type", i->type.to_string());
103
104                         for (PortList::iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
105                                 XMLNode* p = new XMLNode ("Port");
106                                 p->add_property ("name", *j);
107                                 c->add_child_nocopy (*p);
108                         }
109
110                         node->add_child_nocopy (*c);
111                 }
112         }
113
114         return *node;
115 }