summaryrefslogtreecommitdiff
path: root/libs/ardour/audio_track_importer.cc
blob: 68827fb1613170996f081a838cbfb440b0e677fd (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
    Copyright (C) 2008 Paul Davis
    Author: Sakari Bergen

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <ardour/audio_track_importer.h>

#include <ardour/session.h>

#include <pbd/id.h>
#include <pbd/failed_constructor.h>
#include <pbd/convert.h>

#include "i18n.h"

using namespace PBD;
using namespace ARDOUR;

/*** AudioTrackImportHandler ***/

AudioTrackImportHandler::AudioTrackImportHandler (XMLTree const & source, Session & session) :
  ElementImportHandler (source, session)
{
	XMLNode const * root = source.root();
	XMLNode const * routes;
	
	if (!(routes = root->child ("Routes"))) {
		throw failed_constructor();
	}
	
	XMLNodeList const & route_list = routes->children();
	for (XMLNodeList::const_iterator it = route_list.begin(); it != route_list.end(); ++it) {
		const XMLProperty* type = (*it)->property("default-type");
		if ( !type || type->value() == "audio" ) {
			try {
				elements.push_back (ElementPtr ( new AudioTrackImporter (source, session, *this, **it)));
			} catch (failed_constructor err) {
				set_dirty();
			}
		}
	}
}

string
AudioTrackImportHandler::get_info () const
{
	return _("Audio Tracks");
}


/*** AudioTrackImporter ***/

AudioTrackImporter::AudioTrackImporter (XMLTree const & source, Session & session, AudioTrackImportHandler & handler, XMLNode const & node) :
  ElementImporter (source, session),
  xml_track (node)
{
	XMLProperty * prop;

	if (!parse_route_xml ()) {
		throw failed_constructor();
	}
	
	if (!parse_io ()) {
		throw failed_constructor();
	}
	
	XMLNodeList const & controllables = node.children ("controllable");
	for (XMLNodeList::const_iterator it = controllables.begin(); it != controllables.end(); ++it) {
		parse_controllable (**it);
	}
	
	XMLNode * remote_control = xml_track.child ("remote_control");
	if (remote_control && (prop = remote_control->property ("id"))) {
		uint32_t control_id = session.ntracks() + session.nbusses() + 1;
		prop->set_value (to_string (control_id, std::dec));
	}
	
	xml_track.remove_nodes_and_delete ("extra");
}

bool
AudioTrackImporter::parse_route_xml ()
{
	XMLPropertyList const & props = xml_track.properties();

	for (XMLPropertyList::const_iterator it = props.begin(); it != props.end(); ++it) {
		string prop = (*it)->name();
		if (!prop.compare ("default-type") || !prop.compare ("flags") ||
		  !prop.compare ("active") || !prop.compare ("muted") ||
		  !prop.compare ("soloed") || !prop.compare ("phase-invert") ||
		  !prop.compare ("denormal-protection") || !prop.compare("mute-affects-pre-fader") ||
		  !prop.compare ("mute-affects-post-fader") || !prop.compare("mute-affects-control-outs") ||
		  !prop.compare ("mute-affects-main-outs") || !prop.compare("mode")) {
			// All ok
		} else if (!prop.compare("order-keys")) {
			// TODO
		} else if (!prop.compare("diskstream-id")) {
			// TODO
		} else {
			std::cerr << string_compose (X_("AudioTrackImporter: did not recognise XML-property \"%1\""), prop) << endmsg;
		}
	}
	
	return true;
}

bool
AudioTrackImporter::parse_io ()
{
	XMLNode * io;
	bool name_ok = false;
	bool id_ok = false;

	if (!(io = xml_track.child ("IO"))) {
		return false;
	}
	
	XMLPropertyList const & props = io->properties();

	for (XMLPropertyList::const_iterator it = props.begin(); it != props.end(); ++it) {
		string prop = (*it)->name();
		if (!prop.compare ("gain") || !prop.compare ("iolimits")) {
			// All ok
		} else if (!prop.compare("name")) {
			name = prop;
			name_ok = true;
		} else if (!prop.compare("id")) {
			PBD::ID id;
			(*it)->set_value (id.to_s());
			id_ok = true;
			// TODO
		} else if (!prop.compare("inputs")) {
			// TODO
		} else if (!prop.compare("outputs")) {
			// TODO
		} else {
			std::cerr << string_compose (X_("AudioTrackImporter: did not recognise XML-property \"%1\""), prop) << endmsg;
		}
	}
	
	if (!name_ok) {
		error << X_("AudioTrackImporter: did not find necessary XML-property \"name\"") << endmsg;
		return false;
	}
	
	if (!id_ok) {
		error << X_("AudioTrackImporter: did not find necessary XML-property \"id\"") << endmsg;
		return false;
	}
	
	XMLNodeList const & controllables = io->children ("controllable");
	for (XMLNodeList::const_iterator it = controllables.begin(); it != controllables.end(); ++it) {
		parse_controllable (**it);
	}
	
	XMLNodeList const & processors = io->children ("Processor");
	for (XMLNodeList::const_iterator it = processors.begin(); it != processors.end(); ++it) {
		parse_processor (**it);
	}
	
	XMLNodeList const & automations = io->children ("Automation");
	for (XMLNodeList::const_iterator it = automations.begin(); it != automations.end(); ++it) {
		parse_automation (**it);
	}
	
	return true;
}

string
AudioTrackImporter::get_info () const
{
	// TODO
	return name;
}

bool
AudioTrackImporter::prepare_move ()
{
	// TODO
	return false;
}

void
AudioTrackImporter::cancel_move ()
{
	// TODO
}

void
AudioTrackImporter::move ()
{
	// TODO
}

bool
AudioTrackImporter::parse_processor (XMLNode & node)
{
	XMLNode * automation = node.child ("Automation");
	if (automation) {
		parse_automation (*automation);
	}
	
	return true;
}

bool
AudioTrackImporter::parse_controllable (XMLNode & node)
{
	XMLProperty * prop;
	
	if ((prop = node.property ("id"))) {
		PBD::ID new_id;
		prop->set_value (new_id.to_s());
	} else {
		return false;
	}

	return true;
}

bool
AudioTrackImporter::parse_automation (XMLNode & node)
{

	XMLNodeList const & lists = node.children ("AutomationList");
	for (XMLNodeList::const_iterator it = lists.begin(); it != lists.end(); ++it) {
		XMLProperty * prop;
		
		if ((prop = (*it)->property ("id"))) {
			PBD::ID id;
			prop->set_value (id.to_s());
		}
		
		// TODO rate convert events
	}

	return true;
}