Adapt most changes from taglib2

This commit is contained in:
Jonas Kvinge
2020-06-26 23:30:30 +02:00
parent 08882639e0
commit 5f71a558b9
374 changed files with 13708 additions and 4418 deletions

View File

@@ -23,12 +23,14 @@
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include <tbytevector.h>
#include <tstring.h>
#include <tagunion.h>
#include <tdebug.h>
#include <tpropertymap.h>
#include <tagutils.h>
#include <memory>
#include "tbytevector.h"
#include "tstring.h"
#include "tagunion.h"
#include "tdebug.h"
#include "tpropertymap.h"
#include "tagutils.h"
#include "mpcfile.h"
#include "id3v1tag.h"
@@ -45,31 +47,24 @@ enum { MPCAPEIndex = 0,
class MPC::File::FilePrivate {
public:
FilePrivate() : APELocation(-1),
APESize(0),
ID3v1Location(-1),
ID3v2Header(nullptr),
ID3v2Location(-1),
ID3v2Size(0),
properties(nullptr) {}
explicit FilePrivate() : APELocation(-1),
APESize(0),
ID3v1Location(-1),
ID3v2Location(-1),
ID3v2Size(0) {}
~FilePrivate() {
delete ID3v2Header;
delete properties;
}
long long APELocation;
long long APESize;
long APELocation;
long APESize;
long long ID3v1Location;
long ID3v1Location;
std::unique_ptr<ID3v2::Header> ID3v2Header;
long long ID3v2Location;
long long ID3v2Size;
ID3v2::Header *ID3v2Header;
long ID3v2Location;
long ID3v2Size;
DoubleTagUnion tag;
TagUnion tag;
AudioProperties *properties;
std::unique_ptr<AudioProperties> properties;
};
////////////////////////////////////////////////////////////////////////////////
@@ -112,14 +107,6 @@ Strawberry_TagLib::TagLib::Tag *MPC::File::tag() const {
return &d->tag;
}
PropertyMap MPC::File::properties() const {
return d->tag.properties();
}
void MPC::File::removeUnsupportedProperties(const StringList &properties) {
d->tag.removeUnsupportedProperties(properties);
}
PropertyMap MPC::File::setProperties(const PropertyMap &properties) {
if (ID3v1Tag())
ID3v1Tag()->setProperties(properties);
@@ -128,7 +115,7 @@ PropertyMap MPC::File::setProperties(const PropertyMap &properties) {
}
MPC::AudioProperties *MPC::File::audioProperties() const {
return d->properties;
return d->properties.get();
}
bool MPC::File::save() {
@@ -238,11 +225,8 @@ void MPC::File::strip(int tags) {
if (!ID3v1Tag())
APETag(true);
if (tags & ID3v2) {
delete d->ID3v2Header;
d->ID3v2Header = nullptr;
}
if (tags & ID3v2)
d->ID3v2Header.reset();
}
bool MPC::File::hasID3v1Tag() const {
@@ -265,7 +249,7 @@ void MPC::File::read(bool readProperties) {
if (d->ID3v2Location >= 0) {
seek(d->ID3v2Location);
d->ID3v2Header = new ID3v2::Header(readBlock(ID3v2::Header::size()));
d->ID3v2Header.reset(new ID3v2::Header(readBlock(ID3v2::Header::size())));
d->ID3v2Size = d->ID3v2Header->completeTagSize();
}
@@ -293,7 +277,7 @@ void MPC::File::read(bool readProperties) {
if (readProperties) {
long streamLength;
long long streamLength;
if (d->APELocation >= 0)
streamLength = d->APELocation;
@@ -310,7 +294,7 @@ void MPC::File::read(bool readProperties) {
seek(0);
}
d->properties = new AudioProperties(this, streamLength);
d->properties.reset(new AudioProperties(this, streamLength));
}
}

View File

@@ -104,41 +104,33 @@ class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
/*!
* Destroys this instance of the File.
*/
virtual ~File();
~File() override;
/*!
* Returns the Tag for this file.
* This will be an APE tag, an ID3v1 tag or a combination of the two.
*/
virtual Strawberry_TagLib::TagLib::Tag *tag() const;
/*!
* Implements the unified property interface -- export function.
* If the file contains both an APE and an ID3v1 tag, only the APE tag will be converted to the PropertyMap.
*/
PropertyMap properties() const;
void removeUnsupportedProperties(const StringList &properties);
Strawberry_TagLib::TagLib::Tag *tag() const override;
/*!
* Implements the unified property interface -- import function.
* Affects only the APEv2 tag which will be created if necessary.
* If an ID3v1 tag exists, it will be updated as well.
*/
PropertyMap setProperties(const PropertyMap &);
PropertyMap setProperties(const PropertyMap &) override;
/*!
* Returns the MPC::AudioProperties for this file.
* If no audio properties were read then this will return a null pointer.
*/
virtual AudioProperties *audioProperties() const;
AudioProperties *audioProperties() const override;
/*!
* Saves the file.
*
* This returns true if the save was successful.
*/
virtual bool save();
bool save() override;
/*!
* Returns a pointer to the ID3v1 tag of the file.
@@ -205,7 +197,7 @@ class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File {
static bool isSupported(IOStream *stream);
private:
explicit File(const File&);
File(const File&);
File &operator=(const File&);
void read(bool readProperties);

View File

@@ -23,29 +23,35 @@
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include <tstring.h>
#include <tdebug.h>
#include <bitset>
#include <cmath>
#include "tstring.h"
#include "tdebug.h"
#include "mpcproperties.h"
#include "mpcfile.h"
using namespace Strawberry_TagLib::TagLib;
namespace {
const unsigned int HeaderSize = 56;
}
class MPC::AudioProperties::AudioPropertiesPrivate {
public:
AudioPropertiesPrivate() : version(0),
length(0),
bitrate(0),
sampleRate(0),
channels(0),
totalFrames(0),
sampleFrames(0),
trackGain(0),
trackPeak(0),
albumGain(0),
albumPeak(0) {}
explicit AudioPropertiesPrivate() : version(0),
length(0),
bitrate(0),
sampleRate(0),
channels(0),
totalFrames(0),
sampleFrames(0),
trackGain(0),
trackPeak(0),
albumGain(0),
albumPeak(0) {}
int version;
int length;
@@ -54,21 +60,17 @@ class MPC::AudioProperties::AudioPropertiesPrivate {
int channels;
unsigned int totalFrames;
unsigned int sampleFrames;
int trackGain;
int trackPeak;
int albumGain;
int albumPeak;
unsigned int trackGain;
unsigned int trackPeak;
unsigned int albumGain;
unsigned int albumPeak;
};
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
MPC::AudioProperties::AudioProperties(const ByteVector &data, long streamLength, ReadStyle style) : Strawberry_TagLib::TagLib::AudioProperties(style), d(new AudioPropertiesPrivate()) {
readSV7(data, streamLength);
}
MPC::AudioProperties::AudioProperties(File *file, long streamLength, ReadStyle style) : Strawberry_TagLib::TagLib::AudioProperties(style), d(new AudioPropertiesPrivate()) {
MPC::AudioProperties::AudioProperties(File *file, long long streamLength, ReadStyle) : Strawberry_TagLib::TagLib::AudioProperties(), d(new AudioPropertiesPrivate()) {
ByteVector magic = file->readBlock(4);
if (magic == "MPCK") {
@@ -77,7 +79,7 @@ MPC::AudioProperties::AudioProperties(File *file, long streamLength, ReadStyle s
}
else {
// Musepack version 7 or older, fixed size header
readSV7(magic + file->readBlock(MPC::HeaderSize - 4), streamLength);
readSV7(magic + file->readBlock(HeaderSize - 4), streamLength);
}
}
@@ -139,7 +141,7 @@ int MPC::AudioProperties::albumPeak() const {
////////////////////////////////////////////////////////////////////////////////
namespace {
unsigned long readSize(File *file, unsigned int &sizeLength, bool &eof) {
unsigned long readSize(File *file, size_t &sizeLength, bool &eof) {
sizeLength = 0;
eof = false;
@@ -164,7 +166,7 @@ unsigned long readSize(File *file, unsigned int &sizeLength, bool &eof) {
}
unsigned long readSize(const ByteVector &data, unsigned int &pos) {
unsigned long readSize(const ByteVector &data, size_t &pos) {
unsigned char tmp;
unsigned long size = 0;
@@ -184,22 +186,22 @@ unsigned long readSize(const ByteVector &data, unsigned int &pos) {
const unsigned short sftable[8] = { 44100, 48000, 37800, 32000, 0, 0, 0, 0 };
} // namespace
void MPC::AudioProperties::readSV8(File *file, long streamLength) {
void MPC::AudioProperties::readSV8(File *file, long long streamLength) {
bool readSH = false, readRG = false;
while (!readSH && !readRG) {
const ByteVector packetType = file->readBlock(2);
unsigned int packetSizeLength;
size_t packetSizeLength;
bool eof;
const unsigned long packetSize = readSize(file, packetSizeLength, eof);
const size_t packetSize = readSize(file, packetSizeLength, eof);
if (eof) {
debug("MPC::AudioProperties::readSV8() - Reached to EOF.");
break;
}
const unsigned long dataSize = packetSize - 2 - packetSizeLength;
const size_t dataSize = packetSize - 2 - packetSizeLength;
const ByteVector data = file->readBlock(dataSize);
if (data.size() != dataSize) {
@@ -218,7 +220,7 @@ void MPC::AudioProperties::readSV8(File *file, long streamLength) {
readSH = true;
unsigned int pos = 4;
size_t pos = 4;
d->version = data[pos];
pos += 1;
d->sampleFrames = readSize(data, pos);
@@ -233,7 +235,7 @@ void MPC::AudioProperties::readSV8(File *file, long streamLength) {
break;
}
const unsigned short flags = data.toUShort(pos, true);
const unsigned short flags = data.toUInt16BE(pos);
pos += 2;
d->sampleRate = sftable[(flags >> 13) & 0x07];
@@ -259,10 +261,10 @@ void MPC::AudioProperties::readSV8(File *file, long streamLength) {
const int replayGainVersion = data[0];
if (replayGainVersion == 1) {
d->trackGain = data.toShort(1, true);
d->trackPeak = data.toShort(3, true);
d->albumGain = data.toShort(5, true);
d->albumPeak = data.toShort(7, true);
d->trackGain = data.toUInt16BE(1);
d->trackPeak = data.toUInt16BE(3);
d->albumGain = data.toUInt16BE(5);
d->albumPeak = data.toUInt16BE(7);
}
}
@@ -277,25 +279,25 @@ void MPC::AudioProperties::readSV8(File *file, long streamLength) {
}
void MPC::AudioProperties::readSV7(const ByteVector &data, long streamLength) {
void MPC::AudioProperties::readSV7(const ByteVector &data, long long streamLength) {
if (data.startsWith("MP+")) {
d->version = data[3] & 15;
if (d->version < 7)
return;
d->totalFrames = data.toUInt(4, false);
d->totalFrames = data.toUInt32LE(4);
const unsigned int flags = data.toUInt(8, false);
const unsigned int flags = data.toUInt32LE(8);
d->sampleRate = sftable[(flags >> 16) & 0x03];
d->channels = 2;
const unsigned int gapless = data.toUInt(5, false);
const unsigned int gapless = data.toUInt32LE(5);
d->trackGain = data.toShort(14, false);
d->trackPeak = data.toUShort(12, false);
d->albumGain = data.toShort(18, false);
d->albumPeak = data.toUShort(16, false);
d->trackGain = data.toUInt16LE(14);
d->trackPeak = data.toUInt16LE(12);
d->albumGain = data.toUInt16LE(18);
d->albumPeak = data.toUInt16LE(16);
// convert gain info
if (d->trackGain != 0) {
@@ -325,7 +327,7 @@ void MPC::AudioProperties::readSV7(const ByteVector &data, long streamLength) {
d->sampleFrames = d->totalFrames * 1152 - 576;
}
else {
const unsigned int headerData = data.toUInt(0, false);
const unsigned int headerData = data.toUInt32LE(0);
d->bitrate = (headerData >> 23) & 0x01ff;
d->version = (headerData >> 11) & 0x03ff;
@@ -333,9 +335,9 @@ void MPC::AudioProperties::readSV7(const ByteVector &data, long streamLength) {
d->channels = 2;
if (d->version >= 5)
d->totalFrames = data.toUInt(4, false);
d->totalFrames = data.toUInt32LE(4);
else
d->totalFrames = data.toUShort(6, false);
d->totalFrames = data.toUInt16LE(6);
d->sampleFrames = d->totalFrames * 1152 - 576;
}

View File

@@ -36,8 +36,6 @@ namespace MPC {
class File;
static const unsigned int HeaderSize = 8 * 7;
//! An implementation of audio property reading for MPC
/*!
@@ -46,22 +44,15 @@ static const unsigned int HeaderSize = 8 * 7;
class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioProperties {
public:
/*!
* Create an instance of MPC::AudioProperties with the data read from the ByteVector \a data.
*
* This constructor is deprecated. It only works for MPC version up to 7.
*/
explicit AudioProperties(const ByteVector &data, long streamLength, ReadStyle style = Average);
/*!
* Create an instance of MPC::AudioProperties with the data read directly from a MPC::File.
*/
explicit AudioProperties(File *file, long streamLength, ReadStyle style = Average);
explicit AudioProperties(File *file, long long streamLength, ReadStyle style = Average);
/*!
* Destroys this MPC::AudioProperties instance.
*/
virtual ~AudioProperties();
~AudioProperties() override;
/*!
* Returns the length of the file in seconds.
@@ -69,29 +60,29 @@ class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioPro
*
* \see lengthInMilliseconds()
*/
virtual int lengthInSeconds() const;
int lengthInSeconds() const override;
/*!
* Returns the length of the file in milliseconds.
*
* \see lengthInSeconds()
*/
virtual int lengthInMilliseconds() const;
int lengthInMilliseconds() const override;
/*!
* Returns the average bit rate of the file in kb/s.
*/
virtual int bitrate() const;
int bitrate() const override;
/*!
* Returns the sample rate in Hz.
*/
virtual int sampleRate() const;
int sampleRate() const override;
/*!
* Returns the number of audio channels.
*/
virtual int channels() const;
int channels() const override;
/*!
* Returns the version of the bitstream (SV4-SV8)
@@ -128,11 +119,8 @@ class TAGLIB_EXPORT AudioProperties : public Strawberry_TagLib::TagLib::AudioPro
int albumPeak() const;
private:
explicit AudioProperties(const AudioProperties&);
AudioProperties &operator=(const AudioProperties&);
void readSV7(const ByteVector &data, long streamLength);
void readSV8(File *file, long streamLength);
void readSV7(const ByteVector &data, long long streamLength);
void readSV8(File *file, long long streamLength);
class AudioPropertiesPrivate;
AudioPropertiesPrivate *d;