}
seek(4);
writeString(d->tag.title(), 26);
- // TODO: write comment as instrument and sample names
+
+ seek(2, Current);
+
+ ushort length = 0;
+ ushort instrumentCount = 0;
+ ushort sampleCount = 0;
+
+ 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(ushort i = 0; i < instrumentCount; ++ i)
+ {
+ seek(192L + length + ((long)i << 2));
+ ulong instrumentOffset = 0;
+ if(!readU32L(instrumentOffset))
+ return false;
+
+ seek(instrumentOffset + 32);
+
+ if(i < lines.size())
+ writeString(lines[i], 26);
+ else
+ writeString(String::null, 26);
+ }
+
+ for(ushort i = 0; i < sampleCount; ++ i)
+ {
+ seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2));
+ ulong sampleOffset = 0;
+ if(!readU32L(sampleOffset))
+ return false;
+
+ seek(sampleOffset + 20);
+
+ if((i + instrumentCount) < lines.size())
+ writeString(lines[i + instrumentCount], 26);
+ else
+ writeString(String::null, 26);
+ }
+
return true;
}
READ_STRING_AS(instrumentName, 26);
comment.append(instrumentName);
}
-
+
for(ushort i = 0; i < sampleCount; ++ i)
{
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2));
// the file would look like an .xm file
seek(0);
writeString(d->tag.title(), 28);
- // TODO: write comment as sample names
+
+ seek(32);
+
+ ushort length = 0;
+ ushort sampleCount = 0;
+
+ if(!readU16L(length) || !readU16L(sampleCount))
+ return false;
+
+ seek(28, Current);
+
+ int channels = 0;
+ for(int i = 0; i < 32; ++ i)
+ {
+ uchar setting = 0;
+ if(!readByte(setting))
+ return false;
+ // or if(setting >= 128)?
+ // or channels = i + 1;?
+ // need a better spec!
+ if(setting != 0xff) ++ channels;
+ }
+
+ seek(channels, Current);
+
+ StringList lines = d->tag.comment().split("\n");
+ // write comment as sample names:
+ for(ushort i = 0; i < sampleCount; ++ i)
+ {
+ seek(96L + length + ((long)i << 1));
+
+ ushort instrumentOffset = 0;
+ if(!readU16L(instrumentOffset))
+ return false;
+ seek(((long)instrumentOffset << 4) + 48);
+
+ if(i < lines.size())
+ writeString(lines[i], 28);
+ else
+ writeString(String::null, 28);
+ }
return true;
}
int channels = 0;
for(int i = 0; i < 32; ++ i)
{
- READ_BYTE_AS(terminator);
- if(terminator != 0xff) ++ channels;
+ READ_BYTE_AS(setting);
+ // or if(setting >= 128)?
+ // or channels = i + 1;?
+ // need a better spec!
+ if(setting != 0xff) ++ channels;
}
d->properties.setChannels(channels);