annotate tools/xm2jss.c @ 1237:8b6ed580e800

Add sanity check to order list writing.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Mar 2015 16:37:15 +0200
parents 5b8245e5f785
children 5e2b90e3e4bc
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2006-2009 Tecnic Software productions (TNSP)
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 <errno.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "jss.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "jssmod.h"
184
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
12 #include "jssplr.h"
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include "dmargs.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include "dmres.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 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
337
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
67 dmPrintBanner(stdout, dmProgName, "[options] <input.xm> <output.jmod>");
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 856
diff changeset
68 dmArgsPrintHelp(stdout, optList, optListN, 0);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 printf("\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 "Pattern storage modes:\n");
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
72
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 for (i = 1; i < PATMODE_LAST; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 printf(" %d = %s\n", i, patModeTable[i-1]);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
75
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 printf(
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 "\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 "Sample data conversion flags (summative):\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 " 1 = Delta encoding (DEF 8 & 16)\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 " 2 = Flip signedness (DEF 8)\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 " 4 = Swap endianess (affects 16-bit only)\n"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 " 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
83 "\n"
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 }
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 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 (void) optArg;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
90
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 switch (optN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 case 0:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 argShowHelp();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 exit(0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 case 1:
337
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
99 dmVerbosity++;
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
100 break;
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
101
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
102 case 2:
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 optIgnoreErrors = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
337
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
106 case 3:
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 optPatternMode = atoi(optArg);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 if (optPatternMode <= 0 || optPatternMode >= PATMODE_LAST)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
110 dmErrorMsg("Unknown pattern conversion mode %d\n", optPatternMode);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114
337
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
115 case 4: optStripExtInstr = TRUE; break;
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
116 case 5: optStripInstr = TRUE; break;
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
117 case 6: optStripSamples = TRUE; break;
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
118
1099
f309a382d6e7 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1097
diff changeset
119 case 7: optSampMode8 = atoi(optArg) & JM_SAMPLE_MODE_MASK; break;
f309a382d6e7 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1097
diff changeset
120 case 8: optSampMode16 = atoi(optArg) & JM_SAMPLE_MODE_MASK; break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
337
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
122 case 9: optOptimize = TRUE; break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
125 dmErrorMsg("Unknown argument '%s'.\n", currArg);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
128
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 return TRUE;
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
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 BOOL argHandleFile(char *currArg)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 // Was not option argument
300
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
136 if (!optInFilename)
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
137 optInFilename = currArg;
337
b420025e5cd2 Change argument handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
138 else
300
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
139 if (!optOutFilename)
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
140 optOutFilename = currArg;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
143 dmErrorMsg("Too many filename arguments specified, '%s'.\n", currArg);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
146
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 return TRUE;
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 /* These functions and the macro mess are meant to make the
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 * conversion routines themselves clearer and simpler.
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 BOOL jsPutByte(Uint8 *patBuf, size_t patBufSize, size_t *npatBuf, Uint8 val)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 if (*npatBuf >= patBufSize)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 return FALSE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 patBuf[*npatBuf] = val;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 (*npatBuf)++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 return TRUE;
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 }
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 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
167
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 #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
169
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 #define JSCOMPPUT(xf,xv,qv) do { \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 if (qflags & (xf)) { \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 if ((xv) < 0 || (xv) > 255) \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 "%s value out of bounds %d.\n", qv, (xv)); \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 JSPUTBYTE(xv); \
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 } while (0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 #define JSCONVPUT(xv,qv) do { \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 if ((xv) != jsetNotSet) { \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 if ((xv) < 0 || (xv) > 254) \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 "%s value out of bounds %d.\n", qv, (xv)); \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 JSPUTBYTE((xv) + 1); \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 } else { \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 JSPUTBYTE(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 } while (0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 /* Convert a note
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 */
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
193 static int jssConvertNote(
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
194 Uint8 *patBuf, const size_t patBufSize,
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
195 size_t *patSize, const JSSNote *pnote)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 Uint8 tmp;
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
198 if (pnote->note == jsetNotSet)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 tmp = 0;
1194
1f2cfa0119aa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
200 else
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
201 if (pnote->note == jsetNoteOff)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 tmp = 127;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 else
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
204 tmp = pnote->note + 1;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 if (tmp > 0x7f)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 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
208
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 JSPUTBYTE(tmp & 0x7f);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
210
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
211 JSCONVPUT(pnote->instrument, "Instrument");
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
212 JSCONVPUT(pnote->volume, "Volume");
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
213 JSCONVPUT(pnote->effect, "Effect");
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
214
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
215 tmp = (pnote->param != jsetNotSet) ? pnote->param : 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 JSPUTBYTE(tmp);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
217
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 return DMERR_OK;
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 /* Compress a note
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 */
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
224 static int jssCompressNote(
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
225 Uint8 *patBuf, const size_t patBufSize,
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
226 size_t *patSize, const JSSNote *pnote)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 Uint8 qflags = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 int qcomp = 0;
1201
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
230
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
231 // Determine what would get stored,
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
232 // 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
233 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
234 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
235 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
236 JSCOMP(pnote->effect, JM_COMP_EFFECT);
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
237 if (pnote->param != jsetNotSet && pnote->param != 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 {
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1209
diff changeset
239 qflags |= JM_COMP_PARAM;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 qcomp++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
242
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 if (qcomp < 4)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 {
1201
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
245 // Okay, it's less than 4 bytes, so use compressed
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 JSPUTBYTE(qflags | 0x80);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
247
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
248 if (pnote->note != jsetNotSet)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 {
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
250 Uint8 tmp = (pnote->note != jsetNoteOff) ? pnote->note : 127;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 if (tmp > 0x7f)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 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
253 JSPUTBYTE(tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
255
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1209
diff changeset
256 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
257 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
258 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
259 JSCOMPPUT(JM_COMP_PARAM, pnote->param, "Param");
1201
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
260 }
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
261 else
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
262 {
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
263 // Was 4 bytes or more, just dump it all in ..
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
264 return jssConvertNote(patBuf, patBufSize, patSize, pnote);
1201
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
265 }
83693e2797dd Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1195
diff changeset
266
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 return DMERR_OK;
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 /* Compress pattern
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 */
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
273 static int jssConvertPatternCompHoriz(
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
274 Uint8 *patBuf, const size_t patBufSize,
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
275 size_t *patSize, const JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 *patSize = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
279
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 {
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
283 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
284 const int res = jssCompressNote(patBuf, patBufSize, patSize, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 if (res != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 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
288 patBuf, patBufSize, *patSize, row, channel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 return res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
292
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
297 static int jssConvertPatternCompVert(
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
298 Uint8 *patBuf, const size_t patBufSize,
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
299 size_t *patSize, const JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 *patSize = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
303
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 {
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
307 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
308 const int res = jssCompressNote(patBuf, patBufSize, patSize, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 if (res != DMERR_OK)
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 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
312 patBuf, patBufSize, *patSize, row, channel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 return res;
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 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
316
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 /* Convert a pattern
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 */
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
323 static int jssConvertPatternRawHoriz(
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
324 Uint8 *patBuf, const size_t patBufSize,
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
325 size_t *patSize, const JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 *patSize = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
329
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 {
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
333 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
334 const int res = jssConvertNote(patBuf, patBufSize, patSize, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 if (res != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 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
338 patBuf, patBufSize, *patSize, row, channel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 return res;
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 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
342
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 }
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
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
347 static int jssConvertPatternRawVert(
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
348 Uint8 *patBuf, const size_t patBufSize,
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
349 size_t *patSize, const JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 *patSize = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
353
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 {
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
357 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
358 const int res = jssConvertNote(patBuf, patBufSize, patSize, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 if (res != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 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
362 patBuf, patBufSize, *patSize, row, channel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 return res;
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 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
366
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 }
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 #define JSFOREACHNOTE1 \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 for (channel = 0; channel < pattern->nchannels; channel++) \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 for (row = 0; row < pattern->nrows; row++) { \
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
374 const JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
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 #define JSFOREACHNOTE2 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
378 static int jssConvertPatternRawElem(
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
379 Uint8 *patBuf, const size_t patBufSize,
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
380 size_t *patSize, const JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 Uint8 tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 *patSize = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
385
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 JSFOREACHNOTE1;
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
387 if (pnote->note == jsetNotSet)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 tmp = 0;
1194
1f2cfa0119aa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
389 else
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
390 if (pnote->note == jsetNoteOff)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 tmp = 127;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 else
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
393 tmp = pnote->note + 1;
1194
1f2cfa0119aa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
394
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 if (tmp > 0x7f)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 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
397
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 JSPUTBYTE(tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 JSFOREACHNOTE2;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
400
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 JSFOREACHNOTE1;
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
402 JSCONVPUT(pnote->instrument, "Instrument");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 JSFOREACHNOTE2;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
404
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 JSFOREACHNOTE1;
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
406 JSCONVPUT(pnote->volume, "Volume");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 JSFOREACHNOTE2;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
408
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 JSFOREACHNOTE1;
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
410 JSCONVPUT(pnote->effect, "Effect");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 JSFOREACHNOTE2;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
412
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 JSFOREACHNOTE1;
1207
59b5821b5cf9 Rename function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1201
diff changeset
414 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
415 JSPUTBYTE(tmp);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 JSFOREACHNOTE2;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
417
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 #undef JSFOREACHNOTE1
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 #undef JSFOREACHNOTE2
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 static void jssCopyEnvelope(JSSMODEnvelope *je, JSSEnvelope *e)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 int i;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
428
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 je->flags = e->flags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 je->npoints = e->npoints;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 je->sustain = e->sustain;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 je->loopS = e->loopS;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 je->loopE = e->loopE;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
434
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 for (i = 0; i < e->npoints; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 je->points[i].frame = e->points[i].frame;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 je->points[i].value = e->points[i].value;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 /* Save a JSSMOD file
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 int jssSaveJSSMOD(FILE *outFile, JSSModule *m, int patMode, int flags8, int flags16)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 JSSMODHeader jssH;
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
448 int i, pattern, order, instr, totalSize;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 const size_t patBufSize = 64*1024; // 64kB pattern buffer
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 Uint8 *patBuf;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 // Check the module
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 if (m == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, "Module pointer was NULL\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
1233
d4b373d53a64 Add some sanity checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1232
diff changeset
456 if (m->nchannels < 1 || m->npatterns < 1 || m->norders < 1 ||
d4b373d53a64 Add some sanity checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1232
diff changeset
457 m->nchannels > jsetMaxChannels ||
d4b373d53a64 Add some sanity checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1232
diff changeset
458 m->npatterns > jsetMaxPatterns ||
d4b373d53a64 Add some sanity checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1232
diff changeset
459 m->norders > jsetMaxOrders)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS,
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
461 "Module had invalid values (nchannels=%d, npatterns=%d, norders=%d)\n",
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 m->nchannels, m->npatterns, m->norders);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 // Create the JSSMOD header
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 jssH.idMagic[0] = 'J';
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 jssH.idMagic[1] = 'M';
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 jssH.idVersion = JSSMOD_VERSION;
1231
a275b7382ffa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1211
diff changeset
468 jssH.defFlags = m->defFlags;
a275b7382ffa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1211
diff changeset
469 jssH.intVersion = m->intVersion;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 jssH.norders = m->norders;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 jssH.npatterns = m->npatterns;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 jssH.nextInstruments = m->nextInstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 jssH.ninstruments = m->ninstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 jssH.defRestartPos = m->defRestartPos;
1231
a275b7382ffa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1211
diff changeset
475
a275b7382ffa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1211
diff changeset
476 jssH.nchannels = m->nchannels;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 jssH.defSpeed = m->defSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 jssH.defTempo = m->defTempo;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 jssH.patMode = patMode;
1209
cb31e57982f2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1207
diff changeset
480
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 // Write header
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
482 totalSize = sizeof(jssH);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 if (fwrite(&jssH, sizeof(jssH), 1, outFile) != 1)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Could not write JSSMOD header!\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
486 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
487
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 // Write orders list
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
489 for (totalSize = order = 0; order < m->norders; order++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 {
1237
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
491 int tmp = m->orderList[order];
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
492 if (tmp == jsetNotSet || tmp > m->npatterns)
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
493 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
494 "Orderlist entry #%d has invalid value %d.\n",
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
495 order, tmp);
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
496
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
497 if (!dm_fwrite_le16(outFile, tmp))
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
498 JSSERROR(DMERR_FWRITE, DMERR_FWRITE,
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
499 "Could not write JSSMOD orders list entry #%d (%d).\n",
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
500 order, tmp);
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
501
8b6ed580e800 Add sanity check to order list writing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
502 totalSize += sizeof(Uint16);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
505 dmMsg(1," * %d item orders list, %d bytes.\n",
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
506 m->norders, totalSize);
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
507
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 // Allocate pattern compression buffer
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 if ((patBuf = dmMalloc(patBufSize)) == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 "Error allocating memory for pattern compression buffer.\n");
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
512
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
513 // Convert and write patterns
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
514 for (totalSize = pattern = 0; pattern < m->npatterns; pattern++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 {
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
516 JSSPattern *pat = m->patterns[pattern];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 JSSMODPattern patHead;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 size_t finalSize = 0;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
519
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
520 if (pat == NULL)
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
521 JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR,
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
522 "Pattern #%d was NULL.\n", pattern);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
523
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
524 if (pat->nrows > jsetMaxRows)
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
525 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
526 "Pattern #%d has %d rows > %d max.\n",
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
527 pattern, pat->nrows, jsetMaxRows);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
528
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 switch (patMode)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 case PATMODE_RAW_HORIZ:
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
532 i = jssConvertPatternRawHoriz(patBuf, patBufSize, &finalSize, pat);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 case PATMODE_COMP_HORIZ:
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
535 i = jssConvertPatternCompHoriz(patBuf, patBufSize, &finalSize, pat);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 case PATMODE_RAW_VERT:
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
538 i = jssConvertPatternRawVert(patBuf, patBufSize, &finalSize, pat);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 case PATMODE_COMP_VERT:
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
541 i = jssConvertPatternCompVert(patBuf, patBufSize, &finalSize, pat);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 case PATMODE_RAW_ELEM:
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
544 i = jssConvertPatternRawElem(patBuf, patBufSize, &finalSize, pat);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 dmFree(patBuf);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 "Unsupported pattern conversion mode %d.\n", patMode);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 if (i != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 dmFree(patBuf);
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
555 JSSERROR(i, i, "Error converting pattern data #%d\n", pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 }
1211
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
557
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
558 dmMsg(3, " - Pattern %d size %d bytes\n", pattern, finalSize);
1232
10cb3c400451 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1231
diff changeset
559 patHead.nrows = pat->nrows;
1211
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
560 patHead.size = finalSize;
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
561 totalSize += finalSize + sizeof(patHead);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562
1211
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
563 if (fwrite(&patHead, sizeof(patHead), 1, outFile) != 1)
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
564 {
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
565 dmFree(patBuf);
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
566 JSSERROR(DMERR_FWRITE, DMERR_FWRITE,
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
567 "Error writing pattern #%d header\n", pattern);
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
568 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
1211
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
570 if (fwrite(patBuf, sizeof(Uint8), finalSize, outFile) != finalSize)
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
571 {
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
572 dmFree(patBuf);
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
573 JSSERROR(DMERR_FWRITE, DMERR_FWRITE,
83ed44e9630b Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
574 "Error writing pattern #%d data\n", pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 dmFree(patBuf);
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
578 dmMsg(1," * %d patterns, %d bytes.\n", m->npatterns, totalSize);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 // Write extended instruments
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
581 for (totalSize = instr = 0; instr < m->nextInstruments; instr++)
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 JSSMODExtInstrument jssE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 JSSExtInstrument *einst = m->extInstruments[instr];
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
585
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1134
diff changeset
586 dmMemset(&jssE, 0, sizeof(jssE));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 if (einst)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 // Create header
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 jssE.nsamples = einst->nsamples;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 for (i = 0; i < jsetNNotes; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 int snum = einst->sNumForNotes[i];
1118
de25e0f2b856 Fix sNumForNotes conversion/handling in JSSMOD loader and xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents: 1116
diff changeset
595 jssE.sNumForNotes[i] = (snum != jsetNotSet) ? snum + 1: 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
597
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 jssCopyEnvelope(&jssE.volumeEnv, &(einst->volumeEnv));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 jssCopyEnvelope(&jssE.panningEnv, &(einst->panningEnv));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 jssE.vibratoType = einst->vibratoType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 jssE.vibratoSweep = einst->vibratoSweep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 jssE.vibratoDepth = einst->vibratoDepth;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 jssE.fadeOut = einst->fadeOut;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 } else
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
605 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Extended instrument #%d NULL!\n", instr);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
606
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 // Write to file
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
608 totalSize += sizeof(jssE);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 if (fwrite(&jssE, sizeof(jssE), 1, outFile) != 1)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 JSSERROR(DMERR_FWRITE, DMERR_FWRITE,
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
611 "Could not write JSSMOD extended instrument #%d to file!\n", instr);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 }
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
613 dmMsg(1," * %d Extended Instruments, %d bytes.\n", m->nextInstruments, totalSize);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 // Write sample instrument headers
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
617 for (totalSize = instr = 0; instr < m->ninstruments; instr++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 JSSMODInstrument jssI;
1115
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
620 JSSInstrument *inst = m->instruments[instr];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1134
diff changeset
622 dmMemset(&jssI, 0, sizeof(jssI));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 // Create header
1115
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
625 if (inst != NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 {
1115
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
627 jssI.size = inst->size;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
628 jssI.loopS = inst->loopS;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
629 jssI.loopE = inst->loopE;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
630 jssI.volume = inst->volume;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
631 jssI.flags = inst->flags;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
632 jssI.C4BaseSpeed = inst->C4BaseSpeed;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
633 jssI.ERelNote = inst->ERelNote;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
634 jssI.EFineTune = inst->EFineTune;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
635 jssI.EPanning = inst->EPanning;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
636 jssI.hasData = (inst->data != NULL) ? TRUE : FALSE;
bfed0d5f8e8b Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1114
diff changeset
637 jssI.convFlags = (inst->flags & jsf16bit) ? flags16 : flags8;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
639 else
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
640 JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Instrument #%d NULL!\n", instr);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
641
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 // Write to file
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
643 totalSize += sizeof(jssI);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 if (fwrite(&jssI, sizeof(jssI), 1, outFile) != 1)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 JSSERROR(DMERR_FWRITE, DMERR_FWRITE,
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
646 "Could not write JSSMOD instrument #%d to file!\n", instr);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 }
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
648 dmMsg(1," * %d Instrument headers, %d bytes.\n", m->ninstruments, totalSize);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
649
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 // Write sample data
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
651 for (totalSize = instr = 0; instr < m->ninstruments; instr++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 if (m->instruments[instr])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 JSSInstrument *inst = m->instruments[instr];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 if (inst->data != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 size_t res;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 if (inst->flags & jsf16bit)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 jssEncodeSample16(inst->data, inst->size, flags16);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 res = fwrite(inst->data, sizeof(Uint16), inst->size, outFile);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 jssEncodeSample8(inst->data, inst->size, flags8);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666 res = fwrite(inst->data, sizeof(Uint8), inst->size, outFile);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
668
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
669 totalSize += inst->size;
86
7108681151a4 Use a cast.
Matti Hamalainen <ccr@tnsp.org>
parents: 84
diff changeset
670 if (res != (size_t) inst->size)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 JSSERROR(DMERR_FWRITE, DMERR_FWRITE,
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
672 "Could not write JSSMOD sample #%d to file!\n", instr);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 }
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
675 dmMsg(1," * %d samples, %d bytes.\n", m->ninstruments, totalSize);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
676
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
681 /* Optimize a given module
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 JSSModule *optimizeModule(JSSModule *m)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 BOOL usedPatterns[jsetMaxPatterns + 1],
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686 usedInstruments[jsetMaxInstruments + 1],
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 usedExtInstruments[jsetMaxInstruments + 1];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 int mapExtInstruments[jsetMaxInstruments + 1],
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 mapInstruments[jsetMaxInstruments + 1],
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690 mapPatterns[jsetMaxPatterns + 1];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691 JSSModule *r = NULL;
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
692 int i, n8, n16, unused;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 // Allocate a new module
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 if ((r = jssAllocateModule()) == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 return NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 // Copy things
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
699 r->moduleType = m->moduleType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 r->moduleName = dm_strdup(m->moduleName);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 r->trackerName = dm_strdup(m->trackerName);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 r->defSpeed = m->defSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 r->defTempo = m->defTempo;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704 r->defFlags = m->defFlags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 r->defRestartPos = m->defRestartPos;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 r->intVersion = m->intVersion;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707 r->nchannels = m->nchannels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 r->norders = m->norders;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 for (i = 0; i < jsetNChannels; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710 r->defPanning[i] = m->defPanning[i];
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
711
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 // Initialize values
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 for (i = 0; i <= jsetMaxInstruments; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 usedExtInstruments[i] = FALSE;
798
422f85db78fd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
716 usedInstruments[i] = FALSE;
422f85db78fd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
717 mapExtInstruments[i] = jsetNotSet;
422f85db78fd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
718 mapInstruments[i] = jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
720
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 for (i = 0; i <= jsetMaxPatterns; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 usedPatterns[i] = FALSE;
798
422f85db78fd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
724 mapPatterns[i] = jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
727 //
798
422f85db78fd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 797
diff changeset
728 // Find out all actually used patterns and ext.instruments
1100
654602d3d5a5 Improve comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1099
diff changeset
729 // by going through all patterns specified in the order list
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
730 //
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 for (i = 0; i < m->norders; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733 int pattern = m->orderList[i];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734 if (pattern >= 0 && pattern < m->npatterns)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 JSSPattern *p = m->patterns[pattern];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 if (p != NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 JSSNote *n = p->data;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
741
1100
654602d3d5a5 Improve comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1099
diff changeset
742 // Mark this pattern as used
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 usedPatterns[pattern] = TRUE;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
744
1100
654602d3d5a5 Improve comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1099
diff changeset
745 // Check all notes in this pattern to see what instruments are used
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 for (row = 0; row < p->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 for (channel = 0; channel < p->nchannels; channel++, n++)
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
748 if (n->instrument != jsetNotSet)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
750 if (n->instrument >= 0 && n->instrument < m->nextInstruments)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
751 usedExtInstruments[n->instrument] = TRUE;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
752 else
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
754 dmMsg(2, "Pattern 0x%x, row=0x%x, chn=%d has invalid instrument 0x%x\n",
1111
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
755 pattern, row, channel, n->instrument + 1);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
759 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
761 dmErrorMsg("Pattern 0x%x is used on order 0x%x, but has no data!\n",
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
762 pattern, i);
807
d83dc7e47076 Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents: 798
diff changeset
763
d83dc7e47076 Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents: 798
diff changeset
764 // Fix it.
d83dc7e47076 Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents: 798
diff changeset
765 m->orderList[i] = jsetMaxPatterns;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
766 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 if (pattern != jsetMaxPatterns)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 {
1101
0577f10dc3de Improve messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1100
diff changeset
771 dmErrorMsg("Order 0x%x has invalid pattern number 0x%x, changing to empty!\n",
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
772 i, pattern);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
773
807
d83dc7e47076 Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents: 798
diff changeset
774 // Fix it.
d83dc7e47076 Fix some order list and pattern handling things.
Matti Hamalainen <ccr@tnsp.org>
parents: 798
diff changeset
775 m->orderList[i] = jsetMaxPatterns;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
778
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
779 //
1100
654602d3d5a5 Improve comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1099
diff changeset
780 // Find used sample instruments
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
781 //
1101
0577f10dc3de Improve messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1100
diff changeset
782 dmMsg(1, "Checking ext.instruments for used sample instruments...\n");
856
415cc781e127 Fix some brain farts in instrument remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
783 for (i = 0; i < jsetMaxInstruments; i++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
784 if (usedExtInstruments[i] && m->extInstruments[i] != NULL)
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 int note;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 JSSExtInstrument *e = m->extInstruments[i];
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
788
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 for (note = 0; note < jsetNNotes; note++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 if (e->sNumForNotes[note] != jsetNotSet)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 int q = e->sNumForNotes[note];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 if (q >= 0 && q < m->ninstruments)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 usedInstruments[q] = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
799 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
800 i + 1, m->ninstruments, q + 1);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
803 }
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
804
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
805 //
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 // Create pattern mappings
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
807 //
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
808 dmMsg(1, "Creating pattern remaps...\n");
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
809 for (unused = i = 0; i <= jsetMaxPatterns; i++)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
810 if (usedPatterns[i])
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
812 JSSPattern *pat;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
813
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
814 if (i >= m->npatterns)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
816 dmErrorMsg("Pattern 0x%x >= 0x%x, but used!\n", i, m->npatterns);
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
817 continue;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 }
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
819
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
820 if ((pat = m->patterns[i]) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
822 dmErrorMsg("Pattern 0x%x used but is NULL.\n", i);
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
823 continue;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
825
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
826 mapPatterns[i] = r->npatterns;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
827 r->patterns[r->npatterns] = m->patterns[i];
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
828 (r->npatterns)++;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829 }
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
830 else
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
831 if (m->patterns[i] != NULL)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
832 unused++;
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
833
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
834 dmMsg(1, "%d used patterns (%d unused).\n",
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
835 r->npatterns, unused);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
836
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
837
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
838 //
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 // Re-map instruments
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
840 //
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
841 dmMsg(1, "Creating sample instrument remaps...\n");
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
842 for (unused = n8 = n16 = i = 0; i < jsetMaxInstruments; i++)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
843 if (usedInstruments[i])
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
845 JSSInstrument *ip;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
846 if (optStripInstr)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
847 continue;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
848
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
849 if (i >= m->ninstruments)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
851 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
852 i + 1, m->ninstruments);
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
853 continue;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854 }
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
855
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
856 if ((ip = m->instruments[i]) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857 {
1111
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
858 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
859 continue;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
860 }
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
861
1111
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
862 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
863
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
864 mapInstruments[i] = r->ninstruments;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
865 r->instruments[r->ninstruments] = ip;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
866 (r->ninstruments)++;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
868 if (ip->flags & jsf16bit)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
869 n16++;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
870 else
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
871 n8++;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
872 }
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
873 else
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
874 if (m->instruments[i] != NULL)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
875 unused++;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
876
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877 dmPrint(2, "\n");
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
878 dmMsg(1, "Total of %d [16-bit] + %d [8-bit] samples = %d instruments (%d unused).\n",
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
879 n16, n8, r->ninstruments, unused);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
880
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
881 //
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
882 // Re-map ext.instruments
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
883 //
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
884 dmMsg(1, "Creating ext.instrument remaps...\n");
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
885 for (unused = i = 0; i < jsetMaxInstruments; i++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886 if (usedExtInstruments[i])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
887 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
888 JSSExtInstrument *eip;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
889 int note;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
890 if (optStripExtInstr)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
891 continue;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
892
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
893 if (i >= m->nextInstruments)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
894 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
895 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
896 i + 1, m->nextInstruments);
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
897 continue;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
898 }
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
899
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
900 if ((eip = m->extInstruments[i]) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
901 {
1111
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
902 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
903 continue;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
904 }
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
905
1111
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
906 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
907
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
908 mapExtInstruments[i] = r->nextInstruments;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
909 r->extInstruments[r->nextInstruments] = eip;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
910 (r->nextInstruments)++;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
911
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
912 // Re-map sNumForNotes table for this ext.instrument
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
913 for (note = 0; note < jsetNNotes; note++)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
914 {
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
915 int q = eip->sNumForNotes[note];
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
916 if (q != jsetNotSet)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
917 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
918 int map;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
919 if (q >= 0 && q < jsetMaxInstruments)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
920 {
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
921 map = mapInstruments[q];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
922 }
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
923 else
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
924 {
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
925 map = jsetNotSet;
1111
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
926 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
927 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
928 }
1111
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
929
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
930 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
931 eip->sNumForNotes[note] = map;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
932 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
933 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
934 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
935 else
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
936 if (m->extInstruments[i] != NULL)
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
937 unused++;
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
938
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
939 dmPrint(2, "\n");
1097
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
940 dmMsg(1, "%d extended instruments (%d unused).\n",
0e3cb9e61170 Code cleanup, in preparation for bug hunting.
Matti Hamalainen <ccr@tnsp.org>
parents: 1094
diff changeset
941 r->nextInstruments, unused);
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
942
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
943 //
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
944 // Remap pattern data with remapped instrument data
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
945 //
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
946 for (i = 0; i < r->npatterns; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
947 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949 JSSPattern *p = r->patterns[i];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
950 JSSNote *n = p->data;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
951
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
952 for (row = 0; row < p->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
953 for (channel = 0; channel < p->nchannels; channel++, n++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
954 {
184
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
955 char effect;
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
956
1109
c8bcdddf233c Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
957 // If not stripping extended instruments, check for
c8bcdddf233c Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
958 // 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
959 if (!optStripExtInstr)
cd57ba1130eb Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 337
diff changeset
960 {
856
415cc781e127 Fix some brain farts in instrument remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 807
diff changeset
961 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
962 n->instrument = mapExtInstruments[n->instrument];
202
85614db5f577 Warn about invalid instruments.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
963
1116
9d78c880c6e1 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1115
diff changeset
964 if (n->instrument != jsetNotSet &&
9d78c880c6e1 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1115
diff changeset
965 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
966 {
1116
9d78c880c6e1 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1115
diff changeset
967 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
968 n->instrument + 1);
f9a96fc2a932 Adjust messages to show user-visible (1 based) instrument numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1109
diff changeset
969 }
338
cd57ba1130eb Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 337
diff changeset
970 }
cd57ba1130eb Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 337
diff changeset
971
184
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
972 JMPGETEFFECT(effect, n->effect);
1094
8fc475bbfa42 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1093
diff changeset
973
184
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
974 switch (effect)
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
975 {
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
976 case 'C': // Cxx = Set volume
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
977 if (n->volume == jsetNotSet)
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
978 {
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
979 n->volume = n->param;
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
980 n->effect = jsetNotSet;
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
981 n->param = jsetNotSet;
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
982 }
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
983 break;
50f55def91e5 Add a minor optimization in the conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
984 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
985 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
986 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
987
1113
28dcf10fb8a9 Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 1111
diff changeset
988 //
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 // Remap orders list
1113
28dcf10fb8a9 Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 1111
diff changeset
990 //
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991 for (i = 0; i < m->norders; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
993 r->orderList[i] = mapPatterns[m->orderList[i]];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
994 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
995
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
996 return r;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
997 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
998
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
999
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1000 int main(int argc, char *argv[])
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1001 {
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1002 DMResource *inFile = NULL;
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1003 FILE *outFile = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1004 JSSModule *sm, *dm;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1005 int result;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1006
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1007 dmInitProg("xm2jss", "XM to JSSMOD converter", "0.6", NULL, NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1008 dmVerbosity = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1009
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1010 // Parse arguments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1011 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
1012 argHandleOpt, argHandleFile, OPTH_BAILOUT))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1013 exit(1);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1014
300
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1015 // Check arguments
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1016 if (optInFilename == NULL || optOutFilename == NULL)
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1017 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
1018 dmErrorMsg("Input or output file not specified. Try --help.\n");
300
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1019 return 1;
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1020 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1021
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1022 // Read the source file
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1023 if ((result = dmf_create_stdio(optInFilename, "rb", &inFile)) != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1024 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
1025 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
1026 optInFilename, result, dmErrorStr(result));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1027 return 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1028 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1029
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1030 // Initialize miniJSS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1031 jssInit();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1032
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1033 // Read file
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1034 dmMsg(1, "Reading XM-format file ...\n");
797
f066e9dccf29 Oops, fix some inverted booleans.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
1035 result = jssLoadXM(inFile, &sm, FALSE);
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1036 dmf_close(inFile);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1037 if (result != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1038 {
1195
4d27c4ec8d4d Use %d instead of %i in formats.
Matti Hamalainen <ccr@tnsp.org>
parents: 1194
diff changeset
1039 dmErrorMsg("Error while loading XM file (%d), ", result);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1040 if (optIgnoreErrors)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1041 fprintf(stderr, "ignoring. This may cause problems.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1042 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1043 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1044 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
1045 return 2;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1046 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1047 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1048
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1049 // Check stripping settings
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1050 if (optStripExtInstr) optStripInstr = TRUE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1051 if (optStripInstr) optStripSamples = TRUE;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
1052
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1053 // Remove samples
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1054 if (optStripSamples)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1055 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1056 int i;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
1057
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1058 dmMsg(1, "Stripping samples...\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1059 for (i = 0; i < sm->ninstruments; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1060 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1061 dmFree(sm->instruments[i]->data);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1062 sm->instruments[i]->data = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1063 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1064 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1065
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1066 // Remove instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1067 if (optStripInstr)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1068 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1069 int i;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
1070
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1071 dmMsg(1, "Stripping instruments...\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1072 for (i = 0; i < sm->ninstruments; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1073 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1074 dmFree(sm->instruments[i]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1075 sm->instruments[i] = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1076 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1077 sm->ninstruments = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1078 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1079
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1080 // Remove ext.instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1081 if (optStripExtInstr)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1082 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1083 int i;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
1084
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1085 dmMsg(1, "Stripping ext.instruments...\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1086 for (i = 0; i < sm->nextInstruments; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1087 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1088 dmFree(sm->extInstruments[i]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1089 sm->extInstruments[i] = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1090 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1091 sm->nextInstruments = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1092 }
1109
c8bcdddf233c Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
1093
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1094 // Run the optimization procedure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1095 if (optOptimize)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1096 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1097 dmMsg(1, "Optimizing module data...\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1098 dm = optimizeModule(sm);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1099 } else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1100 dm = sm;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1101
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1102 // Write output file
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1103 if ((outFile = fopen(optOutFilename, "wb")) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1104 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
1105 dmErrorMsg("Error creating output file '%s', %d: %s\n",
300
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1106 optOutFilename, errno, strerror(errno));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1107 return 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1108 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1109
9
c42ee907de9c Various improvements in xm2jss output.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
1110 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
1111 optPatternMode, optSampMode8, optSampMode16);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
1112
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1113 result = jssSaveJSSMOD(outFile, dm, optPatternMode, optSampMode8, optSampMode16);
1113
28dcf10fb8a9 Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 1111
diff changeset
1114
1114
7aaab1533c90 Free the source module data at end.
Matti Hamalainen <ccr@tnsp.org>
parents: 1113
diff changeset
1115 dmFree(sm);
7aaab1533c90 Free the source module data at end.
Matti Hamalainen <ccr@tnsp.org>
parents: 1113
diff changeset
1116
730
3d813c81f33c More work on resources API.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1117 fclose(outFile);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1233
diff changeset
1118
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1119 if (result != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1120 {
1113
28dcf10fb8a9 Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 1111
diff changeset
1121 dmErrorMsg(
28dcf10fb8a9 Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 1111
diff changeset
1122 "Error while saving JSSMOD file, %d: %s\n"
28dcf10fb8a9 Comments, cosmetics, combine one error message.
Matti Hamalainen <ccr@tnsp.org>
parents: 1111
diff changeset
1123 "WARNING: The resulting file may be broken!\n",
300
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1124 result, dmErrorStr(result));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1125 }
300
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1126 else
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1127 {
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1128 dmMsg(1, "Conversion complete.\n");
4972ca91d062 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
1129 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1130 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1131 }