1 /***************************************************************************
2 copyright : (C) 2004 by Allan Sandfeld Jensen
3 (C) 2002 - 2008 by Scott Wheeler (id3v2header.cpp)
4 email : kde@carewolf.org
5 ***************************************************************************/
7 /***************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License version *
10 * 2.1 as published by the Free Software Foundation. *
12 * This library is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15 * Lesser General Public License for more details. *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with this library; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22 * Alternatively, this file is available under the Mozilla Public *
23 * License Version 1.1. You may obtain a copy of the License at *
24 * http://www.mozilla.org/MPL/ *
25 ***************************************************************************/
33 #include "apefooter.h"
35 using namespace TagLib;
38 class Footer::FooterPrivate
41 FooterPrivate() : version(0),
60 static const uint size = 32;
63 ////////////////////////////////////////////////////////////////////////////////
65 ////////////////////////////////////////////////////////////////////////////////
67 TagLib::uint Footer::size()
69 return FooterPrivate::size;
72 ByteVector Footer::fileIdentifier()
74 return ByteVector::fromCString("APETAGEX");
77 ////////////////////////////////////////////////////////////////////////////////
79 ////////////////////////////////////////////////////////////////////////////////
83 d = new FooterPrivate;
86 Footer::Footer(const ByteVector &data)
88 d = new FooterPrivate;
97 TagLib::uint Footer::version() const
102 bool Footer::headerPresent() const
104 return d->headerPresent;
107 bool Footer::footerPresent() const
109 return d->footerPresent;
112 bool Footer::isHeader() const
117 void Footer::setHeaderPresent(bool b) const
119 d->headerPresent = b;
122 TagLib::uint Footer::itemCount() const
127 void Footer::setItemCount(uint s)
132 TagLib::uint Footer::tagSize() const
137 TagLib::uint Footer::completeTagSize() const
140 return d->tagSize + d->size;
145 void Footer::setTagSize(uint s)
150 void Footer::setData(const ByteVector &data)
155 ByteVector Footer::renderFooter() const
157 return render(false);
160 ByteVector Footer::renderHeader() const
162 if (!d->headerPresent) return ByteVector();
167 ////////////////////////////////////////////////////////////////////////////////
169 ////////////////////////////////////////////////////////////////////////////////
171 void Footer::parse(const ByteVector &data)
173 if(data.size() < size())
176 // The first eight bytes, data[0..7], are the File Identifier, "APETAGEX".
178 // Read the version number
180 d->version = data.mid(8, 4).toUInt(false);
184 d->tagSize = data.mid(12, 4).toUInt(false);
186 // Read the item count
188 d->itemCount = data.mid(16, 4).toUInt(false);
192 std::bitset<32> flags(data.mid(20, 4).toUInt(false));
194 d->headerPresent = flags[31];
195 d->footerPresent = !flags[30];
196 d->isHeader = flags[29];
200 ByteVector Footer::render(bool isHeader) const
204 // add the file identifier -- "APETAGEX"
206 v.append(fileIdentifier());
208 // add the version number -- we always render a 2.000 tag regardless of what
209 // the tag originally was.
211 v.append(ByteVector::fromUInt(2000, false));
215 v.append(ByteVector::fromUInt(d->tagSize, false));
217 // add the item count
219 v.append(ByteVector::fromUInt(d->itemCount, false));
221 // render and add the flags
223 std::bitset<32> flags;
225 flags[31] = d->headerPresent;
226 flags[30] = false; // footer is always present
227 flags[29] = isHeader;
229 v.append(ByteVector::fromUInt(flags.to_ulong(), false));
231 // add the reserved 64bit
233 v.append(ByteVector::fromLongLong(0));