Mercurial > hg > dmlib
annotate tools/xm2jss.c @ 1975:0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 01 Jul 2018 02:34:52 +0300 |
parents | cedb5ca1533b |
children | c0b062f881e5 |
rev | line source |
---|---|
0 | 1 /* |
2 * xm2jss - Convert XM module to JSSMOD | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1333
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
4 * (C) Copyright 2006-2017 Tecnic Software productions (TNSP) |
0 | 5 * |
6 * Please read file 'COPYING' for information on license and distribution. | |
7 */ | |
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
1431
diff
changeset
|
8 #include "dmtool.h" |
0 | 9 #include <stdio.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 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
277 |
1336 | 278 for (int row = 0; row < pattern->nrows; row++) |
279 for (int channel = 0; channel < pattern->nchannels; channel++) | |
0 | 280 { |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
281 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
282 const int res = jssCompressNote(patBuf, patBufSize, patSize, pnote); |
0 | 283 if (res != DMERR_OK) |
284 { | |
285 JSSERROR(res, res, "Note compression failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
286 patBuf, patBufSize, *patSize, row, channel); | |
287 return res; | |
288 } | |
289 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
290 |
0 | 291 return DMERR_OK; |
292 } | |
293 | |
294 | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
295 static int jssConvertPatternCompVert( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
296 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
297 size_t *patSize, const JSSPattern *pattern) |
0 | 298 { |
299 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
300 |
1336 | 301 for (int channel = 0; channel < pattern->nchannels; channel++) |
302 for (int row = 0; row < pattern->nrows; row++) | |
0 | 303 { |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
304 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
305 const int res = jssCompressNote(patBuf, patBufSize, patSize, pnote); |
0 | 306 if (res != DMERR_OK) |
307 { | |
308 JSSERROR(res, res, "Note compression failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
309 patBuf, patBufSize, *patSize, row, channel); | |
310 return res; | |
311 } | |
312 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
313 |
0 | 314 return DMERR_OK; |
315 } | |
316 | |
317 | |
318 /* Convert a pattern | |
319 */ | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
320 static int jssConvertPatternRawHoriz( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
321 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
322 size_t *patSize, const JSSPattern *pattern) |
0 | 323 { |
324 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
325 |
1336 | 326 for (int row = 0; row < pattern->nrows; row++) |
327 for (int channel = 0; channel < pattern->nchannels; channel++) | |
0 | 328 { |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
329 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
330 const int res = jssConvertNote(patBuf, patBufSize, patSize, pnote); |
0 | 331 if (res != DMERR_OK) |
332 { | |
333 JSSERROR(res, res, "Note conversion failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
334 patBuf, patBufSize, *patSize, row, channel); | |
335 return res; | |
336 } | |
337 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
338 |
0 | 339 return DMERR_OK; |
340 } | |
341 | |
342 | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
343 static int jssConvertPatternRawVert( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
344 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
345 size_t *patSize, const JSSPattern *pattern) |
0 | 346 { |
347 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
348 |
1336 | 349 for (int channel = 0; channel < pattern->nchannels; channel++) |
350 for (int row = 0; row < pattern->nrows; row++) | |
0 | 351 { |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
352 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
353 const int res = jssConvertNote(patBuf, patBufSize, patSize, pnote); |
0 | 354 if (res != DMERR_OK) |
355 { | |
356 JSSERROR(res, res, "Note conversion failed [patBuf=%p, patBufSize=%d, patSize=%d, row=%d, chn=%d]\n", | |
357 patBuf, patBufSize, *patSize, row, channel); | |
358 return res; | |
359 } | |
360 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
361 |
0 | 362 return DMERR_OK; |
363 } | |
364 | |
365 | |
366 #define JSFOREACHNOTE1 \ | |
367 for (channel = 0; channel < pattern->nchannels; channel++) \ | |
368 for (row = 0; row < pattern->nrows; row++) { \ | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
369 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel]; |
0 | 370 |
371 #define JSFOREACHNOTE2 } | |
372 | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
373 static int jssConvertPatternRawElem( |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
374 Uint8 *patBuf, const size_t patBufSize, |
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
375 size_t *patSize, const JSSPattern *pattern) |
0 | 376 { |
377 Uint8 tmp; | |
378 int row, channel; | |
379 *patSize = 0; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
380 |
0 | 381 JSFOREACHNOTE1; |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
382 if (pnote->note == jsetNotSet) |
0 | 383 tmp = 0; |
1194 | 384 else |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
385 if (pnote->note == jsetNoteOff) |
0 | 386 tmp = 127; |
387 else | |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
388 tmp = pnote->note + 1; |
1194 | 389 |
0 | 390 if (tmp > 0x7f) |
391 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Note value out of bounds %d > 0x7f.\n", tmp); | |
1194 | 392 |
0 | 393 JSPUTBYTE(tmp); |
394 JSFOREACHNOTE2; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
395 |
0 | 396 JSFOREACHNOTE1; |
1207
59b5821b5cf9
Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1201
diff
changeset
|
397 JSCONVPUT(pnote->instrument, "Instrument"); |
0 | 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->volume, "Volume"); |
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->effect, "Effect"); |
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 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
|
410 JSPUTBYTE(tmp); |
0 | 411 JSFOREACHNOTE2; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
412 |
0 | 413 return DMERR_OK; |
414 } | |
415 | |
416 #undef JSFOREACHNOTE1 | |
417 #undef JSFOREACHNOTE2 | |
418 | |
419 | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
420 static BOOL jssMODWriteEnvelope(FILE *outFile, JSSEnvelope *env, const char *name, const int ninst) |
0 | 421 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
422 BOOL ok = |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
423 dm_fwrite_byte(outFile, env->flags) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
424 dm_fwrite_byte(outFile, env->npoints) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
425 dm_fwrite_byte(outFile, env->sustain) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
426 dm_fwrite_byte(outFile, env->loopS) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
427 dm_fwrite_byte(outFile, env->loopE); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
428 |
1313 | 429 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
|
430 { |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
431 ok = |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
432 dm_fwrite_le16(outFile, env->points[i].frame) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
433 dm_fwrite_le16(outFile, env->points[i].value); |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
434 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
435 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
436 if (!ok) |
0 | 437 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
438 JSSERROR(DMERR_FWRITE, ok, |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
439 "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
|
440 name, ninst); |
0 | 441 } |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
442 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
443 return ok; |
0 | 444 } |
445 | |
446 | |
447 /* Save a JSSMOD file | |
448 */ | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
449 int jssSaveJSSMOD(FILE *outFile, JSSModule *module, int patMode, int flags8, int flags16) |
0 | 450 { |
451 JSSMODHeader jssH; | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
452 const size_t patBufSize = 256*1024; // 256kB pattern buffer |
0 | 453 Uint8 *patBuf; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
454 size_t totalSize; |
1972
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
455 int index, res; |
0 | 456 |
457 // Check the module | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
458 if (module == NULL) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
459 { |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
460 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
461 "Module pointer was NULL\n"); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
462 } |
0 | 463 |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
464 if (module->nchannels < 1 || module->npatterns < 1 || module->norders < 1 || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
465 module->nchannels > jsetMaxChannels || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
466 module->npatterns > jsetMaxPatterns || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
467 module->norders > jsetMaxOrders) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
468 { |
0 | 469 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, |
1195
4d27c4ec8d4d
Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents:
1194
diff
changeset
|
470 "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
|
471 module->nchannels, module->npatterns, module->norders); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
472 } |
0 | 473 |
474 // Create the JSSMOD header | |
475 jssH.idMagic[0] = 'J'; | |
476 jssH.idMagic[1] = 'M'; | |
477 jssH.idVersion = JSSMOD_VERSION; | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
478 jssH.defFlags = module->defFlags; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
479 jssH.intVersion = module->intVersion; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
480 jssH.norders = module->norders; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
481 jssH.npatterns = module->npatterns; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
482 jssH.nextInstruments = module->nextInstruments; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
483 jssH.ninstruments = module->ninstruments; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
484 jssH.defRestartPos = module->defRestartPos; |
1231 | 485 |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
486 jssH.nchannels = module->nchannels; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
487 jssH.defSpeed = module->defSpeed; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
488 jssH.defTempo = module->defTempo; |
0 | 489 jssH.patMode = patMode; |
1209 | 490 |
0 | 491 // Write header |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
492 if (!dm_fwrite_str(outFile, jssH.idMagic, sizeof(jssH.idMagic)) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
493 !dm_fwrite_byte(outFile, jssH.idVersion) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
494 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
495 !dm_fwrite_le16(outFile, jssH.defFlags) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
496 !dm_fwrite_le16(outFile, jssH.intVersion) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
497 !dm_fwrite_le16(outFile, jssH.norders) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
498 !dm_fwrite_le16(outFile, jssH.npatterns) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
499 !dm_fwrite_le16(outFile, jssH.nextInstruments) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
500 !dm_fwrite_le16(outFile, jssH.ninstruments) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
501 !dm_fwrite_le16(outFile, jssH.defRestartPos) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
502 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
503 !dm_fwrite_byte(outFile, jssH.nchannels) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
504 !dm_fwrite_byte(outFile, jssH.defSpeed) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
505 !dm_fwrite_byte(outFile, jssH.defTempo) || |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
506 !dm_fwrite_byte(outFile, jssH.patMode)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
507 { |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
508 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1245
2a0488078b78
Cleanups, more consistent error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1244
diff
changeset
|
509 "Error writing JSSMOD header!\n"); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
510 } |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
511 |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
512 totalSize = sizeof(jssH); |
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
513 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
|
514 |
0 | 515 // Write orders list |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
516 for (totalSize = index = 0; index < module->norders; index++) |
0 | 517 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
518 int tmp = module->orderList[index]; |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
519 if (tmp != jsetNotSet && tmp > module->npatterns) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
520 { |
1237
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
521 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
522 "Orderlist entry #%d has invalid value %d.\n", |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
523 index, tmp); |
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 |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
526 if (tmp == jsetNotSet) |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
527 tmp = 0xffff; |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
528 |
1237
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
529 if (!dm_fwrite_le16(outFile, tmp)) |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
530 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
531 "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
|
532 index, tmp); |
1237
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
533 |
8b6ed580e800
Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1235
diff
changeset
|
534 totalSize += sizeof(Uint16); |
0 | 535 } |
536 | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
537 dmMsg(1," * %d item orders list, %d bytes.\n", |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
538 module->norders, totalSize); |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
539 |
0 | 540 // Allocate pattern compression buffer |
541 if ((patBuf = dmMalloc(patBufSize)) == NULL) | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
542 { |
0 | 543 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
544 "Error allocating memory for pattern compression buffer.\n"); | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
545 } |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
546 |
1232 | 547 // Convert and write patterns |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
548 for (totalSize = index = 0; index < module->npatterns; index++) |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
549 if (module->patterns[index] != NULL) |
0 | 550 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
551 JSSPattern *pattern = module->patterns[index]; |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
552 size_t dataSize = 0; |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
553 int ret; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
554 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
555 if (pattern->nrows > jsetMaxRows) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
556 { |
1232 | 557 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
558 "Pattern #%d has %d rows > %d max.\n", | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
559 index, pattern->nrows, jsetMaxRows); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
560 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
561 |
0 | 562 switch (patMode) |
563 { | |
564 case PATMODE_RAW_HORIZ: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
565 ret = jssConvertPatternRawHoriz(patBuf, patBufSize, &dataSize, pattern); |
0 | 566 break; |
567 case PATMODE_COMP_HORIZ: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
568 ret = jssConvertPatternCompHoriz(patBuf, patBufSize, &dataSize, pattern); |
0 | 569 break; |
570 case PATMODE_RAW_VERT: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
571 ret = jssConvertPatternRawVert(patBuf, patBufSize, &dataSize, pattern); |
0 | 572 break; |
573 case PATMODE_COMP_VERT: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
574 ret = jssConvertPatternCompVert(patBuf, patBufSize, &dataSize, pattern); |
0 | 575 break; |
576 case PATMODE_RAW_ELEM: | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
577 ret = jssConvertPatternRawElem(patBuf, patBufSize, &dataSize, pattern); |
0 | 578 break; |
579 default: | |
580 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1245
2a0488078b78
Cleanups, more consistent error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1244
diff
changeset
|
581 "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
|
582 patMode, index); |
0 | 583 } |
584 | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
585 if (ret != DMERR_OK) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
586 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
587 JSSERROR(ret, ret, "Error converting pattern data #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
588 pattern); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
589 } |
1211 | 590 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
591 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
|
592 totalSize += dataSize + sizeof(JSSMODPattern); |
0 | 593 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
594 if (!dm_fwrite_le32(outFile, dataSize) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
595 !dm_fwrite_le16(outFile, pattern->nrows) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
596 !dm_fwrite_str(outFile, patBuf, dataSize)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
597 { |
1211 | 598 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
599 "Error writing JSSMOD pattern #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
600 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
601 } |
0 | 602 } |
1242 | 603 else |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
604 { |
1242 | 605 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
606 "Pattern #%d was NULL.\n", index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
607 } |
1242 | 608 |
0 | 609 dmFree(patBuf); |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
610 dmMsg(1," * %d patterns, %d bytes.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
611 module->npatterns, totalSize); |
0 | 612 |
613 // Write extended instruments | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
614 for (totalSize = index = 0; index < module->nextInstruments; index++) |
0 | 615 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
616 JSSExtInstrument *einst = module->extInstruments[index]; |
1975
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
617 JSSExtInstrument tmpEInst; |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
618 |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
619 if (einst == NULL) |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
620 { |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
621 einst = &tmpEInst; |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
622 memset(&tmpEInst, 0, sizeof(tmpEInst)); |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
623 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
624 "Extended instrument #%d NULL!\n", |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
625 index); |
0fddc51788de
Fix writing of JSSMOD for NULL extended instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
1972
diff
changeset
|
626 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
627 |
1334 | 628 // Misc data |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
629 BOOL ok = |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
630 dm_fwrite_byte(outFile, einst->nsamples) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
631 dm_fwrite_byte(outFile, einst->vibratoType) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
632 dm_fwrite_le16(outFile, einst->vibratoSweep) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
633 dm_fwrite_le16(outFile, einst->vibratoDepth) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
634 dm_fwrite_le16(outFile, einst->vibratoRate) && |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
635 dm_fwrite_le16(outFile, einst->fadeOut); |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
636 |
1334 | 637 // Sample number for note(s) |
1313 | 638 for (int i = 0; ok && i < jsetNNotes; i++) |
0 | 639 { |
1242 | 640 int snum = einst->sNumForNotes[i]; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
641 Uint32 tmp = (snum != jsetNotSet) ? snum + 1 : 0; |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
642 ok = dm_fwrite_le32(outFile, tmp); |
1242 | 643 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
644 |
1334 | 645 // Envelopes |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
646 if (!ok || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
647 !jssMODWriteEnvelope(outFile, &einst->volumeEnv, "volume", index) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
648 !jssMODWriteEnvelope(outFile, &einst->panningEnv, "panning", index)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
649 { |
0 | 650 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
651 "Error writing JSSMOD extended instrument #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
652 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
653 } |
0 | 654 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
655 totalSize += sizeof(JSSMODExtInstrument); |
0 | 656 } |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
657 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
658 dmMsg(1," * %d Extended Instruments, %d bytes.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
659 module->nextInstruments, totalSize); |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
660 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
661 // Write sample instrument headers |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
662 for (totalSize = index = 0; index < module->ninstruments; index++) |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
663 if (module->instruments[index] != NULL) |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
664 { |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
665 JSSInstrument *inst = module->instruments[index]; |
1334 | 666 |
667 // Determine conversion flags to use | |
1315
7687412f9aef
Fix jssmod sample conversion flags storing .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
1313
diff
changeset
|
668 inst->convFlags = (inst->flags & jsf16bit) ? flags16 : flags8; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
669 if (inst->data != NULL) |
1315
7687412f9aef
Fix jssmod sample conversion flags storing .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
1313
diff
changeset
|
670 inst->convFlags |= jsampHasData; |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
671 |
1334 | 672 // Write instrument header |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
673 if (!dm_fwrite_le32(outFile, inst->size) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
674 !dm_fwrite_le32(outFile, inst->loopS) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
675 !dm_fwrite_le32(outFile, inst->loopE) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
676 !dm_fwrite_le16(outFile, inst->flags) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
677 !dm_fwrite_le16(outFile, inst->C4BaseSpeed) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
678 !dm_fwrite_le16(outFile, inst->ERelNote) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
679 !dm_fwrite_le16(outFile, inst->EFineTune) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
680 !dm_fwrite_le16(outFile, inst->EPanning) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
681 !dm_fwrite_byte(outFile, inst->volume) || |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
682 !dm_fwrite_byte(outFile, inst->convFlags)) |
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 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
685 "Error writing JSSMOD instrument #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
686 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
687 } |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
688 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
689 totalSize += sizeof(JSSMODInstrument); |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
690 } |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
691 else |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
692 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
693 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, |
1334 | 694 "Instrument #%d NULL!\n", |
695 index); | |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
696 } |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
697 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
698 dmMsg(1," * %d Instrument headers, %d bytes.\n", |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
699 module->ninstruments, totalSize); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
700 |
0 | 701 // Write sample data |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
702 for (totalSize = index = 0; index < module->ninstruments; index++) |
0 | 703 { |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
704 JSSInstrument *inst = module->instruments[index]; |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
705 if (inst != NULL && inst->data != NULL) |
0 | 706 { |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
707 size_t bsize = inst->size; |
0 | 708 if (inst->flags & jsf16bit) |
709 { | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
710 bsize *= sizeof(Uint16); |
1972
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
711 res = jssEncodeSample16(inst->data, inst->size, flags16); |
0 | 712 } |
713 else | |
714 { | |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
715 bsize *= sizeof(Uint8); |
1972
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
716 res = jssEncodeSample8(inst->data, inst->size, flags8); |
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
717 } |
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
718 |
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
719 if (res != DMERR_OK) |
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
720 { |
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
721 JSSERROR(res, res, |
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
722 "Error encoding sample for instrument #%d: %s\n", |
cedb5ca1533b
Clean up the sample conversion code a bit. Improve error handling in xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents:
1606
diff
changeset
|
723 index, dmErrorStr(res)); |
0 | 724 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
725 |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
726 if (!dm_fwrite_str(outFile, inst->data, bsize)) |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
727 { |
0 | 728 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
729 "Error writing JSSMOD sample data for instrument #%d.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
730 index); |
1310
dce4730372c7
Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1249
diff
changeset
|
731 } |
1243
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
732 |
377c8a603d21
Cleanups in JSSMOD writing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1242
diff
changeset
|
733 totalSize += bsize; |
0 | 734 } |
735 } | |
1246
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
736 |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
737 dmMsg(1," * %d samples, %d bytes.\n", |
7bd50496c9ec
Work on improved module conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1245
diff
changeset
|
738 module->ninstruments, totalSize); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
739 |
0 | 740 return DMERR_OK; |
741 } | |
742 | |
743 | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
744 /* Scan given pattern for used instruments and channels. |
1342
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
745 * Also checks if the pattern is empty. |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
746 */ |
1342
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
747 void scanPattern(const JSSModule *module, const JSSPattern *pattern, |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
748 const int npattern, BOOL *usedExtInstruments, BOOL *usedChannels, BOOL *empty) |
1244
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 JSSNote *n = pattern->data; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
751 *empty = FALSE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
752 |
1337 | 753 // Check all notes in this pattern |
1313 | 754 for (int row = 0; row < pattern->nrows; row++) |
755 for (int channel = 0; channel < pattern->nchannels; channel++, n++) | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
756 { |
1337 | 757 // Is the instrument set? |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
758 if (n->instrument != jsetNotSet) |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
759 { |
1337 | 760 // Is it valid? |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
761 if (n->instrument >= 0 && n->instrument < module->nextInstruments) |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
762 usedExtInstruments[n->instrument] = TRUE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
763 else |
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 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
|
766 npattern + 1, row, channel, n->instrument + 1); |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
767 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
768 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
769 |
1337 | 770 // Check if this channel is used |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
771 if (n->note != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
772 n->instrument != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
773 n->volume != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
774 n->effect != jsetNotSet || |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
775 n->param != jsetNotSet) |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
776 { |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
777 usedChannels[channel] = TRUE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
778 *empty = FALSE; |
1337 | 779 } |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
780 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
781 } |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
782 |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
783 |
1317
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
784 /* 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
|
785 */ |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
786 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
|
787 { |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
788 return |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
789 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
|
790 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
|
791 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
|
792 } |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
793 |
2772c16622bb
Add checking of duplicate patterns in the optimization pass of xm2jss. Not
Matti Hamalainen <ccr@tnsp.org>
parents:
1315
diff
changeset
|
794 |
0 | 795 /* Optimize a given module |
796 */ | |
797 JSSModule *optimizeModule(JSSModule *m) | |
798 { | |
799 BOOL usedPatterns[jsetMaxPatterns + 1], | |
800 usedInstruments[jsetMaxInstruments + 1], | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
801 usedExtInstruments[jsetMaxInstruments + 1], |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
802 usedChannels[jsetMaxChannels]; |
0 | 803 int mapExtInstruments[jsetMaxInstruments + 1], |
804 mapInstruments[jsetMaxInstruments + 1], | |
1333
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
805 mapPatterns[jsetMaxPatterns + 1], |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
806 dupPatterns[jsetMaxPatterns + 1]; |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
807 |
0 | 808 JSSModule *r = NULL; |
1320 | 809 int n8, n16, nunused, ndupes; |
0 | 810 |
811 // Allocate a new module | |
812 if ((r = jssAllocateModule()) == NULL) | |
813 return NULL; | |
814 | |
815 // Copy things | |
816 r->moduleType = m->moduleType; | |
817 r->moduleName = dm_strdup(m->moduleName); | |
818 r->trackerName = dm_strdup(m->trackerName); | |
819 r->defSpeed = m->defSpeed; | |
820 r->defTempo = m->defTempo; | |
821 r->defFlags = m->defFlags; | |
822 r->defRestartPos = m->defRestartPos; | |
823 r->intVersion = m->intVersion; | |
824 r->nchannels = m->nchannels; | |
825 r->norders = m->norders; | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
826 |
1320 | 827 for (int i = 0; i < jsetNChannels; i++) |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
828 { |
0 | 829 r->defPanning[i] = m->defPanning[i]; |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
830 usedChannels[i] = FALSE; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
831 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
832 |
0 | 833 // Initialize values |
1320 | 834 for (int i = 0; i <= jsetMaxInstruments; i++) |
0 | 835 { |
836 usedExtInstruments[i] = FALSE; | |
798 | 837 usedInstruments[i] = FALSE; |
838 mapExtInstruments[i] = jsetNotSet; | |
839 mapInstruments[i] = jsetNotSet; | |
0 | 840 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
841 |
1320 | 842 for (int i = 0; i <= jsetMaxPatterns; i++) |
0 | 843 { |
844 usedPatterns[i] = FALSE; | |
798 | 845 mapPatterns[i] = jsetNotSet; |
1333
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
846 dupPatterns[i] = jsetNotSet; |
0 | 847 } |
848 | |
1094 | 849 // |
798 | 850 // Find out all actually used patterns and ext.instruments |
1100 | 851 // by going through all patterns specified in the order list |
1094 | 852 // |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
853 dmMsg(1, "Scanning patterns for used instruments and channels...\n"); |
1320 | 854 for (int norder = 0; norder < m->norders; norder++) |
0 | 855 { |
1320 | 856 int npat = m->orderList[norder]; |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
857 if (npat >= 0 && npat < m->npatterns) |
0 | 858 { |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
859 JSSPattern *pattern = m->patterns[npat]; |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
860 if (pattern != NULL) |
0 | 861 { |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
862 BOOL empty; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
863 |
1100 | 864 // Mark this pattern as used |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
865 usedPatterns[npat] = TRUE; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
866 |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
867 // Scan for used instruments and channels |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
868 scanPattern(m, pattern, npat, usedExtInstruments, usedChannels, &empty); |
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
869 |
1249 | 870 // Empty patterns with known number of rows are "removed" |
871 if (empty && pattern->nrows == jsetDefaultRows) | |
0 | 872 { |
1320 | 873 m->orderList[norder] = jsetNotSet; |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
874 usedPatterns[npat] = FALSE; |
0 | 875 } |
876 } | |
877 else | |
878 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
879 dmErrorMsg("Pattern 0x%x is used on order 0x%x, but has no data!\n", |
1320 | 880 npat, norder); |
807
d83dc7e47076
Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents:
798
diff
changeset
|
881 |
d83dc7e47076
Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents:
798
diff
changeset
|
882 // Fix it. |
1320 | 883 m->orderList[norder] = jsetNotSet; |
0 | 884 } |
885 } | |
886 else | |
1244
072851dcec5c
Improve module optimization.
Matti Hamalainen <ccr@tnsp.org>
parents:
1243
diff
changeset
|
887 if (npat != jsetNotSet) |
0 | 888 { |
1101 | 889 dmErrorMsg("Order 0x%x has invalid pattern number 0x%x, changing to empty!\n", |
1320 | 890 norder, npat); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
891 |
807
d83dc7e47076
Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents:
798
diff
changeset
|
892 // Fix it. |
1320 | 893 m->orderList[norder] = jsetNotSet; |
0 | 894 } |
895 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
896 |
1094 | 897 // |
1100 | 898 // Find used sample instruments |
1094 | 899 // |
1101 | 900 dmMsg(1, "Checking ext.instruments for used sample instruments...\n"); |
1320 | 901 for (int i = 0; i < jsetMaxInstruments; i++) |
0 | 902 if (usedExtInstruments[i] && m->extInstruments[i] != NULL) |
903 { | |
904 JSSExtInstrument *e = m->extInstruments[i]; | |
1094 | 905 |
1347 | 906 for (int note = 0; note < jsetNNotes; note++) |
0 | 907 if (e->sNumForNotes[note] != jsetNotSet) |
908 { | |
909 int q = e->sNumForNotes[note]; | |
910 if (q >= 0 && q < m->ninstruments) | |
911 { | |
912 usedInstruments[q] = TRUE; | |
913 } | |
914 else | |
915 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
916 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
|
917 i + 1, m->ninstruments, q + 1); |
0 | 918 } |
919 } | |
920 } | |
1094 | 921 |
922 // | |
0 | 923 // Create pattern mappings |
1094 | 924 // |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
925 dmMsg(1, "Creating pattern remaps...\n"); |
1320 | 926 nunused = ndupes = 0; |
927 for (int pat1 = 0; pat1 <= jsetMaxPatterns; pat1++) | |
928 if (usedPatterns[pat1]) | |
0 | 929 { |
1333
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
930 // Sanity check patterns |
1320 | 931 if (pat1 >= m->npatterns) |
0 | 932 { |
1320 | 933 dmErrorMsg("Pattern 0x%x >= 0x%x, but used!\n", pat1, m->npatterns); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
934 continue; |
0 | 935 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
936 |
1332 | 937 if (m->patterns[pat1] == NULL) |
0 | 938 { |
1320 | 939 dmErrorMsg("Pattern 0x%x used but is NULL.\n", pat1); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
940 continue; |
0 | 941 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
942 |
1333
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
943 // Check for previously marked dupes |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
944 if (dupPatterns[pat1] != jsetNotSet) |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
945 { |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
946 mapPatterns[pat1] = dupPatterns[pat1]; |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
947 continue; |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
948 } |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
949 |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
950 // Check for duplicate patterns of "pat1" and mark them as such |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
951 for (int pat2 = 0; pat2 < m->npatterns; pat2++) |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
952 if (pat1 != pat2 && m->patterns[pat2] != NULL && |
1343
cffb1597ab06
Fix dupe pattern detection.
Matti Hamalainen <ccr@tnsp.org>
parents:
1342
diff
changeset
|
953 dupPatterns[pat2] == jsetNotSet && |
1333
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
954 comparePattern(m->patterns[pat1], m->patterns[pat2])) |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
955 { |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
956 dmPrint(1, " * %d and %d are dupes.\n", pat1, pat2); |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
957 dupPatterns[pat2] = pat1; |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
958 ndupes++; |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
959 } |
17c23f0494f5
Possibly make dupe pattern elimination work. Still needs some testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1332
diff
changeset
|
960 |
1320 | 961 mapPatterns[pat1] = r->npatterns; |
962 r->patterns[r->npatterns] = m->patterns[pat1]; | |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
963 (r->npatterns)++; |
0 | 964 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
965 else |
1320 | 966 if (m->patterns[pat1] != NULL) |
967 nunused++; | |
1094 | 968 |
1320 | 969 dmMsg(1, "%d used patterns (%d unused, %d duplicates).\n", |
970 r->npatterns, nunused, ndupes); | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
971 |
1094 | 972 // |
0 | 973 // Re-map instruments |
1094 | 974 // |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
975 dmMsg(1, "Creating sample instrument remaps...\n"); |
1320 | 976 nunused = n8 = n16 = 0; |
977 for (int i = 0; i < jsetMaxInstruments; i++) | |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
978 if (usedInstruments[i]) |
0 | 979 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
980 JSSInstrument *ip; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
981 if (optStripInstr) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
982 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
983 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
984 if (i >= m->ninstruments) |
0 | 985 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
986 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
|
987 i + 1, m->ninstruments); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
988 continue; |
0 | 989 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
990 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
991 if ((ip = m->instruments[i]) == NULL) |
0 | 992 { |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
993 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
|
994 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
995 } |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
996 |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
997 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
|
998 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
999 mapInstruments[i] = r->ninstruments; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1000 r->instruments[r->ninstruments] = ip; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1001 (r->ninstruments)++; |
0 | 1002 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1003 if (ip->flags & jsf16bit) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1004 n16++; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1005 else |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1006 n8++; |
0 | 1007 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1008 else |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1009 if (m->instruments[i] != NULL) |
1320 | 1010 nunused++; |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1011 |
0 | 1012 dmPrint(2, "\n"); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1013 dmMsg(1, "Total of %d [16-bit] + %d [8-bit] samples = %d instruments (%d unused).\n", |
1320 | 1014 n16, n8, r->ninstruments, nunused); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1015 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1016 // |
0 | 1017 // Re-map ext.instruments |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1018 // |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1019 dmMsg(1, "Creating ext.instrument remaps...\n"); |
1320 | 1020 nunused = 0; |
1021 for (int i = 0; i < jsetMaxInstruments; i++) | |
0 | 1022 if (usedExtInstruments[i]) |
1023 { | |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1024 JSSExtInstrument *eip; |
1347 | 1025 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1026 if (optStripExtInstr) |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1027 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1028 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1029 if (i >= m->nextInstruments) |
0 | 1030 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
1031 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
|
1032 i + 1, m->nextInstruments); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1033 continue; |
0 | 1034 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1035 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1036 if ((eip = m->extInstruments[i]) == NULL) |
0 | 1037 { |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1038 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
|
1039 continue; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1040 } |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1041 |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1042 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
|
1043 |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1044 mapExtInstruments[i] = r->nextInstruments; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1045 r->extInstruments[r->nextInstruments] = eip; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1046 (r->nextInstruments)++; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1047 |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1048 // Re-map sNumForNotes table for this ext.instrument |
1347 | 1049 for (int note = 0; note < jsetNNotes; note++) |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1050 { |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1051 int q = eip->sNumForNotes[note]; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1052 if (q != jsetNotSet) |
0 | 1053 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1054 int map; |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1055 if (q >= 0 && q < jsetMaxInstruments) |
0 | 1056 { |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1057 map = mapInstruments[q]; |
0 | 1058 } |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1059 else |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1060 { |
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1061 map = jsetNotSet; |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1062 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
|
1063 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
|
1064 } |
1111
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1065 |
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1066 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
|
1067 eip->sNumForNotes[note] = map; |
0 | 1068 } |
1069 } | |
1070 } | |
1071 else | |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1072 if (m->extInstruments[i] != NULL) |
1320 | 1073 nunused++; |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1074 |
0 | 1075 dmPrint(2, "\n"); |
1097
0e3cb9e61170
Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents:
1094
diff
changeset
|
1076 dmMsg(1, "%d extended instruments (%d unused).\n", |
1320 | 1077 r->nextInstruments, nunused); |
1094 | 1078 |
1079 // | |
1335
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1080 // Check for actually used channels |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1081 // XXX TODO: Actually remove the unused channels. |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1082 // |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1083 nunused = 0; |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1084 for (int i = 0; i < r->nchannels; i++) |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1085 { |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1086 if(!usedChannels[i]) |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1087 nunused++; |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1088 } |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1089 dmMsg(1, "%d channels (%d unused).\n", |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1090 r->nchannels - nunused, nunused); |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1091 |
caf414847662
Add informational message about used/unused channels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1334
diff
changeset
|
1092 // |
1094 | 1093 // Remap pattern data with remapped instrument data |
1094 // | |
1320 | 1095 for (int i = 0; i < r->npatterns; i++) |
0 | 1096 { |
1097 JSSPattern *p = r->patterns[i]; | |
1098 JSSNote *n = p->data; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1099 |
1336 | 1100 for (int row = 0; row < p->nrows; row++) |
1101 for (int channel = 0; channel < p->nchannels; channel++, n++) | |
0 | 1102 { |
1109 | 1103 // If not stripping extended instruments, check for |
1104 // 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
|
1105 if (!optStripExtInstr) |
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
1106 { |
856
415cc781e127
Fix some brain farts in instrument remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
807
diff
changeset
|
1107 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
|
1108 n->instrument = mapExtInstruments[n->instrument]; |
202
85614db5f577
Warn about invalid instruments.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1109 |
1116 | 1110 if (n->instrument != jsetNotSet && |
1111 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
|
1112 { |
1116 | 1113 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
|
1114 n->instrument + 1); |
f9a96fc2a932
Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1109
diff
changeset
|
1115 } |
338
cd57ba1130eb
Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
337
diff
changeset
|
1116 } |
1342
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1117 |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1118 // Convert certain effects |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1119 char effect; |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1120 JMPGETEFFECT(effect, n->effect); |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1121 switch (effect) |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1122 { |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1123 case 'C': // Cxx = Set volume |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1124 if (n->volume == jsetNotSet) |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1125 { |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1126 n->volume = n->param; |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1127 n->effect = jsetNotSet; |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1128 n->param = jsetNotSet; |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1129 } |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1130 break; |
f2fd1ad84829
Constify and move effect conversion back to where it was.
Matti Hamalainen <ccr@tnsp.org>
parents:
1337
diff
changeset
|
1131 } |
0 | 1132 } |
1133 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1134 |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1135 // |
0 | 1136 // Remap orders list |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1137 // |
1318 | 1138 dmMsg(1, "Remapping orders list.\n"); |
1352
0ecd5accea1e
Improve verbose output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1347
diff
changeset
|
1139 nunused = 0; |
1320 | 1140 for (int i = 0; i < m->norders; i++) |
0 | 1141 { |
1347 | 1142 int map = mapPatterns[m->orderList[i]]; |
1143 if (map != m->orderList[i]) | |
1352
0ecd5accea1e
Improve verbose output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1347
diff
changeset
|
1144 { |
0ecd5accea1e
Improve verbose output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1347
diff
changeset
|
1145 dmPrint(2, "%02x -> %02x : ", m->orderList[i], map); |
0ecd5accea1e
Improve verbose output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1347
diff
changeset
|
1146 nunused++; |
0ecd5accea1e
Improve verbose output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1347
diff
changeset
|
1147 } |
1347 | 1148 r->orderList[i] = map; |
0 | 1149 } |
1352
0ecd5accea1e
Improve verbose output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1347
diff
changeset
|
1150 if (nunused) |
0ecd5accea1e
Improve verbose output cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
1347
diff
changeset
|
1151 dmPrint(2, "\n"); |
0 | 1152 |
1153 return r; | |
1154 } | |
1155 | |
1156 | |
1157 int main(int argc, char *argv[]) | |
1158 { | |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1159 DMResource *inFile = NULL; |
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1160 FILE *outFile = NULL; |
0 | 1161 JSSModule *sm, *dm; |
1162 int result; | |
1163 | |
1319 | 1164 dmInitProg("xm2jss", "XM to JSSMOD converter", "0.7", NULL, NULL); |
0 | 1165 dmVerbosity = 0; |
1166 | |
1167 // Parse arguments | |
1168 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
|
1169 argHandleOpt, argHandleFile, OPTH_BAILOUT)) |
0 | 1170 exit(1); |
1171 | |
300 | 1172 // Check arguments |
1173 if (optInFilename == NULL || optOutFilename == NULL) | |
1174 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
1175 dmErrorMsg("Input or output file not specified. Try --help.\n"); |
300 | 1176 return 1; |
1177 } | |
0 | 1178 |
1179 // Read the source file | |
1606
93d1050eac99
Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents:
1432
diff
changeset
|
1180 if ((result = dmf_open_stdio(optInFilename, "rb", &inFile)) != DMERR_OK) |
0 | 1181 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
1182 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
|
1183 optInFilename, result, dmErrorStr(result)); |
0 | 1184 return 1; |
1185 } | |
1186 | |
1187 // Initialize miniJSS | |
1188 jssInit(); | |
1189 | |
1190 // Read file | |
1191 dmMsg(1, "Reading XM-format file ...\n"); | |
797
f066e9dccf29
Oops, fix some inverted booleans.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1192 result = jssLoadXM(inFile, &sm, FALSE); |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1193 dmf_close(inFile); |
0 | 1194 if (result != 0) |
1195 { | |
1195
4d27c4ec8d4d
Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents:
1194
diff
changeset
|
1196 dmErrorMsg("Error while loading XM file (%d), ", result); |
0 | 1197 if (optIgnoreErrors) |
1198 fprintf(stderr, "ignoring. This may cause problems.\n"); | |
1199 else | |
1200 { | |
1201 fprintf(stderr, "giving up. Use --ignore if you want to try to convert anyway.\n"); | |
1202 return 2; | |
1203 } | |
1204 } | |
1205 | |
1206 // Check stripping settings | |
1207 if (optStripExtInstr) optStripInstr = TRUE; | |
1208 if (optStripInstr) optStripSamples = TRUE; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1209 |
0 | 1210 // Remove samples |
1211 if (optStripSamples) | |
1212 { | |
1213 int i; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1214 |
0 | 1215 dmMsg(1, "Stripping samples...\n"); |
1216 for (i = 0; i < sm->ninstruments; i++) | |
1217 { | |
1218 dmFree(sm->instruments[i]->data); | |
1219 sm->instruments[i]->data = NULL; | |
1220 } | |
1221 } | |
1222 | |
1223 // Remove instruments | |
1224 if (optStripInstr) | |
1225 { | |
1226 int i; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1227 |
0 | 1228 dmMsg(1, "Stripping instruments...\n"); |
1229 for (i = 0; i < sm->ninstruments; i++) | |
1230 { | |
1231 dmFree(sm->instruments[i]); | |
1232 sm->instruments[i] = NULL; | |
1233 } | |
1234 sm->ninstruments = 0; | |
1235 } | |
1236 | |
1237 // Remove ext.instruments | |
1238 if (optStripExtInstr) | |
1239 { | |
1240 int i; | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1241 |
0 | 1242 dmMsg(1, "Stripping ext.instruments...\n"); |
1243 for (i = 0; i < sm->nextInstruments; i++) | |
1244 { | |
1245 dmFree(sm->extInstruments[i]); | |
1246 sm->extInstruments[i] = NULL; | |
1247 } | |
1248 sm->nextInstruments = 0; | |
1249 } | |
1109 | 1250 |
0 | 1251 // Run the optimization procedure |
1252 if (optOptimize) | |
1253 { | |
1254 dmMsg(1, "Optimizing module data...\n"); | |
1255 dm = optimizeModule(sm); | |
1256 } else | |
1257 dm = sm; | |
1258 | |
1259 // Write output file | |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1260 if ((outFile = fopen(optOutFilename, "wb")) == NULL) |
0 | 1261 { |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1352
diff
changeset
|
1262 int err = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
860
diff
changeset
|
1263 dmErrorMsg("Error creating output file '%s', %d: %s\n", |
1431
ed04fb6da07c
Get rid of direct 'errno' usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
1352
diff
changeset
|
1264 optOutFilename, err, dmErrorStr(err)); |
0 | 1265 return 1; |
1266 } | |
1267 | |
9
c42ee907de9c
Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
1268 dmMsg(1, "Writing JSSMOD-format file [patMode=0x%04x, samp8=0x%02x, samp16=0x%02x]\n", |
0 | 1269 optPatternMode, optSampMode8, optSampMode16); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1270 |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1271 result = jssSaveJSSMOD(outFile, dm, optPatternMode, optSampMode8, optSampMode16); |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1272 |
1114
7aaab1533c90
Free the source module data at end.
Matti Hamalainen <ccr@tnsp.org>
parents:
1113
diff
changeset
|
1273 dmFree(sm); |
7aaab1533c90
Free the source module data at end.
Matti Hamalainen <ccr@tnsp.org>
parents:
1113
diff
changeset
|
1274 |
730
3d813c81f33c
More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
1275 fclose(outFile); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1233
diff
changeset
|
1276 |
0 | 1277 if (result != 0) |
1278 { | |
1113
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1279 dmErrorMsg( |
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1280 "Error while saving JSSMOD file, %d: %s\n" |
28dcf10fb8a9
Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1111
diff
changeset
|
1281 "WARNING: The resulting file may be broken!\n", |
300 | 1282 result, dmErrorStr(result)); |
0 | 1283 } |
300 | 1284 else |
1285 { | |
1286 dmMsg(1, "Conversion complete.\n"); | |
1287 } | |
0 | 1288 return 0; |
1289 } |