mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
standard style nitpicks and make it build with gcc 2.95
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@331313 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
2fd6401354
commit
382f8194c1
194
mpc/apetag.cpp
194
mpc/apetag.cpp
@ -40,8 +40,8 @@ public:
|
||||
|
||||
Map<const String, String> items;
|
||||
Map<const String, ByteVector> unknowns;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
struct APE::Tag::Item
|
||||
{
|
||||
@ -53,7 +53,8 @@ struct APE::Tag::Item
|
||||
ByteVector bin;
|
||||
}
|
||||
bool readOnly;
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -79,14 +80,13 @@ APE::Tag::~Tag()
|
||||
delete d;
|
||||
}
|
||||
|
||||
using TagLib::uint;
|
||||
|
||||
static ByteVector APEItem(String key, String value) {
|
||||
static ByteVector APEItem(String key, String value)
|
||||
{
|
||||
ByteVector data;
|
||||
uint flags = 0;
|
||||
TagLib::uint flags = 0;
|
||||
|
||||
data.append(ByteVector::fromUInt(value.size(),false));
|
||||
data.append(ByteVector::fromUInt(flags,false));
|
||||
data.append(ByteVector::fromUInt(value.size(), false));
|
||||
data.append(ByteVector::fromUInt(flags, false));
|
||||
data.append(key.data(String::UTF8));
|
||||
data.append(char(0));
|
||||
data.append(value.data(String::UTF8));
|
||||
@ -94,19 +94,20 @@ static ByteVector APEItem(String key, String value) {
|
||||
return data;
|
||||
}
|
||||
|
||||
static ByteVector APEFrame(bool isHeader, uint dataSize, uint itemCount) {
|
||||
static ByteVector APEFrame(bool isHeader, TagLib::uint dataSize, TagLib::uint itemCount)
|
||||
{
|
||||
ByteVector header;
|
||||
uint tagSize = 32 + dataSize;
|
||||
TagLib::uint tagSize = 32 + dataSize;
|
||||
// bit 31: Has a header
|
||||
// bit 29: Is the header
|
||||
uint flags = (1U<<31) | ((isHeader) ? (1U<<29) : 0);
|
||||
TagLib::uint flags = (1U << 31) | ((isHeader) ? (1U << 29) : 0);
|
||||
|
||||
header.append(APE::Tag::fileIdentifier());
|
||||
header.append(ByteVector::fromUInt(2,false));
|
||||
header.append(ByteVector::fromUInt(tagSize,false));
|
||||
header.append(ByteVector::fromUInt(itemCount,false));
|
||||
header.append(ByteVector::fromUInt(flags,false));
|
||||
header.append(ByteVector::fromLongLong(0,false));
|
||||
header.append(ByteVector::fromUInt(2, false));
|
||||
header.append(ByteVector::fromUInt(tagSize, false));
|
||||
header.append(ByteVector::fromUInt(itemCount, false));
|
||||
header.append(ByteVector::fromUInt(flags, false));
|
||||
header.append(ByteVector::fromLongLong(0, false));
|
||||
|
||||
return header;
|
||||
}
|
||||
@ -116,9 +117,10 @@ ByteVector APE::Tag::render() const
|
||||
ByteVector data;
|
||||
uint itemCount = 0;
|
||||
|
||||
{ Map<String,String>::Iterator i = d->items.begin();
|
||||
while (i != d->items.end()) {
|
||||
if (!i->second.isEmpty()) {
|
||||
{
|
||||
Map<String,String>::Iterator i = d->items.begin();
|
||||
while(i != d->items.end()) {
|
||||
if(!i->second.isEmpty()) {
|
||||
data.append(APEItem(i->first, i->second));
|
||||
itemCount++;
|
||||
}
|
||||
@ -126,11 +128,12 @@ ByteVector APE::Tag::render() const
|
||||
}
|
||||
}
|
||||
|
||||
{ Map<String,ByteVector>::Iterator i = d->unknowns.begin();
|
||||
while (i != d->unknowns.end()) {
|
||||
if (!i->second.isEmpty()) {
|
||||
data.append(i->second);
|
||||
itemCount++;
|
||||
{
|
||||
Map<String,ByteVector>::Iterator i = d->unknowns.begin();
|
||||
while(i != d->unknowns.end()) {
|
||||
if(!i->second.isEmpty()) {
|
||||
data.append(i->second);
|
||||
itemCount++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@ -151,7 +154,7 @@ ByteVector APE::Tag::fileIdentifier()
|
||||
|
||||
String APE::Tag::title() const
|
||||
{
|
||||
if (d->items.contains("Title"))
|
||||
if(d->items.contains("Title"))
|
||||
return d->items["Title"];
|
||||
else
|
||||
return String::null;
|
||||
@ -159,7 +162,7 @@ String APE::Tag::title() const
|
||||
|
||||
String APE::Tag::artist() const
|
||||
{
|
||||
if (d->items.contains("Artist"))
|
||||
if(d->items.contains("Artist"))
|
||||
return d->items["Artist"];
|
||||
else
|
||||
return String::null;
|
||||
@ -167,7 +170,7 @@ String APE::Tag::artist() const
|
||||
|
||||
String APE::Tag::album() const
|
||||
{
|
||||
if (d->items.contains("Album"))
|
||||
if(d->items.contains("Album"))
|
||||
return d->items["Album"];
|
||||
else
|
||||
return String::null;
|
||||
@ -175,7 +178,7 @@ String APE::Tag::album() const
|
||||
|
||||
String APE::Tag::comment() const
|
||||
{
|
||||
if (d->items.contains("Comment"))
|
||||
if(d->items.contains("Comment"))
|
||||
return d->items["Comment"];
|
||||
else
|
||||
return String::null;
|
||||
@ -183,7 +186,7 @@ String APE::Tag::comment() const
|
||||
|
||||
String APE::Tag::genre() const
|
||||
{
|
||||
if (d->items.contains("Genre"))
|
||||
if(d->items.contains("Genre"))
|
||||
return d->items["Genre"];
|
||||
else
|
||||
return String::null;
|
||||
@ -191,14 +194,14 @@ String APE::Tag::genre() const
|
||||
|
||||
TagLib::uint APE::Tag::year() const
|
||||
{
|
||||
if (d->items.contains("Year"))
|
||||
if(d->items.contains("Year"))
|
||||
return (d->items["Year"]).toInt();
|
||||
return 0;
|
||||
}
|
||||
|
||||
TagLib::uint APE::Tag::track() const
|
||||
{
|
||||
if (d->items.contains("Track"))
|
||||
if(d->items.contains("Track"))
|
||||
return (d->items["Track"]).toInt();
|
||||
return 0;
|
||||
}
|
||||
@ -220,7 +223,7 @@ void APE::Tag::setAlbum(const String &s)
|
||||
|
||||
void APE::Tag::setComment(const String &s)
|
||||
{
|
||||
if(s.isEmpty() )
|
||||
if(s.isEmpty())
|
||||
removeComment("Comment");
|
||||
else
|
||||
d->items["Comment"] = s;
|
||||
@ -236,7 +239,7 @@ void APE::Tag::setGenre(const String &s)
|
||||
|
||||
void APE::Tag::setYear(uint i)
|
||||
{
|
||||
if(i <=0 )
|
||||
if(i <= 0)
|
||||
removeComment("Year");
|
||||
else
|
||||
d->items["Year"] = String::number(i);
|
||||
@ -256,25 +259,25 @@ void APE::Tag::removeComment(const String &key) {
|
||||
d->items.erase(it);
|
||||
}
|
||||
|
||||
void APE::Tag::addComment(const String &key, const String &value) {
|
||||
if (value.isEmpty())
|
||||
void APE::Tag::addComment(const String &key, const String &value)
|
||||
{
|
||||
if(value.isEmpty())
|
||||
removeComment(key);
|
||||
else
|
||||
d->items[key] = value;
|
||||
}
|
||||
|
||||
uint APE::Tag::tagSize(ByteVector footer) {
|
||||
TagLib::uint APE::Tag::tagSize(ByteVector footer)
|
||||
{
|
||||
// The reported length (excl. header)
|
||||
|
||||
// The reported length (excl. header)
|
||||
uint length = footer.mid(12, 4).toUInt(false);
|
||||
|
||||
uint length = footer.mid(12,4).toUInt(false);
|
||||
// Flags (bit 31: tag contains a header)
|
||||
|
||||
// Flags (bit 31: tag contains a header)
|
||||
|
||||
uint flags = footer.mid(20,4).toUInt(false);
|
||||
|
||||
return length + (flags & (1U<<31) ? 32 : 0);
|
||||
uint flags = footer.mid(20, 4).toUInt(false);
|
||||
|
||||
return length + (flags & (1U << 31) ? 32 : 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -295,7 +298,7 @@ void APE::Tag::read()
|
||||
d->tagLength = length;
|
||||
d->file->seek(d->tagOffset + 32 -length);
|
||||
ByteVector data = d->file->readBlock(length-32);
|
||||
parse(data,count);
|
||||
parse(data, count);
|
||||
}
|
||||
else
|
||||
debug("APE tag is not valid or could not be read at the specified offset.");
|
||||
@ -304,62 +307,65 @@ void APE::Tag::read()
|
||||
|
||||
void APE::Tag::parse(const ByteVector &data, uint count)
|
||||
{
|
||||
uint pos = 0;
|
||||
uint vallen, flags;
|
||||
String key, value;
|
||||
while(count > 0) {
|
||||
vallen = data.mid(pos+0,4).toUInt(false);
|
||||
flags = data.mid(pos+4,4).toUInt(false);
|
||||
key = String(data.mid(pos+8), String::UTF8);
|
||||
uint pos = 0;
|
||||
uint vallen, flags;
|
||||
String key, value;
|
||||
while(count > 0) {
|
||||
vallen = data.mid(pos + 0, 4).toUInt(false);
|
||||
flags = data.mid(pos + 4, 4).toUInt(false);
|
||||
key = String(data.mid(pos + 8), String::UTF8);
|
||||
|
||||
if (flags == 0) {
|
||||
value = String(data.mid(pos+8+key.size()+1, vallen), String::UTF8);
|
||||
d->items.insert(key,value);
|
||||
} else {
|
||||
d->unknowns.insert(key,data.mid(pos, 8+key.size()+1+vallen));
|
||||
}
|
||||
|
||||
pos += 8+key.size()+1+vallen;
|
||||
count--;
|
||||
if(flags == 0) {
|
||||
value = String(data.mid(pos + 8 + key.size() + 1, vallen), String::UTF8);
|
||||
d->items.insert(key, value);
|
||||
}
|
||||
else {
|
||||
d->unknowns.insert(key, data.mid(pos, 8 + key.size() + 1 + vallen));
|
||||
}
|
||||
|
||||
pos += 8 + key.size() + 1 + vallen;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void APE::Tag::parse(const ByteVector &data, uint count)
|
||||
{
|
||||
uint pos = 0;
|
||||
uint vallen, flags;
|
||||
String key;
|
||||
while(count > 0) {
|
||||
vallen = data.mid(pos+0,4).toUInt(false);
|
||||
flags = data.mid(pos+4,4).toUInt(false);
|
||||
key = String(data.mid(pos+8), String::UTF8);
|
||||
Item item(key);
|
||||
uint pos = 0;
|
||||
uint vallen, flags;
|
||||
String key;
|
||||
while(count > 0) {
|
||||
vallen = data.mid(pos + 0, 4).toUInt(false);
|
||||
flags = data.mid(pos + 4, 4).toUInt(false);
|
||||
key = String(data.mid(pos + 8), String::UTF8);
|
||||
Item item(key);
|
||||
|
||||
ByteVector value = data.mid(pos+8+key.size()+1, vallen);
|
||||
ByteVector value = data.mid(pos+8+key.size()+1, vallen);
|
||||
|
||||
switch ((flags >> 1) & 3) {
|
||||
case 0:
|
||||
item.value.str = String(value, String::UTF8);
|
||||
item.type = Item::STRING;
|
||||
break;
|
||||
case 1:
|
||||
item.value.bin = value;
|
||||
item.type = Item::BINARY;
|
||||
break;
|
||||
case 2:
|
||||
item.value.str = String(value, String::UTF8);
|
||||
item.type = Item::URL;
|
||||
break;
|
||||
case 3:
|
||||
item.value.bin = value;
|
||||
item.type = Item::RESERVED;
|
||||
break;
|
||||
}
|
||||
item.readOnly = (flags & 1);
|
||||
|
||||
d->items.insert(key,item);
|
||||
|
||||
pos += 8+key.size()+1+vallen;
|
||||
count--;
|
||||
switch ((flags >> 1) & 3) {
|
||||
case 0:
|
||||
item.value.str = String(value, String::UTF8);
|
||||
item.type = Item::STRING;
|
||||
break;
|
||||
case 1:
|
||||
item.value.bin = value;
|
||||
item.type = Item::BINARY;
|
||||
break;
|
||||
case 2:
|
||||
item.value.str = String(value, String::UTF8);
|
||||
item.type = Item::URL;
|
||||
break;
|
||||
case 3:
|
||||
item.value.bin = value;
|
||||
item.type = Item::RESERVED;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
item.readOnly = (flags & 1);
|
||||
|
||||
d->items.insert(key,item);
|
||||
|
||||
pos += 8 + key.size() + 1 + vallen;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MPC::File::File(const char *file, bool readProperties,
|
||||
Properties::ReadStyle propertiesStyle) : TagLib::File(file)
|
||||
Properties::ReadStyle propertiesStyle) : TagLib::File(file)
|
||||
{
|
||||
d = new FilePrivate;
|
||||
read(readProperties, propertiesStyle);
|
||||
@ -95,14 +95,15 @@ MPC::File::~File()
|
||||
|
||||
TagLib::Tag *MPC::File::tag() const
|
||||
{
|
||||
if (d->APETag)
|
||||
return d->APETag;
|
||||
else
|
||||
if (d->ID3v1Tag)
|
||||
return d->ID3v1Tag;
|
||||
else {
|
||||
d->APETag = new APE::Tag;
|
||||
if(d->APETag)
|
||||
return d->APETag;
|
||||
else {
|
||||
if(d->ID3v1Tag)
|
||||
return d->ID3v1Tag;
|
||||
else {
|
||||
d->APETag = new APE::Tag;
|
||||
return d->APETag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,28 +112,21 @@ MPC::Properties *MPC::File::audioProperties() const
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
|
||||
bool MPC::File::save()
|
||||
{
|
||||
|
||||
// Update APE tag
|
||||
|
||||
if(d->hasAPE && d->APETag)
|
||||
{
|
||||
insert(d->APETag->render(), d->APELocation, d->APESize);
|
||||
else {
|
||||
// Update ID3v1 tag
|
||||
|
||||
if(d->hasID3v1 && d->ID3v1Tag) {
|
||||
seek(-128, End);
|
||||
writeBlock(d->ID3v1Tag->render());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// Update ID3v1 tag
|
||||
|
||||
if(d->hasID3v1 && d->ID3v1Tag)
|
||||
{
|
||||
seek(-128, End);
|
||||
writeBlock(d->ID3v1Tag->render());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -152,7 +146,7 @@ void MPC::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
|
||||
|
||||
// Look for an ID3v1 tag
|
||||
|
||||
if (!d->hasAPE) {
|
||||
if(!d->hasAPE) {
|
||||
d->ID3v1Location = findID3v1();
|
||||
|
||||
if(d->ID3v1Location >= 0) {
|
||||
@ -172,7 +166,7 @@ void MPC::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
|
||||
d->hasID3v2 = true;
|
||||
}
|
||||
|
||||
if (d->hasID3v2)
|
||||
if(d->hasID3v2)
|
||||
seek(d->ID3v2Location + d->ID3v2Size);
|
||||
else
|
||||
seek(0);
|
||||
@ -187,7 +181,6 @@ void MPC::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
|
||||
|
||||
bool MPC::File::findAPE()
|
||||
{
|
||||
|
||||
if(!isValid())
|
||||
return false;
|
||||
|
||||
@ -195,8 +188,7 @@ bool MPC::File::findAPE()
|
||||
long p = tell();
|
||||
|
||||
ByteVector footer = readBlock(32);
|
||||
if(footer.mid(0,8) == APE::Tag::fileIdentifier())
|
||||
{
|
||||
if(footer.mid(0,8) == APE::Tag::fileIdentifier()) {
|
||||
d->APEFooter = p;
|
||||
d->APESize = APE::Tag::tagSize(footer);
|
||||
d->APELocation = p + 32 - d->APESize;
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MPC::Properties::Properties(ByteVector data, long streamLength, ReadStyle style) : AudioProperties(style)
|
||||
MPC::Properties::Properties(const ByteVector &data, long streamLength, ReadStyle style) : AudioProperties(style)
|
||||
{
|
||||
d = new PropertiesPrivate(data, streamLength, style);
|
||||
read();
|
||||
@ -80,11 +80,13 @@ int MPC::Properties::sampleRate() const
|
||||
{
|
||||
return d->sampleRate;
|
||||
}
|
||||
|
||||
/*
|
||||
int MPC::Properties::sampleWidth() const
|
||||
{
|
||||
return d->sampleWidth;
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
|
||||
int MPC::Properties::channels() const
|
||||
{
|
||||
@ -104,34 +106,36 @@ static const unsigned short sftable [4] = { 44100, 48000, 37800, 32000 };
|
||||
|
||||
void MPC::Properties::read()
|
||||
{
|
||||
if (d->data.mid(0,3) != "MP+") return;
|
||||
if(d->data.mid(0,3) != "MP+")
|
||||
return;
|
||||
|
||||
d->version = d->data[3] & 15;
|
||||
|
||||
unsigned int frames;
|
||||
if (d->version >= 7) {
|
||||
|
||||
if(d->version >= 7) {
|
||||
frames = d->data.mid(4,4).toUInt(false);
|
||||
|
||||
std::bitset<32> flags = d->data.mid(8,4).toUInt(true);
|
||||
d->sampleRate = sftable[flags[17]*2+flags[16]];
|
||||
std::bitset<32> flags = d->data.mid(8, 4).toUInt(true);
|
||||
d->sampleRate = sftable[flags[17] * 2 + flags[16]];
|
||||
d->channels = 2;
|
||||
|
||||
} else {
|
||||
unsigned int headerData = d->data.mid(0,4).toUInt(false);
|
||||
}
|
||||
else {
|
||||
unsigned int headerData = d->data.mid(0, 4).toUInt(false);
|
||||
d->bitrate = (headerData >> 23) & 0x01ff;
|
||||
d->version = (headerData >> 11) & 0x03ff;
|
||||
d->sampleRate = 44100;
|
||||
d->channels = 2;
|
||||
if (d->version >= 5)
|
||||
frames = d->data.mid(4,4).toUInt(false);
|
||||
if(d->version >= 5)
|
||||
frames = d->data.mid(4, 4).toUInt(false);
|
||||
else
|
||||
frames = d->data.mid(4,2).toUInt(false);
|
||||
frames = d->data.mid(4, 2).toUInt(false);
|
||||
}
|
||||
|
||||
unsigned int samples = frames * 1152 - 576;
|
||||
d->length = (samples+(d->sampleRate/2)) / d->sampleRate;
|
||||
d->length = (samples + (d->sampleRate / 2)) / d->sampleRate;
|
||||
|
||||
if (!d->bitrate)
|
||||
d->bitrate = ((d->streamLength*8L) / d->length)/1000;
|
||||
if(!d->bitrate)
|
||||
d->bitrate = ((d->streamLength * 8L) / d->length) / 1000;
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ namespace TagLib {
|
||||
|
||||
static const uint HeaderSize = 8*7;
|
||||
|
||||
|
||||
//! An implementation of audio property reading for MPC
|
||||
|
||||
/*!
|
||||
@ -47,7 +46,7 @@ namespace TagLib {
|
||||
* Create an instance of MPC::Properties with the data read from the
|
||||
* ByteVector \a data.
|
||||
*/
|
||||
Properties(ByteVector data, long streamLength, ReadStyle style = Average);
|
||||
Properties(const ByteVector &data, long streamLength, ReadStyle style = Average);
|
||||
|
||||
/*!
|
||||
* Destroys this MPC::Properties instance.
|
||||
|
Loading…
x
Reference in New Issue
Block a user