if(!create || d->tag[ID3v2Index])
return static_cast<ID3v2::Tag *>(d->tag[ID3v2Index]);
- d->tag.setTag(ID3v2Index, new ID3v2::Tag);
+ d->tag.set(ID3v2Index, new ID3v2::Tag);
return static_cast<ID3v2::Tag *>(d->tag[ID3v2Index]);
}
ID3v1::Tag *FLAC::File::ID3v1Tag(bool create)
{
- if(!create || d->tag[ID3v1Index])
- return static_cast<ID3v1::Tag *>(d->tag[ID3v1Index]);
-
- d->tag.setTag(ID3v1Index, new ID3v1::Tag);
- return static_cast<ID3v1::Tag *>(d->tag[ID3v1Index]);
+ return d->tag.access<ID3v1::Tag>(ID3v1Index, create);
}
Ogg::XiphComment *FLAC::File::xiphComment(bool create)
{
- if(!create || d->tag[XiphIndex])
- return static_cast<Ogg::XiphComment *>(d->tag[XiphIndex]);
-
- d->tag.setTag(XiphIndex, new Ogg::XiphComment);
- return static_cast<Ogg::XiphComment *>(d->tag[XiphIndex]);
+ return d->tag.access<Ogg::XiphComment>(XiphIndex, create);
}
void FLAC::File::setID3v2FrameFactory(const ID3v2::FrameFactory *factory)
if(d->ID3v2Location >= 0) {
- d->tag.setTag(ID3v2Index, new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory));
+ d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory));
d->ID3v2OriginalSize = ID3v2Tag()->header()->completeTagSize();
if(ID3v2Tag()->header()->tagSize() <= 0)
- d->tag.setTag(ID3v2Index, 0);
+ d->tag.set(ID3v2Index, 0);
else
d->hasID3v2 = true;
}
d->ID3v1Location = findID3v1();
if(d->ID3v1Location >= 0) {
- d->tag.setTag(ID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
+ d->tag.set(ID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
d->hasID3v1 = true;
}
return;
if(d->hasXiphComment)
- d->tag.setTag(XiphIndex, new Ogg::XiphComment(xiphCommentData()));
+ d->tag.set(XiphIndex, new Ogg::XiphComment(xiphCommentData()));
else
- d->tag.setTag(XiphIndex, new Ogg::XiphComment);
+ d->tag.set(XiphIndex, new Ogg::XiphComment);
if(readProperties)
d->properties = new Properties(streamInfoData(), streamLength(), propertiesStyle);
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2004 by Allan Sandfeld Jensen
- email : kde@carewolf.org
- ***************************************************************************/
-
-/***************************************************************************
- * This library is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU Lesser General Public License version *
- * 2.1 as published by the Free Software Foundation. *
- * *
- * This library is distributed in the hope that it will be useful, but *
- * WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this library; if not, write to the Free Software *
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
- * USA *
- * *
- * Alternatively, this file is available under the Mozilla Public *
- * License Version 1.1. You may obtain a copy of the License at *
- * http://www.mozilla.org/MPL/ *
- ***************************************************************************/
-
-#ifndef DO_NOT_DOCUMENT // Tell Doxygen not to document this header
-
-#ifndef TAGLIB_COMBINEDTAG_H
-#define TAGLIB_COMBINEDTAG_H
-
-////////////////////////////////////////////////////////////////////////////////
-// Note that this header is not installed.
-////////////////////////////////////////////////////////////////////////////////
-
-#include <tag.h>
-
-namespace TagLib {
-
- /*!
- * A union of two TagLib::Tags.
- */
- class CombinedTag : public TagLib::Tag
- {
- public:
- CombinedTag(Tag *tag1 = 0, Tag *tag2 = 0)
- : TagLib::Tag(),
- tag1(tag1), tag2(tag2) {}
-
- virtual String title() const {
- if(tag1 && !tag1->title().isEmpty())
- return tag1->title();
-
- if(tag2)
- return tag2->title();
-
- return String::null;
- }
-
- virtual String artist() const {
- if(tag1 && !tag1->artist().isEmpty())
- return tag1->artist();
-
- if(tag2)
- return tag2->artist();
-
- return String::null;
- }
-
- virtual String album() const {
- if(tag1 && !tag1->album().isEmpty())
- return tag1->album();
-
- if(tag2)
- return tag2->album();
-
- return String::null;
- }
-
- virtual String comment() const {
- if(tag1 && !tag1->comment().isEmpty())
- return tag1->comment();
-
- if(tag2)
- return tag2->comment();
-
- return String::null;
- }
-
- virtual String genre() const {
- if(tag1 && !tag1->genre().isEmpty())
- return tag1->genre();
-
- if(tag2)
- return tag2->genre();
-
- return String::null;
- }
-
- virtual uint year() const {
- if(tag1 && tag1->year() > 0)
- return tag1->year();
-
- if(tag2)
- return tag2->year();
-
- return 0;
- }
-
- virtual uint track() const {
- if(tag1 && tag1->track() > 0)
- return tag1->track();
-
- if(tag2)
- return tag2->track();
-
- return 0;
- }
-
- virtual void setTitle(const String &s) {
- if(tag1)
- tag1->setTitle(s);
- if(tag2)
- tag2->setTitle(s);
- }
-
- virtual void setArtist(const String &s) {
- if(tag1)
- tag1->setArtist(s);
- if(tag2)
- tag2->setArtist(s);
- }
-
- virtual void setAlbum(const String &s) {
- if(tag1)
- tag1->setAlbum(s);
- if(tag2)
- tag2->setAlbum(s);
- }
-
- virtual void setComment(const String &s) {
- if(tag1)
- tag1->setComment(s);
- if(tag2)
- tag2->setComment(s);
- }
-
- virtual void setGenre(const String &s) {
- if(tag1)
- tag1->setGenre(s);
- if(tag2)
- tag2->setGenre(s);
- }
-
- virtual void setYear(uint i) {
- if(tag1)
- tag1->setYear(i);
- if(tag2)
- tag2->setYear(i);
- }
-
- virtual void setTrack(uint i) {
- if(tag1)
- tag1->setTrack(i);
- if(tag2)
- tag2->setTrack(i);
- }
-
- private:
- Tag *tag1;
- Tag *tag2;
- };
-}
-
-#endif
-#endif
#include <tbytevector.h>
#include <tstring.h>
+#include <tagunion.h>
#include <tdebug.h>
#include "mpcfile.h"
#include "id3v2header.h"
#include "apetag.h"
#include "apefooter.h"
-#include "combinedtag.h"
using namespace TagLib;
+namespace
+{
+ enum { APEIndex, ID3v1Index };
+}
+
class MPC::File::FilePrivate
{
public:
FilePrivate() :
- APETag(0),
APELocation(-1),
APESize(0),
- ID3v1Tag(0),
ID3v1Location(-1),
ID3v2Header(0),
ID3v2Location(-1),
ID3v2Size(0),
- tag(0),
properties(0),
scanned(false),
hasAPE(false),
~FilePrivate()
{
- if (tag != ID3v1Tag && tag != APETag) delete tag;
- delete ID3v1Tag;
- delete APETag;
delete ID3v2Header;
delete properties;
}
- APE::Tag *APETag;
- // long APEFooter;
long APELocation;
uint APESize;
- ID3v1::Tag *ID3v1Tag;
long ID3v1Location;
ID3v2::Header *ID3v2Header;
long ID3v2Location;
uint ID3v2Size;
- Tag *tag;
+ TagUnion tag;
Properties *properties;
bool scanned;
TagLib::Tag *MPC::File::tag() const
{
- return d->tag;
+ return &d->tag;
}
MPC::Properties *MPC::File::audioProperties() const
// 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
// 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;
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;
}
}
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;
}
}
ID3v1::Tag *MPC::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 *MPC::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 MPC::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 & ID3v2) {
}
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);
}
}
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;
}
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 and skip an ID3v2 tag
namespace
{
enum { ID3v2Index = 0, APEIndex = 1, ID3v1Index = 2 };
-
- class MPEGTag : public TagUnion
- {
- public:
- virtual Tag *tag(int index, AccessType type) const
- {
- if(type == Write)
- {
- if(index == ID3v2Index && !(*this)[ID3v2Index])
- {
- const_cast<MPEGTag *>(this)->setTag(ID3v2Index, new ID3v2::Tag);
- }
- else if(index == ID3v1Index && !(*this)[ID3v1Index])
- {
- const_cast<MPEGTag *>(this)->setTag(ID3v1Index, new ID3v1::Tag);
- }
- }
-
- return TagUnion::tag(index);
- }
- };
}
class MPEG::File::FilePrivate
long ID3v1Location;
- MPEGTag tag;
+ TagUnion tag;
// These indicate whether the file *on disk* has these tags, not if
// this data structure does. This is used in computing offsets.
ID3v2::Tag *MPEG::File::ID3v2Tag(bool create)
{
- return static_cast<ID3v2::Tag *>(
- d->tag.tag(ID3v2Index, create ? MPEGTag::Write : MPEGTag::Read));
+ return d->tag.access<ID3v2::Tag>(ID3v2Index, create);
}
ID3v1::Tag *MPEG::File::ID3v1Tag(bool create)
{
- return static_cast<ID3v1::Tag *>(
- d->tag.tag(ID3v1Index, create ? MPEGTag::Write : MPEGTag::Read));
+ return d->tag.access<ID3v1::Tag>(ID3v1Index, create);
}
APE::Tag *MPEG::File::APETag(bool create)
{
- if(!create || d->tag[APEIndex])
- return static_cast<APE::Tag *>(d->tag[APEIndex]);
-
- debug("Creating APE Tag.");
-
- d->tag.setTag(APEIndex, new APE::Tag);
- return static_cast<APE::Tag *>(d->tag[APEIndex]);
+ return d->tag.access<APE::Tag>(APEIndex, create);
}
bool MPEG::File::strip(int tags)
d->hasID3v2 = false;
if(freeMemory)
- d->tag.setTag(ID3v2Index, 0);
+ d->tag.set(ID3v2Index, 0);
// v1 tag location has changed, update if it exists
d->hasID3v1 = false;
if(freeMemory)
- d->tag.setTag(ID3v1Index, 0);
+ d->tag.set(ID3v1Index, 0);
}
if((tags & APE) && d->hasAPE) {
}
if(freeMemory)
- d->tag.setTag(APEIndex, 0);
+ d->tag.set(APEIndex, 0);
}
return true;
if(d->ID3v2Location >= 0) {
- d->tag.setTag(ID3v2Index, new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory));
+ d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory));
d->ID3v2OriginalSize = ID3v2Tag()->header()->completeTagSize();
if(ID3v2Tag()->header()->tagSize() <= 0)
- d->tag.setTag(ID3v2Index, 0);
+ d->tag.set(ID3v2Index, 0);
else
d->hasID3v2 = true;
}
d->ID3v1Location = findID3v1();
if(d->ID3v1Location >= 0) {
- d->tag.setTag(ID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
+ d->tag.set(ID3v1Index, new ID3v1::Tag(this, d->ID3v1Location));
d->hasID3v1 = true;
}
if(d->APELocation >= 0) {
- debug("Found APE");
-
- d->tag.setTag(APEIndex, new APE::Tag(this, d->APELocation));
+ d->tag.set(APEIndex, new APE::Tag(this, d->APELocation));
d->APEOriginalSize = APETag()->footer()->completeTagSize();
if(readProperties)
d->properties = new Properties(this, propertiesStyle);
+
+ // Make sure that we have our default tag types available.
+
+ ID3v2Tag(true);
+ ID3v1Tag(true);
}
long MPEG::File::findID3v2()
using namespace TagLib;
#define stringUnion(method) \
- if(tag(0, Read) && !tag(0, Read)->method().isEmpty()) \
- return tag(0, Read)->method(); \
- if(tag(1, Read) && !tag(1, Read)->method().isEmpty()) \
- return tag(1, Read)->method(); \
- if(tag(2, Read) && !tag(2, Read)->method().isEmpty()) \
- return tag(2, Read)->method(); \
+ if(tag(0) && !tag(0)->method().isEmpty()) \
+ return tag(0)->method(); \
+ if(tag(1) && !tag(1)->method().isEmpty()) \
+ return tag(1)->method(); \
+ if(tag(2) && !tag(2)->method().isEmpty()) \
+ return tag(2)->method(); \
return String::null \
#define numberUnion(method) \
- if(tag(0, Read) && tag(0, Read)->method() > 0) \
- return tag(0, Read)->method(); \
- if(tag(1, Read) && tag(1, Read)->method() > 0) \
- return tag(1, Read)->method(); \
- if(tag(2, Read) && tag(2, Read)->method() > 0) \
- return tag(2, Read)->method(); \
+ if(tag(0) && tag(0)->method() > 0) \
+ return tag(0)->method(); \
+ if(tag(1) && tag(1)->method() > 0) \
+ return tag(1)->method(); \
+ if(tag(2) && tag(2)->method() > 0) \
+ return tag(2)->method(); \
return 0
#define setUnion(method, value) \
- if(tag(0, Write)) \
- tag(0, Write)->set##method(value); \
- if(tag(1, Write)) \
- tag(1, Write)->set##method(value); \
- if(tag(2, Write)) \
- tag(2, Write)->set##method(value); \
+ if(tag(0)) \
+ tag(0)->set##method(value); \
+ if(tag(1)) \
+ tag(1)->set##method(value); \
+ if(tag(2)) \
+ tag(2)->set##method(value); \
class TagUnion::TagUnionPrivate
{
Tag *TagUnion::operator[](int index) const
{
- return d->tags[index];
+ return tag(index);
}
-Tag *TagUnion::tag(int index, AccessType) const
+Tag *TagUnion::tag(int index) const
{
- return (*this)[index];
+ return d->tags[index];
}
-void TagUnion::setTag(int index, Tag *tag)
+void TagUnion::set(int index, Tag *tag)
{
delete d->tags[index];
d->tags[index] = tag;
virtual ~TagUnion();
- /*!
- * Simply returns the value for the the tag at \a index.
- *
- * \note This does not call tag()
- *
- * \see tag()
- */
Tag *operator[](int index) const;
+ Tag *tag(int index) const;
- /*!
- * By default just a call to operator[], but may be overridden if, for
- * instance, it is desirable to create frames on write.
- */
- virtual Tag *tag(int index, AccessType type = Read) const;
-
- void setTag(int index, Tag *tag);
+ void set(int index, Tag *tag);
virtual String title() const;
virtual String artist() const;
virtual void setTrack(uint i);
virtual bool isEmpty() const;
+ template <class T> T *access(int index, bool create)
+ {
+ if(!create || tag(index))
+ return static_cast<T *>(tag(index));
+
+ set(index, new T);
+ return static_cast<T *>(tag(index));
+ }
+
private:
TagUnion(const Tag &);
TagUnion &operator=(const Tag &);
#include <tbytevector.h>
#include <tstring.h>
#include <tdebug.h>
+#include <tagunion.h>
#include "trueaudiofile.h"
#include "id3v1tag.h"
#include "id3v2tag.h"
#include "id3v2header.h"
-#include "combinedtag.h"
using namespace TagLib;
+namespace
+{
+ enum { ID3v2Index = 0, ID3v1Index = 1 };
+}
+
class TrueAudio::File::FilePrivate
{
public:
FilePrivate(const ID3v2::FrameFactory *frameFactory = ID3v2::FrameFactory::instance()) :
ID3v2FrameFactory(frameFactory),
- ID3v2Tag(0),
ID3v2Location(-1),
ID3v2OriginalSize(0),
- ID3v1Tag(0),
ID3v1Location(-1),
- tag(0),
properties(0),
scanned(false),
hasID3v1(false),
~FilePrivate()
{
- if (tag != ID3v1Tag && tag != ID3v2Tag) delete tag;
- delete ID3v1Tag;
- delete ID3v2Tag;
delete properties;
}
const ID3v2::FrameFactory *ID3v2FrameFactory;
- ID3v2::Tag *ID3v2Tag;
long ID3v2Location;
uint ID3v2OriginalSize;
- ID3v1::Tag *ID3v1Tag;
long ID3v1Location;
- Tag *tag;
+ TagUnion tag;
Properties *properties;
bool scanned;
TagLib::Tag *TrueAudio::File::tag() const
{
- return d->tag;
+ return &d->tag;
}
TrueAudio::Properties *TrueAudio::File::audioProperties() const
// Update ID3v2 tag
- if(d->ID3v2Tag && !d->ID3v2Tag->isEmpty()) {
+ if(ID3v2Tag() && !ID3v2Tag()->isEmpty()) {
if(!d->hasID3v2) {
d->ID3v2Location = 0;
d->ID3v2OriginalSize = 0;
}
- ByteVector data = d->ID3v2Tag->render();
+ ByteVector data = ID3v2Tag()->render();
insert(data, d->ID3v2Location, d->ID3v2OriginalSize);
d->ID3v1Location -= d->ID3v2OriginalSize - data.size();
d->ID3v2OriginalSize = data.size();
// Update ID3v1 tag
- if(d->ID3v1Tag && !d->ID3v1Tag->isEmpty()) {
+ if(ID3v1Tag() && !ID3v1Tag()->isEmpty()) {
if(!d->hasID3v1) {
seek(0, End);
d->ID3v1Location = tell();
}
else
seek(d->ID3v1Location);
- writeBlock(d->ID3v1Tag->render());
+ writeBlock(ID3v1Tag()->render());
d->hasID3v1 = true;
}
else if(d->hasID3v1) {
ID3v1::Tag *TrueAudio::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->ID3v2Tag)
- d->tag = new CombinedTag(d->ID3v2Tag, d->ID3v1Tag);
- else
- d->tag = d->ID3v1Tag;
-
- return d->ID3v1Tag;
+ return d->tag.access<ID3v1::Tag>(ID3v1Index, create);
}
ID3v2::Tag *TrueAudio::File::ID3v2Tag(bool create)
{
- if(!create || d->ID3v2Tag)
- return d->ID3v2Tag;
-
- // no ID3v2 tag exists and we've been asked to create one
-
- d->ID3v2Tag = new ID3v2::Tag;
-
- if(d->ID3v1Tag)
- d->tag = new CombinedTag(d->ID3v2Tag, d->ID3v1Tag);
- else
- d->tag = d->ID3v2Tag;
-
- return d->ID3v2Tag;
+ return d->tag.access<ID3v2::Tag>(ID3v2Index, create);
}
void TrueAudio::File::strip(int tags)
{
if(tags & ID3v1) {
- delete d->ID3v1Tag;
- d->ID3v1Tag = 0;
-
- if(d->ID3v2Tag)
- d->tag = d->ID3v2Tag;
- else
- d->tag = d->ID3v2Tag = new ID3v2::Tag;
+ d->tag.set(ID3v1Index, 0);
+ ID3v2Tag(true);
}
if(tags & ID3v2) {
- delete d->ID3v2Tag;
- d->ID3v2Tag = 0;
+ d->tag.set(ID3v2Index, 0);
- if(d->ID3v1Tag)
- d->tag = d->ID3v1Tag;
- else
- d->tag = d->ID3v2Tag = new ID3v2::Tag;
+ if(!ID3v1Tag())
+ ID3v2Tag(true);
}
}
if(d->ID3v2Location >= 0) {
- d->ID3v2Tag = new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory);
+ d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->ID3v2Location, d->ID3v2FrameFactory));
- d->ID3v2OriginalSize = d->ID3v2Tag->header()->completeTagSize();
+ d->ID3v2OriginalSize = ID3v2Tag()->header()->completeTagSize();
- if(d->ID3v2Tag->header()->tagSize() <= 0) {
- delete d->ID3v2Tag;
- d->ID3v2Tag = 0;
- }
+ if(ID3v2Tag()->header()->tagSize() <= 0)
+ d->tag.set(ID3v2Index, 0);
else
d->hasID3v2 = true;
}
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;
}
- if(d->hasID3v1 && d->hasID3v2)
- d->tag = new CombinedTag(d->ID3v2Tag, d->ID3v1Tag);
- else {
- if(d->hasID3v1)
- d->tag = d->ID3v1Tag;
- else {
- if(d->hasID3v2)
- d->tag = d->ID3v2Tag;
- else
- d->tag = d->ID3v2Tag = new ID3v2::Tag;
- }
- }
+ if(!d->hasID3v1)
+ ID3v2Tag(true);
// Look for TrueAudio metadata
#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),
~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;
TagLib::Tag *WavPack::File::tag() const
{
- return d->tag;
+ return &d->tag;
}
WavPack::Properties *WavPack::File::audioProperties() const
// 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;
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;
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);
}
}
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;
}
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