Collect plugin runtime profile statistics.
[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::_metadata = NULL;  //singleton instance
30
31 SessionMetadata::SessionMetadata ()
32 {
33         /*** General ***/
34         map.insert (Property ("description", ""));
35
36         /*** Track/Song Data ***/
37         map.insert (Property ("comment", ""));
38         map.insert (Property ("copyright", ""));
39         map.insert (Property ("isrc", ""));
40         map.insert (Property ("year", ""));
41
42         /*** Title and friends ***/
43         map.insert (Property ("grouping", ""));
44         map.insert (Property ("title", ""));
45         map.insert (Property ("subtitle", ""));
46
47         /*** People... ***/
48         map.insert (Property ("artist", ""));
49         map.insert (Property ("album_artist", ""));
50         map.insert (Property ("lyricist", ""));
51         map.insert (Property ("composer", ""));
52         map.insert (Property ("conductor", ""));
53         map.insert (Property ("remixer", ""));
54         map.insert (Property ("arranger", ""));
55         map.insert (Property ("engineer", ""));
56         map.insert (Property ("producer", ""));
57         map.insert (Property ("dj_mixer", ""));
58         map.insert (Property ("mixer", ""));
59         //map.insert (Property ("performers", "")); // Multiple values [instrument]
60
61         /*** Education... ***/
62         map.insert (Property ("instructor", ""));
63         map.insert (Property ("course", ""));
64
65         /*** Album info ***/
66         map.insert (Property ("album", ""));
67         map.insert (Property ("compilation", ""));
68         map.insert (Property ("disc_subtitle", ""));
69         map.insert (Property ("disc_number", ""));
70         map.insert (Property ("total_discs", ""));
71         map.insert (Property ("track_number", ""));
72         map.insert (Property ("total_tracks", ""));
73
74         /*** Style ***/
75         map.insert (Property ("genre", ""));
76         //map.insert (Property ("mood", ""));
77         //map.insert (Property ("bpm", ""));
78
79         /*** Other ***/
80         //map.insert (Property ("lyrics", ""));
81         //map.insert (Property ("media", ""));
82         //map.insert (Property ("label", ""));
83         map.insert (Property ("barcode", ""));
84         //map.insert (Property ("encoded_by", ""));
85         //map.insert (Property ("catalog_number", ""));
86
87         /*** Sorting orders ***/
88         //map.insert (Property ("album_sort", ""));
89         //map.insert (Property ("album_artist_sort", ""));
90         //map.insert (Property ("artist_sort", ""));
91         //map.insert (Property ("title_sort", ""));
92
93         /*** Globals ***/
94         user_map.insert (Property ("user_name", ""));
95         user_map.insert (Property ("user_email", ""));
96         user_map.insert (Property ("user_web", ""));
97         user_map.insert (Property ("user_organization", ""));
98         user_map.insert (Property ("user_country", ""));
99 }
100
101 SessionMetadata::~SessionMetadata ()
102 {
103
104 }
105
106 XMLNode *
107 SessionMetadata::get_xml (const string & name)
108 {
109         string value = get_value (name);
110         if (value.empty()) {
111                 return 0;
112         }
113
114         XMLNode val ("value", value);
115         XMLNode * node = new XMLNode (name);
116         node->add_child_copy (val);
117
118         return node;
119 }
120
121 string
122 SessionMetadata::get_value (const string & name) const
123 {
124         PropertyMap::const_iterator it = map.find (name);
125         if (it == map.end()) {
126                 it = user_map.find (name);
127                 if (it == user_map.end()) {
128                         // Should not be reached, except if loading metadata from a newer version with a new type
129                         std::cerr << "Programming error in SessionMetadata::get_value (" << name << ")" << std::endl;
130                         return "";
131                 }
132         }
133
134         return it->second;
135 }
136
137 uint32_t
138 SessionMetadata::get_uint_value (const string & name) const
139 {
140         return atoi (get_value (name).c_str());
141 }
142
143 void
144 SessionMetadata::set_value (const string & name, const string & value)
145 {
146         PropertyMap::iterator it = map.find (name);
147         if (it == map.end()) {
148                 it = user_map.find (name);
149                 if (it == user_map.end()) {
150                         // Should not be reached, except if loading metadata from a newer version with a new type
151                         std::cerr << "Programming error in SessionMetadata::set_value (" << name << ")" << std::endl;
152                         return;
153                 }
154         }
155
156         it->second = value;
157 }
158
159 void
160 SessionMetadata::set_value (const string & name, uint32_t value)
161 {
162         std::ostringstream oss;
163         oss << value;
164         if (oss.str().compare("0")) {
165                 set_value (name, oss.str());
166         } else {
167                 set_value (name, "");
168         }
169 }
170
171 /*** Serialization ***/
172 XMLNode &
173 SessionMetadata::get_state ()
174 {
175         XMLNode * node = new XMLNode ("Metadata");
176         XMLNode * prop;
177
178         for (PropertyMap::const_iterator it = map.begin(); it != map.end(); ++it) {
179                 if ((prop = get_xml (it->first))) {
180                         node->add_child_nocopy (*prop);
181                 }
182         }
183
184         return *node;
185 }
186
187 int
188 SessionMetadata::set_state (const XMLNode & state, int /*version_num*/)
189 {
190         const XMLNodeList & children = state.children();
191         string name;
192         string value;
193         XMLNode * node;
194
195         for (XMLNodeConstIterator it = children.begin(); it != children.end(); it++) {
196                 node = *it;
197                 if (node->children().empty()) {
198                         continue;
199                 }
200
201                 name = node->name();
202                 node = *node->children().begin();
203                 value = node->content();
204
205                 set_value (name, value);
206         }
207
208         return 0;
209 }
210
211
212 XMLNode &
213 SessionMetadata::get_user_state ()
214 {
215         XMLNode * node = new XMLNode ("Metadata");
216         XMLNode * prop;
217
218         for (PropertyMap::const_iterator it = user_map.begin(); it != user_map.end(); ++it) {
219                 if ((prop = get_xml (it->first))) {
220                         node->add_child_nocopy (*prop);
221                 }
222         }
223
224         return *node;
225 }
226
227 /*** Accessing ***/
228 string
229 SessionMetadata::description () const
230 {
231         return get_value("description");
232 }
233
234 string
235 SessionMetadata::comment () const
236 {
237         return get_value("comment");
238 }
239
240 string
241 SessionMetadata::copyright () const
242 {
243         return get_value("copyright");
244 }
245
246 string
247 SessionMetadata::isrc () const
248 {
249         return get_value("isrc");
250 }
251
252 uint32_t
253 SessionMetadata::year () const
254 {
255         return get_uint_value("year");
256 }
257
258 string
259 SessionMetadata::grouping () const
260 {
261         return get_value("grouping");
262 }
263
264 string
265 SessionMetadata::barcode () const
266 {
267         return get_value("barcode");
268 }
269
270 string
271 SessionMetadata::title () const
272 {
273         return get_value("title");
274 }
275
276 string
277 SessionMetadata::subtitle () const
278 {
279         return get_value("subtitle");
280 }
281
282 string
283 SessionMetadata::artist () const
284 {
285         return get_value("artist");
286 }
287
288 string
289 SessionMetadata::album_artist () const
290 {
291         return get_value("album_artist");
292 }
293
294 string
295 SessionMetadata::lyricist () const
296 {
297         return get_value("lyricist");
298 }
299
300 string
301 SessionMetadata::composer () const
302 {
303         return get_value("composer");
304 }
305
306 string
307 SessionMetadata::conductor () const
308 {
309         return get_value("conductor");
310 }
311
312 string
313 SessionMetadata::remixer () const
314 {
315         return get_value("remixer");
316 }
317
318 string
319 SessionMetadata::arranger () const
320 {
321         return get_value("arranger");
322 }
323
324 string
325 SessionMetadata::engineer () const
326 {
327         return get_value("engineer");
328 }
329
330 string
331 SessionMetadata::producer () const
332 {
333         return get_value("producer");
334 }
335
336 string
337 SessionMetadata::dj_mixer () const
338 {
339         return get_value("dj_mixer");
340 }
341
342 string
343 SessionMetadata::mixer () const
344 {
345         return get_value("mixer");
346 }
347
348 string
349 SessionMetadata::album () const
350 {
351         return get_value("album");
352 }
353
354 string
355 SessionMetadata::compilation () const
356 {
357         return get_value("compilation");
358 }
359
360 string
361 SessionMetadata::disc_subtitle () const
362 {
363         return get_value("disc_subtitle");
364 }
365
366 uint32_t
367 SessionMetadata::disc_number () const
368 {
369         return get_uint_value("disc_number");
370 }
371
372 uint32_t
373 SessionMetadata::total_discs () const
374 {
375         return get_uint_value("total_discs");
376 }
377
378 uint32_t
379 SessionMetadata::track_number () const
380 {
381         return get_uint_value("track_number");
382 }
383
384 uint32_t
385 SessionMetadata::total_tracks () const
386 {
387         return get_uint_value("total_tracks");
388 }
389
390 string
391 SessionMetadata::genre () const
392 {
393         return get_value("genre");
394 }
395
396 string
397 SessionMetadata::instructor () const
398 {
399         return get_value("instructor");
400 }
401
402 string
403 SessionMetadata::course () const
404 {
405         return get_value("course");
406 }
407
408
409 string
410 SessionMetadata::user_name () const
411 {
412         return get_value("user_name");
413 }
414
415 string
416 SessionMetadata::user_email () const
417 {
418         return get_value("user_email");
419 }
420
421 string
422 SessionMetadata::user_web () const
423 {
424         return get_value("user_web");
425 }
426
427 string
428 SessionMetadata::organization () const
429 {
430         return get_value("user_organization");
431 }
432
433 string
434 SessionMetadata::country () const
435 {
436         return get_value("user_country");
437 }
438
439
440
441 /*** Editing ***/
442 void
443 SessionMetadata::set_description (const string & v)
444 {
445         set_value ("description", v);
446 }
447
448 void
449 SessionMetadata::set_comment (const string & v)
450 {
451         set_value ("comment", v);
452 }
453
454 void
455 SessionMetadata::set_copyright (const string & v)
456 {
457         set_value ("copyright", v);
458 }
459
460 void
461 SessionMetadata::set_isrc (const string & v)
462 {
463         set_value ("isrc", v);
464 }
465
466 void
467 SessionMetadata::set_year (uint32_t v)
468 {
469         set_value ("year", v);
470 }
471
472 void
473 SessionMetadata::set_grouping (const string & v)
474 {
475         set_value ("grouping", v);
476 }
477
478 void
479 SessionMetadata::set_barcode (const string & v)
480 {
481         set_value ("barcode", v);
482 }
483
484 void
485 SessionMetadata::set_title (const string & v)
486 {
487         set_value ("title", v);
488 }
489
490 void
491 SessionMetadata::set_subtitle (const string & v)
492 {
493         set_value ("subtitle", v);
494 }
495
496 void
497 SessionMetadata::set_artist (const string & v)
498 {
499         set_value ("artist", v);
500 }
501
502 void
503 SessionMetadata::set_album_artist (const string & v)
504 {
505         set_value ("album_artist", v);
506 }
507
508 void
509 SessionMetadata::set_lyricist (const string & v)
510 {
511         set_value ("lyricist", v);
512 }
513
514 void
515 SessionMetadata::set_composer (const string & v)
516 {
517         set_value ("composer", v);
518 }
519
520 void
521 SessionMetadata::set_conductor (const string & v)
522 {
523         set_value ("conductor", v);
524 }
525
526 void
527 SessionMetadata::set_remixer (const string & v)
528 {
529         set_value ("remixer", v);
530 }
531
532 void
533 SessionMetadata::set_arranger (const string & v)
534 {
535         set_value ("arranger", v);
536 }
537
538 void
539 SessionMetadata::set_engineer (const string & v)
540 {
541         set_value ("engineer", v);
542 }
543
544 void
545 SessionMetadata::set_producer (const string & v)
546 {
547         set_value ("producer", v);
548 }
549
550 void
551 SessionMetadata::set_dj_mixer (const string & v)
552 {
553         set_value ("dj_mixer", v);
554 }
555
556 void
557 SessionMetadata::set_mixer (const string & v)
558 {
559         set_value ("mixer", v);
560 }
561
562 void
563 SessionMetadata::set_album (const string & v)
564 {
565         set_value ("album", v);
566 }
567
568 void
569 SessionMetadata::set_compilation (const string & v)
570 {
571         set_value ("compilation", v);
572 }
573
574 void
575 SessionMetadata::set_disc_subtitle (const string & v)
576 {
577         set_value ("disc_subtitle", v);
578 }
579
580 void
581 SessionMetadata::set_disc_number (uint32_t v)
582 {
583         set_value ("disc_number", v);
584 }
585
586 void
587 SessionMetadata::set_total_discs (uint32_t v)
588 {
589         set_value ("total_discs", v);
590 }
591
592 void
593 SessionMetadata::set_track_number (uint32_t v)
594 {
595         set_value ("track_number", v);
596 }
597
598 void
599 SessionMetadata::set_total_tracks (uint32_t v)
600 {
601         set_value ("total_tracks", v);
602 }
603
604 void
605 SessionMetadata::set_genre (const string & v)
606 {
607         set_value ("genre", v);
608 }
609
610 void
611 SessionMetadata::set_instructor (const string & v)
612 {
613         set_value ("instructor", v);
614 }
615
616 void
617 SessionMetadata::set_course (const string & v)
618 {
619         set_value ("course", v);
620 }
621
622 void
623 SessionMetadata::set_user_name (const string & v)
624 {
625         set_value ("user_name", v);
626 }
627
628 void
629 SessionMetadata::set_user_email (const string & v)
630 {
631         set_value ("user_email", v);
632 }
633
634 void
635 SessionMetadata::set_user_web (const string & v)
636 {
637         set_value ("user_web", v);
638 }
639
640 void
641 SessionMetadata::set_organization (const string & v)
642 {
643         set_value ("user_organization", v);
644 }
645 void
646 SessionMetadata::set_country (const string & v)
647 {
648         set_value ("user_country", v);
649 }