* Add SysEx Support to MidiModel / SMF
[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                 add_channel ("XXX");
49
50                 XMLNodeList const ports = (*i)->children ();
51
52                 for (XMLNodeConstIterator j = ports.begin(); j != ports.end(); ++j) {
53                         if ((*j)->name() != "Port") {
54                                 PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*j)->name()) << endmsg;
55                                 return -1;
56                         }
57
58                         if ((name = (*j)->property ("name")) == 0) {
59                                 PBD::error << _("Node for Port has no \"name\" property") << endmsg;
60                                 return -1;
61                         } 
62                         
63                         add_port_to_channel (n, name->value ());
64                 }
65
66                 ++n;
67         }
68
69         return 0;
70 }
71
72 XMLNode&
73 ARDOUR::UserBundle::get_state ()
74 {
75         XMLNode *node;
76         
77         if (ports_are_inputs ()) {
78                 node = new XMLNode ("InputBundle");
79         } else {
80                 node = new XMLNode ("OutputBundle");
81         }
82
83         node->add_property ("name", name ());
84
85         {
86                 Glib::Mutex::Lock lm (_channel_mutex);
87
88                 for (std::vector<Channel>::iterator i = _channel.begin(); i != _channel.end(); ++i) {
89                         XMLNode* c = new XMLNode ("Channel");
90                         c->add_property ("name", i->name);
91                         
92                         for (PortList::iterator j = i->ports.begin(); j != i->ports.end(); ++j) {
93                                 XMLNode* p = new XMLNode ("Port");
94                                 p->add_property ("name", *j);
95                                 c->add_child_nocopy (*p);
96                         }
97                         
98                         node->add_child_nocopy (*c);
99                 }
100         }
101
102         return *node;
103 }