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