untested(!) comment write support for s3m and it files

This commit is contained in:
Mathias Panzenböck 2011-06-19 05:42:16 +02:00
parent 6afb7c04b3
commit e09c2c5a19
2 changed files with 91 additions and 5 deletions

View File

@ -79,7 +79,50 @@ bool IT::File::save()
}
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;
}
@ -135,7 +178,7 @@ void IT::File::read(bool)
READ_STRING_AS(instrumentName, 26);
comment.append(instrumentName);
}
for(ushort i = 0; i < sampleCount; ++ i)
{
seek(192L + length + ((long)instrumentCount << 2) + ((long)i << 2));

View File

@ -81,7 +81,47 @@ bool S3M::File::save()
// 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;
}
@ -129,8 +169,11 @@ void S3M::File::read(bool)
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);