Ok, think I've got this all sorted out a bit. Code is much simpler now,

though much of this could be moved into the base class as there's a lot
of copy-paste action going on.


git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@768992 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Scott Wheeler
2008-01-31 05:46:13 +00:00
parent 6f6ec8d7de
commit 37e2d6293f
8 changed files with 154 additions and 499 deletions

View File

@ -30,26 +30,28 @@
#include <tbytevector.h>
#include <tstring.h>
#include <tdebug.h>
#include <tagunion.h>
#include "wavpackfile.h"
#include "id3v1tag.h"
#include "id3v2header.h"
#include "apetag.h"
#include "apefooter.h"
#include "combinedtag.h"
using namespace TagLib;
namespace
{
enum { APEIndex, ID3v1Index };
}
class WavPack::File::FilePrivate
{
public:
FilePrivate() :
APETag(0),
APELocation(-1),
APESize(0),
ID3v1Tag(0),
ID3v1Location(-1),
tag(0),
properties(0),
scanned(false),
hasAPE(false),
@ -57,20 +59,15 @@ public:
~FilePrivate()
{
if (tag != ID3v1Tag && tag != APETag) delete tag;
delete ID3v1Tag;
delete APETag;
delete properties;
}
APE::Tag *APETag;
long APELocation;
uint APESize;
ID3v1::Tag *ID3v1Tag;
long ID3v1Location;
Tag *tag;
TagUnion tag;
Properties *properties;
bool scanned;
@ -100,7 +97,7 @@ WavPack::File::~File()
TagLib::Tag *WavPack::File::tag() const
{
return d->tag;
return &d->tag;
}
WavPack::Properties *WavPack::File::audioProperties() const
@ -117,18 +114,19 @@ bool WavPack::File::save()
// Update ID3v1 tag
if(d->ID3v1Tag) {
if(ID3v1Tag()) {
if(d->hasID3v1) {
seek(d->ID3v1Location);
writeBlock(d->ID3v1Tag->render());
writeBlock(ID3v1Tag()->render());
}
else {
seek(0, End);
d->ID3v1Location = tell();
writeBlock(d->ID3v1Tag->render());
writeBlock(ID3v1Tag()->render());
d->hasID3v1 = true;
}
} else
}
else {
if(d->hasID3v1) {
removeBlock(d->ID3v1Location, 128);
d->hasID3v1 = false;
@ -137,16 +135,17 @@ bool WavPack::File::save()
d->APELocation -= 128;
}
}
}
// Update APE tag
if(d->APETag) {
if(APETag()) {
if(d->hasAPE)
insert(d->APETag->render(), d->APELocation, d->APESize);
insert(APETag()->render(), d->APELocation, d->APESize);
else {
if(d->hasID3v1) {
insert(d->APETag->render(), d->ID3v1Location, 0);
d->APESize = d->APETag->footer()->completeTagSize();
insert(APETag()->render(), d->ID3v1Location, 0);
d->APESize = APETag()->footer()->completeTagSize();
d->hasAPE = true;
d->APELocation = d->ID3v1Location;
d->ID3v1Location += d->APESize;
@ -154,79 +153,49 @@ bool WavPack::File::save()
else {
seek(0, End);
d->APELocation = tell();
writeBlock(d->APETag->render());
d->APESize = d->APETag->footer()->completeTagSize();
writeBlock(APETag()->render());
d->APESize = APETag()->footer()->completeTagSize();
d->hasAPE = true;
}
}
}
else
else {
if(d->hasAPE) {
removeBlock(d->APELocation, d->APESize);
d->hasAPE = false;
if(d->hasID3v1) {
if (d->ID3v1Location > d->APELocation)
if(d->ID3v1Location > d->APELocation) {
d->ID3v1Location -= d->APESize;
}
}
}
}
return true;
}
ID3v1::Tag *WavPack::File::ID3v1Tag(bool create)
{
if(!create || d->ID3v1Tag)
return d->ID3v1Tag;
// no ID3v1 tag exists and we've been asked to create one
d->ID3v1Tag = new ID3v1::Tag;
if(d->APETag)
d->tag = new CombinedTag(d->APETag, d->ID3v1Tag);
else
d->tag = d->ID3v1Tag;
return d->ID3v1Tag;
return d->tag.access<ID3v1::Tag>(ID3v1Index, create);
}
APE::Tag *WavPack::File::APETag(bool create)
{
if(!create || d->APETag)
return d->APETag;
// no APE tag exists and we've been asked to create one
d->APETag = new APE::Tag;
if(d->ID3v1Tag)
d->tag = new CombinedTag(d->APETag, d->ID3v1Tag);
else
d->tag = d->APETag;
return d->APETag;
return d->tag.access<APE::Tag>(APEIndex, create);
}
void WavPack::File::strip(int tags)
{
if(tags & ID3v1) {
delete d->ID3v1Tag;
d->ID3v1Tag = 0;
if(d->APETag)
d->tag = d->APETag;
else
d->tag = d->APETag = new APE::Tag;
d->tag.set(ID3v1Index, 0);
APETag(true);
}
if(tags & APE) {
delete d->APETag;
d->APETag = 0;
d->tag.set(APEIndex, 0);
if(d->ID3v1Tag)
d->tag = d->ID3v1Tag;
else
d->tag = d->APETag = new APE::Tag;
if(!ID3v1Tag())
APETag(true);
}
}
@ -241,7 +210,7 @@ void WavPack::File::read(bool readProperties, Properties::ReadStyle /* propertie
d->ID3v1Location = findID3v1();
if(d->ID3v1Location >= 0) {
d->ID3v1Tag = new ID3v1::Tag(this, d->ID3v1Location);
d->tag.set(ID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
d->hasID3v1 = true;
}
@ -250,24 +219,14 @@ void WavPack::File::read(bool readProperties, Properties::ReadStyle /* propertie
d->APELocation = findAPE();
if(d->APELocation >= 0) {
d->APETag = new APE::Tag(this, d->APELocation);
d->APESize = d->APETag->footer()->completeTagSize();
d->APELocation = d->APELocation + d->APETag->footer()->size() - d->APESize;
d->tag.set(APEIndex, new APE::Tag(this, d->APELocation));
d->APESize = APETag()->footer()->completeTagSize();
d->APELocation = d->APELocation + APETag()->footer()->size() - d->APESize;
d->hasAPE = true;
}
if(d->hasID3v1 && d->hasAPE)
d->tag = new CombinedTag(d->APETag, d->ID3v1Tag);
else {
if(d->hasID3v1)
d->tag = d->ID3v1Tag;
else {
if(d->hasAPE)
d->tag = d->APETag;
else
d->tag = d->APETag = new APE::Tag;
}
}
if(!d->hasID3v1)
APETag(true);
// Look for WavPack audio properties