#define WANT_CLASS_INSTANTIATION_OF_MAP (1)
#endif
-#include <tdebug.h>
#include <tfile.h>
#include <tstring.h>
#include <tmap.h>
class APE::Tag::TagPrivate
{
public:
- TagPrivate() : file(0), tagOffset(-1), tagLength(0) {}
+ TagPrivate() : file(0), footerLocation(-1), tagLength(0) {}
File *file;
- long tagOffset;
+ long footerLocation;
long tagLength;
Footer footer;
d = new TagPrivate;
}
-APE::Tag::Tag(File *file, long tagOffset) : TagLib::Tag()
+APE::Tag::Tag(File *file, long footerLocation) : TagLib::Tag()
{
d = new TagPrivate;
d->file = file;
- d->tagOffset = tagOffset;
+ d->footerLocation = footerLocation;
read();
}
{
if(d->file && d->file->isValid()) {
- d->file->seek(d->tagOffset);
+ d->file->seek(d->footerLocation);
d->footer.setData(d->file->readBlock(Footer::size()));
if(d->footer.tagSize() <= Footer::size() ||
d->footer.tagSize() > uint(d->file->length()))
return;
- d->file->seek(d->tagOffset + Footer::size() - d->footer.tagSize());
+ d->file->seek(d->footerLocation + Footer::size() - d->footer.tagSize());
parse(d->file->readBlock(d->footer.tagSize() - Footer::size()));
}
}
ID3v2Location(-1),
ID3v2OriginalSize(0),
APELocation(-1),
+ APEFooterLocation(-1),
APEOriginalSize(0),
ID3v1Location(-1),
hasID3v2(false),
uint ID3v2OriginalSize;
long APELocation;
+ long APEFooterLocation;
uint APEOriginalSize;
long ID3v1Location;
// APE tag location has changed, update if it exists
if(APETag())
- d->APELocation = findAPE();
+ findAPE();
}
else if(stripOthers)
success = strip(ID3v2, false) && success;
insert(APETag()->render(), d->APELocation, d->APEOriginalSize);
else {
if(d->hasID3v1) {
- debug("inserting ape tag before id3v1 tag");
insert(APETag()->render(), d->ID3v1Location, 0);
d->APEOriginalSize = APETag()->footer()->completeTagSize();
d->hasAPE = true;
else {
seek(0, End);
d->APELocation = tell();
+ d->APEFooterLocation = d->APELocation
+ + d->tag.access<APE::Tag>(APEIndex, false)->footer()->completeTagSize()
+ - APE::Footer::size();
writeBlock(APETag()->render());
d->APEOriginalSize = APETag()->footer()->completeTagSize();
d->hasAPE = true;
// APE tag location has changed, update if it exists
if(APETag())
- d->APELocation = findAPE();
+ findAPE();
}
if((tags & ID3v1) && d->hasID3v1) {
if((tags & APE) && d->hasAPE) {
removeBlock(d->APELocation, d->APEOriginalSize);
d->APELocation = -1;
+ d->APEFooterLocation = -1;
d->hasAPE = false;
if(d->hasID3v1) {
- if (d->ID3v1Location > d->APELocation)
+ if(d->ID3v1Location > d->APELocation)
d->ID3v1Location -= d->APEOriginalSize;
}
// Look for an APE tag
- d->APELocation = findAPE();
+ findAPE();
if(d->APELocation >= 0) {
- d->tag.set(APEIndex, new APE::Tag(this, d->APELocation));
-
+ d->tag.set(APEIndex, new APE::Tag(this, d->APEFooterLocation));
d->APEOriginalSize = APETag()->footer()->completeTagSize();
-
- d->APELocation = d->APELocation + APETag()->footer()->size() - d->APEOriginalSize;
-
d->hasAPE = true;
}
return -1;
}
-long MPEG::File::findAPE()
+void MPEG::File::findAPE()
{
if(isValid()) {
seek(d->hasID3v1 ? -160 : -32, End);
+
long p = tell();
if(readBlock(8) == APE::Tag::fileIdentifier()) {
- debug("found ape at " + String::number(int(p)));
- return p;
+ d->APEFooterLocation = p;
+ seek(d->APEFooterLocation);
+ APE::Footer footer(readBlock(APE::Footer::size()));
+ d->APELocation = d->APEFooterLocation - footer.completeTagSize()
+ + APE::Footer::size();
+ return;
}
}
- return -1;
+
+ d->APELocation = -1;
+ d->APEFooterLocation = -1;
}
bool MPEG::File::secondSynchByte(char byte)