Mercurial > hg > dmlib
annotate xm2jss.c @ 300:4972ca91d062
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Oct 2012 17:55:15 +0300 |
parents | 245b15cd1919 |
children | b620ffe1c27e |
rev | line source |
---|---|
0 | 1 /* |
2 * xm2jss - Convert XM module to JSSMOD | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2006-2009 Tecnic Software productions (TNSP) | |
5 * | |
6 * Please read file 'COPYING' for information on license and distribution. | |
7 */ | |
8 #include <stdio.h> | |
9 #include <errno.h> | |
10 #include "jss.h" | |
11 #include "jssmod.h" | |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
12 #include "jssplr.h" |
0 | 13 #include "dmlib.h" |
14 #include "dmargs.h" | |
15 #include "dmres.h" | |
285
245b15cd1919
Don't link libSDL uselessly to utilities that do not actually use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
16 #include "dmmutex.h" |
245b15cd1919
Don't link libSDL uselessly to utilities that do not actually use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
17 |
0 | 18 |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
19 #define jmpNMODEffectTable (36) |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
20 static const char jmpMODEffectTable[jmpNMODEffectTable] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
21 |
0 | 22 |
300 | 23 char *optInFilename = NULL, *optOutFilename = NULL; |
0 | 24 BOOL optIgnoreErrors = FALSE, |
25 optStripExtInstr = FALSE, | |
26 optStripInstr = FALSE, | |
27 optStripSamples = FALSE, | |
28 optOptimize = FALSE; | |
29 | |
30 int optPatternMode = PATMODE_COMP_HORIZ, | |
31 optSampMode16 = jsampDelta, | |
32 optSampMode8 = jsampFlipSign | jsampDelta; | |
33 | |
34 #define SAMPMODE_MASK (jsampFlipSign | jsampSwapEndianess | jsampSplit | jsampDelta) | |
35 | |
36 | |
37 static const char* patModeTable[PATMODE_LAST] = | |
38 { | |
39 "Raw horizontal", | |
40 "Compressed horizontal (similar to XM modules)", | |
41 "Raw vertical", | |
42 "Compressed vertical", | |
43 "Raw vertical for each element", | |
44 }; | |
45 | |
46 | |
47 DMOptArg optList[] = { | |
48 { 0, '?', "help", "Show this help", OPT_NONE }, | |
49 { 5, 'v', "verbose", "Be more verbose", OPT_NONE }, | |
50 { 6, 'o', "output", "Output file", OPT_ARGREQ }, | |
51 { 1, 'i', "ignore", "Ignore errors", OPT_NONE }, | |
52 { 2, 'p', "patterns", "Pattern storage mode", OPT_ARGREQ }, | |
53 { 3, 'E', "strip-ext-instr","Strip ext. instruments (implies -I -S)", OPT_NONE }, | |
54 { 9, 'I', "strip-instr", "Strip instruments (implies -S)", OPT_NONE }, | |
55 { 4, 'S', "strip-samples", "Strip instr. sampledata", OPT_NONE }, | |
56 { 7, '8', "smode8", "8-bit sample conversion flags", OPT_ARGREQ }, | |
57 { 8, '1', "smode16", "16-bit sample conversion flags", OPT_ARGREQ }, | |
58 {10, 'O', "optimize", "Optimize module", OPT_NONE }, | |
59 }; | |
60 | |
61 const int optListN = sizeof(optList) / sizeof(optList[0]); | |
62 | |
63 | |
64 void argShowHelp() | |
65 { | |
66 int i; | |
67 | |
68 dmPrintBanner(stdout, dmProgName, "[options] <module.xm>"); | |
69 dmArgsPrintHelp(stdout, optList, optListN); | |
70 | |
71 printf("\n" | |
72 "Pattern storage modes:\n"); | |
73 | |
74 for (i = 1; i < PATMODE_LAST; i++) | |
75 printf(" %d = %s\n", i, patModeTable[i-1]); | |
76 | |
77 printf( | |
78 "\n" | |
79 "Sample data conversion flags (summative):\n" | |
80 " 1 = Delta encoding (DEF 8 & 16)\n" | |
81 " 2 = Flip signedness (DEF 8)\n" | |
82 " 4 = Swap endianess (affects 16-bit only)\n" | |
83 " 8 = Split and de-interleave hi/lo bytes (affects 16-bit only)\n" | |
84 "\n" | |
85 ); | |
86 } | |
87 | |
88 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) | |
89 { | |
90 (void) optArg; | |
91 | |
92 switch (optN) | |
93 { | |
94 case 0: | |
95 argShowHelp(); | |
96 exit(0); | |
97 break; | |
98 | |
99 case 1: | |
100 optIgnoreErrors = TRUE; | |
101 break; | |
102 | |
103 case 2: | |
104 optPatternMode = atoi(optArg); | |
105 if (optPatternMode <= 0 || optPatternMode >= PATMODE_LAST) | |
106 { | |
107 dmError("Unknown pattern conversion mode %d\n", optPatternMode); | |
108 return FALSE; | |
109 } | |
110 break; | |
111 | |
112 case 7: optSampMode8 = atoi(optArg) & SAMPMODE_MASK; break; | |
113 case 8: optSampMode16 = atoi(optArg) & SAMPMODE_MASK; break; | |
114 | |
115 case 4: optStripSamples = TRUE; break; | |
116 case 3: optStripExtInstr = TRUE; break; | |
117 case 9: optStripInstr = TRUE; break; | |
118 case 10: optOptimize = TRUE; break; | |
119 | |
120 case 5: | |
121 dmVerbosity++; | |
122 break; | |
123 | |
124 case 6: | |
300 | 125 optOutFilename = optArg; |
0 | 126 break; |
127 | |
128 default: | |
129 dmError("Unknown argument '%s'.\n", currArg); | |
130 return FALSE; | |
131 } | |
132 | |
133 return TRUE; | |
134 } | |
135 | |
136 | |
137 BOOL argHandleFile(char *currArg) | |
138 { | |
139 // Was not option argument | |
300 | 140 if (!optInFilename) |
141 optInFilename = currArg; | |
142 if (!optOutFilename) | |
143 optOutFilename = currArg; | |
0 | 144 else |
145 { | |
300 | 146 dmError("Too many filename arguments specified, '%s'.\n", currArg); |
0 | 147 return FALSE; |
148 } | |
149 | |
150 return TRUE; | |
151 } | |
152 | |
153 | |
154 /* These functions and the macro mess are meant to make the | |
155 * conversion routines themselves clearer and simpler. | |
156 */ | |
157 BOOL jsPutByte(Uint8 *patBuf, size_t patBufSize, size_t *npatBuf, Uint8 val) | |
158 { | |
159 if (*npatBuf >= patBufSize) | |
160 return FALSE; | |
161 else | |
162 { | |
163 patBuf[*npatBuf] = val; | |
164 (*npatBuf)++; | |
165 return TRUE; | |
166 } | |
167 } | |
168 | |
169 #define JSPUTBYTE(x) do { if (!jsPutByte(patBuf, patBufSize, patSize, x)) return DMERR_BOUNDS; } while (0) | |
170 | |
171 #define JSCOMP(x,z) do { if ((x) != jsetNotSet) { qflags |= (z); qcomp++; } } while (0) | |
172 | |
173 #define JSCOMPPUT(xf,xv,qv) do { \ | |
174 if (qflags & (xf)) { \ | |
175 if ((xv) < 0 || (xv) > 255) \ | |
176 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, \ | |
177 "%s value out of bounds %d.\n", qv, (xv)); \ | |
178 JSPUTBYTE(xv); \ | |
179 } \ | |
180 } while (0) | |
181 | |
182 #define JSCONVPUT(xv,qv) do { \ | |
183 if ((xv) != jsetNotSet) { \ | |
184 if ((xv) < 0 || (xv) > 254) \ | |
185 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, \ | |
186 "%s value out of bounds %d.\n", qv, (xv)); \ | |
187 JSPUTBYTE((xv) + 1); \ | |
188 } else { \ | |
189 JSPUTBYTE(0); \ | |
190 } \ | |
191 } while (0) | |
192 | |
193 | |
194 /* Convert a note | |
195 */ | |
196 static int jssConvertNote(Uint8 *patBuf, const size_t patBufSize, size_t *patSize, const JSSNote *note) | |
197 { | |
198 Uint8 tmp; | |
199 if (note->note == jsetNotSet) | |
200 tmp = 0; | |
201 else if (note->note == jsetNoteOff) | |
202 tmp = 127; | |
203 else | |
204 tmp = note->note + 1; | |
205 | |
206 if (tmp > 0x7f) | |
207 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Note value out of bounds %d > 0x7f.\n", tmp); | |
208 | |
209 JSPUTBYTE(tmp & 0x7f); | |
210 | |
211 JSCONVPUT(note->instrument, "Instrument"); | |
212 JSCONVPUT(note->volume, "Volume"); | |
213 JSCONVPUT(note->effect, "Effect"); | |
214 | |
215 tmp = (note->param != jsetNotSet) ? note->param : 0; | |
216 JSPUTBYTE(tmp); | |
217 | |
218 return DMERR_OK; | |
219 } | |
220 | |
221 | |
222 /* Compress a note | |
223 */ | |
224 static int jssCompressNote(Uint8 *patBuf, const size_t patBufSize, size_t *patSize, const JSSNote *note) | |
225 { | |
226 Uint8 qflags = 0; | |
227 int qcomp = 0; | |
228 | |
229 JSCOMP(note->note, COMP_NOTE); | |
230 JSCOMP(note->instrument, COMP_INSTRUMENT); | |
231 JSCOMP(note->volume, COMP_VOLUME); | |
232 JSCOMP(note->effect, COMP_EFFECT); | |
233 if (note->param != jsetNotSet && note->param != 0) | |
234 { | |
235 qflags |= COMP_PARAM; | |
236 qcomp++; | |
237 } | |
238 | |
239 if (qcomp < 4) | |
240 { | |
241 JSPUTBYTE(qflags | 0x80); | |
242 | |
243 if (note->note != jsetNotSet) | |
244 { | |
245 Uint8 tmp = (note->note != jsetNoteOff) ? note->note : 127; | |
246 if (tmp > 0x7f) | |
247 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Note value out of bounds %d > 0x7f.\n", tmp); | |
248 JSPUTBYTE(tmp); | |
249 } | |
250 | |
251 JSCOMPPUT(COMP_INSTRUMENT, note->instrument, "Instrument"); | |
252 JSCOMPPUT(COMP_VOLUME, note->volume, "Volume"); | |
253 JSCOMPPUT(COMP_EFFECT, note->effect, "Effect"); | |
254 JSCOMPPUT(COMP_PARAM, note->param, "Param"); | |
255 } else | |
256 return jssConvertNote(patBuf, patBufSize, patSize, note); | |
257 | |
258 return DMERR_OK; | |
259 } | |
260 | |
261 | |
262 /* Compress pattern | |
263 */ | |
264 static int jssConvertPatternCompHoriz(Uint8 *patBuf, const size_t patBufSize, size_t *patSize, const JSSPattern *pattern) | |
265 { | |
266 int row, channel; | |
267 *patSize = 0; | |
268 | |
269 for (row = 0; row < pattern->nrows; row++) | |
270 for (channel = 0; channel < pattern->nchannels; channel++) | |
271 { | |
272 const JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel]; | |
273 const int res = jssCompressNote(patBuf, patBufSize, patSize, note); | |
274 if (res != DMERR_OK) | |
275 { | |
276 JSSERROR(res, res, "Note compression failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
277 patBuf, patBufSize, *patSize, row, channel); | |
278 return res; | |
279 } | |
280 } | |
281 | |
282 return DMERR_OK; | |
283 } | |
284 | |
285 | |
286 static int jssConvertPatternCompVert(Uint8 *patBuf, const size_t patBufSize, size_t *patSize, const JSSPattern *pattern) | |
287 { | |
288 int row, channel; | |
289 *patSize = 0; | |
290 | |
291 for (channel = 0; channel < pattern->nchannels; channel++) | |
292 for (row = 0; row < pattern->nrows; row++) | |
293 { | |
294 const JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel]; | |
295 const int res = jssCompressNote(patBuf, patBufSize, patSize, note); | |
296 if (res != DMERR_OK) | |
297 { | |
298 JSSERROR(res, res, "Note compression failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
299 patBuf, patBufSize, *patSize, row, channel); | |
300 return res; | |
301 } | |
302 } | |
303 | |
304 return DMERR_OK; | |
305 } | |
306 | |
307 | |
308 /* Convert a pattern | |
309 */ | |
310 static int jssConvertPatternRawHoriz(Uint8 *patBuf, const size_t patBufSize, size_t *patSize, const JSSPattern *pattern) | |
311 { | |
312 int row, channel; | |
313 *patSize = 0; | |
314 | |
315 for (row = 0; row < pattern->nrows; row++) | |
316 for (channel = 0; channel < pattern->nchannels; channel++) | |
317 { | |
318 const JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel]; | |
319 const int res = jssConvertNote(patBuf, patBufSize, patSize, note); | |
320 if (res != DMERR_OK) | |
321 { | |
322 JSSERROR(res, res, "Note conversion failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
323 patBuf, patBufSize, *patSize, row, channel); | |
324 return res; | |
325 } | |
326 } | |
327 | |
328 return DMERR_OK; | |
329 } | |
330 | |
331 | |
332 static int jssConvertPatternRawVert(Uint8 *patBuf, const size_t patBufSize, size_t *patSize, const JSSPattern *pattern) | |
333 { | |
334 int row, channel; | |
335 *patSize = 0; | |
336 | |
337 for (channel = 0; channel < pattern->nchannels; channel++) | |
338 for (row = 0; row < pattern->nrows; row++) | |
339 { | |
340 const JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel]; | |
341 const int res = jssConvertNote(patBuf, patBufSize, patSize, note); | |
342 if (res != DMERR_OK) | |
343 { | |
344 JSSERROR(res, res, "Note conversion failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
345 patBuf, patBufSize, *patSize, row, channel); | |
346 return res; | |
347 } | |
348 } | |
349 | |
350 return DMERR_OK; | |
351 } | |
352 | |
353 | |
354 #define JSFOREACHNOTE1 \ | |
355 for (channel = 0; channel < pattern->nchannels; channel++) \ | |
356 for (row = 0; row < pattern->nrows; row++) { \ | |
357 const JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel]; | |
358 | |
359 #define JSFOREACHNOTE2 } | |
360 | |
361 static int jssConvertPatternRawElem(Uint8 *patBuf, const size_t patBufSize, size_t *patSize, const JSSPattern *pattern) | |
362 { | |
363 Uint8 tmp; | |
364 int row, channel; | |
365 *patSize = 0; | |
366 | |
367 JSFOREACHNOTE1; | |
368 if (note->note == jsetNotSet) | |
369 tmp = 0; | |
370 else if (note->note == jsetNoteOff) | |
371 tmp = 127; | |
372 else | |
373 tmp = note->note + 1; | |
374 if (tmp > 0x7f) | |
375 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Note value out of bounds %d > 0x7f.\n", tmp); | |
376 JSPUTBYTE(tmp); | |
377 JSFOREACHNOTE2; | |
378 | |
379 JSFOREACHNOTE1; | |
380 JSCONVPUT(note->instrument, "Instrument"); | |
381 JSFOREACHNOTE2; | |
382 | |
383 JSFOREACHNOTE1; | |
384 JSCONVPUT(note->volume, "Volume"); | |
385 JSFOREACHNOTE2; | |
386 | |
387 JSFOREACHNOTE1; | |
388 JSCONVPUT(note->effect, "Effect"); | |
389 JSFOREACHNOTE2; | |
390 | |
391 JSFOREACHNOTE1; | |
392 JSCONVPUT(note->param, "Param"); | |
393 JSFOREACHNOTE2; | |
394 | |
395 return DMERR_OK; | |
396 } | |
397 | |
398 #undef JSFOREACHNOTE1 | |
399 #undef JSFOREACHNOTE2 | |
400 | |
401 | |
402 static void jssCopyEnvelope(JSSMODEnvelope *je, JSSEnvelope *e) | |
403 { | |
404 int i; | |
405 | |
406 je->flags = e->flags; | |
407 je->npoints = e->npoints; | |
408 je->sustain = e->sustain; | |
409 je->loopS = e->loopS; | |
410 je->loopE = e->loopE; | |
411 | |
412 for (i = 0; i < e->npoints; i++) | |
413 { | |
414 je->points[i].frame = e->points[i].frame; | |
415 je->points[i].value = e->points[i].value; | |
416 } | |
417 } | |
418 | |
419 | |
420 /* Save a JSSMOD file | |
421 */ | |
422 int jssSaveJSSMOD(FILE *outFile, JSSModule *m, int patMode, int flags8, int flags16) | |
423 { | |
424 JSSMODHeader jssH; | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
425 int i, pattern, order, instr, totalSize; |
0 | 426 const size_t patBufSize = 64*1024; // 64kB pattern buffer |
427 Uint8 *patBuf; | |
428 | |
429 // Check the module | |
430 if (m == NULL) | |
431 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, "Module pointer was NULL\n"); | |
432 | |
433 if ((m->nchannels < 1) || (m->npatterns < 1) || (m->norders < 1)) | |
434 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, | |
435 "Module had invalid values (nchannels=%i, npatterns=%i, norders=%i)\n", | |
436 m->nchannels, m->npatterns, m->norders); | |
437 | |
438 // Create the JSSMOD header | |
439 jssH.idMagic[0] = 'J'; | |
440 jssH.idMagic[1] = 'M'; | |
441 jssH.idVersion = JSSMOD_VERSION; | |
442 jssH.norders = m->norders; | |
443 jssH.npatterns = m->npatterns; | |
444 jssH.nchannels = m->nchannels; | |
445 jssH.nextInstruments = m->nextInstruments; | |
446 jssH.ninstruments = m->ninstruments; | |
447 jssH.defFlags = m->defFlags; | |
448 jssH.intVersion = m->intVersion; | |
449 jssH.defRestartPos = m->defRestartPos; | |
450 jssH.defSpeed = m->defSpeed; | |
451 jssH.defTempo = m->defTempo; | |
452 jssH.patMode = patMode; | |
453 | |
454 // Write header | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
455 totalSize = sizeof(jssH); |
0 | 456 if (fwrite(&jssH, sizeof(jssH), 1, outFile) != 1) |
457 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD header!\n"); | |
458 | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
459 dmMsg(1," * JSSMOD-header 0x%04x, %d bytes.\n", JSSMOD_VERSION, totalSize); |
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
460 |
0 | 461 // Write orders list |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
462 for (totalSize = order = 0; order < m->norders; order++) |
0 | 463 { |
464 Uint16 tmp = m->orderList[order]; | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
465 totalSize += sizeof(tmp); |
0 | 466 if (fwrite(&tmp, sizeof(tmp), 1, outFile) != 1) |
467 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD orders list.\n"); | |
468 } | |
469 | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
470 dmMsg(1," * %d item orders list, %d bytes.\n", |
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
471 m->norders, totalSize); |
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
472 |
0 | 473 // Allocate pattern compression buffer |
474 if ((patBuf = dmMalloc(patBufSize)) == NULL) | |
475 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, | |
476 "Error allocating memory for pattern compression buffer.\n"); | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
477 |
0 | 478 |
479 // Write patterns | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
480 for (totalSize = pattern = 0; pattern < m->npatterns; pattern++) |
0 | 481 { |
482 JSSMODPattern patHead; | |
483 size_t finalSize = 0; | |
484 | |
485 switch (patMode) | |
486 { | |
487 case PATMODE_RAW_HORIZ: | |
488 i = jssConvertPatternRawHoriz(patBuf, patBufSize, &finalSize, m->patterns[pattern]); | |
489 break; | |
490 case PATMODE_COMP_HORIZ: | |
491 i = jssConvertPatternCompHoriz(patBuf, patBufSize, &finalSize, m->patterns[pattern]); | |
492 break; | |
493 case PATMODE_RAW_VERT: | |
494 i = jssConvertPatternRawVert(patBuf, patBufSize, &finalSize, m->patterns[pattern]); | |
495 break; | |
496 case PATMODE_COMP_VERT: | |
497 i = jssConvertPatternCompVert(patBuf, patBufSize, &finalSize, m->patterns[pattern]); | |
498 break; | |
499 case PATMODE_RAW_ELEM: | |
500 i = jssConvertPatternRawElem(patBuf, patBufSize, &finalSize, m->patterns[pattern]); | |
501 break; | |
502 default: | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
503 i = DMERR_INVALID_DATA; |
0 | 504 dmFree(patBuf); |
505 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
506 "Unsupported pattern conversion mode %d.\n", patMode); | |
507 break; | |
508 } | |
509 | |
510 if (i != DMERR_OK) | |
511 { | |
512 dmFree(patBuf); | |
513 JSSERROR(i, i, "Error converting pattern data #%i\n", pattern); | |
514 } | |
515 else | |
516 { | |
517 dmMsg(3, " - Pattern %d size %d bytes\n", pattern, finalSize); | |
518 patHead.nrows = m->patterns[pattern]->nrows; | |
519 patHead.size = finalSize; | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
520 totalSize += finalSize + sizeof(patHead); |
0 | 521 |
522 if (fwrite(&patHead, sizeof(patHead), 1, outFile) != 1) | |
523 { | |
524 dmFree(patBuf); | |
525 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, | |
526 "Error writing pattern #%d header\n", pattern); | |
527 } | |
528 | |
529 if (fwrite(patBuf, sizeof(Uint8), finalSize, outFile) != finalSize) | |
530 { | |
531 dmFree(patBuf); | |
532 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, | |
533 "Error writing pattern #%d data\n", pattern); | |
534 } | |
535 } | |
536 } | |
537 dmFree(patBuf); | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
538 dmMsg(1," * %d patterns, %d bytes.\n", m->npatterns, totalSize); |
0 | 539 |
540 // Write extended instruments | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
541 for (totalSize = instr = 0; instr < m->nextInstruments; instr++) |
0 | 542 { |
543 JSSMODExtInstrument jssE; | |
544 JSSExtInstrument *einst = m->extInstruments[instr]; | |
545 | |
546 memset(&jssE, 0, sizeof(jssE)); | |
547 | |
548 if (einst) | |
549 { | |
550 // Create header | |
551 jssE.nsamples = einst->nsamples; | |
552 for (i = 0; i < jsetNNotes; i++) | |
553 { | |
554 int snum = einst->sNumForNotes[i]; | |
555 jssE.sNumForNotes[i] = (snum != jsetNotSet) ? snum : 0; | |
556 } | |
557 | |
558 jssCopyEnvelope(&jssE.volumeEnv, &(einst->volumeEnv)); | |
559 jssCopyEnvelope(&jssE.panningEnv, &(einst->panningEnv)); | |
560 jssE.vibratoType = einst->vibratoType; | |
561 jssE.vibratoSweep = einst->vibratoSweep; | |
562 jssE.vibratoDepth = einst->vibratoDepth; | |
563 jssE.fadeOut = einst->fadeOut; | |
564 } else | |
565 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Extended instrument #%i NULL!\n", instr); | |
566 | |
567 // Write to file | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
568 totalSize += sizeof(jssE); |
0 | 569 if (fwrite(&jssE, sizeof(jssE), 1, outFile) != 1) |
570 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, | |
571 "Could not write JSSMOD extended instrument #%i to file!\n", instr); | |
572 } | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
573 dmMsg(1," * %d Extended Instruments, %d bytes.\n", m->nextInstruments, totalSize); |
0 | 574 |
575 | |
576 // Write sample instrument headers | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
577 for (totalSize = instr = 0; instr < m->ninstruments; instr++) |
0 | 578 { |
579 JSSMODInstrument jssI; | |
580 JSSInstrument *pInst = m->instruments[instr]; | |
581 | |
582 memset(&jssI, 0, sizeof(jssI)); | |
583 | |
584 // Create header | |
585 if (pInst) | |
586 { | |
587 jssI.size = pInst->size; | |
588 jssI.loopS = pInst->loopS; | |
589 jssI.loopE = pInst->loopE; | |
590 jssI.volume = pInst->volume; | |
591 jssI.flags = pInst->flags; | |
592 jssI.C4BaseSpeed = pInst->C4BaseSpeed; | |
593 jssI.ERelNote = pInst->ERelNote; | |
594 jssI.EFineTune = pInst->EFineTune; | |
595 jssI.EPanning = pInst->EPanning; | |
596 jssI.hasData = (pInst->data != NULL) ? TRUE : FALSE; | |
597 jssI.convFlags = (pInst->flags & jsf16bit) ? flags16 : flags8; | |
598 } | |
599 else | |
600 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Instrument #%i NULL!\n", instr); | |
601 | |
602 // Write to file | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
603 totalSize += sizeof(jssI); |
0 | 604 if (fwrite(&jssI, sizeof(jssI), 1, outFile) != 1) |
605 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, | |
606 "Could not write JSSMOD instrument #%i to file!\n", instr); | |
607 } | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
608 dmMsg(1," * %d Instrument headers, %d bytes.\n", m->ninstruments, totalSize); |
0 | 609 |
610 // Write sample data | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
611 for (totalSize = instr = 0; instr < m->ninstruments; instr++) |
0 | 612 if (m->instruments[instr]) |
613 { | |
614 JSSInstrument *inst = m->instruments[instr]; | |
615 if (inst->data != NULL) | |
616 { | |
617 size_t res; | |
618 if (inst->flags & jsf16bit) | |
619 { | |
620 jssEncodeSample16(inst->data, inst->size, flags16); | |
621 res = fwrite(inst->data, sizeof(Uint16), inst->size, outFile); | |
622 } | |
623 else | |
624 { | |
625 jssEncodeSample8(inst->data, inst->size, flags8); | |
626 res = fwrite(inst->data, sizeof(Uint8), inst->size, outFile); | |
627 } | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
628 |
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
629 totalSize += inst->size; |
86 | 630 if (res != (size_t) inst->size) |
0 | 631 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
632 "Could not write JSSMOD sample #%i to file!\n", instr); | |
633 } | |
634 } | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
635 dmMsg(1," * %d samples, %d bytes.\n", m->ninstruments, totalSize); |
0 | 636 |
637 return DMERR_OK; | |
638 } | |
639 | |
640 | |
641 /* Optimize a given module | |
642 */ | |
643 JSSModule *optimizeModule(JSSModule *m) | |
644 { | |
645 BOOL usedPatterns[jsetMaxPatterns + 1], | |
646 usedInstruments[jsetMaxInstruments + 1], | |
647 usedExtInstruments[jsetMaxInstruments + 1]; | |
648 int mapExtInstruments[jsetMaxInstruments + 1], | |
649 mapInstruments[jsetMaxInstruments + 1], | |
650 mapPatterns[jsetMaxPatterns + 1]; | |
651 JSSModule *r = NULL; | |
652 int i, n8, n16; | |
653 | |
654 // Allocate a new module | |
655 if ((r = jssAllocateModule()) == NULL) | |
656 return NULL; | |
657 | |
658 // Allocate tables | |
659 | |
660 // Copy things | |
661 r->moduleType = m->moduleType; | |
662 r->moduleName = dm_strdup(m->moduleName); | |
663 r->trackerName = dm_strdup(m->trackerName); | |
664 r->defSpeed = m->defSpeed; | |
665 r->defTempo = m->defTempo; | |
666 r->defFlags = m->defFlags; | |
667 r->defRestartPos = m->defRestartPos; | |
668 r->intVersion = m->intVersion; | |
669 r->nchannels = m->nchannels; | |
670 r->norders = m->norders; | |
671 for (i = 0; i < jsetNChannels; i++) | |
672 r->defPanning[i] = m->defPanning[i]; | |
673 | |
674 // Initialize values | |
675 for (i = 0; i <= jsetMaxInstruments; i++) | |
676 { | |
677 usedExtInstruments[i] = FALSE; | |
678 usedInstruments[i] = FALSE; | |
679 mapExtInstruments[i] = jsetNotSet; | |
680 mapInstruments[i] = jsetNotSet; | |
681 } | |
682 | |
683 for (i = 0; i <= jsetMaxPatterns; i++) | |
684 { | |
685 usedPatterns[i] = FALSE; | |
686 mapPatterns[i] = jsetNotSet; | |
687 } | |
688 | |
689 // Find out all used patterns and ext.instruments | |
690 for (i = 0; i < m->norders; i++) | |
691 { | |
692 int pattern = m->orderList[i]; | |
693 if (pattern >= 0 && pattern < m->npatterns) | |
694 { | |
695 JSSPattern *p = m->patterns[pattern]; | |
696 if (p != NULL) | |
697 { | |
698 int row, channel; | |
699 JSSNote *n = p->data; | |
700 | |
701 // Mark pattern as used | |
702 usedPatterns[pattern] = TRUE; | |
703 | |
704 // Check all notes | |
705 for (row = 0; row < p->nrows; row++) | |
706 for (channel = 0; channel < p->nchannels; channel++, n++) | |
707 { | |
708 if (n->instrument != jsetNotSet) | |
709 { | |
710 if (n->instrument >= 0 && n->instrument < m->nextInstruments) | |
711 usedExtInstruments[n->instrument] = TRUE; | |
712 else | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
713 dmMsg(2, "Pattern 0x%x, row=0x%x, chn=%d has invalid instrument 0x%x\n", |
0 | 714 pattern, row, channel, n->instrument); |
715 } | |
716 } | |
717 } | |
718 else | |
719 { | |
720 dmError("Pattern 0x%x is used on order 0x%x, but has no data!\n", | |
721 pattern, i); | |
722 } | |
723 } | |
724 else | |
725 if (pattern != jsetMaxPatterns) | |
726 { | |
727 dmError("Order 0x%x has invalid pattern number 0x%x!\n", | |
728 i, pattern); | |
729 } | |
730 } | |
731 | |
732 // Find out used instruments | |
733 for (i = 0; i <= jsetMaxInstruments; i++) | |
734 if (usedExtInstruments[i] && m->extInstruments[i] != NULL) | |
735 { | |
736 int note; | |
737 JSSExtInstrument *e = m->extInstruments[i]; | |
738 | |
739 for (note = 0; note < jsetNNotes; note++) | |
740 if (e->sNumForNotes[note] != jsetNotSet) | |
741 { | |
742 int q = e->sNumForNotes[note]; | |
743 if (q >= 0 && q < m->ninstruments) | |
744 { | |
745 usedInstruments[q] = TRUE; | |
746 } | |
747 else | |
748 { | |
749 dmError("Ext.instrument #%d sNumForNotes[%d] value out range (%d < %d).\n", | |
750 i, m->ninstruments, q); | |
751 } | |
752 } | |
753 } | |
754 | |
755 // Create pattern mappings | |
756 r->npatterns = 0; | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
757 dmMsg(1, "Unused patterns: "); |
0 | 758 |
759 for (i = 0; i <= jsetMaxPatterns; i++) | |
760 if (m->patterns[i] != NULL) | |
761 { | |
762 if (!usedPatterns[i]) | |
763 { | |
764 dmPrint(2, "0x%x, ", i); | |
765 } | |
766 else | |
767 { | |
768 if (i >= m->npatterns) | |
769 dmError("Pattern 0x%x >= 0x%x, but used!\n", i, m->npatterns); | |
770 | |
771 mapPatterns[i] = r->npatterns; | |
772 r->patterns[r->npatterns] = m->patterns[i]; | |
773 (r->npatterns)++; | |
774 } | |
775 } | |
776 dmPrint(2, "\n"); | |
777 | |
778 dmMsg(1, "%d used patterns, %d unused.\n", | |
779 r->npatterns, m->npatterns - r->npatterns); | |
780 | |
781 | |
782 // Re-map instruments | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
783 dmMsg(1, "Unused instruments: "); |
0 | 784 for (n8 = n16 = i = 0; i <= jsetMaxInstruments; i++) |
785 if (m->instruments[i] != NULL) | |
786 { | |
787 if (!usedInstruments[i]) | |
788 { | |
789 dmPrint(2, "0x%x, ", i); | |
790 } | |
791 else | |
792 { | |
793 JSSInstrument *ip = m->instruments[i]; | |
794 if (i >= m->ninstruments) | |
795 dmError("Instrument 0x%x >= 0x%x, but used!\n", i, m->ninstruments); | |
796 | |
797 mapInstruments[i] = r->ninstruments; | |
798 r->instruments[r->ninstruments] = ip; | |
799 (r->ninstruments)++; | |
800 | |
801 if (ip->flags & jsf16bit) | |
802 n16++; | |
803 else | |
804 n8++; | |
805 } | |
806 } | |
807 dmPrint(2, "\n"); | |
808 dmMsg(1, "Total of (%d) 16-bit, (%d) 8-bit samples, (%d) instruments.\n", | |
809 n16, n8, r->ninstruments); | |
810 | |
811 // Re-map ext.instruments | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
812 dmMsg(1, "Unused ext.instruments: "); |
0 | 813 for (i = 0; i < jsetMaxInstruments; i++) |
814 if (usedExtInstruments[i]) | |
815 { | |
816 if (i >= m->nextInstruments) | |
817 { | |
818 dmError("Ext.instrument 0x%x >= 0x%x, but used!\n", | |
819 i, m->nextInstruments); | |
820 } | |
821 else | |
822 if (m->extInstruments[i] != NULL) | |
823 { | |
824 JSSExtInstrument *e = m->extInstruments[i]; | |
825 int note; | |
826 | |
827 mapExtInstruments[i] = r->nextInstruments; | |
828 r->extInstruments[r->nextInstruments] = e; | |
829 (r->nextInstruments)++; | |
830 | |
831 // Re-map sNumForNotes | |
832 for (note = 0; note < jsetNNotes; note++) | |
833 { | |
834 int q = e->sNumForNotes[note]; | |
835 if (q != jsetNotSet) | |
836 { | |
837 int map; | |
838 if (q >= 0 && q <= jsetMaxInstruments) | |
839 { | |
840 map = mapInstruments[q]; | |
841 } | |
842 else | |
843 { | |
844 map = jsetNotSet; | |
845 dmError("e=%d, note=%d, q=%d/%d\n", i, note, q, r->ninstruments); | |
846 } | |
847 e->sNumForNotes[note] = map; | |
848 } | |
849 } | |
850 } | |
851 else | |
852 { | |
853 dmPrint(2, "[0x%x==NULL], ", i); | |
854 mapExtInstruments[i] = jsetNotSet; | |
855 } | |
856 } | |
857 else | |
858 { | |
859 if (i < m->nextInstruments && m->extInstruments[i] != NULL) | |
860 { | |
861 dmPrint(2, "0x%x, ", i); | |
862 } | |
863 } | |
864 dmPrint(2, "\n"); | |
865 dmMsg(1, "%d extended instruments.\n", r->nextInstruments); | |
866 | |
867 | |
868 // Remap pattern instrument data | |
869 for (i = 0; i < r->npatterns; i++) | |
870 { | |
871 int row, channel; | |
872 JSSPattern *p = r->patterns[i]; | |
873 JSSNote *n = p->data; | |
874 | |
875 for (row = 0; row < p->nrows; row++) | |
876 for (channel = 0; channel < p->nchannels; channel++, n++) | |
877 { | |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
878 char effect; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
879 |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
880 if (n->instrument >= 0 && n->instrument <= jsetMaxInstruments) |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
881 n->instrument = mapExtInstruments[n->instrument]; |
202
85614db5f577
Warn about invalid instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
882 |
85614db5f577
Warn about invalid instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
883 if (n->instrument != jsetNotSet && r->extInstruments[n->instrument] == NULL) |
85614db5f577
Warn about invalid instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
884 dmError("Non-existing instrument used #%d.\n", n->instrument); |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
885 |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
886 JMPGETEFFECT(effect, n->effect); |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
887 |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
888 switch (effect) |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
889 { |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
890 case 'C': // Cxx = Set volume |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
891 if (n->volume == jsetNotSet) |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
892 { |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
893 n->volume = n->param; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
894 n->effect = jsetNotSet; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
895 n->param = jsetNotSet; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
896 } |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
897 break; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
898 } |
0 | 899 } |
900 } | |
901 | |
902 // Remap orders list | |
903 for (i = 0; i < m->norders; i++) | |
904 { | |
905 r->orderList[i] = mapPatterns[m->orderList[i]]; | |
906 } | |
907 | |
908 return r; | |
909 } | |
910 | |
911 | |
912 int main(int argc, char *argv[]) | |
913 { | |
914 DMResource *sfile = NULL; | |
915 FILE *dfile = NULL; | |
916 JSSModule *sm, *dm; | |
917 int result; | |
918 | |
919 dmInitProg("xm2jss", "XM to JSSMOD converter", "0.6", NULL, NULL); | |
920 dmVerbosity = 0; | |
921 | |
922 // Parse arguments | |
923 if (!dmArgsProcess(argc, argv, optList, optListN, | |
924 argHandleOpt, argHandleFile, TRUE)) | |
925 exit(1); | |
926 | |
300 | 927 // Check arguments |
928 if (optInFilename == NULL || optOutFilename == NULL) | |
929 { | |
930 dmError("Source and/or destination filename not specified. Try --help.\n"); | |
931 dmError("Input or output file not specified. Try --help.\n"); | |
932 return 1; | |
933 } | |
0 | 934 |
935 // Read the source file | |
300 | 936 if ((sfile = dmf_create_stdio(optInFilename, "rb")) == NULL) |
0 | 937 { |
84
35db15881923
Oops, another fix for dmf_create_stdio() changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
938 dmError("Error opening input file '%s', %d: %s\n", |
300 | 939 optInFilename, errno, strerror(errno)); |
0 | 940 return 1; |
941 } | |
942 | |
943 // Initialize miniJSS | |
944 jssInit(); | |
945 | |
946 // Read file | |
947 dmMsg(1, "Reading XM-format file ...\n"); | |
948 result = jssLoadXM(sfile, &sm); | |
949 dmf_close(sfile); | |
950 if (result != 0) | |
951 { | |
952 dmError("Error while loading XM file (%i), ", result); | |
953 if (optIgnoreErrors) | |
954 fprintf(stderr, "ignoring. This may cause problems.\n"); | |
955 else | |
956 { | |
957 fprintf(stderr, "giving up. Use --ignore if you want to try to convert anyway.\n"); | |
958 return 2; | |
959 } | |
960 } | |
961 | |
962 // Check stripping settings | |
963 if (optStripExtInstr) optStripInstr = TRUE; | |
964 if (optStripInstr) optStripSamples = TRUE; | |
965 | |
966 // Remove samples | |
967 if (optStripSamples) | |
968 { | |
969 int i; | |
970 | |
971 dmMsg(1, "Stripping samples...\n"); | |
972 for (i = 0; i < sm->ninstruments; i++) | |
973 { | |
974 dmFree(sm->instruments[i]->data); | |
975 sm->instruments[i]->data = NULL; | |
976 } | |
977 } | |
978 | |
979 // Remove instruments | |
980 if (optStripInstr) | |
981 { | |
982 int i; | |
983 | |
984 dmMsg(1, "Stripping instruments...\n"); | |
985 for (i = 0; i < sm->ninstruments; i++) | |
986 { | |
987 dmFree(sm->instruments[i]); | |
988 sm->instruments[i] = NULL; | |
989 } | |
990 sm->ninstruments = 0; | |
991 } | |
992 | |
993 // Remove ext.instruments | |
994 if (optStripExtInstr) | |
995 { | |
996 int i; | |
997 | |
998 dmMsg(1, "Stripping ext.instruments...\n"); | |
999 for (i = 0; i < sm->nextInstruments; i++) | |
1000 { | |
1001 dmFree(sm->extInstruments[i]); | |
1002 sm->extInstruments[i] = NULL; | |
1003 } | |
1004 sm->nextInstruments = 0; | |
1005 } | |
1006 // Run the optimization procedure | |
1007 if (optOptimize) | |
1008 { | |
1009 dmMsg(1, "Optimizing module data...\n"); | |
1010 dm = optimizeModule(sm); | |
1011 } else | |
1012 dm = sm; | |
1013 | |
1014 // Write output file | |
300 | 1015 if ((dfile = fopen(optOutFilename, "wb")) == NULL) |
0 | 1016 { |
300 | 1017 dmError("Error creating output file '%s', %d: %s\n", |
1018 optOutFilename, errno, strerror(errno)); | |
0 | 1019 return 1; |
1020 } | |
1021 | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1022 dmMsg(1, "Writing JSSMOD-format file [patMode=0x%04x, samp8=0x%02x, samp16=0x%02x]\n", |
0 | 1023 optPatternMode, optSampMode8, optSampMode16); |
1024 | |
1025 result = jssSaveJSSMOD(dfile, dm, optPatternMode, optSampMode8, optSampMode16); | |
1026 | |
1027 fclose(dfile); | |
1028 | |
1029 if (result != 0) | |
1030 { | |
300 | 1031 dmError("Error while saving JSSMOD file, %d: %s\n", |
1032 result, dmErrorStr(result)); | |
1033 dmError("WARNING: The resulting file may be broken!\n"); | |
0 | 1034 } |
300 | 1035 else |
1036 { | |
1037 dmMsg(1, "Conversion complete.\n"); | |
1038 } | |
0 | 1039 return 0; |
1040 } |