# HG changeset patch # User Matti Hamalainen # Date 1425542222 -7200 # Node ID afdbf62ce8ad50106f9de754287abe0881eff906 # Parent 165c673ee0124bc69b8c492e2748002460efa4e9 Revamp instrument sample loading somewhat. diff -r 165c673ee012 -r afdbf62ce8ad minijss/jloadxm.c --- a/minijss/jloadxm.c Thu Mar 05 09:32:58 2015 +0200 +++ b/minijss/jloadxm.c Thu Mar 05 09:57:02 2015 +0200 @@ -31,7 +31,7 @@ char songName[20]; // Module song name Uint8 unUsed1A; // ALWAYS 0x1a char trackerName[20]; // ID-string of tracker software - Uint16 version; // XM-version 0x0104 + Uint16 version; // XM-version tag Uint32 headSize; // Module header size, FROM THIS POINT! Uint16 norders, // Number of orders defRestartPos, // Default song restart position @@ -296,7 +296,9 @@ } -static int jssXMLoadInstrument(DMResource *inFile, JSSModule *module, int ninst, int nsample, int *xmConvTable) +static int jssXMLoadSampleInstrument( + DMResource *inFile, JSSModule *module, + JSSExtInstrument *einst, int ninst, int nsample) { XMSample xmS; JSSInstrument *inst; @@ -325,7 +327,7 @@ JSSDEBUG("Allocating sample #%d/%d [%d]\n", ninst, nsample, module->ninstruments); - xmConvTable[nsample] = module->ninstruments; + einst->instConvTable[nsample] = module->ninstruments; inst = module->instruments[module->ninstruments] = jssAllocateInstrument(); if (inst == NULL) { @@ -461,10 +463,29 @@ (Uint8 *) inst->data, inst->size, (jsampDelta | jsampFlipSign)); } + return ret; } +static int jssXMLoadInstrumentSamples( + DMResource *inFile, JSSModule *module, + JSSExtInstrument *einst, int ninst) +{ + int nsample, ret; + + for (nsample = 0; nsample < einst->nsamples; nsample++) + if (einst->instConvTable[nsample] != jsetNotSet) + { + JSSInstrument *inst = module->instruments[einst->instConvTable[nsample]]; + if ((ret = jssXMLoadSampleData(inFile, inst, ninst, nsample)) != DMERR_OK) + return ret; + } + + return DMERR_OK; +} + + static BOOL jssXMLoadEnvelopePoints(DMResource *inFile, XMEnvelope *env) { int i; @@ -493,7 +514,6 @@ { XMInstrument1 xmI1; off_t remainder, pos = dmftell(inFile); - int xmConvTable[XM_MaxInstruments + 1]; JSSExtInstrument *einst; XMInstrument2 xmI2; int i, nsample, ret; @@ -601,31 +621,21 @@ // Initialize the SNumForNotes conversion table for (i = 0; i < XM_MaxInstruments; i++) - xmConvTable[i] = jsetNotSet; + einst->instConvTable[i] = jsetNotSet; // Read sample headers for (nsample = 0; nsample < xmI1.nsamples; nsample++) { - if ((ret = jssXMLoadInstrument(inFile, module, ninst, nsample, xmConvTable)) != DMERR_OK) + if ((ret = jssXMLoadSampleInstrument(inFile, module, einst, ninst, nsample)) != DMERR_OK) return ret; } - // Read sample data - for (nsample = 0; nsample < xmI1.nsamples; nsample++) - if (xmConvTable[nsample] != jsetNotSet) - { - JSSInstrument *inst = module->instruments[xmConvTable[nsample]]; - if ((ret = jssXMLoadSampleData(inFile, inst, ninst, nsample)) != DMERR_OK) - return ret; - } - - // Apply new values to sNumForNotes values for (i = 0; i < XM_MaxNotes; i++) { int tmp = xmI2.sNumForNotes[i]; if (tmp >= 0 && tmp < xmI1.nsamples) - einst->sNumForNotes[i] = xmConvTable[tmp]; + einst->sNumForNotes[i] = einst->instConvTable[tmp]; else { einst->sNumForNotes[i] = jsetNotSet; @@ -635,6 +645,8 @@ } } + if ((ret = jssXMLoadInstrumentSamples(inFile, module, einst, ninst)) != DMERR_OK) + return ret; return DMERR_OK; } @@ -730,7 +742,7 @@ { JSSModule *module; XMHeader xmH; - int index, result; + int index, ret; assert(ppModule != NULL); assert(inFile != NULL); @@ -880,11 +892,19 @@ module->defPanning[index] = jchPanMiddle; // Load rest of the module - if ((result = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK) - return result; + switch (xmH.version) + { + case 0x0104: + if ((ret = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK) + goto out; - if ((result = jssXMLoadInstruments(inFile, module)) != DMERR_OK) - return result; + if ((ret = jssXMLoadInstruments(inFile, module)) != DMERR_OK) + goto out; + break; - return DMERR_OK; + } + +out: + + return ret; }