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