summaryrefslogtreecommitdiff
path: root/libs/ardour/user_bundle.cc
blob: d53bf8b155764c7622fc803bc5e74ef59a61677d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <cassert>
#include <pbd/failed_constructor.h>
#include <pbd/compose.h>
#include <pbd/xml++.h>
#include "ardour/user_bundle.h"
#include "ardour/port_set.h"
#include "ardour/io.h"
#include "ardour/session.h"
#include "ardour/audioengine.h"
#include "i18n.h"

ARDOUR::UserBundle::UserBundle (std::string const & n)
	: Bundle (n)
{

}

ARDOUR::UserBundle::UserBundle (XMLNode const & x, bool i)
	: Bundle (i)
{
	if (set_state (x)) {
		throw failed_constructor ();
	}
}

int
ARDOUR::UserBundle::set_state (XMLNode const & node)
{
	XMLProperty const * name;
	
	if ((name = node.property ("name")) == 0) {
		PBD::error << _("Node for Bundle has no \"name\" property") << endmsg;
		return -1;
	}

	set_name (name->value ());

	XMLNodeList const channels = node.children ();

	int n = 0;
	for (XMLNodeConstIterator i = channels.begin(); i != channels.end(); ++i) {

		if ((*i)->name() != "Channel") {
			PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*i)->name()) << endmsg;
			return -1;
		}

		add_channel ();

		XMLNodeList const ports = (*i)->children ();

		for (XMLNodeConstIterator j = ports.begin(); j != ports.end(); ++j) {
			if ((*j)->name() != "Port") {
				PBD::error << string_compose (_("Unknown node \"%s\" in Bundle"), (*j)->name()) << endmsg;
				return -1;
			}

			if ((name = (*j)->property ("name")) == 0) {
				PBD::error << _("Node for Port has no \"name\" property") << endmsg;
				return -1;
			} 
			
			add_port_to_channel (n, name->value ());
		}

		++n;
	}

	return 0;
}

XMLNode&
ARDOUR::UserBundle::get_state ()
{
	XMLNode *node;
	
	if (ports_are_inputs ()) {
		node = new XMLNode ("InputBundle");
	} else {
		node = new XMLNode ("OutputBundle");
	}

	node->add_property ("name", name ());

	{
		Glib::Mutex::Lock lm (_ports_mutex);

		for (std::vector<PortList>::iterator i = _ports.begin(); i != _ports.end(); ++i) {
			
			XMLNode* c = new XMLNode ("Channel");
			
			for (PortList::iterator j = i->begin(); j != i->end(); ++j) {
				XMLNode* p = new XMLNode ("Port");
				p->add_property ("name", *j);
				c->add_child_nocopy (*p);
			}
			
			node->add_child_nocopy (*c);
		}
	}

	return *node;
}