Part 1 of loading 2.X sessions; some things work, some things don't, hacks a-plenty.
[ardour.git] / libs / ardour / session_metadata.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 it
6     under the terms of the GNU General Public License as published by the Free
7     Software Foundation; either version 2 of the License, or (at your option)
8     any later version.
9
10     This program is distributed in the hope that it will be useful, but WITHOUT
11     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13     for more details.
14
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "ardour/session_metadata.h"
21
22 #include <iostream>
23 #include <sstream>
24
25 using namespace std;
26 using namespace Glib;
27 using namespace ARDOUR;
28
29 SessionMetadata::SessionMetadata ()
30 {
31         /*** General ***/
32         map.insert (Property ("comment", ""));
33         map.insert (Property ("copyright", ""));
34         map.insert (Property ("isrc", ""));
35         map.insert (Property ("year", ""));
36
37         /*** Title and friends ***/
38         map.insert (Property ("grouping", ""));
39         map.insert (Property ("title", ""));
40         map.insert (Property ("subtitle", ""));
41
42         /*** People... ***/
43         map.insert (Property ("artist", ""));
44         map.insert (Property ("album_artist", ""));
45         map.insert (Property ("lyricist", ""));
46         map.insert (Property ("composer", ""));
47         map.insert (Property ("conductor", ""));
48         map.insert (Property ("remixer", ""));
49         map.insert (Property ("arranger", ""));
50         map.insert (Property ("engineer", ""));
51         map.insert (Property ("producer", ""));
52         map.insert (Property ("dj_mixer", ""));
53         map.insert (Property ("mixer", ""));
54         //map.insert (Property ("performers", "")); // Multiple values [instrument]
55
56         /*** Album info ***/
57         map.insert (Property ("album", ""));
58         map.insert (Property ("compilation", ""));
59         map.insert (Property ("disc_subtitle", ""));
60         map.insert (Property ("disc_number", ""));
61         map.insert (Property ("total_discs", ""));
62         map.insert (Property ("track_number", ""));
63         map.insert (Property ("total_tracks", ""));
64
65         /*** Style ***/
66         map.insert (Property ("genre", ""));
67         //map.insert (Property ("mood", ""));
68         //map.insert (Property ("bpm", ""));
69
70         /*** Other ***/
71         //map.insert (Property ("lyrics", ""));
72         //map.insert (Property ("media", ""));
73         //map.insert (Property ("label", ""));
74         //map.insert (Property ("barcode", ""));
75         //map.insert (Property ("encoded_by", ""));
76         //map.insert (Property ("catalog_number", ""));
77
78         /*** Sorting orders ***/
79         //map.insert (Property ("album_sort", ""));
80         //map.insert (Property ("album_artist_sort", ""));
81         //map.insert (Property ("artist_sort", ""));
82         //map.insert (Property ("title_sort", ""));
83 }
84
85 SessionMetadata::~SessionMetadata ()
86 {
87
88 }
89
90 XMLNode *
91 SessionMetadata::get_xml (const ustring & name)
92 {
93         ustring value = get_value (name);
94         if (value.empty()) {
95                 return 0;
96         }
97
98         XMLNode val ("value", value);
99         XMLNode * node = new XMLNode (name);
100         node->add_child_copy (val);
101
102         return node;
103 }
104
105 ustring
106 SessionMetadata::get_value (const ustring & name) const
107 {
108         PropertyMap::const_iterator it = map.find (name);
109         if (it == map.end()) {
110                 // Should not be reached!
111                 std::cerr << "Programming error in SessionMetadata::get_value" << std::endl;
112                 return "";
113         }
114
115         return it->second;
116 }
117
118 uint32_t
119 SessionMetadata::get_uint_value (const ustring & name) const
120 {
121         return atoi (get_value (name).c_str());
122 }
123
124 void
125 SessionMetadata::set_value (const ustring & name, const ustring & value)
126 {
127         PropertyMap::iterator it = map.find (name);
128         if (it == map.end()) {
129                 // Should not be reached!
130                 std::cerr << "Programming error in SessionMetadata::set_value" << std::endl;
131                 return;
132         }
133
134         it->second = value;
135 }
136
137 void
138 SessionMetadata::set_value (const ustring & name, uint32_t value)
139 {
140         std::ostringstream oss;
141         oss << value;
142         if (oss.str().compare("0")) {
143                 set_value (name, oss.str());
144         } else {
145                 set_value (name, "");
146         }
147 }
148
149 /*** Serialization ***/
150 XMLNode &
151 SessionMetadata::get_state ()
152 {
153         XMLNode * node = new XMLNode ("Metadata");
154         XMLNode * prop;
155
156         for (PropertyMap::const_iterator it = map.begin(); it != map.end(); ++it) {
157                 if ((prop = get_xml (it->first))) {
158                         node->add_child_nocopy (*prop);
159                 }
160         }
161
162         return *node;
163 }
164
165 int
166 SessionMetadata::set_state (const XMLNode & state, int version)
167 {
168         const XMLNodeList & children = state.children();
169         ustring name;
170         ustring value;
171         XMLNode * node;
172
173         for (XMLNodeConstIterator it = children.begin(); it != children.end(); it++) {
174                 node = *it;
175                 if (node->children().empty()) {
176                         continue;
177                 }
178
179                 name = node->name();
180                 node = *node->children().begin();
181                 value = node->content();
182
183                 set_value (name, value);
184         }
185
186         return 0;
187 }
188
189 /*** Accessing ***/
190 ustring
191 SessionMetadata::comment () const
192 {
193         return get_value("comment");
194 }
195
196 ustring
197 SessionMetadata::copyright () const
198 {
199         return get_value("copyright");
200 }
201
202 ustring
203 SessionMetadata::isrc () const
204 {
205         return get_value("isrc");
206 }
207
208 uint32_t
209 SessionMetadata::year () const
210 {
211         return get_uint_value("year");
212 }
213
214 ustring
215 SessionMetadata::grouping () const
216 {
217         return get_value("grouping");
218 }
219
220 ustring
221 SessionMetadata::title () const
222 {
223         return get_value("title");
224 }
225
226 ustring
227 SessionMetadata::subtitle () const
228 {
229         return get_value("subtitle");
230 }
231
232 ustring
233 SessionMetadata::artist () const
234 {
235         return get_value("artist");
236 }
237
238 ustring
239 SessionMetadata::album_artist () const
240 {
241         return get_value("album_artist");
242 }
243
244 ustring
245 SessionMetadata::lyricist () const
246 {
247         return get_value("lyricist");
248 }
249
250 ustring
251 SessionMetadata::composer () const
252 {
253         return get_value("composer");
254 }
255
256 ustring
257 SessionMetadata::conductor () const
258 {
259         return get_value("conductor");
260 }
261
262 ustring
263 SessionMetadata::remixer () const
264 {
265         return get_value("remixer");
266 }
267
268 ustring
269 SessionMetadata::arranger () const
270 {
271         return get_value("arranger");
272 }
273
274 ustring
275 SessionMetadata::engineer () const
276 {
277         return get_value("engineer");
278 }
279
280 ustring
281 SessionMetadata::producer () const
282 {
283         return get_value("producer");
284 }
285
286 ustring
287 SessionMetadata::dj_mixer () const
288 {
289         return get_value("dj_mixer");
290 }
291
292 ustring
293 SessionMetadata::mixer () const
294 {
295         return get_value("mixer");
296 }
297
298 ustring
299 SessionMetadata::album () const
300 {
301         return get_value("album");
302 }
303
304 ustring
305 SessionMetadata::compilation () const
306 {
307         return get_value("compilation");
308 }
309
310 ustring
311 SessionMetadata::disc_subtitle () const
312 {
313         return get_value("disc_subtitle");
314 }
315
316 uint32_t
317 SessionMetadata::disc_number () const
318 {
319         return get_uint_value("disc_number");
320 }
321
322 uint32_t
323 SessionMetadata::total_discs () const
324 {
325         return get_uint_value("total_discs");
326 }
327
328 uint32_t
329 SessionMetadata::track_number () const
330 {
331         return get_uint_value("track_number");
332 }
333
334 uint32_t
335 SessionMetadata::total_tracks () const
336 {
337         return get_uint_value("total_tracks");
338 }
339
340 ustring
341 SessionMetadata::genre () const
342 {
343         return get_value("genre");
344 }
345
346 /*** Editing ***/
347 void
348 SessionMetadata::set_comment (const ustring & v)
349 {
350         set_value ("comment", v);
351 }
352
353 void
354 SessionMetadata::set_copyright (const ustring & v)
355 {
356         set_value ("copyright", v);
357 }
358
359 void
360 SessionMetadata::set_isrc (const ustring & v)
361 {
362         set_value ("isrc", v);
363 }
364
365 void
366 SessionMetadata::set_year (uint32_t v)
367 {
368         set_value ("year", v);
369 }
370
371 void
372 SessionMetadata::set_grouping (const ustring & v)
373 {
374         set_value ("grouping", v);
375 }
376
377 void
378 SessionMetadata::set_title (const ustring & v)
379 {
380         set_value ("title", v);
381 }
382
383 void
384 SessionMetadata::set_subtitle (const ustring & v)
385 {
386         set_value ("subtitle", v);
387 }
388
389 void
390 SessionMetadata::set_artist (const ustring & v)
391 {
392         set_value ("artist", v);
393 }
394
395 void
396 SessionMetadata::set_album_artist (const ustring & v)
397 {
398         set_value ("album_artist", v);
399 }
400
401 void
402 SessionMetadata::set_lyricist (const ustring & v)
403 {
404         set_value ("lyricist", v);
405 }
406
407 void
408 SessionMetadata::set_composer (const ustring & v)
409 {
410         set_value ("composer", v);
411 }
412
413 void
414 SessionMetadata::set_conductor (const ustring & v)
415 {
416         set_value ("conductor", v);
417 }
418
419 void
420 SessionMetadata::set_remixer (const ustring & v)
421 {
422         set_value ("remixer", v);
423 }
424
425 void
426 SessionMetadata::set_arranger (const ustring & v)
427 {
428         set_value ("arranger", v);
429 }
430
431 void
432 SessionMetadata::set_engineer (const ustring & v)
433 {
434         set_value ("engineer", v);
435 }
436
437 void
438 SessionMetadata::set_producer (const ustring & v)
439 {
440         set_value ("producer", v);
441 }
442
443 void
444 SessionMetadata::set_dj_mixer (const ustring & v)
445 {
446         set_value ("dj_mixer", v);
447 }
448
449 void
450 SessionMetadata::set_mixer (const ustring & v)
451 {
452         set_value ("mixer", v);
453 }
454
455 void
456 SessionMetadata::set_album (const ustring & v)
457 {
458         set_value ("album", v);
459 }
460
461 void
462 SessionMetadata::set_compilation (const ustring & v)
463 {
464         set_value ("compilation", v);
465 }
466
467 void
468 SessionMetadata::set_disc_subtitle (const ustring & v)
469 {
470         set_value ("disc_subtitle", v);
471 }
472
473 void
474 SessionMetadata::set_disc_number (uint32_t v)
475 {
476         set_value ("disc_number", v);
477 }
478
479 void
480 SessionMetadata::set_total_discs (uint32_t v)
481 {
482         set_value ("total_discs", v);
483 }
484
485 void
486 SessionMetadata::set_track_number (uint32_t v)
487 {
488         set_value ("track_number", v);
489 }
490
491 void
492 SessionMetadata::set_total_tracks (uint32_t v)
493 {
494         set_value ("total_tracks", v);
495 }
496
497 void
498 SessionMetadata::set_genre (const ustring & v)
499 {
500         set_value ("genre", v);
501 }