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