Format taglib sources

This commit is contained in:
Jonas Kvinge
2020-06-13 19:02:42 +02:00
parent 72bff7fa35
commit 4ce099294c
224 changed files with 12905 additions and 15623 deletions

View File

@@ -33,65 +33,52 @@
using namespace Strawberry_TagLib::TagLib;
using namespace IT;
class IT::File::FilePrivate
{
public:
class IT::File::FilePrivate {
public:
explicit FilePrivate(AudioProperties::ReadStyle propertiesStyle)
: tag(), properties(propertiesStyle)
{
: tag(), properties(propertiesStyle) {
}
Mod::Tag tag;
Mod::Tag tag;
IT::Properties properties;
};
IT::File::File(FileName file, bool readProperties,
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(file),
d(new FilePrivate(propertiesStyle))
{
if(isOpen())
AudioProperties::ReadStyle propertiesStyle) : Mod::FileBase(file),
d(new FilePrivate(propertiesStyle)) {
if (isOpen())
read(readProperties);
}
IT::File::File(IOStream *stream, bool readProperties,
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(stream),
d(new FilePrivate(propertiesStyle))
{
if(isOpen())
AudioProperties::ReadStyle propertiesStyle) : Mod::FileBase(stream),
d(new FilePrivate(propertiesStyle)) {
if (isOpen())
read(readProperties);
}
IT::File::~File()
{
IT::File::~File() {
delete d;
}
Mod::Tag *IT::File::tag() const
{
Mod::Tag *IT::File::tag() const {
return &d->tag;
}
PropertyMap IT::File::properties() const
{
PropertyMap IT::File::properties() const {
return d->tag.properties();
}
PropertyMap IT::File::setProperties(const PropertyMap &properties)
{
PropertyMap IT::File::setProperties(const PropertyMap &properties) {
return d->tag.setProperties(properties);
}
IT::Properties *IT::File::audioProperties() const
{
IT::Properties *IT::File::audioProperties() const {
return &d->properties;
}
bool IT::File::save()
{
if(readOnly())
{
bool IT::File::save() {
if (readOnly()) {
debug("IT::File::save() - Cannot save to a read only file.");
return false;
}
@@ -105,37 +92,37 @@ bool IT::File::save()
unsigned short instrumentCount = 0;
unsigned short sampleCount = 0;
if(!readU16L(length) || !readU16L(instrumentCount) || !readU16L(sampleCount))
if (!readU16L(length) || !readU16L(instrumentCount) || !readU16L(sampleCount))
return false;
seek(15, Current);
// write comment as instrument and sample names:
StringList lines = d->tag.comment().split("\n");
for(unsigned short i = 0; i < instrumentCount; ++ i) {
for (unsigned short i = 0; i < instrumentCount; ++i) {
seek(192L + length + ((long)i << 2));
unsigned long instrumentOffset = 0;
if(!readU32L(instrumentOffset))
if (!readU32L(instrumentOffset))
return false;
seek(instrumentOffset + 32);
if(i < lines.size())
if (i < lines.size())
writeString(lines[i], 25);
else
writeString(String(), 25);
writeByte(0);
}
for(unsigned short i = 0; i < sampleCount; ++ i) {
for (unsigned short i = 0; i < sampleCount; ++i) {
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2));
unsigned long sampleOffset = 0;
if(!readU32L(sampleOffset))
if (!readU32L(sampleOffset))
return false;
seek(sampleOffset + 20);
if((unsigned int)(i + instrumentCount) < lines.size())
if ((unsigned int)(i + instrumentCount) < lines.size())
writeString(lines[i + instrumentCount], 25);
else
writeString(String(), 25);
@@ -144,41 +131,40 @@ bool IT::File::save()
// write rest as message:
StringList messageLines;
for(unsigned int i = instrumentCount + sampleCount; i < lines.size(); ++ i)
for (unsigned int i = instrumentCount + sampleCount; i < lines.size(); ++i)
messageLines.append(lines[i]);
ByteVector message = messageLines.toString("\r").data(String::Latin1);
// it's actually not really stated if the message needs a
// terminating NUL but it does not hurt to add one:
if(message.size() > 7999)
if (message.size() > 7999)
message.resize(7999);
message.append((char)0);
unsigned short special = 0;
unsigned short messageLength = 0;
unsigned long messageOffset = 0;
unsigned long messageOffset = 0;
seek(46);
if(!readU16L(special))
if (!readU16L(special))
return false;
unsigned long fileSize = File::length();
if(special & Properties::MessageAttached) {
if (special & Properties::MessageAttached) {
seek(54);
if(!readU16L(messageLength) || !readU32L(messageOffset))
if (!readU16L(messageLength) || !readU32L(messageOffset))
return false;
if(messageLength == 0)
if (messageLength == 0)
messageOffset = fileSize;
}
else
{
else {
messageOffset = fileSize;
seek(46);
writeU16L(special | 0x1);
}
if(messageOffset + messageLength >= fileSize) {
if (messageOffset + messageLength >= fileSize) {
// append new message
seek(54);
writeU16L(message.size());
@@ -199,9 +185,8 @@ bool IT::File::save()
return true;
}
void IT::File::read(bool)
{
if(!isOpen())
void IT::File::read(bool) {
if (!isOpen())
return;
seek(0);
@@ -233,14 +218,14 @@ void IT::File::read(bool)
// sample/instrument names are abused as comments so
// I just add all together.
String message;
if(special & Properties::MessageAttached) {
if (special & Properties::MessageAttached) {
READ_U16L_AS(messageLength);
READ_U32L_AS(messageOffset);
seek(messageOffset);
ByteVector messageBytes = readBlock(messageLength);
READ_ASSERT(messageBytes.size() == messageLength);
int index = messageBytes.find((char) 0);
if(index > -1)
int index = messageBytes.find((char)0);
if (index > -1)
messageBytes.resize(index, 0);
messageBytes.replace('\r', '\n');
message = messageBytes;
@@ -249,26 +234,26 @@ void IT::File::read(bool)
seek(64);
ByteVector pannings = readBlock(64);
ByteVector volumes = readBlock(64);
ByteVector volumes = readBlock(64);
READ_ASSERT(pannings.size() == 64 && volumes.size() == 64);
int channels = 0;
for(int i = 0; i < 64; ++ i) {
for (int i = 0; i < 64; ++i) {
// Strictly speaking an IT file has always 64 channels, but
// I don't count disabled and muted channels.
// But this always gives 64 channels for all my files anyway.
// Strangely VLC does report other values. I wonder how VLC
// gets it's values.
if((unsigned char) pannings[i] < 128 && volumes[i] > 0)
++channels;
if ((unsigned char)pannings[i] < 128 && volumes[i] > 0)
++channels;
}
d->properties.setChannels(channels);
// real length might be shorter because of skips and terminator
unsigned short realLength = 0;
for(unsigned short i = 0; i < length; ++ i) {
for (unsigned short i = 0; i < length; ++i) {
READ_BYTE_AS(order);
if(order == 255) break;
if(order != 254) ++ realLength;
if (order == 255) break;
if (order != 254) ++realLength;
}
d->properties.setLengthInPatterns(realLength);
@@ -279,7 +264,7 @@ void IT::File::read(bool)
// Currently I just discard anything after a nil, but
// e.g. VLC seems to interpret a nil as a space. I
// don't know what is the proper behaviour.
for(unsigned short i = 0; i < instrumentCount; ++ i) {
for (unsigned short i = 0; i < instrumentCount; ++i) {
seek(192L + length + ((long)i << 2));
READ_U32L_AS(instrumentOffset);
seek(instrumentOffset);
@@ -295,7 +280,7 @@ void IT::File::read(bool)
comment.append(instrumentName);
}
for(unsigned short i = 0; i < sampleCount; ++ i) {
for (unsigned short i = 0; i < sampleCount; ++i) {
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2));
READ_U32L_AS(sampleOffset);
@@ -328,7 +313,7 @@ void IT::File::read(bool)
comment.append(sampleName);
}
if(message.size() > 0)
if (message.size() > 0)
comment.append(message);
d->tag.setComment(comment.toString("\n"));
d->tag.setTrackerName("Impulse Tracker");

View File

@@ -32,22 +32,22 @@
namespace Strawberry_TagLib {
namespace TagLib {
namespace IT {
namespace IT {
class TAGLIB_EXPORT File : public Mod::FileBase {
public:
/*!
class TAGLIB_EXPORT File : public Mod::FileBase {
public:
/*!
* Constructs a Impulse Tracker file from \a file.
*
* \note In the current implementation, both \a readProperties and
* \a propertiesStyle are ignored. The audio properties are always
* read.
*/
File(FileName file, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
File(FileName file, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*!
/*!
* Constructs a Impulse Tracker file from \a stream.
*
* \note In the current implementation, both \a readProperties and
@@ -57,55 +57,55 @@ namespace TagLib {
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*/
File(IOStream *stream, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
File(IOStream *stream, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*!
/*!
* Destroys this instance of the File.
*/
virtual ~File();
virtual ~File();
Mod::Tag *tag() const;
Mod::Tag *tag() const;
/*!
/*!
* Forwards to Mod::Tag::properties().
* BIC: will be removed once File::toDict() is made virtual
*/
PropertyMap properties() const;
PropertyMap properties() const;
/*!
/*!
* Forwards to Mod::Tag::setProperties().
* BIC: will be removed once File::setProperties() is made virtual
*/
PropertyMap setProperties(const PropertyMap &);
PropertyMap setProperties(const PropertyMap &);
/*!
/*!
* Returns the IT::Properties for this file. If no audio properties
* were read then this will return a null pointer.
*/
IT::Properties *audioProperties() const;
IT::Properties *audioProperties() const;
/*!
/*!
* Save the file.
* This is the same as calling save(AllTags);
*
* \note Saving Impulse Tracker tags is not supported.
*/
bool save();
bool save();
private:
File(const File &);
File &operator=(const File &);
private:
File(const File &);
File &operator=(const File &);
void read(bool readProperties);
void read(bool readProperties);
class FilePrivate;
FilePrivate *d;
};
}
}
}
class FilePrivate;
FilePrivate *d;
};
} // namespace IT
} // namespace TagLib
} // namespace Strawberry_TagLib
#endif

View File

@@ -29,29 +29,26 @@
using namespace Strawberry_TagLib::TagLib;
using namespace IT;
class IT::Properties::PropertiesPrivate
{
public:
PropertiesPrivate() :
channels(0),
lengthInPatterns(0),
instrumentCount(0),
sampleCount(0),
patternCount(0),
version(0),
compatibleVersion(0),
flags(0),
special(0),
globalVolume(0),
mixVolume(0),
tempo(0),
bpmSpeed(0),
panningSeparation(0),
pitchWheelDepth(0)
{
class IT::Properties::PropertiesPrivate {
public:
PropertiesPrivate() : channels(0),
lengthInPatterns(0),
instrumentCount(0),
sampleCount(0),
patternCount(0),
version(0),
compatibleVersion(0),
flags(0),
special(0),
globalVolume(0),
mixVolume(0),
tempo(0),
bpmSpeed(0),
panningSeparation(0),
pitchWheelDepth(0) {
}
int channels;
int channels;
unsigned short lengthInPatterns;
unsigned short instrumentCount;
unsigned short sampleCount;
@@ -60,201 +57,162 @@ public:
unsigned short compatibleVersion;
unsigned short flags;
unsigned short special;
unsigned char globalVolume;
unsigned char mixVolume;
unsigned char tempo;
unsigned char bpmSpeed;
unsigned char panningSeparation;
unsigned char pitchWheelDepth;
unsigned char globalVolume;
unsigned char mixVolume;
unsigned char tempo;
unsigned char bpmSpeed;
unsigned char panningSeparation;
unsigned char pitchWheelDepth;
};
IT::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) :
AudioProperties(propertiesStyle),
d(new PropertiesPrivate())
{
IT::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) : AudioProperties(propertiesStyle),
d(new PropertiesPrivate()) {
}
IT::Properties::~Properties()
{
IT::Properties::~Properties() {
delete d;
}
int IT::Properties::length() const
{
int IT::Properties::length() const {
return 0;
}
int IT::Properties::lengthInSeconds() const
{
int IT::Properties::lengthInSeconds() const {
return 0;
}
int IT::Properties::lengthInMilliseconds() const
{
int IT::Properties::lengthInMilliseconds() const {
return 0;
}
int IT::Properties::bitrate() const
{
int IT::Properties::bitrate() const {
return 0;
}
int IT::Properties::sampleRate() const
{
int IT::Properties::sampleRate() const {
return 0;
}
int IT::Properties::channels() const
{
int IT::Properties::channels() const {
return d->channels;
}
unsigned short IT::Properties::lengthInPatterns() const
{
unsigned short IT::Properties::lengthInPatterns() const {
return d->lengthInPatterns;
}
bool IT::Properties::stereo() const
{
bool IT::Properties::stereo() const {
return d->flags & Stereo;
}
unsigned short IT::Properties::instrumentCount() const
{
unsigned short IT::Properties::instrumentCount() const {
return d->instrumentCount;
}
unsigned short IT::Properties::sampleCount() const
{
unsigned short IT::Properties::sampleCount() const {
return d->sampleCount;
}
unsigned short IT::Properties::patternCount() const
{
unsigned short IT::Properties::patternCount() const {
return d->patternCount;
}
unsigned short IT::Properties::version() const
{
unsigned short IT::Properties::version() const {
return d->version;
}
unsigned short IT::Properties::compatibleVersion() const
{
unsigned short IT::Properties::compatibleVersion() const {
return d->compatibleVersion;
}
unsigned short IT::Properties::flags() const
{
unsigned short IT::Properties::flags() const {
return d->flags;
}
unsigned short IT::Properties::special() const
{
unsigned short IT::Properties::special() const {
return d->special;
}
unsigned char IT::Properties::globalVolume() const
{
unsigned char IT::Properties::globalVolume() const {
return d->globalVolume;
}
unsigned char IT::Properties::mixVolume() const
{
unsigned char IT::Properties::mixVolume() const {
return d->mixVolume;
}
unsigned char IT::Properties::tempo() const
{
unsigned char IT::Properties::tempo() const {
return d->tempo;
}
unsigned char IT::Properties::bpmSpeed() const
{
unsigned char IT::Properties::bpmSpeed() const {
return d->bpmSpeed;
}
unsigned char IT::Properties::panningSeparation() const
{
unsigned char IT::Properties::panningSeparation() const {
return d->panningSeparation;
}
unsigned char IT::Properties::pitchWheelDepth() const
{
unsigned char IT::Properties::pitchWheelDepth() const {
return d->pitchWheelDepth;
}
void IT::Properties::setChannels(int channels)
{
void IT::Properties::setChannels(int channels) {
d->channels = channels;
}
void IT::Properties::setLengthInPatterns(unsigned short lengthInPatterns)
{
void IT::Properties::setLengthInPatterns(unsigned short lengthInPatterns) {
d->lengthInPatterns = lengthInPatterns;
}
void IT::Properties::setInstrumentCount(unsigned short instrumentCount)
{
void IT::Properties::setInstrumentCount(unsigned short instrumentCount) {
d->instrumentCount = instrumentCount;
}
void IT::Properties::setSampleCount(unsigned short sampleCount)
{
void IT::Properties::setSampleCount(unsigned short sampleCount) {
d->sampleCount = sampleCount;
}
void IT::Properties::setPatternCount(unsigned short patternCount)
{
void IT::Properties::setPatternCount(unsigned short patternCount) {
d->patternCount = patternCount;
}
void IT::Properties::setFlags(unsigned short flags)
{
void IT::Properties::setFlags(unsigned short flags) {
d->flags = flags;
}
void IT::Properties::setSpecial(unsigned short special)
{
void IT::Properties::setSpecial(unsigned short special) {
d->special = special;
}
void IT::Properties::setCompatibleVersion(unsigned short compatibleVersion)
{
void IT::Properties::setCompatibleVersion(unsigned short compatibleVersion) {
d->compatibleVersion = compatibleVersion;
}
void IT::Properties::setVersion(unsigned short version)
{
void IT::Properties::setVersion(unsigned short version) {
d->version = version;
}
void IT::Properties::setGlobalVolume(unsigned char globalVolume)
{
void IT::Properties::setGlobalVolume(unsigned char globalVolume) {
d->globalVolume = globalVolume;
}
void IT::Properties::setMixVolume(unsigned char mixVolume)
{
void IT::Properties::setMixVolume(unsigned char mixVolume) {
d->mixVolume = mixVolume;
}
void IT::Properties::setTempo(unsigned char tempo)
{
void IT::Properties::setTempo(unsigned char tempo) {
d->tempo = tempo;
}
void IT::Properties::setBpmSpeed(unsigned char bpmSpeed)
{
void IT::Properties::setBpmSpeed(unsigned char bpmSpeed) {
d->bpmSpeed = bpmSpeed;
}
void IT::Properties::setPanningSeparation(unsigned char panningSeparation)
{
void IT::Properties::setPanningSeparation(unsigned char panningSeparation) {
d->panningSeparation = panningSeparation;
}
void IT::Properties::setPitchWheelDepth(unsigned char pitchWheelDepth)
{
void IT::Properties::setPitchWheelDepth(unsigned char pitchWheelDepth) {
d->pitchWheelDepth = pitchWheelDepth;
}

View File

@@ -31,79 +31,80 @@
namespace Strawberry_TagLib {
namespace TagLib {
namespace IT {
class TAGLIB_EXPORT Properties : public AudioProperties {
friend class File;
public:
/*! Flag bits. */
enum {
Stereo = 1,
Vol0MixOptimizations = 2,
UseInstruments = 4,
LinearSlides = 8,
OldEffects = 16,
LinkEffects = 32,
UseMidiPitchController = 64,
RequestEmbeddedMidiConf = 128
};
namespace IT {
class TAGLIB_EXPORT Properties : public AudioProperties {
friend class File;
/*! Special bits. */
enum {
MessageAttached = 1,
MidiConfEmbedded = 8
};
public:
/*! Flag bits. */
enum {
Stereo = 1,
Vol0MixOptimizations = 2,
UseInstruments = 4,
LinearSlides = 8,
OldEffects = 16,
LinkEffects = 32,
UseMidiPitchController = 64,
RequestEmbeddedMidiConf = 128
};
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
/*! Special bits. */
enum {
MessageAttached = 1,
MidiConfEmbedded = 8
};
int length() const;
int lengthInSeconds() const;
int lengthInMilliseconds() const;
int bitrate() const;
int sampleRate() const;
int channels() const;
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
unsigned short lengthInPatterns() const;
bool stereo() const;
unsigned short instrumentCount() const;
unsigned short sampleCount() const;
unsigned short patternCount() const;
unsigned short version() const;
unsigned short compatibleVersion() const;
unsigned short flags() const;
unsigned short special() const;
unsigned char globalVolume() const;
unsigned char mixVolume() const;
unsigned char tempo() const;
unsigned char bpmSpeed() const;
unsigned char panningSeparation() const;
unsigned char pitchWheelDepth() const;
int length() const;
int lengthInSeconds() const;
int lengthInMilliseconds() const;
int bitrate() const;
int sampleRate() const;
int channels() const;
void setChannels(int channels);
void setLengthInPatterns(unsigned short lengthInPatterns);
void setInstrumentCount(unsigned short instrumentCount);
void setSampleCount (unsigned short sampleCount);
void setPatternCount(unsigned short patternCount);
void setVersion (unsigned short version);
void setCompatibleVersion(unsigned short compatibleVersion);
void setFlags (unsigned short flags);
void setSpecial (unsigned short special);
void setGlobalVolume(unsigned char globalVolume);
void setMixVolume (unsigned char mixVolume);
void setTempo (unsigned char tempo);
void setBpmSpeed (unsigned char bpmSpeed);
void setPanningSeparation(unsigned char panningSeparation);
void setPitchWheelDepth (unsigned char pitchWheelDepth);
unsigned short lengthInPatterns() const;
bool stereo() const;
unsigned short instrumentCount() const;
unsigned short sampleCount() const;
unsigned short patternCount() const;
unsigned short version() const;
unsigned short compatibleVersion() const;
unsigned short flags() const;
unsigned short special() const;
unsigned char globalVolume() const;
unsigned char mixVolume() const;
unsigned char tempo() const;
unsigned char bpmSpeed() const;
unsigned char panningSeparation() const;
unsigned char pitchWheelDepth() const;
private:
Properties(const Properties&);
Properties &operator=(const Properties&);
void setChannels(int channels);
void setLengthInPatterns(unsigned short lengthInPatterns);
void setInstrumentCount(unsigned short instrumentCount);
void setSampleCount(unsigned short sampleCount);
void setPatternCount(unsigned short patternCount);
void setVersion(unsigned short version);
void setCompatibleVersion(unsigned short compatibleVersion);
void setFlags(unsigned short flags);
void setSpecial(unsigned short special);
void setGlobalVolume(unsigned char globalVolume);
void setMixVolume(unsigned char mixVolume);
void setTempo(unsigned char tempo);
void setBpmSpeed(unsigned char bpmSpeed);
void setPanningSeparation(unsigned char panningSeparation);
void setPitchWheelDepth(unsigned char pitchWheelDepth);
class PropertiesPrivate;
PropertiesPrivate *d;
};
}
}
}
private:
Properties(const Properties &);
Properties &operator=(const Properties &);
class PropertiesPrivate;
PropertiesPrivate *d;
};
} // namespace IT
} // namespace TagLib
} // namespace Strawberry_TagLib
#endif