Code (Text): for (I = 0; I < ninst; I++) { int nsamps; QStringList sn; if (readlelong(f) != 0x107) return QString("instrument header length for instrument %1 not 0x107 - probably nonstandard XM file").arg(I, 0, 16); instrNames.append(readFLString(f, 22)); if (readbyte(f) != 0) return QString("instrument type for instrument %1 not 0 - probably nonstandard XM file").arg(I, 0, 16); nsamps = readleword(f); sn.clear(); if (readlelong(f) != 0x28) return QString("sample header size for instrument %1 not 0x28 - probably nonstandard XM file").arg(I, 0, 16); skipnbytes(f, 96+48+48+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2); // skip instrument settings for (int j = 0; j < nsamps; j++) { quint32 samplen; samplen = readlelong(f); skipnbytes(f, 4+4+1+1+1+1+1+1); // skip other sample settings sn.append(readFLString(f, 22)); skipnbytes(f, samplen); } sampleNames.push_back(sn); } If f is pointed to where the XM instruments start, the code doesn't get the instrument information correctly; right at the samplen=readlelong(f) it appears to be 20 (decimal) bytes before where it should be. What am I doing wrong? Thanks.
Ok, I found two things I was doing wrong and I changed some lines to Code (Text): if (nsamps > 0) { if (readlelong(f) != 0x28) return QString("sample header size for instrument %1 not 0x28 - probably nonstandard XM file").arg(I, 0, 16); skipnbytes(f, 96+48+48+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+22); // skip instrument settings } However, now I'm winding up with the last instrument before an empty one leaving the file pointer 145 bytes before where it should be; namely, this file on the first instrument without any samples. What am I doing wrong now?
Bah, figured it out: MilkyTracker is dumb and writes a header size of 0x1D instead of 0x107 for instruments that have no samples. Thanks anyway.
Yes this is for importing; in fact I can release a build with importing in it as soon as I squash one last bug.