2 Copyright (C) 2008 Paul Davis
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)
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
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.
20 #include "ardour/session_metadata.h"
27 using namespace ARDOUR
;
29 SessionMetadata::SessionMetadata ()
32 map
.insert (Property ("comment", ""));
33 map
.insert (Property ("copyright", ""));
34 map
.insert (Property ("isrc", ""));
35 map
.insert (Property ("year", ""));
37 /*** Title and friends ***/
38 map
.insert (Property ("grouping", ""));
39 map
.insert (Property ("title", ""));
40 map
.insert (Property ("subtitle", ""));
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]
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", ""));
66 map
.insert (Property ("genre", ""));
67 //map.insert (Property ("mood", ""));
68 //map.insert (Property ("bpm", ""));
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", ""));
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", ""));
85 SessionMetadata::~SessionMetadata ()
91 SessionMetadata::get_xml (const string
& name
)
93 string value
= get_value (name
);
98 XMLNode
val ("value", value
);
99 XMLNode
* node
= new XMLNode (name
);
100 node
->add_child_copy (val
);
106 SessionMetadata::get_value (const string
& name
) const
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
;
119 SessionMetadata::get_uint_value (const string
& name
) const
121 return atoi (get_value (name
).c_str());
125 SessionMetadata::set_value (const string
& name
, const string
& value
)
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
;
138 SessionMetadata::set_value (const string
& name
, uint32_t value
)
140 std::ostringstream oss
;
142 if (oss
.str().compare("0")) {
143 set_value (name
, oss
.str());
145 set_value (name
, "");
149 /*** Serialization ***/
151 SessionMetadata::get_state ()
153 XMLNode
* node
= new XMLNode ("Metadata");
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
);
166 SessionMetadata::set_state (const XMLNode
& state
, int /*version*/)
168 const XMLNodeList
& children
= state
.children();
173 for (XMLNodeConstIterator it
= children
.begin(); it
!= children
.end(); it
++) {
175 if (node
->children().empty()) {
180 node
= *node
->children().begin();
181 value
= node
->content();
183 set_value (name
, value
);
191 SessionMetadata::comment () const
193 return get_value("comment");
197 SessionMetadata::copyright () const
199 return get_value("copyright");
203 SessionMetadata::isrc () const
205 return get_value("isrc");
209 SessionMetadata::year () const
211 return get_uint_value("year");
215 SessionMetadata::grouping () const
217 return get_value("grouping");
221 SessionMetadata::title () const
223 return get_value("title");
227 SessionMetadata::subtitle () const
229 return get_value("subtitle");
233 SessionMetadata::artist () const
235 return get_value("artist");
239 SessionMetadata::album_artist () const
241 return get_value("album_artist");
245 SessionMetadata::lyricist () const
247 return get_value("lyricist");
251 SessionMetadata::composer () const
253 return get_value("composer");
257 SessionMetadata::conductor () const
259 return get_value("conductor");
263 SessionMetadata::remixer () const
265 return get_value("remixer");
269 SessionMetadata::arranger () const
271 return get_value("arranger");
275 SessionMetadata::engineer () const
277 return get_value("engineer");
281 SessionMetadata::producer () const
283 return get_value("producer");
287 SessionMetadata::dj_mixer () const
289 return get_value("dj_mixer");
293 SessionMetadata::mixer () const
295 return get_value("mixer");
299 SessionMetadata::album () const
301 return get_value("album");
305 SessionMetadata::compilation () const
307 return get_value("compilation");
311 SessionMetadata::disc_subtitle () const
313 return get_value("disc_subtitle");
317 SessionMetadata::disc_number () const
319 return get_uint_value("disc_number");
323 SessionMetadata::total_discs () const
325 return get_uint_value("total_discs");
329 SessionMetadata::track_number () const
331 return get_uint_value("track_number");
335 SessionMetadata::total_tracks () const
337 return get_uint_value("total_tracks");
341 SessionMetadata::genre () const
343 return get_value("genre");
348 SessionMetadata::set_comment (const string
& v
)
350 set_value ("comment", v
);
354 SessionMetadata::set_copyright (const string
& v
)
356 set_value ("copyright", v
);
360 SessionMetadata::set_isrc (const string
& v
)
362 set_value ("isrc", v
);
366 SessionMetadata::set_year (uint32_t v
)
368 set_value ("year", v
);
372 SessionMetadata::set_grouping (const string
& v
)
374 set_value ("grouping", v
);
378 SessionMetadata::set_title (const string
& v
)
380 set_value ("title", v
);
384 SessionMetadata::set_subtitle (const string
& v
)
386 set_value ("subtitle", v
);
390 SessionMetadata::set_artist (const string
& v
)
392 set_value ("artist", v
);
396 SessionMetadata::set_album_artist (const string
& v
)
398 set_value ("album_artist", v
);
402 SessionMetadata::set_lyricist (const string
& v
)
404 set_value ("lyricist", v
);
408 SessionMetadata::set_composer (const string
& v
)
410 set_value ("composer", v
);
414 SessionMetadata::set_conductor (const string
& v
)
416 set_value ("conductor", v
);
420 SessionMetadata::set_remixer (const string
& v
)
422 set_value ("remixer", v
);
426 SessionMetadata::set_arranger (const string
& v
)
428 set_value ("arranger", v
);
432 SessionMetadata::set_engineer (const string
& v
)
434 set_value ("engineer", v
);
438 SessionMetadata::set_producer (const string
& v
)
440 set_value ("producer", v
);
444 SessionMetadata::set_dj_mixer (const string
& v
)
446 set_value ("dj_mixer", v
);
450 SessionMetadata::set_mixer (const string
& v
)
452 set_value ("mixer", v
);
456 SessionMetadata::set_album (const string
& v
)
458 set_value ("album", v
);
462 SessionMetadata::set_compilation (const string
& v
)
464 set_value ("compilation", v
);
468 SessionMetadata::set_disc_subtitle (const string
& v
)
470 set_value ("disc_subtitle", v
);
474 SessionMetadata::set_disc_number (uint32_t v
)
476 set_value ("disc_number", v
);
480 SessionMetadata::set_total_discs (uint32_t v
)
482 set_value ("total_discs", v
);
486 SessionMetadata::set_track_number (uint32_t v
)
488 set_value ("track_number", v
);
492 SessionMetadata::set_total_tracks (uint32_t v
)
494 set_value ("total_tracks", v
);
498 SessionMetadata::set_genre (const string
& v
)
500 set_value ("genre", v
);