MythTV  0.28pre
 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 
46 bool MetaIOWavPack::write(const QString &filename, MusicMetadata* mdata)
47 {
48  if (!mdata)
49  return false;
50 
51  if (filename.isEmpty())
52  return false;
53 
55 
56  TagLib::WavPack::File *wpfile = OpenFile(m_filename);
57 
58  if (!wpfile)
59  return false;
60 
61  TagLib::APE::Tag *tag = wpfile->APETag();
62 
63  if (!tag)
64  {
65  delete wpfile;
66  return false;
67  }
68 
69  WriteGenericMetadata(tag, mdata);
70 
71  // Compilation Artist ("Album artist")
72  if (mdata->Compilation())
73  {
74  TagLib::String key = "Album artist";
75  TagLib::APE::Item item = TagLib::APE::Item(key,
76  QStringToTString(mdata->CompilationArtist()));
77  tag->setItem(key, item);
78  }
79  else
80  tag->removeItem("Album artist");
81 
83  bool result = wpfile->save();
85 
86  if (wpfile)
87  delete wpfile;
88 
89  return (result);
90 }
91 
96 {
97  TagLib::WavPack::File *wpfile = OpenFile(filename);
98 
99  if (!wpfile)
100  return NULL;
101 
102  TagLib::APE::Tag *tag = wpfile->APETag();
103 
104  if (!tag)
105  {
106  delete wpfile;
107  return NULL;
108  }
109 
110  MusicMetadata *metadata = new MusicMetadata(filename);
111 
112  ReadGenericMetadata(tag, metadata);
113 
114  bool compilation = false;
115 
116  // Compilation Artist ("Album artist")
117  if(tag->itemListMap().contains("Album artist"))
118  {
119  compilation = true;
120  QString compilation_artist = TStringToQString(
121  tag->itemListMap()["Album artist"].toString()).trimmed();
122  metadata->setCompilationArtist(compilation_artist);
123  }
124 
125  metadata->setCompilation(compilation);
126 
127  if (metadata->Length() <= 0)
128  metadata->setLength(getTrackLength(wpfile));
129 
130  delete wpfile;
131 
132  return metadata;
133 }
void setCompilationArtist(const QString &lcompilation_artist)
void setLength(int llength)
const char * filename
Definition: ioapi.h:135
void WriteGenericMetadata(TagLib::Tag *tag, const MusicMetadata *metadata)
Writes metadata common to all tag formats to the tag.
void setCompilation(bool state)
TagLib::WavPack::File * OpenFile(const QString &filename)
Open the file to read the tag.
bool write(const QString &filename, MusicMetadata *mdata)
Writes all metadata back to a file.
virtual ~MetaIOWavPack(void)
void saveTimeStamps(void)
Definition: metaio.cpp:229
bool Compilation() const
void ReadGenericMetadata(TagLib::Tag *tag, MusicMetadata *metadata)
Writes metadata common to all tag formats to the tag.
int Length() const
int getTrackLength(TagLib::File *file)
Find the length of the track (in seconds)
QString m_filename
Definition: metaio.h:172
Base for Taglib metadata classes.
Definition: metaiotaglib.h:20
MusicMetadata * read(const QString &filename)
Reads MusicMetadata from a file.
QString CompilationArtist() const
void restoreTimeStamps(void)
Definition: metaio.cpp:238