Mercurial > hg > dmlib
annotate tools/xm2jss.c @ 1317:2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
actually removing the dupes yet.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 20 Aug 2017 02:14:02 +0300 |
parents | 7687412f9aef |
children | f8c45f7aac79 |
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" | |
1241
5e2b90e3e4bc
Fix hasData handling and include dmfile.h header.
Matti Hamalainen <ccr@tnsp.org>
parents:
1237
diff
changeset
|
16 #include "dmfile.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
|
17 #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
|
18 |
0 | 19 |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
20 #define jmpNMODEffectTable (36) |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
21 static const char jmpMODEffectTable[jmpNMODEffectTable] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
1099 | 22 #define JM_SAMPLE_MODE_MASK (jsampFlipSign | jsampSwapEndianess | jsampSplit | jsampDelta) |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
23 |
0 | 24 |
300 | 25 char *optInFilename = NULL, *optOutFilename = NULL; |
0 | 26 BOOL optIgnoreErrors = FALSE, |
27 optStripExtInstr = FALSE, | |
28 optStripInstr = FALSE, | |
29 optStripSamples = FALSE, | |
30 optOptimize = FALSE; | |
31 | |
32 int optPatternMode = PATMODE_COMP_HORIZ, | |
33 optSampMode16 = jsampDelta, | |
34 optSampMode8 = jsampFlipSign | 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 | |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
856
diff
changeset
|
47 static const DMOptArg optList[] = |
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
856
diff
changeset
|
48 { |
0 | 49 { 0, '?', "help", "Show this help", OPT_NONE }, |
337 | 50 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
51 { 2, 'i', "ignore", "Ignore errors", OPT_NONE }, | |
52 { 3, 'p', "patterns", "Pattern storage mode", OPT_ARGREQ }, | |
53 { 4, 'E', "strip-ext-instr","Strip ext. instruments (implies -I -S)", OPT_NONE }, | |
54 { 5, 'I', "strip-instr", "Strip instruments (implies -S)", OPT_NONE }, | |
55 { 6, 'S', "strip-samples", "Strip instr. sampledata", OPT_NONE }, | |
0 | 56 { 7, '8', "smode8", "8-bit sample conversion flags", OPT_ARGREQ }, |
57 { 8, '1', "smode16", "16-bit sample conversion flags", OPT_ARGREQ }, | |
337 | 58 { 9, 'O', "optimize", "Optimize module", OPT_NONE }, |
0 | 59 }; |
60 | |
61 const int optListN = sizeof(optList) / sizeof(optList[0]); | |
62 | |
63 | |
64 void argShowHelp() | |
65 { | |
337 | 66 dmPrintBanner(stdout, dmProgName, "[options] <input.xm> <output.jmod>"); |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
856
diff
changeset
|
67 dmArgsPrintHelp(stdout, optList, optListN, 0); |
0 | 68 |
69 printf("\n" | |
70 "Pattern storage modes:\n"); | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
71 |
1313 | 72 for (int i = 1; i < PATMODE_LAST; i++) |
0 | 73 printf(" %d = %s\n", i, patModeTable[i-1]); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
74 |
0 | 75 printf( |
76 "\n" | |
77 "Sample data conversion flags (summative):\n" | |
78 " 1 = Delta encoding (DEF 8 & 16)\n" | |
79 " 2 = Flip signedness (DEF 8)\n" | |
80 " 4 = Swap endianess (affects 16-bit only)\n" | |
81 " 8 = Split and de-interleave hi/lo bytes (affects 16-bit only)\n" | |
82 "\n" | |
83 ); | |
84 } | |
85 | |
86 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) | |
87 { | |
88 (void) optArg; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
89 |
0 | 90 switch (optN) |
91 { | |
92 case 0: | |
93 argShowHelp(); | |
94 exit(0); | |
95 break; | |
96 | |
97 case 1: | |
337 | 98 dmVerbosity++; |
99 break; | |
100 | |
101 case 2: | |
0 | 102 optIgnoreErrors = TRUE; |
103 break; | |
104 | |
337 | 105 case 3: |
0 | 106 optPatternMode = atoi(optArg); |
107 if (optPatternMode <= 0 || optPatternMode >= PATMODE_LAST) | |
108 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
109 dmErrorMsg("Unknown pattern conversion mode %d\n", optPatternMode); |
0 | 110 return FALSE; |
111 } | |
112 break; | |
113 | |
337 | 114 case 4: optStripExtInstr = TRUE; break; |
115 case 5: optStripInstr = TRUE; break; | |
116 case 6: optStripSamples = TRUE; break; | |
117 | |
1099 | 118 case 7: optSampMode8 = atoi(optArg) & JM_SAMPLE_MODE_MASK; break; |
119 case 8: optSampMode16 = atoi(optArg) & JM_SAMPLE_MODE_MASK; break; | |
0 | 120 |
337 | 121 case 9: optOptimize = TRUE; break; |
0 | 122 |
123 default: | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
124 dmErrorMsg("Unknown argument '%s'.\n", currArg); |
0 | 125 return FALSE; |
126 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
127 |
0 | 128 return TRUE; |
129 } | |
130 | |
131 | |
132 BOOL argHandleFile(char *currArg) | |
133 { | |
134 // Was not option argument | |
300 | 135 if (!optInFilename) |
136 optInFilename = currArg; | |
337 | 137 else |
300 | 138 if (!optOutFilename) |
139 optOutFilename = currArg; | |
0 | 140 else |
141 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
142 dmErrorMsg("Too many filename arguments specified, '%s'.\n", currArg); |
0 | 143 return FALSE; |
144 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
145 |
0 | 146 return TRUE; |
147 } | |
148 | |
149 | |
150 /* These functions and the macro mess are meant to make the | |
151 * conversion routines themselves clearer and simpler. | |
152 */ | |
153 BOOL jsPutByte(Uint8 *patBuf, size_t patBufSize, size_t *npatBuf, Uint8 val) | |
154 { | |
155 if (*npatBuf >= patBufSize) | |
156 return FALSE; | |
157 else | |
158 { | |
159 patBuf[*npatBuf] = val; | |
160 (*npatBuf)++; | |
161 return TRUE; | |
162 } | |
163 } | |
164 | |
165 #define JSPUTBYTE(x) do { if (!jsPutByte(patBuf, patBufSize, patSize, x)) return DMERR_BOUNDS; } while (0) | |
166 | |
167 #define JSCOMP(x,z) do { if ((x) != jsetNotSet) { qflags |= (z); qcomp++; } } while (0) | |
168 | |
169 #define JSCOMPPUT(xf,xv,qv) do { \ | |
170 if (qflags & (xf)) { \ | |
171 if ((xv) < 0 || (xv) > 255) \ | |
172 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, \ | |
173 "%s value out of bounds %d.\n", qv, (xv)); \ | |
174 JSPUTBYTE(xv); \ | |
175 } \ | |
176 } while (0) | |
177 | |
178 #define JSCONVPUT(xv,qv) do { \ | |
179 if ((xv) != jsetNotSet) { \ | |
180 if ((xv) < 0 || (xv) > 254) \ | |
181 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, \ | |
182 "%s value out of bounds %d.\n", qv, (xv)); \ | |
183 JSPUTBYTE((xv) + 1); \ | |
184 } else { \ | |
185 JSPUTBYTE(0); \ | |
186 } \ | |
187 } while (0) | |
188 | |
189 | |
190 /* Convert a note | |
191 */ | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
192 static int jssConvertNote( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
193 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
194 size_t *patSize, const JSSNote *pnote) |
0 | 195 { |
196 Uint8 tmp; | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
197 if (pnote->note == jsetNotSet) |
0 | 198 tmp = 0; |
1194 | 199 else |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
200 if (pnote->note == jsetNoteOff) |
0 | 201 tmp = 127; |
202 else | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
203 tmp = pnote->note + 1; |
0 | 204 |
205 if (tmp > 0x7f) | |
206 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Note value out of bounds %d > 0x7f.\n", tmp); | |
207 | |
208 JSPUTBYTE(tmp & 0x7f); | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
209 |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
210 JSCONVPUT(pnote->instrument, "Instrument"); |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
211 JSCONVPUT(pnote->volume, "Volume"); |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
212 JSCONVPUT(pnote->effect, "Effect"); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
213 |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
214 tmp = (pnote->param != jsetNotSet) ? pnote->param : 0; |
0 | 215 JSPUTBYTE(tmp); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
216 |
0 | 217 return DMERR_OK; |
218 } | |
219 | |
220 | |
221 /* Compress a note | |
222 */ | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
223 static int jssCompressNote( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
224 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
225 size_t *patSize, const JSSNote *pnote) |
0 | 226 { |
227 Uint8 qflags = 0; | |
228 int qcomp = 0; | |
1201 | 229 |
230 // Determine what would get stored, | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
231 // aka actually how much space we use |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
232 JSCOMP(pnote->note, JM_COMP_NOTE); |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
233 JSCOMP(pnote->instrument, JM_COMP_INSTRUMENT); |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
234 JSCOMP(pnote->volume, JM_COMP_VOLUME); |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
235 JSCOMP(pnote->effect, JM_COMP_EFFECT); |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
236 if (pnote->param != jsetNotSet && pnote->param != 0) |
0 | 237 { |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
238 qflags |= JM_COMP_PARAM; |
0 | 239 qcomp++; |
240 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
241 |
0 | 242 if (qcomp < 4) |
243 { | |
1201 | 244 // Okay, it's less than 4 bytes, so use compressed |
0 | 245 JSPUTBYTE(qflags | 0x80); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
246 |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
247 if (pnote->note != jsetNotSet) |
0 | 248 { |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
249 Uint8 tmp = (pnote->note != jsetNoteOff) ? pnote->note : 127; |
0 | 250 if (tmp > 0x7f) |
251 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Note value out of bounds %d > 0x7f.\n", tmp); | |
252 JSPUTBYTE(tmp); | |
253 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
254 |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
255 JSCOMPPUT(JM_COMP_INSTRUMENT, pnote->instrument, "Instrument"); |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
256 JSCOMPPUT(JM_COMP_VOLUME, pnote->volume, "Volume"); |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
257 JSCOMPPUT(JM_COMP_EFFECT, pnote->effect, "Effect"); |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
258 JSCOMPPUT(JM_COMP_PARAM, pnote->param, "Param"); |
1201 | 259 } |
260 else | |
261 { | |
262 // Was 4 bytes or more, just dump it all in .. | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
263 return jssConvertNote(patBuf, patBufSize, patSize, pnote); |
1201 | 264 } |
265 | |
0 | 266 return DMERR_OK; |
267 } | |
268 | |
269 | |
270 /* Compress pattern | |
271 */ | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
272 static int jssConvertPatternCompHoriz( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
273 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
274 size_t *patSize, const JSSPattern *pattern) |
0 | 275 { |
276 int row, channel; | |
277 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
278 |
0 | 279 for (row = 0; row < pattern->nrows; row++) |
280 for (channel = 0; channel < pattern->nchannels; channel++) | |
281 { | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
282 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
283 const int res = jssCompressNote(patBuf, patBufSize, patSize, pnote); |
0 | 284 if (res != DMERR_OK) |
285 { | |
286 JSSERROR(res, res, "Note compression failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
287 patBuf, patBufSize, *patSize, row, channel); | |
288 return res; | |
289 } | |
290 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
291 |
0 | 292 return DMERR_OK; |
293 } | |
294 | |
295 | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
296 static int jssConvertPatternCompVert( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
297 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
298 size_t *patSize, const JSSPattern *pattern) |
0 | 299 { |
300 int row, channel; | |
301 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
302 |
0 | 303 for (channel = 0; channel < pattern->nchannels; channel++) |
304 for (row = 0; row < pattern->nrows; row++) | |
305 { | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
306 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
307 const int res = jssCompressNote(patBuf, patBufSize, patSize, pnote); |
0 | 308 if (res != DMERR_OK) |
309 { | |
310 JSSERROR(res, res, "Note compression failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
311 patBuf, patBufSize, *patSize, row, channel); | |
312 return res; | |
313 } | |
314 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
315 |
0 | 316 return DMERR_OK; |
317 } | |
318 | |
319 | |
320 /* Convert a pattern | |
321 */ | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
322 static int jssConvertPatternRawHoriz( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
323 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
324 size_t *patSize, const JSSPattern *pattern) |
0 | 325 { |
326 int row, channel; | |
327 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
328 |
0 | 329 for (row = 0; row < pattern->nrows; row++) |
330 for (channel = 0; channel < pattern->nchannels; channel++) | |
331 { | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
332 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
333 const int res = jssConvertNote(patBuf, patBufSize, patSize, pnote); |
0 | 334 if (res != DMERR_OK) |
335 { | |
336 JSSERROR(res, res, "Note conversion failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
337 patBuf, patBufSize, *patSize, row, channel); | |
338 return res; | |
339 } | |
340 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
341 |
0 | 342 return DMERR_OK; |
343 } | |
344 | |
345 | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
346 static int jssConvertPatternRawVert( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
347 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
348 size_t *patSize, const JSSPattern *pattern) |
0 | 349 { |
350 int row, channel; | |
351 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
352 |
0 | 353 for (channel = 0; channel < pattern->nchannels; channel++) |
354 for (row = 0; row < pattern->nrows; row++) | |
355 { | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
356 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
357 const int res = jssConvertNote(patBuf, patBufSize, patSize, pnote); |
0 | 358 if (res != DMERR_OK) |
359 { | |
360 JSSERROR(res, res, "Note conversion failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
361 patBuf, patBufSize, *patSize, row, channel); | |
362 return res; | |
363 } | |
364 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
365 |
0 | 366 return DMERR_OK; |
367 } | |
368 | |
369 | |
370 #define JSFOREACHNOTE1 \ | |
371 for (channel = 0; channel < pattern->nchannels; channel++) \ | |
372 for (row = 0; row < pattern->nrows; row++) { \ | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
373 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
0 | 374 |
375 #define JSFOREACHNOTE2 } | |
376 | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
377 static int jssConvertPatternRawElem( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
378 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
379 size_t *patSize, const JSSPattern *pattern) |
0 | 380 { |
381 Uint8 tmp; | |
382 int row, channel; | |
383 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
384 |
0 | 385 JSFOREACHNOTE1; |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
386 if (pnote->note == jsetNotSet) |
0 | 387 tmp = 0; |
1194 | 388 else |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
389 if (pnote->note == jsetNoteOff) |
0 | 390 tmp = 127; |
391 else | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
392 tmp = pnote->note + 1; |
1194 | 393 |
0 | 394 if (tmp > 0x7f) |
395 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Note value out of bounds %d > 0x7f.\n", tmp); | |
1194 | 396 |
0 | 397 JSPUTBYTE(tmp); |
398 JSFOREACHNOTE2; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
399 |
0 | 400 JSFOREACHNOTE1; |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
401 JSCONVPUT(pnote->instrument, "Instrument"); |
0 | 402 JSFOREACHNOTE2; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
403 |
0 | 404 JSFOREACHNOTE1; |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
405 JSCONVPUT(pnote->volume, "Volume"); |
0 | 406 JSFOREACHNOTE2; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
407 |
0 | 408 JSFOREACHNOTE1; |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
409 JSCONVPUT(pnote->effect, "Effect"); |
0 | 410 JSFOREACHNOTE2; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
411 |
0 | 412 JSFOREACHNOTE1; |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
413 tmp = (pnote->param != jsetNotSet) ? pnote->param : 0; |
338
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
414 JSPUTBYTE(tmp); |
0 | 415 JSFOREACHNOTE2; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
416 |
0 | 417 return DMERR_OK; |
418 } | |
419 | |
420 #undef JSFOREACHNOTE1 | |
421 #undef JSFOREACHNOTE2 | |
422 | |
423 | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
424 static BOOL jssMODWriteEnvelope(FILE *outFile, JSSEnvelope *env, const char *name, const int ninst) |
0 | 425 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
426 BOOL ok = |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
427 dm_fwrite_byte(outFile, env->flags) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
428 dm_fwrite_byte(outFile, env->npoints) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
429 dm_fwrite_byte(outFile, env->sustain) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
430 dm_fwrite_byte(outFile, env->loopS) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
431 dm_fwrite_byte(outFile, env->loopE); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
432 |
1313 | 433 for (int i = 0; ok && i < env->npoints; i++) |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
434 { |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
435 ok = |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
436 dm_fwrite_le16(outFile, env->points[i].frame) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
437 dm_fwrite_le16(outFile, env->points[i].value); |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
438 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
439 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
440 if (!ok) |
0 | 441 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
442 JSSERROR(DMERR_FWRITE, ok, |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
443 "Failed to write JSSMOD %s-envelope for instrument #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
444 name, ninst); |
0 | 445 } |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
446 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
447 return ok; |
0 | 448 } |
449 | |
450 | |
451 /* Save a JSSMOD file | |
452 */ | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
453 int jssSaveJSSMOD(FILE *outFile, JSSModule *module, int patMode, int flags8, int flags16) |
0 | 454 { |
455 JSSMODHeader jssH; | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
456 const size_t patBufSize = 256*1024; // 256kB pattern buffer |
0 | 457 Uint8 *patBuf; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
458 size_t totalSize; |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
459 int index; |
0 | 460 |
461 // Check the module | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
462 if (module == NULL) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
463 { |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
464 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
465 "Module pointer was NULL\n"); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
466 } |
0 | 467 |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
468 if (module->nchannels < 1 || module->npatterns < 1 || module->norders < 1 || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
469 module->nchannels > jsetMaxChannels || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
470 module->npatterns > jsetMaxPatterns || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
471 module->norders > jsetMaxOrders) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
472 { |
0 | 473 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, |
1195
4d27c4ec8d4d
Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents:
1194
diff
changeset
|
474 "Module had invalid values (nchannels=%d, npatterns=%d, norders=%d)\n", |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
475 module->nchannels, module->npatterns, module->norders); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
476 } |
0 | 477 |
478 // Create the JSSMOD header | |
479 jssH.idMagic[0] = 'J'; | |
480 jssH.idMagic[1] = 'M'; | |
481 jssH.idVersion = JSSMOD_VERSION; | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
482 jssH.defFlags = module->defFlags; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
483 jssH.intVersion = module->intVersion; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
484 jssH.norders = module->norders; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
485 jssH.npatterns = module->npatterns; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
486 jssH.nextInstruments = module->nextInstruments; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
487 jssH.ninstruments = module->ninstruments; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
488 jssH.defRestartPos = module->defRestartPos; |
1231 | 489 |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
490 jssH.nchannels = module->nchannels; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
491 jssH.defSpeed = module->defSpeed; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
492 jssH.defTempo = module->defTempo; |
0 | 493 jssH.patMode = patMode; |
1209 | 494 |
0 | 495 // Write header |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
496 if (!dm_fwrite_str(outFile, jssH.idMagic, sizeof(jssH.idMagic)) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
497 !dm_fwrite_byte(outFile, jssH.idVersion) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
498 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
499 !dm_fwrite_le16(outFile, jssH.defFlags) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
500 !dm_fwrite_le16(outFile, jssH.intVersion) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
501 !dm_fwrite_le16(outFile, jssH.norders) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
502 !dm_fwrite_le16(outFile, jssH.npatterns) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
503 !dm_fwrite_le16(outFile, jssH.nextInstruments) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
504 !dm_fwrite_le16(outFile, jssH.ninstruments) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
505 !dm_fwrite_le16(outFile, jssH.defRestartPos) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
506 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
507 !dm_fwrite_byte(outFile, jssH.nchannels) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
508 !dm_fwrite_byte(outFile, jssH.defSpeed) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
509 !dm_fwrite_byte(outFile, jssH.defTempo) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
510 !dm_fwrite_byte(outFile, jssH.patMode)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
511 { |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
512 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1245
2a0488078b78
Cleanups, more consistent error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1244
diff
changeset
|
513 "Error writing JSSMOD header!\n"); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
514 } |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
515 |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
516 totalSize = sizeof(jssH); |
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
517 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
|
518 |
0 | 519 // Write orders list |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
520 for (totalSize = index = 0; index < module->norders; index++) |
0 | 521 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
522 int tmp = module->orderList[index]; |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
523 if (tmp != jsetNotSet && tmp > module->npatterns) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
524 { |
1237
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
525 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
526 "Orderlist entry #%d has invalid value %d.\n", |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
527 index, tmp); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
528 } |
1237
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
529 |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
530 if (tmp == jsetNotSet) |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
531 tmp = 0xffff; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
532 |
1237
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
533 if (!dm_fwrite_le16(outFile, tmp)) |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
534 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
535 "Could not write JSSMOD orders list entry #%d (%d).\n", |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
536 index, tmp); |
1237
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
537 |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
538 totalSize += sizeof(Uint16); |
0 | 539 } |
540 | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
541 dmMsg(1," * %d item orders list, %d bytes.\n", |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
542 module->norders, totalSize); |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
543 |
0 | 544 // Allocate pattern compression buffer |
545 if ((patBuf = dmMalloc(patBufSize)) == NULL) | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
546 { |
0 | 547 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
548 "Error allocating memory for pattern compression buffer.\n"); | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
549 } |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
550 |
1232 | 551 // Convert and write patterns |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
552 for (totalSize = index = 0; index < module->npatterns; index++) |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
553 if (module->patterns[index] != NULL) |
0 | 554 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
555 JSSPattern *pattern = module->patterns[index]; |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
556 size_t dataSize = 0; |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
557 int ret; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
558 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
559 if (pattern->nrows > jsetMaxRows) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
560 { |
1232 | 561 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
562 "Pattern #%d has %d rows > %d max.\n", | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
563 index, pattern->nrows, jsetMaxRows); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
564 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
565 |
0 | 566 switch (patMode) |
567 { | |
568 case PATMODE_RAW_HORIZ: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
569 ret = jssConvertPatternRawHoriz(patBuf, patBufSize, &dataSize, pattern); |
0 | 570 break; |
571 case PATMODE_COMP_HORIZ: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
572 ret = jssConvertPatternCompHoriz(patBuf, patBufSize, &dataSize, pattern); |
0 | 573 break; |
574 case PATMODE_RAW_VERT: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
575 ret = jssConvertPatternRawVert(patBuf, patBufSize, &dataSize, pattern); |
0 | 576 break; |
577 case PATMODE_COMP_VERT: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
578 ret = jssConvertPatternCompVert(patBuf, patBufSize, &dataSize, pattern); |
0 | 579 break; |
580 case PATMODE_RAW_ELEM: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
581 ret = jssConvertPatternRawElem(patBuf, patBufSize, &dataSize, pattern); |
0 | 582 break; |
583 default: | |
584 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1245
2a0488078b78
Cleanups, more consistent error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1244
diff
changeset
|
585 "Unsupported pattern conversion mode %d for pattern #%d.\n", |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
586 patMode, index); |
0 | 587 } |
588 | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
589 if (ret != DMERR_OK) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
590 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
591 JSSERROR(ret, ret, "Error converting pattern data #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
592 pattern); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
593 } |
1211 | 594 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
595 dmMsg(3, " - Pattern %d size %d bytes\n", index, dataSize); |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
596 totalSize += dataSize + sizeof(JSSMODPattern); |
0 | 597 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
598 if (!dm_fwrite_le32(outFile, dataSize) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
599 !dm_fwrite_le16(outFile, pattern->nrows) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
600 !dm_fwrite_str(outFile, patBuf, dataSize)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
601 { |
1211 | 602 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
603 "Error writing JSSMOD pattern #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
604 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
605 } |
0 | 606 } |
1242 | 607 else |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
608 { |
1242 | 609 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
610 "Pattern #%d was NULL.\n", index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
611 } |
1242 | 612 |
0 | 613 dmFree(patBuf); |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
614 dmMsg(1," * %d patterns, %d bytes.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
615 module->npatterns, totalSize); |
0 | 616 |
617 // Write extended instruments | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
618 for (totalSize = index = 0; index < module->nextInstruments; index++) |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
619 if (module->extInstruments[index] != NULL) |
0 | 620 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
621 JSSExtInstrument *einst = module->extInstruments[index]; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
622 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
623 BOOL ok = |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
624 dm_fwrite_byte(outFile, einst->nsamples) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
625 dm_fwrite_byte(outFile, einst->vibratoType) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
626 dm_fwrite_le16(outFile, einst->vibratoSweep) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
627 dm_fwrite_le16(outFile, einst->vibratoDepth) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
628 dm_fwrite_le16(outFile, einst->vibratoRate) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
629 dm_fwrite_le16(outFile, einst->fadeOut); |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
630 |
1313 | 631 for (int i = 0; ok && i < jsetNNotes; i++) |
0 | 632 { |
1242 | 633 int snum = einst->sNumForNotes[i]; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
634 Uint32 tmp = (snum != jsetNotSet) ? snum + 1 : 0; |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
635 ok = dm_fwrite_le32(outFile, tmp); |
1242 | 636 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
637 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
638 if (!ok || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
639 !jssMODWriteEnvelope(outFile, &einst->volumeEnv, "volume", index) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
640 !jssMODWriteEnvelope(outFile, &einst->panningEnv, "panning", index)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
641 { |
0 | 642 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
643 "Error writing JSSMOD extended instrument #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
644 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
645 } |
0 | 646 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
647 totalSize += sizeof(JSSMODExtInstrument); |
0 | 648 } |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
649 else |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
650 { |
1245
2a0488078b78
Cleanups, more consistent error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1244
diff
changeset
|
651 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
652 "Extended instrument #%d NULL!\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
653 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
654 } |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
655 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
656 dmMsg(1," * %d Extended Instruments, %d bytes.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
657 module->nextInstruments, totalSize); |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
658 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
659 // Write sample instrument headers |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
660 for (totalSize = index = 0; index < module->ninstruments; index++) |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
661 if (module->instruments[index] != NULL) |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
662 { |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
663 JSSInstrument *inst = module->instruments[index]; |
1315
7687412f9aef
Fix jssmod sample conversion flags storing .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
1313
diff
changeset
|
664 inst->convFlags = (inst->flags & jsf16bit) ? flags16 : flags8; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
665 if (inst->data != NULL) |
1315
7687412f9aef
Fix jssmod sample conversion flags storing .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
1313
diff
changeset
|
666 inst->convFlags |= jsampHasData; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
667 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
668 // Write instrument header to file |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
669 if (!dm_fwrite_le32(outFile, inst->size) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
670 !dm_fwrite_le32(outFile, inst->loopS) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
671 !dm_fwrite_le32(outFile, inst->loopE) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
672 !dm_fwrite_le16(outFile, inst->flags) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
673 !dm_fwrite_le16(outFile, inst->C4BaseSpeed) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
674 !dm_fwrite_le16(outFile, inst->ERelNote) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
675 !dm_fwrite_le16(outFile, inst->EFineTune) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
676 !dm_fwrite_le16(outFile, inst->EPanning) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
677 !dm_fwrite_byte(outFile, inst->volume) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
678 !dm_fwrite_byte(outFile, inst->convFlags)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
679 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
680 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
681 "Error writing JSSMOD instrument #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
682 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
683 } |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
684 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
685 totalSize += sizeof(JSSMODInstrument); |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
686 } |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
687 else |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
688 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
689 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
690 "Instrument #%d NULL!\n", index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
691 } |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
692 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
693 dmMsg(1," * %d Instrument headers, %d bytes.\n", |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
694 module->ninstruments, totalSize); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
695 |
0 | 696 // Write sample data |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
697 for (totalSize = index = 0; index < module->ninstruments; index++) |
0 | 698 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
699 JSSInstrument *inst = module->instruments[index]; |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
700 if (inst != NULL && inst->data != NULL) |
0 | 701 { |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
702 size_t bsize = inst->size; |
0 | 703 if (inst->flags & jsf16bit) |
704 { | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
705 bsize *= sizeof(Uint16); |
0 | 706 jssEncodeSample16(inst->data, inst->size, flags16); |
707 } | |
708 else | |
709 { | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
710 bsize *= sizeof(Uint8); |
0 | 711 jssEncodeSample8(inst->data, inst->size, flags8); |
712 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
713 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
714 if (!dm_fwrite_str(outFile, inst->data, bsize)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
715 { |
0 | 716 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
717 "Error writing JSSMOD sample data for instrument #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
718 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
719 } |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
720 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
721 totalSize += bsize; |
0 | 722 } |
723 } | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
724 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
725 dmMsg(1," * %d samples, %d bytes.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
726 module->ninstruments, totalSize); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
727 |
0 | 728 return DMERR_OK; |
729 } | |
730 | |
731 | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
732 /* Scan given pattern for used instruments and channels. |
1313 | 733 * Also checks if the pattern is empty. |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
734 */ |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
735 void scanPattern(JSSModule *module, JSSPattern *pattern, int npattern, BOOL *usedExtInstruments, BOOL *usedChannels, BOOL *empty) |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
736 { |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
737 JSSNote *n = pattern->data; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
738 *empty = FALSE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
739 |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
740 // Check all notes in this pattern to see what instruments are used |
1313 | 741 for (int row = 0; row < pattern->nrows; row++) |
742 for (int channel = 0; channel < pattern->nchannels; channel++, n++) | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
743 { |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
744 if (n->instrument != jsetNotSet) |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
745 { |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
746 if (n->instrument >= 0 && n->instrument < module->nextInstruments) |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
747 usedExtInstruments[n->instrument] = TRUE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
748 else |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
749 { |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
750 dmMsg(2, "Pattern 0x%x, row=0x%x, chn=%d has invalid instrument 0x%x\n", |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
751 npattern + 1, row, channel, n->instrument + 1); |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
752 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
753 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
754 |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
755 if (n->note != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
756 n->instrument != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
757 n->volume != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
758 n->effect != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
759 n->param != jsetNotSet) |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
760 { |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
761 usedChannels[channel] = TRUE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
762 *empty = FALSE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
763 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
764 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
765 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
766 |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
767 |
1317
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
768 /* Check if two given patterns are dupes |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
769 */ |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
770 BOOL comparePattern(const JSSPattern *pat1, const JSSPattern *pat2) |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
771 { |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
772 return |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
773 pat1->nrows == pat2->nrows && |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
774 pat1->nchannels == pat2->nchannels && |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
775 memcmp(pat1->data, pat2->data, sizeof(JSSNote) * pat1->nrows * pat1->nchannels) == 0; |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
776 } |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
777 |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
778 |
0 | 779 /* Optimize a given module |
780 */ | |
781 JSSModule *optimizeModule(JSSModule *m) | |
782 { | |
783 BOOL usedPatterns[jsetMaxPatterns + 1], | |
784 usedInstruments[jsetMaxInstruments + 1], | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
785 usedExtInstruments[jsetMaxInstruments + 1], |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
786 usedChannels[jsetMaxChannels]; |
0 | 787 int mapExtInstruments[jsetMaxInstruments + 1], |
788 mapInstruments[jsetMaxInstruments + 1], | |
789 mapPatterns[jsetMaxPatterns + 1]; | |
790 JSSModule *r = NULL; | |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
791 int i, n8, n16, unused; |
0 | 792 |
793 // Allocate a new module | |
794 if ((r = jssAllocateModule()) == NULL) | |
795 return NULL; | |
796 | |
797 // Copy things | |
798 r->moduleType = m->moduleType; | |
799 r->moduleName = dm_strdup(m->moduleName); | |
800 r->trackerName = dm_strdup(m->trackerName); | |
801 r->defSpeed = m->defSpeed; | |
802 r->defTempo = m->defTempo; | |
803 r->defFlags = m->defFlags; | |
804 r->defRestartPos = m->defRestartPos; | |
805 r->intVersion = m->intVersion; | |
806 r->nchannels = m->nchannels; | |
807 r->norders = m->norders; | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
808 |
0 | 809 for (i = 0; i < jsetNChannels; i++) |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
810 { |
0 | 811 r->defPanning[i] = m->defPanning[i]; |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
812 usedChannels[i] = FALSE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
813 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
814 |
0 | 815 // Initialize values |
816 for (i = 0; i <= jsetMaxInstruments; i++) | |
817 { | |
818 usedExtInstruments[i] = FALSE; | |
798 | 819 usedInstruments[i] = FALSE; |
820 mapExtInstruments[i] = jsetNotSet; | |
821 mapInstruments[i] = jsetNotSet; | |
0 | 822 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
823 |
0 | 824 for (i = 0; i <= jsetMaxPatterns; i++) |
825 { | |
826 usedPatterns[i] = FALSE; | |
798 | 827 mapPatterns[i] = jsetNotSet; |
0 | 828 } |
829 | |
1094 | 830 // |
798 | 831 // Find out all actually used patterns and ext.instruments |
1100 | 832 // by going through all patterns specified in the order list |
1094 | 833 // |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
834 dmMsg(1, "Scanning patterns for used instruments and channels...\n"); |
0 | 835 for (i = 0; i < m->norders; i++) |
836 { | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
837 int npat = m->orderList[i]; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
838 if (npat >= 0 && npat < m->npatterns) |
0 | 839 { |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
840 JSSPattern *pattern = m->patterns[npat]; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
841 if (pattern != NULL) |
0 | 842 { |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
843 BOOL empty; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
844 |
1100 | 845 // Mark this pattern as used |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
846 usedPatterns[npat] = TRUE; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
847 |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
848 // Scan for used instruments and channels |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
849 scanPattern(m, pattern, npat, usedExtInstruments, usedChannels, &empty); |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
850 |
1249 | 851 // Empty patterns with known number of rows are "removed" |
852 if (empty && pattern->nrows == jsetDefaultRows) | |
0 | 853 { |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
854 m->orderList[i] = jsetNotSet; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
855 usedPatterns[npat] = FALSE; |
0 | 856 } |
857 } | |
858 else | |
859 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
860 dmErrorMsg("Pattern 0x%x is used on order 0x%x, but has no data!\n", |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
861 npat, i); |
807
d83dc7e47076
Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents:
798
diff
changeset
|
862 |
d83dc7e47076
Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents:
798
diff
changeset
|
863 // Fix it. |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
864 m->orderList[i] = jsetNotSet; |
0 | 865 } |
866 } | |
867 else | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
868 if (npat != jsetNotSet) |
0 | 869 { |
1101 | 870 dmErrorMsg("Order 0x%x has invalid pattern number 0x%x, changing to empty!\n", |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
871 i, npat); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
872 |
807
d83dc7e47076
Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents:
798
diff
changeset
|
873 // Fix it. |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
874 m->orderList[i] = jsetNotSet; |
0 | 875 } |
876 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
877 |
1094 | 878 // |
1100 | 879 // Find used sample instruments |
1094 | 880 // |
1101 | 881 dmMsg(1, "Checking ext.instruments for used sample instruments...\n"); |
856
415cc781e127
Fix some brain farts in instrument remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
807
diff
changeset
|
882 for (i = 0; i < jsetMaxInstruments; i++) |
0 | 883 if (usedExtInstruments[i] && m->extInstruments[i] != NULL) |
884 { | |
885 int note; | |
886 JSSExtInstrument *e = m->extInstruments[i]; | |
1094 | 887 |
0 | 888 for (note = 0; note < jsetNNotes; note++) |
889 if (e->sNumForNotes[note] != jsetNotSet) | |
890 { | |
891 int q = e->sNumForNotes[note]; | |
892 if (q >= 0 && q < m->ninstruments) | |
893 { | |
894 usedInstruments[q] = TRUE; | |
895 } | |
896 else | |
897 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
898 dmErrorMsg("Ext.instrument #%d sNumForNotes[%d] value out range (%d < %d).\n", |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
899 i + 1, m->ninstruments, q + 1); |
0 | 900 } |
901 } | |
902 } | |
1094 | 903 |
904 // | |
0 | 905 // Create pattern mappings |
1094 | 906 // |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
907 dmMsg(1, "Creating pattern remaps...\n"); |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
908 for (unused = i = 0; i <= jsetMaxPatterns; i++) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
909 if (usedPatterns[i]) |
0 | 910 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
911 JSSPattern *pat; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
912 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
913 if (i >= m->npatterns) |
0 | 914 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
915 dmErrorMsg("Pattern 0x%x >= 0x%x, but used!\n", i, m->npatterns); |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
916 continue; |
0 | 917 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
918 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
919 if ((pat = m->patterns[i]) == NULL) |
0 | 920 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
921 dmErrorMsg("Pattern 0x%x used but is NULL.\n", i); |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
922 continue; |
0 | 923 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
924 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
925 mapPatterns[i] = r->npatterns; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
926 r->patterns[r->npatterns] = m->patterns[i]; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
927 (r->npatterns)++; |
0 | 928 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
929 else |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
930 if (m->patterns[i] != NULL) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
931 unused++; |
1094 | 932 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
933 dmMsg(1, "%d used patterns (%d unused).\n", |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
934 r->npatterns, unused); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
935 |
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
936 |
1094 | 937 // |
0 | 938 // Re-map instruments |
1094 | 939 // |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
940 dmMsg(1, "Creating sample instrument remaps...\n"); |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
941 for (unused = n8 = n16 = i = 0; i < jsetMaxInstruments; i++) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
942 if (usedInstruments[i]) |
0 | 943 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
944 JSSInstrument *ip; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
945 if (optStripInstr) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
946 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
947 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
948 if (i >= m->ninstruments) |
0 | 949 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
950 dmErrorMsg("Instrument 0x%x >= 0x%x, but used!\n", |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
951 i + 1, m->ninstruments); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
952 continue; |
0 | 953 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
954 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
955 if ((ip = m->instruments[i]) == NULL) |
0 | 956 { |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
957 dmErrorMsg("Instrument 0x%x used but is NULL.\n", i + 1); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
958 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
959 } |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
960 |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
961 dmPrint(2, "%02x -> %02x : ", i + 1, r->ninstruments + 1); |
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
962 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
963 mapInstruments[i] = r->ninstruments; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
964 r->instruments[r->ninstruments] = ip; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
965 (r->ninstruments)++; |
0 | 966 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
967 if (ip->flags & jsf16bit) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
968 n16++; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
969 else |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
970 n8++; |
0 | 971 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
972 else |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
973 if (m->instruments[i] != NULL) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
974 unused++; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
975 |
0 | 976 dmPrint(2, "\n"); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
977 dmMsg(1, "Total of %d [16-bit] + %d [8-bit] samples = %d instruments (%d unused).\n", |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
978 n16, n8, r->ninstruments, unused); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
979 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
980 // |
0 | 981 // Re-map ext.instruments |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
982 // |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
983 dmMsg(1, "Creating ext.instrument remaps...\n"); |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
984 for (unused = i = 0; i < jsetMaxInstruments; i++) |
0 | 985 if (usedExtInstruments[i]) |
986 { | |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
987 JSSExtInstrument *eip; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
988 int note; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
989 if (optStripExtInstr) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
990 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
991 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
992 if (i >= m->nextInstruments) |
0 | 993 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
994 dmErrorMsg("Ext.instrument 0x%x >= 0x%x, but used!\n", |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
995 i + 1, m->nextInstruments); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
996 continue; |
0 | 997 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
998 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
999 if ((eip = m->extInstruments[i]) == NULL) |
0 | 1000 { |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1001 dmErrorMsg("Extended instrument 0x%x used but is NULL.\n", i + 1); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1002 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1003 } |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1004 |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1005 dmPrint(2, "%02x -> %02x : ", i + 1, r->nextInstruments + 1); |
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1006 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1007 mapExtInstruments[i] = r->nextInstruments; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1008 r->extInstruments[r->nextInstruments] = eip; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1009 (r->nextInstruments)++; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1010 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1011 // Re-map sNumForNotes table for this ext.instrument |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1012 for (note = 0; note < jsetNNotes; note++) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1013 { |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1014 int q = eip->sNumForNotes[note]; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1015 if (q != jsetNotSet) |
0 | 1016 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1017 int map; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1018 if (q >= 0 && q < jsetMaxInstruments) |
0 | 1019 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1020 map = mapInstruments[q]; |
0 | 1021 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1022 else |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1023 { |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1024 map = jsetNotSet; |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1025 dmErrorMsg("Einst=%d, note=%d, sNumForNote=%d (%d max)\n", |
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1026 i + 1, note, q + 1, r->ninstruments); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1027 } |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1028 |
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1029 dmPrint(3, "%02x.%02x ", q + 1, map + 1); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1030 eip->sNumForNotes[note] = map; |
0 | 1031 } |
1032 } | |
1033 } | |
1034 else | |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1035 if (m->extInstruments[i] != NULL) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1036 unused++; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1037 |
0 | 1038 dmPrint(2, "\n"); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1039 dmMsg(1, "%d extended instruments (%d unused).\n", |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1040 r->nextInstruments, unused); |
1094 | 1041 |
1042 // | |
1043 // Remap pattern data with remapped instrument data | |
1044 // | |
0 | 1045 for (i = 0; i < r->npatterns; i++) |
1046 { | |
1047 int row, channel; | |
1048 JSSPattern *p = r->patterns[i]; | |
1049 JSSNote *n = p->data; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1050 |
0 | 1051 for (row = 0; row < p->nrows; row++) |
1052 for (channel = 0; channel < p->nchannels; channel++, n++) | |
1053 { | |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1054 char effect; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1055 |
1109 | 1056 // If not stripping extended instruments, check for |
1057 // the validity of the used instrument and remap | |
338
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
1058 if (!optStripExtInstr) |
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
1059 { |
856
415cc781e127
Fix some brain farts in instrument remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
807
diff
changeset
|
1060 if (n->instrument >= 0 && n->instrument < jsetMaxInstruments) |
338
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
1061 n->instrument = mapExtInstruments[n->instrument]; |
202
85614db5f577
Warn about invalid instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1062 |
1116 | 1063 if (n->instrument != jsetNotSet && |
1064 r->extInstruments[n->instrument] == NULL) | |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1065 { |
1116 | 1066 dmErrorMsg("Non-existing instrument used #%d, INTERNAL ERROR.\n", |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1067 n->instrument + 1); |
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1068 } |
338
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
1069 } |
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
1070 |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1071 JMPGETEFFECT(effect, n->effect); |
1094 | 1072 |
1313 | 1073 // Convert certain effects |
184
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1074 switch (effect) |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1075 { |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1076 case 'C': // Cxx = Set volume |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1077 if (n->volume == jsetNotSet) |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1078 { |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1079 n->volume = n->param; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1080 n->effect = jsetNotSet; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1081 n->param = jsetNotSet; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1082 } |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1083 break; |
50f55def91e5
Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1084 } |
0 | 1085 } |
1086 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1087 |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1088 // |
1317
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1089 // Check for duplicate patterns .. |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1090 // |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1091 dmMsg(1, "Checking for duplicate patterns ...\n"); |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1092 for (int pat1 = 0; pat1 < r->npatterns; pat1++) |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1093 for (int pat2 = 0; pat2 < r->npatterns; pat2++) |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1094 if (pat1 != pat2 && comparePattern(r->patterns[pat1], r->patterns[pat2])) |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1095 { |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1096 dmPrint(1, " * %d and %d are dupes.\n"); |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1097 } |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1098 |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
1099 // |
0 | 1100 // Remap orders list |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1101 // |
0 | 1102 for (i = 0; i < m->norders; i++) |
1103 { | |
1104 r->orderList[i] = mapPatterns[m->orderList[i]]; | |
1105 } | |
1106 | |
1107 return r; | |
1108 } | |
1109 | |
1110 | |
1111 int main(int argc, char *argv[]) | |
1112 { | |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1113 DMResource *inFile = NULL; |
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1114 FILE *outFile = NULL; |
0 | 1115 JSSModule *sm, *dm; |
1116 int result; | |
1117 | |
1118 dmInitProg("xm2jss", "XM to JSSMOD converter", "0.6", NULL, NULL); | |
1119 dmVerbosity = 0; | |
1120 | |
1121 // Parse arguments | |
1122 if (!dmArgsProcess(argc, argv, optList, optListN, | |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
856
diff
changeset
|
1123 argHandleOpt, argHandleFile, OPTH_BAILOUT)) |
0 | 1124 exit(1); |
1125 | |
300 | 1126 // Check arguments |
1127 if (optInFilename == NULL || optOutFilename == NULL) | |
1128 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
1129 dmErrorMsg("Input or output file not specified. Try --help.\n"); |
300 | 1130 return 1; |
1131 } | |
0 | 1132 |
1133 // Read the source file | |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1134 if ((result = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) |
0 | 1135 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
1136 dmErrorMsg("Error opening input file '%s', %d: %s\n", |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1137 optInFilename, result, dmErrorStr(result)); |
0 | 1138 return 1; |
1139 } | |
1140 | |
1141 // Initialize miniJSS | |
1142 jssInit(); | |
1143 | |
1144 // Read file | |
1145 dmMsg(1, "Reading XM-format file ...\n"); | |
797
f066e9dccf29
Oops, fix some inverted booleans.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1146 result = jssLoadXM(inFile, &sm, FALSE); |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1147 dmf_close(inFile); |
0 | 1148 if (result != 0) |
1149 { | |
1195
4d27c4ec8d4d
Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents:
1194
diff
changeset
|
1150 dmErrorMsg("Error while loading XM file (%d), ", result); |
0 | 1151 if (optIgnoreErrors) |
1152 fprintf(stderr, "ignoring. This may cause problems.\n"); | |
1153 else | |
1154 { | |
1155 fprintf(stderr, "giving up. Use --ignore if you want to try to convert anyway.\n"); | |
1156 return 2; | |
1157 } | |
1158 } | |
1159 | |
1160 // Check stripping settings | |
1161 if (optStripExtInstr) optStripInstr = TRUE; | |
1162 if (optStripInstr) optStripSamples = TRUE; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1163 |
0 | 1164 // Remove samples |
1165 if (optStripSamples) | |
1166 { | |
1167 int i; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1168 |
0 | 1169 dmMsg(1, "Stripping samples...\n"); |
1170 for (i = 0; i < sm->ninstruments; i++) | |
1171 { | |
1172 dmFree(sm->instruments[i]->data); | |
1173 sm->instruments[i]->data = NULL; | |
1174 } | |
1175 } | |
1176 | |
1177 // Remove instruments | |
1178 if (optStripInstr) | |
1179 { | |
1180 int i; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1181 |
0 | 1182 dmMsg(1, "Stripping instruments...\n"); |
1183 for (i = 0; i < sm->ninstruments; i++) | |
1184 { | |
1185 dmFree(sm->instruments[i]); | |
1186 sm->instruments[i] = NULL; | |
1187 } | |
1188 sm->ninstruments = 0; | |
1189 } | |
1190 | |
1191 // Remove ext.instruments | |
1192 if (optStripExtInstr) | |
1193 { | |
1194 int i; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1195 |
0 | 1196 dmMsg(1, "Stripping ext.instruments...\n"); |
1197 for (i = 0; i < sm->nextInstruments; i++) | |
1198 { | |
1199 dmFree(sm->extInstruments[i]); | |
1200 sm->extInstruments[i] = NULL; | |
1201 } | |
1202 sm->nextInstruments = 0; | |
1203 } | |
1109 | 1204 |
0 | 1205 // Run the optimization procedure |
1206 if (optOptimize) | |
1207 { | |
1208 dmMsg(1, "Optimizing module data...\n"); | |
1209 dm = optimizeModule(sm); | |
1210 } else | |
1211 dm = sm; | |
1212 | |
1213 // Write output file | |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1214 if ((outFile = fopen(optOutFilename, "wb")) == NULL) |
0 | 1215 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
1216 dmErrorMsg("Error creating output file '%s', %d: %s\n", |
300 | 1217 optOutFilename, errno, strerror(errno)); |
0 | 1218 return 1; |
1219 } | |
1220 | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1221 dmMsg(1, "Writing JSSMOD-format file [patMode=0x%04x, samp8=0x%02x, samp16=0x%02x]\n", |
0 | 1222 optPatternMode, optSampMode8, optSampMode16); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1223 |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1224 result = jssSaveJSSMOD(outFile, dm, optPatternMode, optSampMode8, optSampMode16); |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1225 |
1114
7aaab1533c90
Free the source module data at end.
Matti Hamalainen <ccr@tnsp.org>
parents:
1113
diff
changeset
|
1226 dmFree(sm); |
7aaab1533c90
Free the source module data at end.
Matti Hamalainen <ccr@tnsp.org>
parents:
1113
diff
changeset
|
1227 |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1228 fclose(outFile); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1229 |
0 | 1230 if (result != 0) |
1231 { | |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1232 dmErrorMsg( |
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1233 "Error while saving JSSMOD file, %d: %s\n" |
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1234 "WARNING: The resulting file may be broken!\n", |
300 | 1235 result, dmErrorStr(result)); |
0 | 1236 } |
300 | 1237 else |
1238 { | |
1239 dmMsg(1, "Conversion complete.\n"); | |
1240 } | |
0 | 1241 return 0; |
1242 } |