mirror of
https://github.com/taglib/taglib.git
synced 2025-10-06 03:24:38 -04:00
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:
@ -1,175 +0,0 @@
|
||||
/***************************************************************************
|
||||
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
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <tbytevector.h>
|
||||
#include <tstring.h>
|
||||
#include <tagunion.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include "mpcfile.h"
|
||||
@ -32,23 +33,24 @@
|
||||
#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),
|
||||
@ -57,26 +59,20 @@ public:
|
||||
|
||||
~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;
|
||||
@ -107,7 +103,7 @@ MPC::File::~File()
|
||||
|
||||
TagLib::Tag *MPC::File::tag() const
|
||||
{
|
||||
return d->tag;
|
||||
return &d->tag;
|
||||
}
|
||||
|
||||
MPC::Properties *MPC::File::audioProperties() const
|
||||
@ -135,15 +131,15 @@ bool MPC::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
|
||||
@ -158,13 +154,13 @@ bool MPC::File::save()
|
||||
|
||||
// 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;
|
||||
@ -172,8 +168,8 @@ bool MPC::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;
|
||||
}
|
||||
}
|
||||
@ -183,7 +179,7 @@ bool MPC::File::save()
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -193,48 +189,19 @@ bool MPC::File::save()
|
||||
|
||||
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) {
|
||||
@ -243,13 +210,10 @@ void MPC::File::strip(int tags)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +234,7 @@ void MPC::File::read(bool readProperties, Properties::ReadStyle /* propertiesSty
|
||||
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;
|
||||
}
|
||||
|
||||
@ -281,24 +245,15 @@ void MPC::File::read(bool readProperties, Properties::ReadStyle /* propertiesSty
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user