From: Mathias Panzenböck Date: Sun, 19 Jun 2011 03:42:16 +0000 (+0200) Subject: untested(!) comment write support for s3m and it files X-Git-Tag: v1.8beta~91 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e09c2c5a19ae3a45eca5891cdf55c4350cc02300;p=taglib untested(!) comment write support for s3m and it files --- diff --git a/taglib/it/itfile.cpp b/taglib/it/itfile.cpp index e3d880be..f810ee1d 100644 --- a/taglib/it/itfile.cpp +++ b/taglib/it/itfile.cpp @@ -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)); diff --git a/taglib/s3m/s3mfile.cpp b/taglib/s3m/s3mfile.cpp index 2b13d6e3..d48911d7 100644 --- a/taglib/s3m/s3mfile.cpp +++ b/taglib/s3m/s3mfile.cpp @@ -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);