Mercurial > hg > dmlib
annotate minijss/jloadxm.c @ 2202:455a3849b8ac
Comments and cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 01:56:47 +0300 |
parents | b47109fce375 |
children | e0f9200b94ad |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Fast Tracker ][ (XM) module loader | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1125 | 4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
0 | 5 * |
6 * TO DO: | |
7 * - Add support for 1.02/1.03 XM-format versions. | |
8 * (Not very useful, but if it's not too hard, then do it) | |
9 */ | |
10 #include "jssmod.h" | |
11 | |
12 | |
13 /* XM value limit definitions | |
14 */ | |
15 #define XM_MaxChannels (32) | |
16 #define XM_MaxPatterns (256) | |
17 #define XM_MaxOrders (255) | |
18 #define XM_MaxInstruments (128) | |
19 #define XM_MaxInstSamples (16) | |
20 #define XM_MaxEnvPoints (12) | |
21 #define XM_MaxNotes (96) | |
22 #define XM_MaxSampleVolume (64) | |
1161
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
23 #define XM_HeaderSize 276 |
0 | 24 |
1174 | 25 |
0 | 26 /* XM format structures |
27 */ | |
28 typedef struct | |
29 { | |
30 char idMagic[17]; // XM header ID "Extended Module: " | |
31 char songName[20]; // Module song name | |
32 Uint8 unUsed1A; // ALWAYS 0x1a | |
33 char trackerName[20]; // ID-string of tracker software | |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
34 Uint16 version; // XM-version tag |
0 | 35 Uint32 headSize; // Module header size, FROM THIS POINT! |
36 Uint16 norders, // Number of orders | |
37 defRestartPos, // Default song restart position | |
38 nchannels, // Number of channels | |
39 npatterns, // Number of patterns | |
40 ninstruments, // Number of instruments | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
41 flags, // Module flags: |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
42 // bit0: 0 = Amiga frequency table |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
43 // 1 = Linear frequency table |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
44 // |
0 | 45 defSpeed, // Default speed |
46 defTempo; // Default tempo | |
47 Uint8 orderList[256]; // Order list | |
48 } XMHeader; | |
49 | |
50 | |
51 typedef struct | |
52 { | |
53 Uint32 headSize; // Instrument header size (see docs!) | |
54 char instName[22]; // Name/description | |
55 Uint8 instType; // Type | |
56 Uint16 nsamples; // Number of samples | |
57 } XMInstrument1; | |
58 | |
59 | |
60 typedef struct | |
61 { | |
62 Uint16 frame, value; | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
63 } XMEnvPoint; |
0 | 64 |
65 | |
66 typedef struct | |
67 { | |
68 Uint8 flags, npoints, sustain, loopS, loopE; | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
69 XMEnvPoint points[XM_MaxEnvPoints]; |
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
70 } XMEnvelope; |
0 | 71 |
72 | |
73 typedef struct | |
74 { | |
75 Uint32 headSize; // Header size | |
76 Uint8 sNumForNotes[XM_MaxNotes]; // Sample numbers for notes | |
552
d4cee32e7050
Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
77 XMEnvelope volumeEnv, panningEnv; |
0 | 78 Uint8 vibratoType, vibratoSweep, vibratoDepth, vibratoRate; |
79 | |
80 Uint16 fadeOut, ARESERVED; | |
81 } XMInstrument2; | |
82 | |
83 | |
84 typedef struct | |
85 { | |
86 Uint32 size, loopS, loopL; | |
87 Uint8 volume; | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
88 Sint8 fineTune; |
0 | 89 Uint8 type, panning; |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
90 Sint8 relNote; |
0 | 91 Uint8 ARESERVED; |
92 char sampleName[22]; | |
93 } XMSample; | |
94 | |
95 | |
96 typedef struct | |
97 { | |
98 Uint32 headSize; | |
99 Uint8 packing; | |
100 Uint16 nrows, size; | |
101 } XMPattern; | |
102 | |
103 | |
104 | |
105 /* Unpack XM-format pattern from file-stream into JSS-pattern structure | |
106 */ | |
1148 | 107 #define JSGETBYTE(XV) \ |
108 do { \ | |
1181 | 109 if (size <= 0) \ |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
110 JSSERROR(DMERR_OUT_OF_DATA, DMERR_OUT_OF_DATA, \ |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
111 "Unexpected end of packed pattern data.\n"); \ |
1181 | 112 size--; \ |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
113 XV = dmfgetc(inFile); \ |
0 | 114 } while (0) |
115 | |
116 | |
1148 | 117 /* Convert XM note value to internal JSS note |
118 */ | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
119 static int jssXMConvertNote(int val) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
120 { |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
121 if (val < 1 || val > 97) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
122 return jsetNotSet; |
1148 | 123 else |
124 if (val == 97) | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
125 return jsetNoteOff; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
126 else |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
127 return val - 1; |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
128 } |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
129 |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
130 |
1148 | 131 /* Unpack a XM pattern structure from resource to given JSS pattern |
132 */ | |
1180
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
133 static int jssXMUnpackPattern104(DMResource *inFile, int size, JSSPattern *pattern) |
0 | 134 { |
135 JSSNote *pnote; | |
1179
e7a951937374
Move variable definitions closer to where they are used.
Matti Hamalainen <ccr@tnsp.org>
parents:
1177
diff
changeset
|
136 int row, channel; |
0 | 137 assert(pattern != NULL); |
138 | |
139 pnote = pattern->data; | |
140 | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
141 for (row = 0; row < pattern->nrows && size > 0; row++) |
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
142 for (channel = 0; channel < pattern->nchannels && size > 0; channel++) |
0 | 143 { |
1179
e7a951937374
Move variable definitions closer to where they are used.
Matti Hamalainen <ccr@tnsp.org>
parents:
1177
diff
changeset
|
144 int packb, tmp; |
0 | 145 JSGETBYTE(packb); |
146 if (packb & 0x80) | |
147 { | |
148 if (packb & 0x01) | |
149 { | |
150 // PACK 0x01: Read note | |
151 JSGETBYTE(tmp); | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
152 pnote->note = jssXMConvertNote(tmp); |
0 | 153 } |
154 | |
155 if (packb & 0x02) | |
156 { | |
157 // PACK 0x02: Read instrument | |
158 JSGETBYTE(tmp); | |
159 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
160 } | |
161 | |
162 if (packb & 0x04) | |
163 { | |
164 // PACK 0x04: Read volume | |
165 JSGETBYTE(tmp); | |
166 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; | |
167 } | |
168 | |
169 if (packb & 0x08) | |
170 { | |
171 // PACK 0x08: Read effect | |
172 JSGETBYTE(pnote->effect); | |
173 pnote->param = 0; | |
174 } | |
175 | |
176 if (packb & 0x10) | |
177 { | |
178 // PACK 0x10: Read effect parameter | |
179 JSGETBYTE(pnote->param); | |
180 if (pnote->effect == jsetNotSet && pnote->param != 0) | |
181 pnote->effect = 0; | |
182 } | |
183 } | |
184 else | |
185 { | |
186 // All data available | |
313
a89500f26dde
Cleanup the pattern decoder a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
183
diff
changeset
|
187 pnote->note = jssXMConvertNote(packb & 0x7f); |
0 | 188 |
189 // Get instrument | |
190 JSGETBYTE(tmp); | |
191 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; | |
192 | |
193 // Get volume | |
194 JSGETBYTE(tmp); | |
195 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; | |
196 | |
197 // Get effect | |
198 JSGETBYTE(pnote->effect); | |
199 | |
200 // Get parameter | |
201 JSGETBYTE(pnote->param); | |
202 if (pnote->effect == 0 && pnote->param == 0) | |
203 pnote->effect = pnote->param = jsetNotSet; | |
204 } | |
205 pnote++; | |
206 } | |
207 | |
208 // Check the state | |
209 if (size > 0) | |
210 { | |
211 // Some data left unparsed | |
212 JSSWARNING(DMERR_EXTRA_DATA, DMERR_EXTRA_DATA, | |
1397 | 213 "Unparsed data after pattern (%d bytes), possibly broken file.\n", |
214 size); | |
0 | 215 } |
216 | |
217 return DMERR_OK; | |
218 } | |
219 | |
220 | |
1180
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
221 static int jssXMUnpackPattern102(DMResource *inFile, int size, JSSPattern *pattern) |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
222 { |
1192
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
223 JSSNote *pnote; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
224 int row, channel; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
225 assert(pattern != NULL); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
226 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
227 pnote = pattern->data; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
228 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
229 for (row = 0; row < pattern->nrows && size > 0; row++) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
230 for (channel = 0; channel < pattern->nchannels && size > 0; channel++) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
231 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
232 int packb, tmp; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
233 JSGETBYTE(packb); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
234 if (packb & 0x80) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
235 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
236 if (packb & 0x01) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
237 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
238 // PACK 0x01: Read note |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
239 JSGETBYTE(tmp); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
240 pnote->note = jssXMConvertNote(tmp); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
241 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
242 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
243 if (packb & 0x02) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
244 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
245 // PACK 0x02: Read instrument |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
246 JSGETBYTE(tmp); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
247 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
248 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
249 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
250 if (packb & 0x04) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
251 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
252 // PACK 0x04: Read volume |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
253 JSGETBYTE(tmp); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
254 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
255 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
256 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
257 if (packb & 0x08) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
258 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
259 // PACK 0x08: Read effect |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
260 JSGETBYTE(pnote->effect); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
261 pnote->param = 0; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
262 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
263 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
264 if (packb & 0x10) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
265 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
266 // PACK 0x10: Read effect parameter |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
267 JSGETBYTE(pnote->param); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
268 if (pnote->effect == jsetNotSet && pnote->param != 0) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
269 pnote->effect = 0; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
270 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
271 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
272 else |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
273 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
274 // All data available |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
275 pnote->note = jssXMConvertNote(packb & 0x7f); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
276 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
277 // Get instrument |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
278 JSGETBYTE(tmp); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
279 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
280 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
281 // Get volume |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
282 JSGETBYTE(tmp); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
283 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
284 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
285 if (tmp & 0xc0) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
286 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
287 JSGETBYTE(pnote->effect); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
288 JSGETBYTE(pnote->param); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
289 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
290 else |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
291 { |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
292 JSGETBYTE(pnote->param); |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
293 pnote->effect = tmp & 0xf; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
294 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
295 |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
296 if (pnote->effect == 0 && pnote->param == 0) |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
297 pnote->effect = pnote->param = jsetNotSet; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
298 } |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
299 pnote++; |
8841c7f8c608
Some work on the 0x0102 pattern loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1191
diff
changeset
|
300 } |
1180
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
301 |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
302 // Check the state |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
303 if (size > 0) |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
304 { |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
305 // Some data left unparsed |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
306 JSSWARNING(DMERR_EXTRA_DATA, DMERR_EXTRA_DATA, |
1397 | 307 "Unparsed data after pattern (%d bytes), possibly broken file.\n", |
308 size); | |
1180
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
309 } |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
310 |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
311 return DMERR_OK; |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
312 } |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
313 |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
314 |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
315 static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
316 { |
1184 | 317 int index, ret; |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
318 XMPattern xmP; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
319 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
320 for (index = 0; index < module->npatterns; index++) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
321 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
322 off_t remainder, pos = dmftell(inFile); |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
323 Uint32 headSize; |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
324 |
1217 | 325 // Get the pattern header size and packing |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
326 if (!dmf_read_le32(inFile, &xmP.headSize) || |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
327 !dmf_read_byte(inFile, &xmP.packing)) |
1259 | 328 { |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
329 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1397 | 330 "Could not read pattern header #%d.\n", |
331 index); | |
1259 | 332 } |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
333 |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
334 // Different format versions have slightly different headers |
1185
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
335 if (module->intVersion == 0x0102) |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
336 { |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
337 Uint8 tmp; |
1217 | 338 // 0x0102 has one byte number of rows |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
339 ret = dmf_read_byte(inFile, &tmp); |
1186
eca2784bff75
It seems that the number of rows in XM format version 0x0102 needs + 1.
Matti Hamalainen <ccr@tnsp.org>
parents:
1185
diff
changeset
|
340 xmP.nrows = ((Uint16) tmp) + 1; |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
341 headSize = 4 + 1 + 1 + 2; |
1185
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
342 } |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
343 else |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
344 { |
1217 | 345 // 0x0104 has 16-bit word for nrows |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
346 ret = dmf_read_le16(inFile, &xmP.nrows); |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
347 headSize = 4 + 1 + 2 + 2; |
1185
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
348 } |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
349 |
1217 | 350 // Check header size against known values |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
351 if (headSize != xmP.headSize) |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
352 { |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
353 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
1397 | 354 "Invalid pattern #%d header size %d, expected %d bytes.\n", |
355 index, xmP.headSize, headSize); | |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
356 } |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
357 |
1217 | 358 // Read rest of the header |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
359 if (!ret || !dmf_read_le16(inFile, &xmP.size)) |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
360 { |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
361 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1397 | 362 "Could not read pattern header data #%d.\n", |
363 index); | |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
364 } |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
365 |
1217 | 366 // Sanity-check rest of the header data |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
367 if (xmP.packing != 0) |
1259 | 368 { |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
369 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 370 "Pattern #%d packing type unsupported (%d)\n", |
371 index, xmP.packing); | |
1259 | 372 } |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
373 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
374 if (xmP.nrows == 0) |
1259 | 375 { |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
376 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 377 "Pattern #%d has %d rows, invalid data.\n", |
378 index, xmP.nrows); | |
1259 | 379 } |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
380 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
381 if (xmP.size > 0) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
382 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
383 // Allocate and unpack pattern |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
384 module->patterns[index] = jssAllocatePattern(xmP.nrows, module->nchannels); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
385 if (module->patterns[index] == NULL) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
386 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
387 "Could not allocate memory for pattern #%d\n", index); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
388 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
389 switch (module->intVersion) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
390 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
391 case 0x0104: |
1184 | 392 ret = jssXMUnpackPattern104(inFile, xmP.size, module->patterns[index]); |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
393 break; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
394 case 0x0102: |
1184 | 395 ret = jssXMUnpackPattern102(inFile, xmP.size, module->patterns[index]); |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
396 break; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
397 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
398 |
1184 | 399 if (ret != 0) |
400 JSSERROR(ret, ret, "Error in unpacking pattern #%d data\n", index); | |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
401 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
402 |
1217 | 403 // Skip extra data if there is any .. shouldn't usually happen tho. |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
404 remainder = xmP.headSize - (dmftell(inFile) - pos); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
405 if (remainder > 0) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
406 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
407 JSSDEBUG("xmP Skipping: %li\n", remainder); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
408 dmfseek(inFile, remainder, SEEK_CUR); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
409 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
410 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
411 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
412 // Allocate the empty pattern |
1225
e8f0305f8e6b
Use module->npatterns instead of jsetMaxPatterns for the special empty pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
1217
diff
changeset
|
413 module->patterns[module->npatterns] = jssAllocatePattern(64, module->nchannels); |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
414 |
1217 | 415 /* Convert song orders list by replacing nonexisting |
416 * pattern numbers with pattern number jsetMaxPatterns. | |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
417 */ |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
418 for (index = 0; index < module->norders; index++) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
419 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
420 int tmp = xmH->orderList[index]; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
421 if (tmp >= module->npatterns || |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
422 module->patterns[tmp] == NULL) |
1225
e8f0305f8e6b
Use module->npatterns instead of jsetMaxPatterns for the special empty pattern.
Matti Hamalainen <ccr@tnsp.org>
parents:
1217
diff
changeset
|
423 tmp = module->npatterns; |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
424 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
425 module->orderList[index] = tmp; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
426 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
427 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
428 return DMERR_OK; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
429 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
430 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
431 |
0 | 432 /* Convert XM envelope structure to JSS envelope structure |
433 */ | |
1174 | 434 static int jssXMConvertEnvelope( |
435 JSSEnvelope *dst, XMEnvelope *src, | |
436 const char *name, const int ninstr) | |
0 | 437 { |
438 int i; | |
1148 | 439 (void) name; |
440 (void) ninstr; | |
0 | 441 |
442 // Convert envelope points | |
443 for (i = 0; i < XM_MaxEnvPoints; i++) | |
444 { | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
445 dst->points[i].frame = src->points[i].frame; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
446 dst->points[i].value = src->points[i].value; |
0 | 447 } |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
448 |
0 | 449 // Convert other values |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
450 dst->npoints = src->npoints; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
451 dst->sustain = src->sustain; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
452 dst->loopS = src->loopS; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
453 dst->loopE = src->loopE; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
454 |
0 | 455 // Check if the envelope is used |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
456 if (src->flags & 0x01) |
0 | 457 { |
458 // Convert envelope flags | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
459 dst->flags = jenvfUsed; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
460 if (src->flags & 0x02) |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
461 dst->flags |= jenvfSustain; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
462 |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
463 if (src->flags & 0x04) |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
464 dst->flags |= jenvfLooped; |
0 | 465 |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
466 if (src->flags & 0xf0) |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
467 { |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
468 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 469 "Inst#%d/%s-env: Uses unsupported flags values, 0x%02x.\n", |
470 ninstr, name, src->flags); | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
471 } |
0 | 472 |
473 // Check other values | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
474 if (src->npoints > XM_MaxEnvPoints) |
0 | 475 { |
476 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1397 | 477 "Inst#%d/%s-env: npoints > MAX, possibly broken file.\n", |
478 ninstr, name); | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
479 dst->npoints = XM_MaxEnvPoints; |
0 | 480 } |
481 | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
482 if ((dst->flags & jenvfSustain) && src->sustain > src->npoints) |
0 | 483 { |
484 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1397 | 485 "Inst#%d/%s-env: sustain > npoints (%d > %d), possibly broken file.\n", |
486 ninstr, name, src->sustain, src->npoints); | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
487 dst->sustain = src->npoints; |
0 | 488 } |
489 | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
490 if ((dst->flags & jenvfLooped) && src->loopE > src->npoints) |
0 | 491 { |
492 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1397 | 493 "Inst#%d/%s-env: loopE > npoints (%d > %d), possibly broken file.\n", |
494 ninstr, name, src->loopE, src->npoints); | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
495 dst->loopE = src->npoints; |
0 | 496 } |
497 | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
498 if ((dst->flags & jenvfLooped) && src->loopS > src->loopE) |
0 | 499 { |
500 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1397 | 501 "Inst#%d/%s-env: loopS > loopE (%d > %d), possibly broken file.\n", |
502 ninstr, name, src->loopS, src->loopE); | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
503 dst->loopS = src->loopE; |
0 | 504 } |
505 } | |
506 | |
507 return DMERR_OK; | |
508 } | |
509 | |
510 | |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
511 static int jssXMLoadSampleInstrument( |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
512 DMResource *inFile, JSSModule *module, |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
513 JSSExtInstrument *einst, int neinst, int nsample) |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
514 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
515 XMSample xmS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
516 JSSInstrument *inst; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
517 |
1322
c2000337ac3f
Silence some unused function argument warnings (unused due to debug not
Matti Hamalainen <ccr@tnsp.org>
parents:
1260
diff
changeset
|
518 (void) neinst; |
c2000337ac3f
Silence some unused function argument warnings (unused due to debug not
Matti Hamalainen <ccr@tnsp.org>
parents:
1260
diff
changeset
|
519 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
520 // Read header data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
521 if (!dmf_read_le32(inFile, &xmS.size) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
522 !dmf_read_le32(inFile, &xmS.loopS) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
523 !dmf_read_le32(inFile, &xmS.loopL) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
524 !dmf_read_byte(inFile, &xmS.volume) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
525 !dmf_read_byte(inFile, (Uint8 *) &xmS.fineTune) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
526 !dmf_read_byte(inFile, &xmS.type) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
527 !dmf_read_byte(inFile, &xmS.panning) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
528 !dmf_read_byte(inFile, (Uint8 *) &xmS.relNote) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
529 !dmf_read_byte(inFile, &xmS.ARESERVED) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
530 !dmf_read_str(inFile, &xmS.sampleName, sizeof(xmS.sampleName))) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
531 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
532 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1400
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
533 "Error reading instrument sample header #%d/%d [%d]\n", |
1397 | 534 neinst, nsample, module->ninstruments); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
535 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
536 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
537 if (xmS.size <= 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
538 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
539 |
1400
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
540 if (xmS.size > 16 * 1024 * 1024) |
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
541 { |
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
542 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
543 "Sample instrument #%d/%d [%d] too large, %d bytes.\n", |
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
544 neinst, nsample, module->ninstruments, xmS.size); |
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
545 } |
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
546 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
547 // Allocate sample instrument |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
548 JSSDEBUG("Allocating sample #%d/%d [%d]\n", |
1397 | 549 neinst, nsample, module->ninstruments); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
550 |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
551 einst->instConvTable[nsample] = module->ninstruments; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
552 inst = module->instruments[module->ninstruments] = jssAllocateInstrument(); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
553 if (inst == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
554 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
555 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
1397 | 556 "Could not allocate sample #%d/%d [%d]\n", |
557 neinst, nsample, module->ninstruments); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
558 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
559 module->ninstruments++; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
560 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
561 // Copy values |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
562 if (xmS.volume > XM_MaxSampleVolume) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
563 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
564 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 565 "Samp #%d/%d: volume > MAX\n", neinst, nsample); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
566 xmS.volume = XM_MaxSampleVolume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
567 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
568 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
569 inst->volume = xmS.volume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
570 inst->ERelNote = xmS.relNote; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
571 inst->EFineTune = xmS.fineTune; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
572 inst->EPanning = xmS.panning; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
573 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
574 inst->desc = jssASCIItoStr(xmS.sampleName, 0, sizeof(xmS.sampleName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
575 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
576 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
577 // Convert flags |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
578 switch (xmS.type & 0x03) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
579 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
580 case 0: inst->flags = 0; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
581 case 1: inst->flags = jsfLooped; break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
582 default: |
1171
bc7473c0b9ce
Assume that sample type 3 is basically misinterpretation of the field as a
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
583 // Basically 2 is the value for bidi-loop, and |
bc7473c0b9ce
Assume that sample type 3 is basically misinterpretation of the field as a
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
584 // 3 is undefined, but some module writers might've |
bc7473c0b9ce
Assume that sample type 3 is basically misinterpretation of the field as a
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
585 // assumed that this is a bit-field, e.g. 1 | 2 = 3 |
bc7473c0b9ce
Assume that sample type 3 is basically misinterpretation of the field as a
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
586 inst->flags = jsfLooped | jsfBiDi; break; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
587 break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
588 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
589 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
590 if (xmS.type & 0x10) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
591 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
592 // 16-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
593 JSFSET(inst->flags, jsf16bit); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
594 inst->size = xmS.size / sizeof(Uint16); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
595 inst->loopS = xmS.loopS / sizeof(Uint16); |
1174 | 596 inst->loopE = (xmS.loopS + xmS.loopL) / sizeof(Uint16); |
1254
47d8e5e0e592
Add extra sanity checking to 16-bit sample instruments in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
597 if ((xmS.size & 1) || (xmS.loopS & 1) || (xmS.loopL & 1)) |
1259 | 598 { |
1254
47d8e5e0e592
Add extra sanity checking to 16-bit sample instruments in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1239
diff
changeset
|
599 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 600 "Samp #%d/%d: size=%d, loopS=%d or loopL=%d not divisible by 2 for 16-bit sample.\n", |
601 neinst, nsample, xmS.size, xmS.loopS, xmS.loopL); | |
1259 | 602 } |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
603 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
604 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
605 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
606 // 8-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
607 inst->size = xmS.size; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
608 inst->loopS = xmS.loopS; |
1174 | 609 inst->loopE = xmS.loopS + xmS.loopL; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
610 } |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
611 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
612 if (xmS.loopL == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
613 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
614 // Always unset loop, if loop length is zero |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
615 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
616 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
617 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
618 if (inst->flags & jsfLooped) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
619 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
620 if (inst->loopS >= inst->size) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
621 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
622 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 623 "Samp #%d/%d: loopS >= size (%d >= %d)\n", |
624 neinst, nsample, inst->loopS, inst->size); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
625 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
626 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
627 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
628 if (inst->loopE > inst->size) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
629 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
630 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 631 "Samp #%d/%d: loopE > size (%d > %d)\n", |
632 neinst, nsample, inst->loopE, inst->size); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
633 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
634 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
635 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
636 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
637 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
638 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
639 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
640 |
1158 | 641 static int jssXMLoadSampleData(DMResource *inFile, JSSInstrument *inst, int ninst, int nsample) |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
642 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
643 int ret; |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
644 size_t bsize; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
645 |
1322
c2000337ac3f
Silence some unused function argument warnings (unused due to debug not
Matti Hamalainen <ccr@tnsp.org>
parents:
1260
diff
changeset
|
646 (void) ninst; |
c2000337ac3f
Silence some unused function argument warnings (unused due to debug not
Matti Hamalainen <ccr@tnsp.org>
parents:
1260
diff
changeset
|
647 (void) nsample; |
c2000337ac3f
Silence some unused function argument warnings (unused due to debug not
Matti Hamalainen <ccr@tnsp.org>
parents:
1260
diff
changeset
|
648 |
1397 | 649 JSSDEBUG( |
650 "desc....: '%s'\n" | |
651 "size....: %d\n" | |
652 "loopS...: %d\n" | |
653 "loopE...: %d\n" | |
654 "volume..: %d\n" | |
655 "flags...: %x\n", | |
656 inst->desc, | |
657 inst->size, inst->loopS, inst->loopE, | |
658 inst->volume, inst->flags); | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
659 |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
660 // Allocate memory for sample data |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
661 bsize = (inst->flags & jsf16bit) ? sizeof(Uint16) : sizeof(Uint8); |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
662 bsize *= inst->size; |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
663 |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
664 if ((inst->data = dmMalloc(bsize)) == NULL) |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
665 { |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
666 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
1397 | 667 "Could not allocate %d bytes of sample data for instrument/sample #%d/%d.\n", |
668 bsize, ninst, nsample); | |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
669 } |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
670 |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
671 // Read sampledata |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
672 if (dmfread(inst->data, sizeof(Uint8), bsize, inFile) != bsize) |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
673 { |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
674 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1397 | 675 "Error reading sample data for instrument #%d/%d, %d bytes.\n", |
676 ninst, nsample, bsize); | |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
677 } |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
678 |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
679 // Convert the sample data |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
680 if (inst->flags & jsf16bit) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
681 { |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
682 ret = jssDecodeSample16( |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
683 (Uint16 *) inst->data, inst->size, |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
684 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
685 (jsampDelta | jsampSwapEndianess) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
686 #else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
687 (jsampDelta) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
688 #endif |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
689 ); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
690 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
691 else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
692 { |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
693 ret = jssDecodeSample8( |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
694 (Uint8 *) inst->data, inst->size, |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
695 (jsampDelta | jsampFlipSign)); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
696 } |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
697 |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
698 return ret; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
699 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
700 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
701 |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
702 static int jssXMLoadInstrumentSamples( |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
703 DMResource *inFile, JSSModule *module, |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
704 JSSExtInstrument *einst, int neinst) |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
705 { |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
706 int nsample, ret; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
707 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
708 for (nsample = 0; nsample < einst->nsamples; nsample++) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
709 if (einst->instConvTable[nsample] != jsetNotSet) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
710 { |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
711 JSSInstrument *inst = module->instruments[einst->instConvTable[nsample]]; |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
712 if ((ret = jssXMLoadSampleData(inFile, inst, neinst, nsample)) != DMERR_OK) |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
713 return ret; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
714 } |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
715 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
716 return DMERR_OK; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
717 } |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
718 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
719 |
1132 | 720 static BOOL jssXMLoadEnvelopePoints(DMResource *inFile, XMEnvelope *env) |
1131
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
721 { |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
722 int i; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
723 for (i = 0; i < XM_MaxEnvPoints; i++) |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
724 { |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
725 if (!dmf_read_le16(inFile, &(env->points[i].frame)) || |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
726 !dmf_read_le16(inFile, &(env->points[i].value))) |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
727 return FALSE; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
728 } |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
729 return TRUE; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
730 } |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
731 |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
732 |
1132 | 733 static BOOL jssXMLoadEnvelopeData(DMResource *inFile, XMEnvelope *env) |
734 { | |
735 return | |
736 dmf_read_byte(inFile, &(env->sustain)) && | |
737 dmf_read_byte(inFile, &(env->loopS)) && | |
738 dmf_read_byte(inFile, &(env->loopE)); | |
739 } | |
740 | |
741 | |
0 | 742 /* Load XM-format extended instrument from file-stream into JSS module's given inst |
743 */ | |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
744 static int jssXMLoadExtInstrument(DMResource *inFile, int neinst, JSSModule *module) |
0 | 745 { |
746 XMInstrument1 xmI1; | |
1126 | 747 off_t remainder, pos = dmftell(inFile); |
1175 | 748 JSSExtInstrument *einst; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
749 XMInstrument2 xmI2; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
750 int i, nsample, ret; |
0 | 751 |
752 // Get instrument header #1 | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
753 if (!dmf_read_le32(inFile, &xmI1.headSize) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
754 !dmf_read_str(inFile, &xmI1.instName, sizeof(xmI1.instName)) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
755 !dmf_read_byte(inFile, &xmI1.instType) || |
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
756 !dmf_read_le16(inFile, &xmI1.nsamples)) |
1159
29dc9337fa11
Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents:
1158
diff
changeset
|
757 { |
29dc9337fa11
Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents:
1158
diff
changeset
|
758 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1397 | 759 "Failed to read primary extended instrument header #%d.\n", |
760 neinst); | |
1159
29dc9337fa11
Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents:
1158
diff
changeset
|
761 } |
0 | 762 |
763 // If there are samples, there is header #2 | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
764 if (xmI1.nsamples == 0) |
0 | 765 { |
766 // We may STILL need to skip extra data after 1st instr. header | |
767 remainder = xmI1.headSize - (dmftell(inFile) - pos); | |
768 if (remainder > 0) | |
769 { | |
98 | 770 JSSDEBUG("xmI1#2 Skipping: %li\n", remainder); |
0 | 771 dmfseek(inFile, remainder, SEEK_CUR); |
772 } | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
773 return DMERR_OK; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
774 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
775 |
1402
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
776 if (xmI1.nsamples > XM_MaxInstSamples) |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
777 { |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
778 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
779 "Extended instrument #%d has invalid number of samples %d.\n", |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
780 neinst, xmI1.nsamples); |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
781 } |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
782 |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
783 // Allocate instrument |
1257 | 784 JSSDEBUG("Allocating extended instrument #%d [%d]\n", |
785 neinst, module->nextInstruments); | |
786 | |
1175 | 787 if ((einst = jssAllocateExtInstrument()) == NULL) |
1259 | 788 { |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
789 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
1397 | 790 "Could not allocate extended instrument #%d.\n", |
791 neinst); | |
1259 | 792 } |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
793 |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
794 module->extInstruments[neinst] = einst; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
795 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
796 // Get instrument header #2 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
797 if (!dmf_read_le32(inFile, &xmI2.headSize) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
798 !dmf_read_str(inFile, &xmI2.sNumForNotes, sizeof(xmI2.sNumForNotes))) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
799 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
800 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1397 | 801 "Could not read secondary instrument header part #1 for #%d.\n", |
802 neinst); | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
803 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
804 |
1132 | 805 if (!jssXMLoadEnvelopePoints(inFile, &xmI2.volumeEnv) || |
806 !jssXMLoadEnvelopePoints(inFile, &xmI2.panningEnv)) | |
807 { | |
808 JSSERROR(DMERR_FREAD, DMERR_FREAD, | |
1397 | 809 "Could not read envelope point data for instrument #%d.\n", |
810 neinst); | |
1132 | 811 } |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
812 |
1132 | 813 if (!dmf_read_byte(inFile, &xmI2.volumeEnv.npoints) || |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
814 !dmf_read_byte(inFile, &xmI2.panningEnv.npoints) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
815 |
1132 | 816 !jssXMLoadEnvelopeData(inFile, &xmI2.volumeEnv) || |
817 !jssXMLoadEnvelopeData(inFile, &xmI2.panningEnv) || | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
818 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
819 !dmf_read_byte(inFile, &xmI2.volumeEnv.flags) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
820 !dmf_read_byte(inFile, &xmI2.panningEnv.flags) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
821 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
822 !dmf_read_byte(inFile, &xmI2.vibratoType) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
823 !dmf_read_byte(inFile, &xmI2.vibratoSweep) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
824 !dmf_read_byte(inFile, &xmI2.vibratoDepth) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
825 !dmf_read_byte(inFile, &xmI2.vibratoRate) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
826 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
827 !dmf_read_le16(inFile, &xmI2.fadeOut) || |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
828 !dmf_read_le16(inFile, &xmI2.ARESERVED)) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
829 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
830 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1397 | 831 "Could not read secondary instrument header part #2 for #%d.\n", |
832 neinst); | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
833 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
834 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
835 // Skip the extra data after header #2 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
836 remainder = xmI1.headSize - (dmftell(inFile) - pos); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
837 if (remainder > 0) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
838 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
839 JSSDEBUG("xmI1#1 Skipping: %li\n", remainder); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
840 dmfseek(inFile, remainder, SEEK_CUR); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
841 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
842 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
843 // Check and convert all ext instrument information |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
844 #ifndef JSS_LIGHT |
1175 | 845 einst->desc = jssASCIItoStr(xmI1.instName, 0, sizeof(xmI1.instName)); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
846 #endif |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
847 jssXMConvertEnvelope(&einst->volumeEnv, &xmI2.volumeEnv, "vol", neinst); |
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
848 jssXMConvertEnvelope(&einst->panningEnv, &xmI2.panningEnv, "pan", neinst); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
849 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
850 switch (xmI2.vibratoType) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
851 { |
1175 | 852 case 0: einst->vibratoType = jvibSine; break; |
853 case 1: einst->vibratoType = jvibRamp; break; | |
854 case 2: einst->vibratoType = jvibSquare; break; | |
855 case 3: einst->vibratoType = jvibRandom; break; | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
856 default: |
1175 | 857 einst->vibratoType = jvibSine; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
858 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 859 "Invalid extinstrument vibrato type %d for inst #%d\n", |
860 neinst); | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
861 break; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
862 } |
1175 | 863 einst->vibratoSweep = xmI2.vibratoSweep; |
864 einst->vibratoDepth = xmI2.vibratoDepth; | |
865 einst->vibratoRate = xmI2.vibratoRate; | |
866 einst->fadeOut = xmI2.fadeOut; | |
867 einst->nsamples = xmI1.nsamples; | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
868 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
869 // Initialize the SNumForNotes conversion table |
1402
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
870 if ((einst->instConvTable = dmCalloc(XM_MaxInstruments + 1, sizeof(int))) == NULL) |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
871 { |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
872 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
873 "Could not allocate memory for instConvTable of instrument #%d.\n", |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
874 neinst); |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
875 } |
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
876 |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
877 for (i = 0; i < XM_MaxInstruments; i++) |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
878 einst->instConvTable[i] = jsetNotSet; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
879 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
880 // Read sample headers |
1402
b47109fce375
Make JSSExtInstrument.instConvSamples dynamically allocated and add check
Matti Hamalainen <ccr@tnsp.org>
parents:
1400
diff
changeset
|
881 for (nsample = 0; nsample < einst->nsamples; nsample++) |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
882 { |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
883 if ((ret = jssXMLoadSampleInstrument(inFile, module, einst, neinst, nsample)) != DMERR_OK) |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
884 return ret; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
885 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
886 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
887 // Apply new values to sNumForNotes values |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
888 for (i = 0; i < XM_MaxNotes; i++) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
889 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
890 int tmp = xmI2.sNumForNotes[i]; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
891 if (tmp >= 0 && tmp < xmI1.nsamples) |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
892 einst->sNumForNotes[i] = einst->instConvTable[tmp]; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
893 else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
894 { |
1175 | 895 einst->sNumForNotes[i] = jsetNotSet; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
896 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 897 "Ext.instrument #%d sNumForNotes[%d] out of range (%d).\n", |
898 neinst, i, tmp); | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
899 } |
0 | 900 } |
901 | |
1177
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
902 // Read sample data if needed |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
903 if (module->intVersion == 0x0104) |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
904 { |
1226
18baa42db260
Rename some function arguments to better reflect their meaning.
Matti Hamalainen <ccr@tnsp.org>
parents:
1225
diff
changeset
|
905 if ((ret = jssXMLoadInstrumentSamples(inFile, module, einst, neinst)) != DMERR_OK) |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
906 return ret; |
1177
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
907 } |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
908 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
909 return DMERR_OK; |
0 | 910 } |
911 | |
912 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
913 static int jssXMLoadInstruments(DMResource *inFile, JSSModule *module) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
914 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
915 int index; |
0 | 916 for (index = 0; index < module->nextInstruments; index++) |
917 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
918 int result = jssXMLoadExtInstrument(inFile, index, module); |
0 | 919 if (result != 0) |
1397 | 920 JSSERROR(result, result, "Errors while reading instrument #%d\n", |
921 index); | |
0 | 922 } |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
923 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
924 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
925 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
926 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
927 /* Load XM-format module from given file-stream |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
928 */ |
1256 | 929 int jssLoadXM(DMResource *inFile, JSSModule **pmodule, BOOL probe) |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
930 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
931 JSSModule *module; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
932 XMHeader xmH; |
1187
f195dd7bfa48
Initialize return variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1186
diff
changeset
|
933 int index, ret = DMERR_OK; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
934 |
1256 | 935 *pmodule = NULL; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
936 |
1257 | 937 // Try to read the XM header |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
938 if (!dmf_read_str(inFile, &xmH.idMagic, sizeof(xmH.idMagic)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
939 !dmf_read_str(inFile, &xmH.songName, sizeof(xmH.songName)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
940 !dmf_read_byte(inFile, &xmH.unUsed1A) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
941 !dmf_read_str(inFile, &xmH.trackerName, sizeof(xmH.trackerName)) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
942 !dmf_read_le16(inFile, &xmH.version) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
943 !dmf_read_le32(inFile, &xmH.headSize) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
944 !dmf_read_le16(inFile, &xmH.norders) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
945 !dmf_read_le16(inFile, &xmH.defRestartPos) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
946 !dmf_read_le16(inFile, &xmH.nchannels) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
947 !dmf_read_le16(inFile, &xmH.npatterns) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
948 !dmf_read_le16(inFile, &xmH.ninstruments) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
949 !dmf_read_le16(inFile, &xmH.flags) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
950 !dmf_read_le16(inFile, &xmH.defSpeed) || |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
951 !dmf_read_le16(inFile, &xmH.defTempo)) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
952 return DMERR_FREAD; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
953 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
954 // Check the fields, none of these are considered fatal |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
955 if (strncmp(xmH.idMagic, "Extended Module: ", 17) != 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
956 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
957 if (probe) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
958 return DMERR_NOT_SUPPORTED; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
959 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
960 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
1397 | 961 "Not a FT2 Extended Module (XM), header signature mismatch!\n"); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
962 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
963 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
964 if (xmH.unUsed1A != 0x1a) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
965 { |
1198 | 966 if (!probe) |
1397 | 967 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
968 "Possibly modified or corrupted XM [%x]\n", | |
969 xmH.unUsed1A); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
970 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
971 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
972 if (xmH.norders > XM_MaxOrders) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
973 { |
1198 | 974 if (!probe) |
1400
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
975 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 976 "Number of orders %d > %d, possibly broken module.\n", |
977 xmH.norders, XM_MaxOrders); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
978 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
979 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
980 if (xmH.norders == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
981 { |
1198 | 982 if (!probe) |
1397 | 983 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
984 "Number of orders was zero.\n"); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
985 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
986 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
987 if (xmH.npatterns > XM_MaxPatterns) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
988 { |
1198 | 989 if (!probe) |
1400
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
990 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 991 "Number of patterns %d > %d, possibly broken module.\n", |
992 xmH.npatterns, XM_MaxPatterns); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
993 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
994 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
995 if (xmH.npatterns == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
996 { |
1198 | 997 if (!probe) |
1400
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
998 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 999 "Number of patterns was zero.\n"); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1000 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1001 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1002 if (xmH.nchannels <= 0 || xmH.nchannels > XM_MaxChannels) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1003 { |
1397 | 1004 if (!probe) |
1400
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
1005 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 1006 "Number of channels was invalid, %d (should be 1 - %d).\n", |
1007 xmH.nchannels, XM_MaxChannels); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1008 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1009 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1010 if (xmH.ninstruments <= 0 || xmH.ninstruments > XM_MaxInstruments) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1011 { |
1198 | 1012 if (!probe) |
1400
496d04ab495f
Improve error checking and resiliency a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1397
diff
changeset
|
1013 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1397 | 1014 "Number of instruments was invalid, %d (should be 1 - %d).\n", |
1015 xmH.ninstruments, XM_MaxInstruments); | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1016 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1017 |
1161
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1018 if (xmH.headSize < XM_HeaderSize) |
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1019 { |
1198 | 1020 if (probe) |
1021 return DMERR_NOT_SUPPORTED; | |
1022 else | |
1397 | 1023 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
1024 "XM header size less than %d bytes (%d bytes).\n", | |
1025 XM_HeaderSize, xmH.headSize); | |
1161
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1026 } |
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1027 |
1160
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1028 switch (xmH.version) |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1029 { |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1030 case 0x0104: |
1177
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1031 case 0x0102: |
1160
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1032 break; |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1033 |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1034 default: |
1198 | 1035 if (!probe) |
1397 | 1036 JSSWARNING(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
1037 "Unsupported version of XM format 0x%04x.\n", | |
1038 xmH.version); | |
1160
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1039 } |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
1040 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1041 if (!dmf_read_str(inFile, &xmH.orderList, sizeof(xmH.orderList))) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1042 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1043 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1397 | 1044 "Error reading pattern order list.\n"); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1045 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1046 |
1161
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1047 if (xmH.headSize > 276) |
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1048 { |
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1049 JSSWARNING(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
1397 | 1050 "XM header size > %d bytes, skipping the rest.\n", |
1051 XM_HeaderSize, xmH.headSize); | |
1052 | |
1161
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1053 dmfseek(inFile, xmH.headSize - XM_HeaderSize, SEEK_CUR); |
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1054 } |
92cee852a8af
Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents:
1160
diff
changeset
|
1055 |
1198 | 1056 if (probe) |
1057 return DMERR_OK; | |
1058 | |
1239 | 1059 // Okay, allocate a module structure |
1256 | 1060 if ((*pmodule = module = jssAllocateModule()) == NULL) |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1061 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1062 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
1397 | 1063 "Could not allocate memory for module structure.\n"); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1064 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1065 |
1239 | 1066 // Convert the module header data |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1067 module->moduleType = jmdtXM; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1068 module->intVersion = xmH.version; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1069 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1070 module->moduleName = jssASCIItoStr(xmH.songName, 0, sizeof(xmH.songName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1071 module->trackerName = jssASCIItoStr(xmH.trackerName, 0, sizeof(xmH.trackerName)); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1072 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1073 module->defSpeed = xmH.defSpeed; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1074 module->defTempo = xmH.defTempo; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1075 module->nextInstruments = xmH.ninstruments; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1076 module->ninstruments = 0; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1077 module->npatterns = xmH.npatterns; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1078 module->norders = xmH.norders; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1079 module->nchannels = xmH.nchannels; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1080 module->defFlags = jmdfStereo | jmdfFT2Replay; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1081 module->defRestartPos = xmH.defRestartPos; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1082 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1083 if ((xmH.flags & 1) == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1084 module->defFlags |= jmdfAmigaPeriods; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1085 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1086 // Setup the default pannings |
1260
94e9444b0fa7
Only initialize defpannings up to nchannels.
Matti Hamalainen <ccr@tnsp.org>
parents:
1259
diff
changeset
|
1087 for (index = 0; index < module->nchannels; index++) |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1088 module->defPanning[index] = jchPanMiddle; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1089 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1090 // Load rest of the module |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1091 switch (xmH.version) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1092 { |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1093 case 0x0104: |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1094 if ((ret = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1095 goto out; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
1096 |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1097 if ((ret = jssXMLoadInstruments(inFile, module)) != DMERR_OK) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1098 goto out; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1099 break; |
0 | 1100 |
1177
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1101 case 0x0102: |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1102 if ((ret = jssXMLoadInstruments(inFile, module)) != DMERR_OK) |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1103 goto out; |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1104 |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1105 if ((ret = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK) |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1106 goto out; |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1107 |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1108 // Read sample data if needed |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1109 for (index = 0; index < module->nextInstruments; index++) |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1110 { |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1111 JSSExtInstrument *einst = module->extInstruments[index]; |
1190
51eb5788c1fc
Add a NULL pointer check here.
Matti Hamalainen <ccr@tnsp.org>
parents:
1188
diff
changeset
|
1112 if (einst != NULL && (ret = jssXMLoadInstrumentSamples(inFile, module, einst, index)) != DMERR_OK) |
1177
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1113 goto out; |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1114 } |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
1115 break; |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1116 } |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1117 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1118 out: |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
1119 return ret; |
0 | 1120 } |