Mercurial > hg > dmlib
annotate minijss/jloadxm.c @ 1191:1f1225b509fb
Fix error message to reflect reality better.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Mar 2015 13:10:36 +0200 |
parents | 51eb5788c1fc |
children | 8841c7f8c608 |
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, | |
1162 | 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 { |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
223 |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
224 // Check the state |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
225 if (size > 0) |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
226 { |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
227 // Some data left unparsed |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
228 JSSWARNING(DMERR_EXTRA_DATA, DMERR_EXTRA_DATA, |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
229 "Unparsed data after pattern (%d bytes), possibly broken file.\n", |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
230 size); |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
231 } |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
232 |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
233 return DMERR_OK; |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
234 } |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
235 |
08c93ebb85b9
Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1179
diff
changeset
|
236 |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
237 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
|
238 { |
1184 | 239 int index, ret; |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
240 XMPattern xmP; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
241 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
242 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
|
243 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
244 // Get the pattern header |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
245 off_t remainder, pos = dmftell(inFile); |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
246 Uint32 headSize; |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
247 |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
248 // Get the pattern header size |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
249 if (!dmf_read_le32(inFile, &xmP.headSize) || |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
250 !dmf_read_byte(inFile, &xmP.packing)) |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
251 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1191
1f1225b509fb
Fix error message to reflect reality better.
Matti Hamalainen <ccr@tnsp.org>
parents:
1190
diff
changeset
|
252 "Could not read pattern header #%d.\n", |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
253 index); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
254 |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
255 // 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
|
256 if (module->intVersion == 0x0102) |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
257 { |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
258 Uint8 tmp; |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
259 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
|
260 xmP.nrows = ((Uint16) tmp) + 1; |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
261 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
|
262 } |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
263 else |
cdba23d3fd0d
Version 0x0102 has slightly different pattern header than 0x0104.
Matti Hamalainen <ccr@tnsp.org>
parents:
1184
diff
changeset
|
264 { |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
265 ret = dmf_read_le16(inFile, &xmP.nrows); |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
266 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
|
267 } |
1183
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
268 |
1188
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
269 if (headSize != xmP.headSize) |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
270 { |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
271 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
272 "Invalid pattern #%d header size %d, expected %d bytes.\n", |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
273 index, xmP.headSize, headSize); |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
274 } |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
275 |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
276 if (!ret || !dmf_read_le16(inFile, &xmP.size)) |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
277 { |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
278 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
279 "Could not read pattern header data #%d.\n", |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
280 index); |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
281 } |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
282 |
d18c50f88d44
Clean up the pattern header parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1187
diff
changeset
|
283 // 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
|
284 if (xmP.packing != 0) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
285 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
286 "Pattern #%d packing type unsupported (%d)\n", |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
287 index, xmP.packing); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
288 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
289 if (xmP.nrows == 0) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
290 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
291 "Pattern #%d has %d rows, invalid data.\n", |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
292 index, xmP.nrows); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
293 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
294 if (xmP.size > 0) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
295 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
296 // Allocate and unpack pattern |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
297 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
|
298 if (module->patterns[index] == NULL) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
299 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
300 "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
|
301 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
302 switch (module->intVersion) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
303 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
304 case 0x0104: |
1184 | 305 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
|
306 break; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
307 case 0x0102: |
1184 | 308 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
|
309 break; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
310 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
311 |
1184 | 312 if (ret != 0) |
313 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
|
314 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
315 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
316 // Skip extra data (if the file is damaged) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
317 remainder = xmP.headSize - (dmftell(inFile) - pos); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
318 if (remainder > 0) |
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 JSSDEBUG("xmP Skipping: %li\n", remainder); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
321 dmfseek(inFile, remainder, SEEK_CUR); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
322 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
323 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
324 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
325 // Allocate the empty pattern |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
326 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels); |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
327 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
328 /* Convert song orders list by replacing nonexisting patterns |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
329 * with pattern number jsetMaxPatterns. |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
330 */ |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
331 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
|
332 { |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
333 int tmp = xmH->orderList[index]; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
334 if (tmp >= module->npatterns || |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
335 module->patterns[tmp] == NULL) |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
336 tmp = jsetMaxPatterns; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
337 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
338 module->orderList[index] = tmp; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
339 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
340 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
341 return DMERR_OK; |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
342 } |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
343 |
ae17e0a004f4
Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1182
diff
changeset
|
344 |
0 | 345 /* Convert XM envelope structure to JSS envelope structure |
346 */ | |
1174 | 347 static int jssXMConvertEnvelope( |
348 JSSEnvelope *dst, XMEnvelope *src, | |
349 const char *name, const int ninstr) | |
0 | 350 { |
351 int i; | |
1148 | 352 (void) name; |
353 (void) ninstr; | |
0 | 354 |
355 // Convert envelope points | |
356 for (i = 0; i < XM_MaxEnvPoints; i++) | |
357 { | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
358 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
|
359 dst->points[i].value = src->points[i].value; |
0 | 360 } |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
361 |
0 | 362 // 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
|
363 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
|
364 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
|
365 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
|
366 dst->loopE = src->loopE; |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
367 |
0 | 368 // 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
|
369 if (src->flags & 0x01) |
0 | 370 { |
371 // 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
|
372 dst->flags = jenvfUsed; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
373 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
|
374 dst->flags |= jenvfSustain; |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
375 |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
376 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
|
377 dst->flags |= jenvfLooped; |
0 | 378 |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
379 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
|
380 { |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
381 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
382 "Inst#%d/%s-env: Uses unsupported flags values, 0x%02x.\n", |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
383 ninstr, name, src->flags); |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
384 } |
0 | 385 |
386 // 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
|
387 if (src->npoints > XM_MaxEnvPoints) |
0 | 388 { |
389 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1174 | 390 "Inst#%d/%s-env: npoints > MAX, possibly broken file.\n", |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
391 ninstr, name); |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
392 dst->npoints = XM_MaxEnvPoints; |
0 | 393 } |
394 | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
395 if ((dst->flags & jenvfSustain) && src->sustain > src->npoints) |
0 | 396 { |
397 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1174 | 398 "Inst#%d/%s-env: sustain > npoints (%d > %d), possibly broken file.\n", |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
399 ninstr, name, src->sustain, src->npoints); |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
400 dst->sustain = src->npoints; |
0 | 401 } |
402 | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
403 if ((dst->flags & jenvfLooped) && src->loopE > src->npoints) |
0 | 404 { |
405 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
1174 | 406 "Inst#%d/%s-env: loopE > npoints (%d > %d), possibly broken file.\n", |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
407 ninstr, name, src->loopE, src->npoints); |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
408 dst->loopE = src->npoints; |
0 | 409 } |
410 | |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
411 if ((dst->flags & jenvfLooped) && src->loopS > src->loopE) |
0 | 412 { |
413 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, | |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
414 "Inst#%d/%s-env: loopS > loopE (%d > %d), possibly broken file.\n", |
1149
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
415 ninstr, name, src->loopS, src->loopE); |
f5edb39a8db1
Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents:
1148
diff
changeset
|
416 dst->loopS = src->loopE; |
0 | 417 } |
418 } | |
419 | |
420 return DMERR_OK; | |
421 } | |
422 | |
423 | |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
424 static int jssXMLoadSampleInstrument( |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
425 DMResource *inFile, JSSModule *module, |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
426 JSSExtInstrument *einst, int ninst, int nsample) |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
427 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
428 XMSample xmS; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
429 JSSInstrument *inst; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
430 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
431 // Read header data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
432 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
|
433 !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
|
434 !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
|
435 !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
|
436 !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
|
437 !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
|
438 !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
|
439 !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
|
440 !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
|
441 !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
|
442 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
443 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
444 "Error reading instrument sample header #%d/%d [%d]", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
445 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
446 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
447 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
448 if (xmS.size <= 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
449 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
450 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
451 // Allocate sample instrument |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
452 JSSDEBUG("Allocating sample #%d/%d [%d]\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
453 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
454 |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
455 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
|
456 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
|
457 if (inst == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
458 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
459 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
460 "Could not allocate sample #%d/%d [%d]\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
461 ninst, nsample, module->ninstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
462 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
463 module->ninstruments++; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
464 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
465 // Copy values |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
466 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
|
467 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
468 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
1162 | 469 "Samp #%d/%d: volume > MAX\n", ninst, nsample); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
470 xmS.volume = XM_MaxSampleVolume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
471 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
472 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
473 inst->volume = xmS.volume; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
474 inst->ERelNote = xmS.relNote; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
475 inst->EFineTune = xmS.fineTune; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
476 inst->EPanning = xmS.panning; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
477 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
478 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
|
479 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
480 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
481 // Convert flags |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
482 switch (xmS.type & 0x03) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
483 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
484 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
|
485 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
|
486 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
|
487 // 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
|
488 // 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
|
489 // 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
|
490 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
|
491 break; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
492 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
493 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
494 if (xmS.type & 0x10) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
495 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
496 // 16-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
497 JSFSET(inst->flags, jsf16bit); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
498 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
|
499 inst->loopS = xmS.loopS / sizeof(Uint16); |
1174 | 500 inst->loopE = (xmS.loopS + xmS.loopL) / sizeof(Uint16); |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
501 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
502 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
503 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
504 // 8-bit sample |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
505 inst->size = xmS.size; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
506 inst->loopS = xmS.loopS; |
1174 | 507 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
|
508 } |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1126
diff
changeset
|
509 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
510 if (xmS.loopL == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
511 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
512 // 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
|
513 JSFUNSET(inst->flags, jsfLooped); |
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 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
516 if (inst->flags & jsfLooped) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
517 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
518 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
|
519 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
520 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
521 "Samp #%d/%d: loopS >= size (%d >= %d)\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
522 ninst, nsample, inst->loopS, inst->size); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
523 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
524 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
525 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
526 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
|
527 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
528 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
529 "Samp #%d/%d: loopE > size (%d > %d)\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
530 ninst, nsample, inst->loopE, inst->size); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
531 JSFUNSET(inst->flags, jsfLooped); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
532 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
533 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
534 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
535 return DMERR_OK; |
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 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
538 |
1158 | 539 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
|
540 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
541 int ret; |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
542 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
|
543 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
544 JSSDEBUG("desc....: '%s'\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
545 "size....: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
546 "loopS...: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
547 "loopE...: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
548 "volume..: %d\n" |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
549 "flags...: %x\n", |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
550 inst->desc, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
551 inst->size, inst->loopS, inst->loopE, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
552 inst->volume, inst->flags); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
553 |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
554 // Allocate memory for sample data |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
555 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
|
556 bsize *= inst->size; |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
557 |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
558 if ((inst->data = dmMalloc(bsize)) == NULL) |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
559 { |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
560 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
561 "Could not allocate %d bytes of sample data for instrument/sample #%d/%d.\n", |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
562 bsize, ninst, nsample); |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
563 } |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
564 |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
565 // Read sampledata |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
566 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
|
567 { |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
568 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
569 "Error reading sample data for instrument #%d/%d, %d bytes.\n", |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
570 ninst, nsample, bsize); |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
571 } |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
572 |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
573 // 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
|
574 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
|
575 { |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
576 ret = jssDecodeSample16( |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
577 (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
|
578 #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
|
579 (jsampDelta | jsampSwapEndianess) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
580 #else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
581 (jsampDelta) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
582 #endif |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
583 ); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
584 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
585 else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
586 { |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
587 ret = jssDecodeSample8( |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
588 (Uint8 *) inst->data, inst->size, |
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
589 (jsampDelta | jsampFlipSign)); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
590 } |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
591 |
1157
e13269e17422
Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1149
diff
changeset
|
592 return ret; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
593 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
594 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
595 |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
596 static int jssXMLoadInstrumentSamples( |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
597 DMResource *inFile, JSSModule *module, |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
598 JSSExtInstrument *einst, int ninst) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
599 { |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
600 int nsample, ret; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
601 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
602 for (nsample = 0; nsample < einst->nsamples; nsample++) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
603 if (einst->instConvTable[nsample] != jsetNotSet) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
604 { |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
605 JSSInstrument *inst = module->instruments[einst->instConvTable[nsample]]; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
606 if ((ret = jssXMLoadSampleData(inFile, inst, ninst, nsample)) != DMERR_OK) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
607 return ret; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
608 } |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
609 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
610 return DMERR_OK; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
611 } |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
612 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
613 |
1132 | 614 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
|
615 { |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
616 int i; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
617 for (i = 0; i < XM_MaxEnvPoints; i++) |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
618 { |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
619 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
|
620 !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
|
621 return FALSE; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
622 } |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
623 return TRUE; |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
624 } |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
625 |
b349646f19a0
Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1130
diff
changeset
|
626 |
1132 | 627 static BOOL jssXMLoadEnvelopeData(DMResource *inFile, XMEnvelope *env) |
628 { | |
629 return | |
630 dmf_read_byte(inFile, &(env->sustain)) && | |
631 dmf_read_byte(inFile, &(env->loopS)) && | |
632 dmf_read_byte(inFile, &(env->loopE)); | |
633 } | |
634 | |
635 | |
0 | 636 /* Load XM-format extended instrument from file-stream into JSS module's given inst |
637 */ | |
638 static int jssXMLoadExtInstrument(DMResource *inFile, int ninst, JSSModule *module) | |
639 { | |
640 XMInstrument1 xmI1; | |
1126 | 641 off_t remainder, pos = dmftell(inFile); |
1175 | 642 JSSExtInstrument *einst; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
643 XMInstrument2 xmI2; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
644 int i, nsample, ret; |
0 | 645 |
646 // 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
|
647 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
|
648 !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
|
649 !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
|
650 !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
|
651 { |
29dc9337fa11
Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents:
1158
diff
changeset
|
652 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
29dc9337fa11
Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents:
1158
diff
changeset
|
653 "Failed to read primary extended instrument header #%d\n", ninst); |
29dc9337fa11
Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents:
1158
diff
changeset
|
654 } |
0 | 655 |
656 // 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
|
657 if (xmI1.nsamples == 0) |
0 | 658 { |
659 // We may STILL need to skip extra data after 1st instr. header | |
660 remainder = xmI1.headSize - (dmftell(inFile) - pos); | |
661 if (remainder > 0) | |
662 { | |
98 | 663 JSSDEBUG("xmI1#2 Skipping: %li\n", remainder); |
0 | 664 dmfseek(inFile, remainder, SEEK_CUR); |
665 } | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
666 return DMERR_OK; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
667 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
668 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
669 // Allocate instrument |
1175 | 670 if ((einst = jssAllocateExtInstrument()) == NULL) |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
671 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
672 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
673 "Could not allocate extended instrument structure #%d\n", ninst); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
674 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
675 |
1175 | 676 module->extInstruments[ninst] = einst; |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
677 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
678 // 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
|
679 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
|
680 !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
|
681 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
682 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1132 | 683 "Could not read secondary instrument header part #1 for #%d.\n", ninst); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
684 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
685 |
1132 | 686 if (!jssXMLoadEnvelopePoints(inFile, &xmI2.volumeEnv) || |
687 !jssXMLoadEnvelopePoints(inFile, &xmI2.panningEnv)) | |
688 { | |
689 JSSERROR(DMERR_FREAD, DMERR_FREAD, | |
690 "Could not read envelope point data for instrument #%d.\n", ninst); | |
691 } | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
692 |
1132 | 693 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
|
694 !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
|
695 |
1132 | 696 !jssXMLoadEnvelopeData(inFile, &xmI2.volumeEnv) || |
697 !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
|
698 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
699 !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
|
700 !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
|
701 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
702 !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
|
703 !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
|
704 !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
|
705 !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
|
706 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
707 !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
|
708 !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
|
709 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
710 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
1132 | 711 "Could not read secondary instrument header part #2 for #%d.\n", ninst); |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
712 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
713 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
714 // 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
|
715 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
|
716 if (remainder > 0) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
717 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
718 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
|
719 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
|
720 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
721 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
722 // 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
|
723 #ifndef JSS_LIGHT |
1175 | 724 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
|
725 #endif |
1175 | 726 jssXMConvertEnvelope(&einst->volumeEnv, &xmI2.volumeEnv, "vol", ninst); |
727 jssXMConvertEnvelope(&einst->panningEnv, &xmI2.panningEnv, "pan", ninst); | |
1130
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
728 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
729 switch (xmI2.vibratoType) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
730 { |
1175 | 731 case 0: einst->vibratoType = jvibSine; break; |
732 case 1: einst->vibratoType = jvibRamp; break; | |
733 case 2: einst->vibratoType = jvibSquare; break; | |
734 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
|
735 default: |
1175 | 736 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
|
737 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
738 "Invalid extinstrument vibrato type %d for inst #%d\n", ninst); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
739 break; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
740 } |
1175 | 741 einst->vibratoSweep = xmI2.vibratoSweep; |
742 einst->vibratoDepth = xmI2.vibratoDepth; | |
743 einst->vibratoRate = xmI2.vibratoRate; | |
744 einst->fadeOut = xmI2.fadeOut; | |
745 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
|
746 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
747 // Initialize the SNumForNotes conversion table |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
748 for (i = 0; i < XM_MaxInstruments; i++) |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
749 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
|
750 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
751 // Read sample headers |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
752 for (nsample = 0; nsample < xmI1.nsamples; nsample++) |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
753 { |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
754 if ((ret = jssXMLoadSampleInstrument(inFile, module, einst, ninst, 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
|
755 return ret; |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
756 } |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
757 |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
758 // 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
|
759 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
|
760 { |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
761 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
|
762 if (tmp >= 0 && tmp < xmI1.nsamples) |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
763 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
|
764 else |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
765 { |
1175 | 766 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
|
767 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
768 "Ext.instrument #%d sNumForNotes[%d] out of range (%d).\n", |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
769 ninst, i, tmp); |
725e7caa43a0
Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
770 } |
0 | 771 } |
772 | |
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
|
773 // 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
|
774 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
|
775 { |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
776 if ((ret = jssXMLoadInstrumentSamples(inFile, module, einst, ninst)) != DMERR_OK) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
777 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
|
778 } |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
779 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
780 return DMERR_OK; |
0 | 781 } |
782 | |
783 | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
784 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
|
785 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
786 int index; |
0 | 787 for (index = 0; index < module->nextInstruments; index++) |
788 { | |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
789 int result = jssXMLoadExtInstrument(inFile, index, module); |
0 | 790 if (result != 0) |
778
a4cf7716ba58
Clean up the XM module loader a bit, add more error checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
658
diff
changeset
|
791 JSSERROR(result, result, "Errors while reading instrument #%d\n", index); |
0 | 792 } |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
793 return DMERR_OK; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
794 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
795 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
796 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
797 /* 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
|
798 */ |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
799 int jssLoadXM(DMResource *inFile, JSSModule **ppModule, BOOL probe) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
800 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
801 JSSModule *module; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
802 XMHeader xmH; |
1187
f195dd7bfa48
Initialize return variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1186
diff
changeset
|
803 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
|
804 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
805 assert(ppModule != NULL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
806 assert(inFile != NULL); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
807 *ppModule = NULL; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
808 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
809 // Try to get the XM-header |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
810 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
|
811 !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
|
812 !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
|
813 !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
|
814 !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
|
815 !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
|
816 !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
|
817 !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
|
818 !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
|
819 !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
|
820 !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
|
821 !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
|
822 !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
|
823 !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
|
824 return DMERR_FREAD; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
825 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
826 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
827 // 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
|
828 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
|
829 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
830 if (probe) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
831 return DMERR_NOT_SUPPORTED; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
832 else |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
833 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
834 "Not a FT2 Extended Module (XM), header signature mismatch!\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
835 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
836 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
837 if (xmH.unUsed1A != 0x1a) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
838 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
839 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
840 "Possibly modified or corrupted XM [%x]\n", xmH.unUsed1A); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
841 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
842 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
843 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
|
844 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
845 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
846 "Number of orders %d > %d, possibly broken module.\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
847 xmH.norders, XM_MaxOrders); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
848 xmH.norders = XM_MaxOrders; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
849 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
850 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
851 if (xmH.norders == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
852 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
853 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
854 "Number of orders was zero.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
855 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
856 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
857 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
|
858 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
859 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
860 "Number of patterns %d > %d, possibly broken module.\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
861 xmH.npatterns, XM_MaxPatterns); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
862 xmH.npatterns = XM_MaxPatterns; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
863 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
864 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
865 if (xmH.npatterns == 0) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
866 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
867 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
868 "Number of patterns was zero.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
869 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
870 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
871 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
|
872 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
873 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
874 "Number of channels was invalid, %d (should be 1 - %d).\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
875 xmH.nchannels, XM_MaxChannels); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
876 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
877 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
878 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
|
879 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
880 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
881 "Number of instruments was invalid, %d (should be 1 - %d).\n", |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
882 xmH.ninstruments, XM_MaxInstruments); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
883 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
884 |
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
|
885 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
|
886 { |
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
|
887 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
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
|
888 "XM header size less than %d bytes (%d bytes).\n", |
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
|
889 XM_HeaderSize, xmH.headSize); |
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
|
890 } |
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
|
891 |
1160
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
892 switch (xmH.version) |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
893 { |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
894 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
|
895 case 0x0102: |
1160
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
896 break; |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
897 |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
898 default: |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
899 JSSWARNING(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
900 "Unsupported version of XM format 0x%04x.\n", |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
901 xmH.version); |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
902 } |
b122ad2d3fbe
Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents:
1159
diff
changeset
|
903 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
904 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
|
905 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
906 JSSERROR(DMERR_FREAD, DMERR_FREAD, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
907 "Error reading pattern order list.\n"); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
908 } |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
909 |
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
|
910 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
|
911 { |
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
|
912 JSSWARNING(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, |
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
|
913 "XM header size > %d bytes, skipping the rest.\n", |
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
|
914 XM_HeaderSize, xmH.headSize); |
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
|
915 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
|
916 } |
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
|
917 |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
918 /* Okay, allocate a module structure |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
919 */ |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
920 module = jssAllocateModule(); |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
921 if (module == NULL) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
922 { |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
923 JSSERROR(DMERR_MALLOC, DMERR_MALLOC, |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
924 "Could not allocate memory for module structure.\n"); |
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 *ppModule = module; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
927 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
928 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
929 // Convert and check the header data |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
930 module->moduleType = jmdtXM; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
931 module->intVersion = xmH.version; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
932 #ifndef JSS_LIGHT |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
933 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
|
934 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
|
935 #endif |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
936 module->defSpeed = xmH.defSpeed; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
937 module->defTempo = xmH.defTempo; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
938 module->nextInstruments = xmH.ninstruments; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
939 module->ninstruments = 0; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
940 module->npatterns = xmH.npatterns; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
941 module->norders = xmH.norders; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
942 module->nchannels = xmH.nchannels; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
943 module->defFlags = jmdfStereo | jmdfFT2Replay; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
944 module->defRestartPos = xmH.defRestartPos; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
945 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
946 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
|
947 module->defFlags |= jmdfAmigaPeriods; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
948 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
949 // Setup the default pannings |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
950 for (index = 0; index < jsetNChannels; index++) |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
951 module->defPanning[index] = jchPanMiddle; |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
952 |
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
953 // Load rest of the module |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
954 switch (xmH.version) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
955 { |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
956 case 0x0104: |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
957 if ((ret = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
958 goto out; |
1124
b8bfd9fbe1d9
Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
959 |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
960 if ((ret = jssXMLoadInstruments(inFile, module)) != DMERR_OK) |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
961 goto out; |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
962 break; |
0 | 963 |
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
|
964 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
|
965 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
|
966 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
|
967 |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
968 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
|
969 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
|
970 |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
971 // 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
|
972 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
|
973 { |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
974 JSSExtInstrument *einst = module->extInstruments[index]; |
1190
51eb5788c1fc
Add a NULL pointer check here.
Matti Hamalainen <ccr@tnsp.org>
parents:
1188
diff
changeset
|
975 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
|
976 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
|
977 } |
dc26df8b642c
Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents:
1176
diff
changeset
|
978 break; |
1176
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
979 } |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
980 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
981 out: |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
982 |
afdbf62ce8ad
Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
1175
diff
changeset
|
983 return ret; |
0 | 984 } |