MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
metaiowavpack.cpp
Go to the documentation of this file.
1 #include <math.h>
2 
3 #include <apetag.h>
4 #include <apeitem.h>
5 
6 #include <mythcontext.h>
7 
8 // libmythmetadata
9 #include "metaiowavpack.h"
10 #include "musicmetadata.h"
11 #include "musicutils.h"
12 
14  : MetaIOTagLib()
15 {
16 }
17 
19 {
20 }
21 
28 TagLib::WavPack::File *MetaIOWavPack::OpenFile(const QString &filename)
29 {
30  QByteArray fname = filename.toLocal8Bit();
31  TagLib::WavPack::File *wpfile = new TagLib::WavPack::File(fname.constData());
32 
33  if (!wpfile->isOpen())
34  {
35  delete wpfile;
36  wpfile = NULL;
37  }
38 
39  return wpfile;
40 }
41 
42 
47 {
48  if (!mdata)
49  return false;
50 
51  TagLib::WavPack::File *wpfile = OpenFile(mdata->Filename());
52 
53  if (!wpfile)
54  return false;
55 
56  TagLib::APE::Tag *tag = wpfile->APETag();
57 
58  if (!tag)
59  {
60  delete wpfile;
61  return false;
62  }
63 
64  WriteGenericMetadata(tag, mdata);
65 
66  // Compilation Artist ("Album artist")
67  if (mdata->Compilation())
68  {
69  TagLib::String key = "Album artist";
70  TagLib::APE::Item item = TagLib::APE::Item(key,
71  QStringToTString(mdata->CompilationArtist()));
72  tag->setItem(key, item);
73  }
74  else
75  tag->removeItem("Album artist");
76 
77  bool result = wpfile->save();
78 
79  if (wpfile)
80  delete wpfile;
81 
82  return (result);
83 }
84 
88 MusicMetadata* MetaIOWavPack::read(const QString &filename)
89 {
90  TagLib::WavPack::File *wpfile = OpenFile(filename);
91 
92  if (!wpfile)
93  return NULL;
94 
95  TagLib::APE::Tag *tag = wpfile->APETag();
96 
97  if (!tag)
98  {
99  delete wpfile;
100  return NULL;
101  }
102 
103  MusicMetadata *metadata = new MusicMetadata(filename);
104 
105  ReadGenericMetadata(tag, metadata);
106 
107  bool compilation = false;
108 
109  // Compilation Artist ("Album artist")
110  if(tag->itemListMap().contains("Album artist"))
111  {
112  compilation = true;
113  QString compilation_artist = TStringToQString(
114  tag->itemListMap()["Album artist"].toString()).trimmed();
115  metadata->setCompilationArtist(compilation_artist);
116  }
117 
118  metadata->setCompilation(compilation);
119 
120  if (metadata->Length() <= 0)
121  metadata->setLength(getTrackLength(wpfile));
122 
123  delete wpfile;
124 
125  return metadata;
126 }