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