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