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