annotate tools/xm2jss.c @ 1431:ed04fb6da07c

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