IT: strings require term. NUL. mod files: tableLength -> lengthInPatterns

Also added enums for S3M/IT/XM flags.
This commit is contained in:
Mathias Panzenböck 2011-06-24 01:11:10 +02:00
parent e71806b6df
commit 9c27c45eb8
15 changed files with 116 additions and 85 deletions

View File

@ -78,7 +78,8 @@ bool IT::File::save()
return false;
}
seek(4);
writeString(d->tag.title(), 26);
writeString(d->tag.title(), 25);
writeByte(0);
seek(2, Current);
@ -103,9 +104,10 @@ bool IT::File::save()
seek(instrumentOffset + 32);
if(i < lines.size())
writeString(lines[i], 26);
writeString(lines[i], 25);
else
writeString(String::null, 26);
writeString(String::null, 25);
writeByte(0);
}
for(ushort i = 0; i < sampleCount; ++ i)
@ -118,9 +120,10 @@ bool IT::File::save()
seek(sampleOffset + 20);
if((i + instrumentCount) < lines.size())
writeString(lines[i + instrumentCount], 26);
writeString(lines[i + instrumentCount], 25);
else
writeString(String::null, 26);
writeString(String::null, 25);
writeByte(0);
}
// write rest as message:
@ -128,6 +131,9 @@ bool IT::File::save()
for(uint i = instrumentCount + sampleCount; i < lines.size(); ++ i)
messageLines.append(lines[i]);
ByteVector message = messageLines.toString("\r").data(String::Latin1);
if(message.size() > 8000)
message.resize(8000);
ushort special = 0;
ushort messageLength = 0;
ulong messageOffset = 0;
@ -249,7 +255,7 @@ void IT::File::read(bool)
if(order == 255) break;
if(order != 254) ++ realLength;
}
d->properties.setTableLength(realLength);
d->properties.setLengthInPatterns(realLength);
StringList comment;
// Note: I found files that have nil characters somewhere
@ -290,6 +296,7 @@ void IT::File::read(bool)
READ_BYTE_AS(sampleFlags);
READ_BYTE_AS(sampleVolume);
READ_STRING_AS(sampleName, 26);
/*
READ_BYTE_AS(sampleCvt);
READ_BYTE_AS(samplePanning);
READ_U32L_AS(sampleLength);
@ -303,15 +310,13 @@ void IT::File::read(bool)
READ_BYTE_AS(vibratoDepth);
READ_BYTE_AS(vibratoRate);
READ_BYTE_AS(vibratoType);
*/
comment.append(sampleName);
}
if(comment.size() > 0 && message.size() > 0)
d->tag.setComment(comment.toString("\n") + "\n" + message);
else if(comment.size() > 0)
d->tag.setComment(comment.toString("\n"));
else
d->tag.setComment(message);
if(message.size() > 0)
comment.append(message);
d->tag.setComment(comment.toString("\n"));
d->tag.setTrackerName("Impulse Tracker");
}

View File

@ -29,8 +29,7 @@ class IT::Properties::PropertiesPrivate
public:
PropertiesPrivate() :
channels(0),
tableLength(0),
stereo(false),
lengthInPatterns(0),
instrumentCount(0),
sampleCount(0),
patternCount(0),
@ -48,8 +47,7 @@ public:
}
int channels;
ushort tableLength;
bool stereo;
ushort lengthInPatterns;
ushort instrumentCount;
ushort sampleCount;
ushort patternCount;
@ -96,14 +94,14 @@ int IT::Properties::channels() const
return d->channels;
}
ushort IT::Properties::tableLength() const
ushort IT::Properties::lengthInPatterns() const
{
return d->tableLength;
return d->lengthInPatterns;
}
bool IT::Properties::stereo() const
{
return d->stereo;
return d->flags & F_STEREO;
}
ushort IT::Properties::instrumentCount() const
@ -176,14 +174,9 @@ void IT::Properties::setChannels(int channels)
d->channels = channels;
}
void IT::Properties::setTableLength(ushort tableLength)
void IT::Properties::setLengthInPatterns(ushort lengthInPatterns)
{
d->tableLength = tableLength;
}
void IT::Properties::setStereo(bool stereo)
{
d->stereo = stereo;
d->lengthInPatterns = lengthInPatterns;
}
void IT::Properties::setInstrumentCount(ushort instrumentCount) {

View File

@ -30,6 +30,24 @@ namespace TagLib {
class TAGLIB_EXPORT Properties : public AudioProperties {
friend class File;
public:
/*! Flag bits. */
enum {
F_STEREO = 1,
F_VOL0_MIX_OPT = 2,
F_INSTRUMENTS = 4,
F_LINEAR_SLIDES = 8,
F_OLD_EFFECTS = 16,
F_LINK_EFFECT = 32,
F_MIDI_PITCH_CTRL = 64,
F_EMBEDDED_MIDI_CONF = 128
};
/*! Special bits. */
enum {
S_MESSAGE = 1,
S_EMBEDDED_MIDI_CONF = 8
};
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
@ -38,7 +56,7 @@ namespace TagLib {
int sampleRate() const;
int channels() const;
ushort tableLength() const;
ushort lengthInPatterns() const;
bool stereo() const;
ushort instrumentCount() const;
ushort sampleCount() const;
@ -57,8 +75,7 @@ namespace TagLib {
protected:
void setChannels(int channels);
void setTableLength(ushort tableLength);
void setStereo(bool stereo);
void setLengthInPatterns(ushort lengthInPatterns);
void setInstrumentCount(ushort instrumentCount);
void setSampleCount (ushort sampleCount);
void setPatternCount(ushort patternCount);

View File

@ -178,7 +178,7 @@ void Mod::File::read(bool)
comment.append(instrumentName);
}
READ_BYTE(d->properties.setTableLength);
READ_BYTE(d->properties.setLengthInPatterns);
d->tag.setComment(comment.toString("\n"));
}

View File

@ -30,13 +30,13 @@ public:
PropertiesPrivate() :
channels(0),
instrumentCount(0),
tableLength(0)
lengthInPatterns(0)
{
}
int channels;
uint instrumentCount;
uchar tableLength;
uchar lengthInPatterns;
};
Mod::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) :
@ -75,9 +75,9 @@ uint Mod::Properties::instrumentCount() const
return d->instrumentCount;
}
uchar Mod::Properties::tableLength() const
uchar Mod::Properties::lengthInPatterns() const
{
return d->tableLength;
return d->lengthInPatterns;
}
void Mod::Properties::setChannels(int channels)
@ -90,7 +90,7 @@ void Mod::Properties::setInstrumentCount(uint instrumentCount)
d->instrumentCount = instrumentCount;
}
void Mod::Properties::setTableLength(uchar tableLength)
void Mod::Properties::setLengthInPatterns(uchar lengthInPatterns)
{
d->tableLength = tableLength;
d->lengthInPatterns = lengthInPatterns;
}

View File

@ -38,14 +38,14 @@ namespace TagLib {
int sampleRate() const;
int channels() const;
uint instrumentCount() const;
uchar tableLength() const;
uint instrumentCount() const;
uchar lengthInPatterns() const;
protected:
void setChannels(int channels);
void setInstrumentCount(uint sampleCount);
void setTableLength(uchar tableLength);
void setLengthInPatterns(uchar lengthInPatterns);
private:
Properties(const Properties&);

View File

@ -191,7 +191,7 @@ void S3M::File::read(bool)
if(order == 255) break;
if(order != 254) ++ realLength;
}
d->properties.setTableLength(realLength);
d->properties.setLengthInPatterns(realLength);
seek(channels, Current);

View File

@ -28,7 +28,7 @@ class S3M::Properties::PropertiesPrivate
{
public:
PropertiesPrivate() :
tableLength(0),
lengthInPatterns(0),
channels(0),
stereo(false),
sampleCount(0),
@ -43,7 +43,7 @@ public:
{
}
ushort tableLength;
ushort lengthInPatterns;
int channels;
bool stereo;
ushort sampleCount;
@ -88,9 +88,9 @@ int S3M::Properties::channels() const
return d->channels;
}
ushort S3M::Properties::tableLength() const
ushort S3M::Properties::lengthInPatterns() const
{
return d->tableLength;
return d->lengthInPatterns;
}
bool S3M::Properties::stereo() const
@ -143,9 +143,9 @@ uchar S3M::Properties::bpmSpeed() const
return d->bpmSpeed;
}
void S3M::Properties::setTableLength(ushort tableLength)
void S3M::Properties::setLengthInPatterns(ushort lengthInPatterns)
{
d->tableLength = tableLength;
d->lengthInPatterns = lengthInPatterns;
}
void S3M::Properties::setChannels(int channels)

View File

@ -30,6 +30,17 @@ namespace TagLib {
class TAGLIB_EXPORT Properties : public AudioProperties {
friend class File;
public:
/*! Flag bits. */
enum {
F_ST2_VIBRATO = 1,
F_ST2_TEMPO = 2,
F_AMIGA_SLIDES = 4,
F_VOL0_MIX_OPT = 8,
F_AMIGA_LIMITS = 16,
F_ENABLE_FILTER = 32,
F_CUSTOM_DATA = 128
};
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
@ -38,7 +49,7 @@ namespace TagLib {
int sampleRate() const;
int channels() const;
ushort tableLength() const;
ushort lengthInPatterns() const;
bool stereo() const;
ushort sampleCount() const;
ushort patternCount() const;
@ -51,9 +62,9 @@ namespace TagLib {
uchar bpmSpeed() const;
protected:
void setTableLength(ushort tableLength);
void setChannels(int channels);
void setLengthInPatterns (ushort lengthInPatterns);
void setStereo (bool stereo);
void setSampleCount (ushort sampleCount);
void setPatternCount (ushort patternCount);

View File

@ -465,10 +465,10 @@ bool XM::File::save()
{
if(sampleHeaderSize > 4U)
{
ulong length = 0;
if(!readU32L(length))
ulong sampleLength = 0;
if(!readU32L(sampleLength))
return false;
offset += length;
offset += sampleLength;
seek(std::min(sampleHeaderSize, 14UL), Current);
if(sampleHeaderSize > 18U)
@ -523,7 +523,7 @@ void XM::File::read(bool)
READ_U32L_AS(headerSize);
READ_ASSERT(headerSize >= 4);
ushort tableLength = 0;
ushort length = 0;
ushort restartPosition = 0;
ushort channels = 0;
ushort patternCount = 0;
@ -533,7 +533,7 @@ void XM::File::read(bool)
ushort bpmSpeed = 0;
StructReader header;
header.u16L(tableLength)
header.u16L(length)
.u16L(restartPosition)
.u16L(channels)
.u16L(patternCount)
@ -547,7 +547,7 @@ void XM::File::read(bool)
READ_ASSERT(count == size);
d->properties.setTableLength(tableLength);
d->properties.setLengthInPatterns(length);
d->properties.setRestartPosition(restartPosition);
d->properties.setChannels(channels);
d->properties.setPatternCount(patternCount);
@ -609,18 +609,18 @@ void XM::File::read(bool)
for(ushort j = 0; j < sampleCount; ++ j)
{
ulong length = 0;
ulong loopStart = 0;
ulong loopLength = 0;
uchar volume = 0;
uchar finetune = 0;
uchar sampleType = 0;
uchar panning = 0;
uchar noteNumber = 0;
uchar compression = 0;
ulong sampleLength = 0;
ulong loopStart = 0;
ulong loopLength = 0;
uchar volume = 0;
uchar finetune = 0;
uchar sampleType = 0;
uchar panning = 0;
uchar noteNumber = 0;
uchar compression = 0;
String sampleName;
StructReader sample;
sample.u32L(length)
sample.u32L(sampleLength)
.u32L(loopStart)
.u32L(loopLength)
.byte(volume)
@ -636,7 +636,7 @@ void XM::File::read(bool)
// skip unhandeled header proportion:
seek(sampleHeaderSize - count, Current);
offset += length;
offset += sampleLength;
sampleNames.append(sampleName);
}
}

View File

@ -28,7 +28,7 @@ class XM::Properties::PropertiesPrivate
{
public:
PropertiesPrivate() :
tableLength(0),
lengthInPatterns(0),
channels(0),
version(0),
restartPosition(0),
@ -41,7 +41,7 @@ public:
{
}
ushort tableLength;
ushort lengthInPatterns;
int channels;
ushort version;
ushort restartPosition;
@ -84,9 +84,9 @@ int XM::Properties::channels() const
return d->channels;
}
ushort XM::Properties::tableLength() const
ushort XM::Properties::lengthInPatterns() const
{
return d->tableLength;
return d->lengthInPatterns;
}
ushort XM::Properties::version() const
@ -129,9 +129,9 @@ ushort XM::Properties::bpmSpeed() const
return d->bpmSpeed;
}
void XM::Properties::setTableLength(ushort tableLength)
void XM::Properties::setLengthInPatterns(ushort lengthInPatterns)
{
d->tableLength = tableLength;
d->lengthInPatterns = lengthInPatterns;
}
void XM::Properties::setChannels(int channels)

View File

@ -31,6 +31,11 @@ namespace TagLib {
class Properties : public AudioProperties {
friend class File;
public:
/*! Flag bits. */
enum {
F_AMIGA_FREQ = 1
};
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
@ -39,20 +44,20 @@ namespace TagLib {
int sampleRate() const;
int channels() const;
ushort tableLength() const;
ushort version() const;
ushort restartPosition() const;
ushort patternCount() const;
ushort instrumentCount() const;
uint sampleCount() const;
ushort flags() const;
ushort tempo() const;
ushort bpmSpeed() const;
ushort lengthInPatterns() const;
ushort version() const;
ushort restartPosition() const;
ushort patternCount() const;
ushort instrumentCount() const;
uint sampleCount() const;
ushort flags() const;
ushort tempo() const;
ushort bpmSpeed() const;
protected:
void setChannels(int channels);
void setTableLength(ushort tableLength);
void setLengthInPatterns(ushort lengthInPatterns);
void setVersion(ushort version);
void setRestartPosition(ushort restartPosition);
void setPatternCount(ushort patternCount);

View File

@ -93,7 +93,7 @@ private:
CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
CPPUNIT_ASSERT_EQUAL(8, p->channels());
CPPUNIT_ASSERT_EQUAL(31U, p->instrumentCount());
CPPUNIT_ASSERT_EQUAL((uchar)1, p->tableLength());
CPPUNIT_ASSERT_EQUAL((uchar)1, p->lengthInPatterns());
CPPUNIT_ASSERT_EQUAL(title, t->title());
CPPUNIT_ASSERT_EQUAL(String::null, t->artist());
CPPUNIT_ASSERT_EQUAL(String::null, t->album());

View File

@ -98,7 +98,7 @@ private:
CPPUNIT_ASSERT_EQUAL( 0, p->bitrate());
CPPUNIT_ASSERT_EQUAL( 0, p->sampleRate());
CPPUNIT_ASSERT_EQUAL(16, p->channels());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0, p->tableLength());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0, p->lengthInPatterns());
CPPUNIT_ASSERT_EQUAL(false, p->stereo());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 5, p->sampleCount());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->patternCount());

View File

@ -130,7 +130,7 @@ public:
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
CPPUNIT_ASSERT_EQUAL(8, p->channels());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->tableLength());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->lengthInPatterns());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0, p->version());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0 , p->restartPosition());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->patternCount());
@ -176,7 +176,7 @@ private:
CPPUNIT_ASSERT_EQUAL(0, p->bitrate());
CPPUNIT_ASSERT_EQUAL(0, p->sampleRate());
CPPUNIT_ASSERT_EQUAL(8, p->channels());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->tableLength());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->lengthInPatterns());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort)260, p->version());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 0, p->restartPosition());
CPPUNIT_ASSERT_EQUAL((TagLib::ushort) 1, p->patternCount());