summaryrefslogtreecommitdiff
path: root/libs/ardour/audio_track_importer.cc
blob: 752203f2cb79186cdb8374bcf4903bfd28110625 (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
/*
    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 <pbd/id.h>
#include <pbd/failed_constructor.h>

#include "i18n.h"

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 ("Route")
{
	// TODO Parse top-level XML
	
	if (!parse_io (node)) {
		throw failed_constructor();
	}
	
	XMLNodeList const & controllables = node.children ("controllable");
	for (XMLNodeList::const_iterator it = controllables.begin(); it != controllables.end(); ++it) {
		parse_controllable (**it, xml_track);
	}
	
	// TODO parse remote-control and extra?
	
}

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_io (XMLNode const & node)
{
	XMLNode * io;
	XMLProperty * prop;

	if (!(io = node.child ("IO"))) {
		return false;
	}
	
	if ((prop = io->property ("name"))) {
		name = prop->value();
	} else {
		return false;
	}
	
	// TODO parse rest of the XML

	return true;
}

bool
AudioTrackImporter::parse_controllable (XMLNode const & node, XMLNode & dest_parent)
{
	XMLProperty * prop;
	XMLNode new_node (node);
	
	if ((prop = new_node.property ("id"))) {
		PBD::ID old_id (prop->value());
		PBD::ID new_id;
		
		prop->set_value (new_id.to_s());
		// TODO do id mapping and everything else necessary...
		
	} else {
		return false;
	}
	
	dest_parent.add_child_copy (new_node);

	return true;
}

} // namespace ARDOUR