// write comment as instrument and sample names:
StringList lines = d->tag.comment().split("\n");
- for(ushort i = 0; i < instrumentCount; ++ i)
- {
+ for(ushort i = 0; i < instrumentCount; ++ i) {
seek(192L + length + ((long)i << 2));
ulong instrumentOffset = 0;
if(!readU32L(instrumentOffset))
writeByte(0);
}
- for(ushort i = 0; i < sampleCount; ++ i)
- {
+ for(ushort i = 0; i < sampleCount; ++ i) {
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2));
ulong sampleOffset = 0;
if(!readU32L(sampleOffset))
return false;
long fileSize = this->length();
- if(special & 0x1)
- {
+ if(special & Properties::S_MESSAGE) {
seek(54);
if(!readU16L(messageLength) || !readU32L(messageOffset))
return false;
writeU16L(special | 0x1);
}
- if((messageOffset + messageLength) >= fileSize)
- {
+ if((messageOffset + messageLength) >= fileSize) {
// append new message
seek(54);
writeU16L(message.size());
writeBlock(message);
truncate(messageOffset + message.size());
}
- else
- {
+ else {
// Only overwrite existing message.
// I'd need to parse (understand!) the whole file for more.
// Although I could just move the message to the end of file
// sample/instrument names are abused as comments so
// I just add all together.
String message;
- if(special & 0x1)
- {
+ if(special & Properties::S_MESSAGE) {
READ_U16L_AS(messageLength);
READ_U32L_AS(messageOffset);
seek(messageOffset);
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.
// real length might be shorter because of skips and terminator
ushort realLength = 0;
- for(ushort i = 0; i < length; ++ i)
- {
+ for(ushort i = 0; i < length; ++ i) {
READ_BYTE_AS(order);
if(order == 255) break;
if(order != 254) ++ realLength;
// Currently I just discard anything after a nil, but
// e.g. VLC seems to interprete a nil as a space. I
// don't know what is the proper behaviour.
- for(ushort i = 0; i < instrumentCount; ++ i)
- {
+ for(ushort i = 0; i < instrumentCount; ++ i) {
seek(192L + length + ((long)i << 2));
READ_U32L_AS(instrumentOffset);
seek(instrumentOffset);
comment.append(instrumentName);
}
- for(ushort i = 0; i < sampleCount; ++ i)
- {
+ for(ushort i = 0; i < sampleCount; ++ i) {
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2));
READ_U32L_AS(sampleOffset);
d->lengthInPatterns = lengthInPatterns;
}
-void IT::Properties::setInstrumentCount(ushort instrumentCount) {
+void IT::Properties::setInstrumentCount(ushort instrumentCount)
+{
d->instrumentCount = instrumentCount;
}
bool Mod::File::save()
{
- if(readOnly())
- {
+ if(readOnly()) {
debug("Mod::File::save() - Cannot save to a read only file.");
return false;
}
writeString(d->tag.title(), 20);
StringList lines = d->tag.comment().split("\n");
uint n = std::min(lines.size(), d->properties.instrumentCount());
- for(uint i = 0; i < n; ++ i)
- {
+ for(uint i = 0; i < n; ++ i) {
writeString(lines[i], 22);
seek(8, Current);
}
- for(uint i = n; i < d->properties.instrumentCount(); ++ i)
- {
+ for(uint i = n; i < d->properties.instrumentCount(); ++ i) {
writeString(String::null, 22);
seek(8, Current);
}
int channels = 4;
uint instruments = 31;
- if(modId == "M.K." || modId == "M!K!" || modId == "M&K!" || modId == "N.T.")
- {
+ if(modId == "M.K." || modId == "M!K!" || modId == "M&K!" || modId == "N.T.") {
d->tag.setTrackerName("ProTracker");
channels = 4;
}
- else if(modId.startsWith("FLT") || modId.startsWith("TDZ"))
- {
+ else if(modId.startsWith("FLT") || modId.startsWith("TDZ")) {
d->tag.setTrackerName("StarTrekker");
char digit = modId[3];
READ_ASSERT(digit >= '0' && digit <= '9');
channels = digit - '0';
}
- else if(modId.endsWith("CHN"))
- {
+ else if(modId.endsWith("CHN")) {
d->tag.setTrackerName("StarTrekker");
char digit = modId[0];
READ_ASSERT(digit >= '0' && digit <= '9');
channels = digit - '0';
}
- else if(modId == "CD81" || modId == "OKTA")
- {
+ else if(modId == "CD81" || modId == "OKTA") {
d->tag.setTrackerName("Atari Oktalyzer");
channels = 8;
}
- else if(modId.endsWith("CH") || modId.endsWith("CN"))
- {
+ else if(modId.endsWith("CH") || modId.endsWith("CN")) {
d->tag.setTrackerName("TakeTracker");
char digit = modId[0];
READ_ASSERT(digit >= '0' && digit <= '9');
READ_ASSERT(digit >= '0' && digit <= '9');
channels += digit - '0';
}
- else
- {
+ else {
// Not sure if this is correct. I'd need a file
// created with NoiseTracker to check this.
d->tag.setTrackerName("NoiseTracker"); // probably
READ_STRING(d->tag.setTitle, 20);
StringList comment;
- for(uint i = 0; i < instruments; ++ i)
- {
+ for(uint i = 0; i < instruments; ++ i) {
READ_STRING_AS(instrumentName, 22);
// value in words, * 2 (<< 1) for bytes:
READ_U16B_AS(sampleLength);
class Mod::Tag::TagPrivate
{
public:
- TagPrivate() {}
+ TagPrivate()
+ {
+ }
String title;
String comment;
bool S3M::File::save()
{
- if(readOnly())
- {
+ if(readOnly()) {
debug("S3M::File::save() - Cannot save to a read only file.");
return false;
}
seek(28, Current);
int channels = 0;
- for(int i = 0; i < 32; ++ i)
- {
+ for(int i = 0; i < 32; ++ i) {
uchar setting = 0;
if(!readByte(setting))
return false;
StringList lines = d->tag.comment().split("\n");
// write comment as sample names:
- for(ushort i = 0; i < sampleCount; ++ i)
- {
+ for(ushort i = 0; i < sampleCount; ++ i) {
seek(96L + length + ((long)i << 1));
ushort instrumentOffset = 0;
seek(12, Current);
int channels = 0;
- for(int i = 0; i < 32; ++ i)
- {
+ for(int i = 0; i < 32; ++ i) {
READ_BYTE_AS(setting);
// or if(setting >= 128)?
// or channels = i + 1;?
seek(96);
ushort realLength = 0;
- for(ushort i = 0; i < length; ++ i)
- {
+ for(ushort i = 0; i < length; ++ i) {
READ_BYTE_AS(order);
if(order == 255) break;
if(order != 254) ++ realLength;
// However, there I never found instruments (SCRI) but
// instead samples (SCRS).
StringList comment;
- for(ushort i = 0; i < sampleCount; ++ i)
- {
+ for(ushort i = 0; i < sampleCount; ++ i) {
seek(96L + length + ((long)i << 1));
READ_U16L_AS(sampleHeaderOffset);
*
* Using these classes this code:
*
- * if(headerSize >= 4)
- * {
+ * if(headerSize >= 4) {
* if(!readU16L(value1)) ERROR();
- * if(headerSize >= 8)
- * {
+ * if(headerSize >= 8) {
* if(!readU16L(value2)) ERROR();
- * if(headerSize >= 12)
- * {
+ * if(headerSize >= 12) {
* if(!readString(value3, 22)) ERROR();
* ...
* }
ByteVector data = file.readBlock(std::min(m_size,limit));
uint count = data.size();
int index = data.find((char) 0);
- if(index > -1)
- {
+ if(index > -1) {
data.resize(index);
}
data.replace((char) 0xff, ' ');
uint read(TagLib::File &file, uint limit)
{
ByteVector data = file.readBlock(std::min(1U,limit));
- if(data.size() > 0)
- {
+ if(data.size() > 0) {
value = data[0];
}
return data.size();
uint size() const
{
uint size = 0;
- for(List<Reader*>::ConstIterator i = m_readers.begin(); i != m_readers.end(); ++ i)
- {
+ for(List<Reader*>::ConstIterator i = m_readers.begin();
+ i != m_readers.end(); ++ i) {
size += (*i)->size();
}
return size;
uint read(TagLib::File &file, uint limit)
{
uint sumcount = 0;
- for(List<Reader*>::Iterator i = m_readers.begin(); limit > 0 && i != m_readers.end(); ++ i)
- {
+ for(List<Reader*>::Iterator i = m_readers.begin();
+ limit > 0 && i != m_readers.end(); ++ i) {
uint count = (*i)->read(file, limit);
limit -= count;
sumcount += count;
bool XM::File::save()
{
- if(readOnly())
- {
+ if(readOnly()) {
debug("XM::File::save() - Cannot save to a read only file.");
return false;
}
seek(60 + headerSize);
// need to read patterns again in order to seek to the instruments:
- for(ushort i = 0; i < patternCount; ++ i)
- {
+ for(ushort i = 0; i < patternCount; ++ i) {
ulong patternHeaderLength = 0;
if(!readU32L(patternHeaderLength) || patternHeaderLength < 4)
return false;
StringList lines = d->tag.comment().split("\n");
uint sampleNameIndex = instrumentCount;
- for(ushort i = 0; i < instrumentCount; ++ i)
- {
+ for(ushort i = 0; i < instrumentCount; ++ i) {
ulong instrumentHeaderSize = 0;
if(!readU32L(instrumentHeaderSize) || instrumentHeaderSize < 4)
return false;
writeString(lines[i], len);
long offset = 0;
- if(instrumentHeaderSize >= 29U)
- {
+ if(instrumentHeaderSize >= 29U) {
ushort sampleCount = 0;
seek(1, Current);
if(!readU16L(sampleCount))
return false;
- if(sampleCount > 0)
- {
+ if(sampleCount > 0) {
ulong sampleHeaderSize = 0;
if(instrumentHeaderSize < 33U || !readU32L(sampleHeaderSize))
return false;
// skip unhandeled header proportion:
seek(instrumentHeaderSize - 33, Current);
- for(ushort j = 0; j < sampleCount; ++ j)
- {
- if(sampleHeaderSize > 4U)
- {
+ for(ushort j = 0; j < sampleCount; ++ j) {
+ if(sampleHeaderSize > 4U) {
ulong sampleLength = 0;
if(!readU32L(sampleLength))
return false;
offset += sampleLength;
seek(std::min(sampleHeaderSize, 14UL), Current);
- if(sampleHeaderSize > 18U)
- {
+ if(sampleHeaderSize > 18U) {
uint len = std::min(sampleHeaderSize - 18U, 22UL);
if(sampleNameIndex >= lines.size())
writeString(String::null, len);
seek(sampleHeaderSize - (18U + len), Current);
}
}
- else
- {
+ else {
seek(sampleHeaderSize, Current);
}
}
}
- else
- {
+ else {
offset = instrumentHeaderSize - 29;
}
}
- else
- {
+ else {
offset = instrumentHeaderSize - (4 + len);
}
seek(offset, Current);
seek(60 + headerSize);
// read patterns:
- for(ushort i = 0; i < patternCount; ++ i)
- {
+ for(ushort i = 0; i < patternCount; ++ i) {
READ_U32L_AS(patternHeaderLength);
READ_ASSERT(patternHeaderLength >= 4);
uint sumSampleCount = 0;
// read instruments:
- for(ushort i = 0; i < instrumentCount; ++ i)
- {
+ for(ushort i = 0; i < instrumentCount; ++ i) {
READ_U32L_AS(instrumentHeaderSize);
READ_ASSERT(instrumentHeaderSize >= 4);
ulong sampleHeaderSize = 0;
long offset = 0;
- if(sampleCount > 0)
- {
+ if(sampleCount > 0) {
sumSampleCount += sampleCount;
// wouldn't know which header size to assume otherwise:
READ_ASSERT(instrumentHeaderSize >= count + 4 && readU32L(sampleHeaderSize));
// skip unhandeled header proportion:
seek(instrumentHeaderSize - count - 4, Current);
- for(ushort j = 0; j < sampleCount; ++ j)
- {
+ for(ushort j = 0; j < sampleCount; ++ j) {
ulong sampleLength = 0;
ulong loopStart = 0;
ulong loopLength = 0;
sampleNames.append(sampleName);
}
}
- else
- {
+ else {
offset = instrumentHeaderSize - count;
}
intrumentNames.append(instrumentName);
d->properties.setSampleCount(sumSampleCount);
String comment(intrumentNames.toString("\n"));
- if(sampleNames.size() > 0)
- {
+ if(sampleNames.size() > 0) {
comment += "\n";
comment += sampleNames.toString("\n");
}