752203f2cb79186cdb8374bcf4903bfd28110625
[ardour.git] / libs / ardour / audio_track_importer.cc
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include <ardour/audio_track_importer.h>
22
23 #include <pbd/id.h>
24 #include <pbd/failed_constructor.h>
25
26 #include "i18n.h"
27
28 namespace ARDOUR {
29
30 /*** AudioTrackImportHandler ***/
31
32 AudioTrackImportHandler::AudioTrackImportHandler (XMLTree const & source, Session & session) :
33   ElementImportHandler (source, session)
34 {
35         XMLNode const * root = source.root();
36         XMLNode const * routes;
37         
38         if (!(routes = root->child ("Routes"))) {
39                 throw failed_constructor();
40         }
41         
42         XMLNodeList const & route_list = routes->children();
43         for (XMLNodeList::const_iterator it = route_list.begin(); it != route_list.end(); ++it) {
44                 const XMLProperty* type = (*it)->property("default-type");
45                 if ( !type || type->value() == "audio" ) {
46                         try {
47                                 elements.push_back (ElementPtr ( new AudioTrackImporter (source, session, *this, **it)));
48                         } catch (failed_constructor err) {
49                                 set_dirty();
50                         }
51                 }
52         }
53 }
54
55 string
56 AudioTrackImportHandler::get_info () const
57 {
58         return _("Audio Tracks");
59 }
60
61
62 /*** AudioTrackImporter ***/
63
64 AudioTrackImporter::AudioTrackImporter (XMLTree const & source, Session & session, AudioTrackImportHandler & handler, XMLNode const & node) :
65   ElementImporter (source, session),
66   xml_track ("Route")
67 {
68         // TODO Parse top-level XML
69         
70         if (!parse_io (node)) {
71                 throw failed_constructor();
72         }
73         
74         XMLNodeList const & controllables = node.children ("controllable");
75         for (XMLNodeList::const_iterator it = controllables.begin(); it != controllables.end(); ++it) {
76                 parse_controllable (**it, xml_track);
77         }
78         
79         // TODO parse remote-control and extra?
80         
81 }
82
83 string
84 AudioTrackImporter::get_info () const
85 {
86         // TODO
87         return name;
88 }
89
90 bool
91 AudioTrackImporter::prepare_move ()
92 {
93         // TODO
94         return false;
95 }
96
97 void
98 AudioTrackImporter::cancel_move ()
99 {
100         // TODO
101 }
102
103 void
104 AudioTrackImporter::move ()
105 {
106         // TODO
107 }
108
109 bool
110 AudioTrackImporter::parse_io (XMLNode const & node)
111 {
112         XMLNode * io;
113         XMLProperty * prop;
114
115         if (!(io = node.child ("IO"))) {
116                 return false;
117         }
118         
119         if ((prop = io->property ("name"))) {
120                 name = prop->value();
121         } else {
122                 return false;
123         }
124         
125         // TODO parse rest of the XML
126
127         return true;
128 }
129
130 bool
131 AudioTrackImporter::parse_controllable (XMLNode const & node, XMLNode & dest_parent)
132 {
133         XMLProperty * prop;
134         XMLNode new_node (node);
135         
136         if ((prop = new_node.property ("id"))) {
137                 PBD::ID old_id (prop->value());
138                 PBD::ID new_id;
139                 
140                 prop->set_value (new_id.to_s());
141                 // TODO do id mapping and everything else necessary...
142                 
143         } else {
144                 return false;
145         }
146         
147         dest_parent.add_child_copy (new_node);
148
149         return true;
150 }
151
152 } // namespace ARDOUR