1 /***************************************************************************
2 copyright : (C) 2006 by Lukáš Lalinský
3 email : lalinsky@gmail.com
5 copyright : (C) 2004 by Allan Sandfeld Jensen
6 email : kde@carewolf.org
7 (original MPC implementation)
8 ***************************************************************************/
10 /***************************************************************************
11 * This library is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU Lesser General Public License version *
13 * 2.1 as published by the Free Software Foundation. *
15 * This library is distributed in the hope that it will be useful, but *
16 * WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18 * Lesser General Public License for more details. *
20 * You should have received a copy of the GNU Lesser General Public *
21 * License along with this library; if not, write to the Free Software *
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
25 * Alternatively, this file is available under the Mozilla Public *
26 * License Version 1.1. You may obtain a copy of the License at *
27 * http://www.mozilla.org/MPL/ *
28 ***************************************************************************/
30 #include <tbytevector.h>
35 #include "wavpackfile.h"
37 #include "id3v2header.h"
39 #include "apefooter.h"
41 using namespace TagLib;
45 enum { APEIndex, ID3v1Index };
48 class WavPack::File::FilePrivate
72 Properties *properties;
75 // These indicate whether the file *on disk* has these tags, not if
76 // this data structure does. This is used in computing offsets.
82 ////////////////////////////////////////////////////////////////////////////////
84 ////////////////////////////////////////////////////////////////////////////////
86 WavPack::File::File(FileName file, bool readProperties,
87 Properties::ReadStyle propertiesStyle) : TagLib::File(file)
90 read(readProperties, propertiesStyle);
93 WavPack::File::~File()
98 TagLib::Tag *WavPack::File::tag() const
103 WavPack::Properties *WavPack::File::audioProperties() const
105 return d->properties;
108 bool WavPack::File::save()
111 debug("WavPack::File::save() -- File is read only.");
119 seek(d->ID3v1Location);
120 writeBlock(ID3v1Tag()->render());
124 d->ID3v1Location = tell();
125 writeBlock(ID3v1Tag()->render());
131 removeBlock(d->ID3v1Location, 128);
134 if(d->APELocation > d->ID3v1Location)
135 d->APELocation -= 128;
144 insert(APETag()->render(), d->APELocation, d->APESize);
147 insert(APETag()->render(), d->ID3v1Location, 0);
148 d->APESize = APETag()->footer()->completeTagSize();
150 d->APELocation = d->ID3v1Location;
151 d->ID3v1Location += d->APESize;
155 d->APELocation = tell();
156 writeBlock(APETag()->render());
157 d->APESize = APETag()->footer()->completeTagSize();
164 removeBlock(d->APELocation, d->APESize);
167 if(d->ID3v1Location > d->APELocation) {
168 d->ID3v1Location -= d->APESize;
177 ID3v1::Tag *WavPack::File::ID3v1Tag(bool create)
179 return d->tag.access<ID3v1::Tag>(ID3v1Index, create);
182 APE::Tag *WavPack::File::APETag(bool create)
184 return d->tag.access<APE::Tag>(APEIndex, create);
187 void WavPack::File::strip(int tags)
190 d->tag.set(ID3v1Index, 0);
195 d->tag.set(APEIndex, 0);
202 ////////////////////////////////////////////////////////////////////////////////
204 ////////////////////////////////////////////////////////////////////////////////
206 void WavPack::File::read(bool readProperties, Properties::ReadStyle /* propertiesStyle */)
208 // Look for an ID3v1 tag
210 d->ID3v1Location = findID3v1();
212 if(d->ID3v1Location >= 0) {
213 d->tag.set(ID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
217 // Look for an APE tag
219 d->APELocation = findAPE();
221 if(d->APELocation >= 0) {
222 d->tag.set(APEIndex, new APE::Tag(this, d->APELocation));
223 d->APESize = APETag()->footer()->completeTagSize();
224 d->APELocation = d->APELocation + APETag()->footer()->size() - d->APESize;
231 // Look for WavPack audio properties
235 d->properties = new Properties(readBlock(WavPack::HeaderSize),
236 length() - d->APESize);
240 long WavPack::File::findAPE()
252 if(readBlock(8) == APE::Tag::fileIdentifier())
258 long WavPack::File::findID3v1()
266 if(readBlock(3) == ID3v1::Tag::fileIdentifier())