annotate minijss/jloadxm.c @ 1183:ae17e0a004f4

Move jssXMLoadPatterns() closer to the pattern unpacking functions.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 11:34:07 +0200
parents 9d32da6ba785
children d144ebb1cdea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * miniJSS - Fast Tracker ][ (XM) module loader
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
1125
44ed439b1c6b Bump copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 1124
diff changeset
4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * TO DO:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 * - Add support for 1.02/1.03 XM-format versions.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 * (Not very useful, but if it's not too hard, then do it)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "jssmod.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 /* XM value limit definitions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #define XM_MaxChannels (32)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #define XM_MaxPatterns (256)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #define XM_MaxOrders (255)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #define XM_MaxInstruments (128)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #define XM_MaxInstSamples (16)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #define XM_MaxEnvPoints (12)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 #define XM_MaxNotes (96)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
1174
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
25
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 /* XM format structures
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 char idMagic[17]; // XM header ID "Extended Module: "
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 char songName[20]; // Module song name
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 Uint8 unUsed1A; // ALWAYS 0x1a
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 Uint32 headSize; // Module header size, FROM THIS POINT!
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 Uint16 norders, // Number of orders
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 defRestartPos, // Default song restart position
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 nchannels, // Number of channels
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 npatterns, // Number of patterns
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 defSpeed, // Default speed
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 defTempo; // Default tempo
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 Uint8 orderList[256]; // Order list
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 } XMHeader;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 Uint32 headSize; // Instrument header size (see docs!)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 char instName[22]; // Name/description
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 Uint8 instType; // Type
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 Uint16 nsamples; // Number of samples
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 } XMInstrument1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 Uint16 frame, value;
552
d4cee32e7050 Rename internal structures, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 313
diff changeset
63 } XMEnvPoint;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 Uint32 headSize; // Header size
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 Uint8 vibratoType, vibratoSweep, vibratoDepth, vibratoRate;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 Uint16 fadeOut, ARESERVED;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 } XMInstrument2;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 Uint32 size, loopS, loopL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 Uint8 ARESERVED;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 char sampleName[22];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 } XMSample;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 Uint32 headSize;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 Uint8 packing;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 Uint16 nrows, size;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 } XMPattern;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 /* Unpack XM-format pattern from file-stream into JSS-pattern structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 */
1148
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
107 #define JSGETBYTE(XV) \
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
108 do { \
1181
5d3c948ed426 Mostly cosmetic change.
Matti Hamalainen <ccr@tnsp.org>
parents: 1180
diff changeset
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
5d3c948ed426 Mostly cosmetic change.
Matti Hamalainen <ccr@tnsp.org>
parents: 1180
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 } while (0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
1148
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
117 /* Convert XM note value to internal JSS note
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
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
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
123 else
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
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
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
131 /* Unpack a XM pattern structure from resource to given JSS pattern
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 pnote = pattern->data;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 JSGETBYTE(packb);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 if (packb & 0x80)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 if (packb & 0x01)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 // PACK 0x01: Read note
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 if (packb & 0x02)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 // PACK 0x02: Read instrument
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 JSGETBYTE(tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 if (packb & 0x04)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 // PACK 0x04: Read volume
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 JSGETBYTE(tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 if (packb & 0x08)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 // PACK 0x08: Read effect
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 JSGETBYTE(pnote->effect);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 pnote->param = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 if (packb & 0x10)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 // PACK 0x10: Read effect parameter
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 JSGETBYTE(pnote->param);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 if (pnote->effect == jsetNotSet && pnote->param != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 pnote->effect = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 // 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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 // Get instrument
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 JSGETBYTE(tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 // Get volume
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 JSGETBYTE(tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 pnote->volume = (tmp >= 0x10) ? tmp - 0x10 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 // Get effect
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 JSGETBYTE(pnote->effect);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 // Get parameter
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 JSGETBYTE(pnote->param);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 if (pnote->effect == 0 && pnote->param == 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 pnote->effect = pnote->param = jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 pnote++;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 // Check the state
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 if (size > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 // Some data left unparsed
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 JSSWARNING(DMERR_EXTRA_DATA, DMERR_EXTRA_DATA,
1162
409926df7bea Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1161
diff changeset
213 "Unparsed data after pattern (%d bytes), possibly broken file.\n",
409926df7bea Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1161
diff changeset
214 size);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
1180
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
221 static int jssXMUnpackPattern102(DMResource *inFile, int size, JSSPattern *pattern)
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
222 {
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
223
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
224 // Check the state
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
225 if (size > 0)
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
226 {
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
227 // Some data left unparsed
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
228 JSSWARNING(DMERR_EXTRA_DATA, DMERR_EXTRA_DATA,
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
229 "Unparsed data after pattern (%d bytes), possibly broken file.\n",
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
230 size);
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
231 }
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
232
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
233 return DMERR_OK;
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
234 }
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
235
08c93ebb85b9 Some preliminary code for 0x0102 format pattern support.
Matti Hamalainen <ccr@tnsp.org>
parents: 1179
diff changeset
236
1183
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
237 static int jssXMLoadPatterns(DMResource *inFile, JSSModule *module, XMHeader *xmH)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
238 {
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
239 int index, result;
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
240 XMPattern xmP;
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
241
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
242 for (index = 0; index < module->npatterns; index++)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
243 {
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
244 // Get the pattern header
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
245 off_t remainder, pos = dmftell(inFile);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
246
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
247 if (!dmf_read_le32(inFile, &xmP.headSize) ||
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
248 !dmf_read_byte(inFile, &xmP.packing) ||
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
249 !dmf_read_le16(inFile, &xmP.nrows) ||
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
250 !dmf_read_le16(inFile, &xmP.size))
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
251 JSSERROR(DMERR_FREAD, DMERR_FREAD,
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
252 "Could not read pattern header data #%d.\n",
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
253 index);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
254
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
255
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
256 // Check the header
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
257 if (xmP.packing != 0)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
258 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
259 "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
260 index, xmP.packing);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
261
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
262 if (xmP.nrows == 0)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
263 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
264 "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
265 index, xmP.nrows);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
266
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
267 if (xmP.size > 0)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
268 {
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
269 // Allocate and unpack pattern
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
270 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
271 if (module->patterns[index] == NULL)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
272 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
273 "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
274
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
275 switch (module->intVersion)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
276 {
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
277 case 0x0104:
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
278 result = jssXMUnpackPattern104(inFile, xmP.size, module->patterns[index]);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
279 break;
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
280 case 0x0102:
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
281 result = jssXMUnpackPattern102(inFile, xmP.size, module->patterns[index]);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
282 break;
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
283 }
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
284
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
285 if (result != 0)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
286 JSSERROR(result, result, "Error in unpacking pattern #%d data\n", index);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
287 }
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
288
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
289 // Skip extra data (if the file is damaged)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
290 remainder = xmP.headSize - (dmftell(inFile) - pos);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
291 if (remainder > 0)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
292 {
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
293 JSSDEBUG("xmP Skipping: %li\n", remainder);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
294 dmfseek(inFile, remainder, SEEK_CUR);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
295 }
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
296 }
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
297
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
298 // Allocate the empty pattern
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
299 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels);
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
300
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
301 /* Convert song orders list by replacing nonexisting patterns
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
302 * with pattern number jsetMaxPatterns.
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
303 */
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
304 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
305 {
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
306 int tmp = xmH->orderList[index];
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
307 if (tmp >= module->npatterns ||
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
308 module->patterns[tmp] == NULL)
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
309 tmp = jsetMaxPatterns;
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
310
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
311 module->orderList[index] = tmp;
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
312 }
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
313
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
314 return DMERR_OK;
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
315 }
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
316
ae17e0a004f4 Move jssXMLoadPatterns() closer to the pattern unpacking functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1182
diff changeset
317
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 /* Convert XM envelope structure to JSS envelope structure
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 */
1174
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
320 static int jssXMConvertEnvelope(
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
321 JSSEnvelope *dst, XMEnvelope *src,
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
322 const char *name, const int ninstr)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 int i;
1148
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
325 (void) name;
1ed8af15581a Comments and cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1132
diff changeset
326 (void) ninstr;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 // Convert envelope points
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 for (i = 0; i < XM_MaxEnvPoints; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 {
1149
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
331 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
332 dst->points[i].value = src->points[i].value;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1126
diff changeset
334
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 // 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
336 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
337 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
338 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
339 dst->loopE = src->loopE;
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1126
diff changeset
340
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 // 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
342 if (src->flags & 0x01)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 // 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
345 dst->flags = jenvfUsed;
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
346 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
347 dst->flags |= jenvfSustain;
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
348
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
349 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
350 dst->flags |= jenvfLooped;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351
1149
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
352 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
353 {
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
354 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
355 "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
356 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
357 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 // 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
360 if (src->npoints > XM_MaxEnvPoints)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
1174
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
363 "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
364 ninstr, name);
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
365 dst->npoints = XM_MaxEnvPoints;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367
1149
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
368 if ((dst->flags & jenvfSustain) && src->sustain > src->npoints)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
1174
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
371 "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
372 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
373 dst->sustain = src->npoints;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
1149
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
376 if ((dst->flags & jenvfLooped) && src->loopE > src->npoints)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
1174
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
379 "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
380 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
381 dst->loopE = src->npoints;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383
1149
f5edb39a8db1 Rename some function arguments for clarity. One letter variable names are
Matti Hamalainen <ccr@tnsp.org>
parents: 1148
diff changeset
384 if ((dst->flags & jenvfLooped) && src->loopS > src->loopE)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 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
387 "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
388 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
389 dst->loopS = src->loopE;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
397 static int jssXMLoadSampleInstrument(
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
398 DMResource *inFile, JSSModule *module,
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
399 JSSExtInstrument *einst, int ninst, int nsample)
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
400 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
401 XMSample xmS;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
402 JSSInstrument *inst;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
403
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
404 // Read header data
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
405 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
406 !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
407 !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
408 !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
409 !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
410 !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
411 !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
412 !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
413 !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
414 !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
415 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
416 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
417 "Error reading instrument sample header #%d/%d [%d]",
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
418 ninst, nsample, module->ninstruments);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
419 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
420
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
421 if (xmS.size <= 0)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
422 return DMERR_OK;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
423
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
424 // Allocate sample instrument
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
425 JSSDEBUG("Allocating sample #%d/%d [%d]\n",
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
426 ninst, nsample, module->ninstruments);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
427
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
428 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
429 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
430 if (inst == NULL)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
431 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
432 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
433 "Could not allocate sample #%d/%d [%d]\n",
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
434 ninst, nsample, module->ninstruments);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
435 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
436 module->ninstruments++;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
437
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
438 // Copy values
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
439 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
440 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
441 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
1162
409926df7bea Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1161
diff changeset
442 "Samp #%d/%d: volume > MAX\n", ninst, nsample);
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
443 xmS.volume = XM_MaxSampleVolume;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
444 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
445
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
446 inst->volume = xmS.volume;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
447 inst->ERelNote = xmS.relNote;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
448 inst->EFineTune = xmS.fineTune;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
449 inst->EPanning = xmS.panning;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
450 #ifndef JSS_LIGHT
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
451 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
452 #endif
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
453
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
454 // Convert flags
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
455 switch (xmS.type & 0x03)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
456 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
457 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
458 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
459 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
460 // 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
461 // 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
462 // 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
463 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
464 break;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
465 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
466
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
467 if (xmS.type & 0x10)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
468 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
469 // 16-bit sample
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
470 JSFSET(inst->flags, jsf16bit);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
471 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
472 inst->loopS = xmS.loopS / sizeof(Uint16);
1174
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
473 inst->loopE = (xmS.loopS + xmS.loopL) / sizeof(Uint16);
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
474 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
475 else
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
476 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
477 // 8-bit sample
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
478 inst->size = xmS.size;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
479 inst->loopS = xmS.loopS;
1174
14ac28580059 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1171
diff changeset
480 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
481 }
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1126
diff changeset
482
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
483 if (xmS.loopL == 0)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
484 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
485 // 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
486 JSFUNSET(inst->flags, jsfLooped);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
487 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
488
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
489 if (inst->flags & jsfLooped)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
490 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
491 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
492 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
493 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
494 "Samp #%d/%d: loopS >= size (%d >= %d)\n",
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
495 ninst, nsample, inst->loopS, inst->size);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
496 JSFUNSET(inst->flags, jsfLooped);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
497 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
498
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
499 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
500 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
501 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
502 "Samp #%d/%d: loopE > size (%d > %d)\n",
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
503 ninst, nsample, inst->loopE, inst->size);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
504 JSFUNSET(inst->flags, jsfLooped);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
505 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
506 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
507
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
508 return DMERR_OK;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
509 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
510
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
511
1158
31bc984b7cd4 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1157
diff changeset
512 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
513 {
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
514 int ret;
1157
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
515 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
516
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
517 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
518 "size....: %d\n"
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
519 "loopS...: %d\n"
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
520 "loopE...: %d\n"
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
521 "volume..: %d\n"
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
522 "flags...: %x\n",
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
523 inst->desc,
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
524 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
525 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
526
1157
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
527 // Allocate memory for sample data
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
528 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
529 bsize *= inst->size;
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
530
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
531 if ((inst->data = dmMalloc(bsize)) == NULL)
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
532 {
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
533 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
534 "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
535 bsize, ninst, nsample);
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
536 }
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
537
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
538 // Read sampledata
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
539 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
540 {
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
541 JSSERROR(DMERR_FREAD, DMERR_FREAD,
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
542 "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
543 ninst, nsample, bsize);
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
544 }
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
545
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
546 // 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
547 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
548 {
1157
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
549 ret = jssDecodeSample16(
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
550 (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
551 #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
552 (jsampDelta | jsampSwapEndianess)
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
553 #else
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
554 (jsampDelta)
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
555 #endif
1157
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
556 );
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
557 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
558 else
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
559 {
1157
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
560 ret = jssDecodeSample8(
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
561 (Uint8 *) inst->data, inst->size,
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
562 (jsampDelta | jsampFlipSign));
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
563 }
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
564
1157
e13269e17422 Clean up the sample data loading a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1149
diff changeset
565 return ret;
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
566 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
567
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
568
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
569 static int jssXMLoadInstrumentSamples(
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
570 DMResource *inFile, JSSModule *module,
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
571 JSSExtInstrument *einst, int ninst)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
572 {
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
573 int nsample, ret;
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
574
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
575 for (nsample = 0; nsample < einst->nsamples; nsample++)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
576 if (einst->instConvTable[nsample] != jsetNotSet)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
577 {
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
578 JSSInstrument *inst = module->instruments[einst->instConvTable[nsample]];
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
579 if ((ret = jssXMLoadSampleData(inFile, inst, ninst, nsample)) != DMERR_OK)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
580 return ret;
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
581 }
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
582
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
583 return DMERR_OK;
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
584 }
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
585
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
586
1132
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
587 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
588 {
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
589 int i;
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
590 for (i = 0; i < XM_MaxEnvPoints; i++)
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
591 {
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
592 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
593 !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
594 return FALSE;
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
595 }
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
596 return TRUE;
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
597 }
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
598
b349646f19a0 Split envelope reading to tiny helper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1130
diff changeset
599
1132
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
600 static BOOL jssXMLoadEnvelopeData(DMResource *inFile, XMEnvelope *env)
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
601 {
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
602 return
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
603 dmf_read_byte(inFile, &(env->sustain)) &&
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
604 dmf_read_byte(inFile, &(env->loopS)) &&
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
605 dmf_read_byte(inFile, &(env->loopE));
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
606 }
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
607
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
608
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 /* Load XM-format extended instrument from file-stream into JSS module's given inst
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 static int jssXMLoadExtInstrument(DMResource *inFile, int ninst, JSSModule *module)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613 XMInstrument1 xmI1;
1126
0888764d01cd Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1125
diff changeset
614 off_t remainder, pos = dmftell(inFile);
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
615 JSSExtInstrument *einst;
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
616 XMInstrument2 xmI2;
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
617 int i, nsample, ret;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 // 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
620 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
621 !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
622 !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
623 !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
624 {
29dc9337fa11 Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents: 1158
diff changeset
625 JSSERROR(DMERR_FREAD, DMERR_FREAD,
29dc9337fa11 Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents: 1158
diff changeset
626 "Failed to read primary extended instrument header #%d\n", ninst);
29dc9337fa11 Add a meaningful error message for instrument header read failure.
Matti Hamalainen <ccr@tnsp.org>
parents: 1158
diff changeset
627 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 // 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
630 if (xmI1.nsamples == 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 // We may STILL need to skip extra data after 1st instr. header
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 remainder = xmI1.headSize - (dmftell(inFile) - pos);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 if (remainder > 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 {
98
82b825bb08b0 Fix XM loading. Oops.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
636 JSSDEBUG("xmI1#2 Skipping: %li\n", remainder);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 dmfseek(inFile, remainder, SEEK_CUR);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 }
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
639 return DMERR_OK;
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
640 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
641
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
642 // Allocate instrument
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
643 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
644 {
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
645 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
646 "Could not allocate extended instrument structure #%d\n", ninst);
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
647 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
648
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
649 module->extInstruments[ninst] = einst;
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
650
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
651 // 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
652 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
653 !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
654 {
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
655 JSSERROR(DMERR_FREAD, DMERR_FREAD,
1132
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
656 "Could not read secondary instrument header part #1 for #%d.\n", ninst);
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
657 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
658
1132
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
659 if (!jssXMLoadEnvelopePoints(inFile, &xmI2.volumeEnv) ||
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
660 !jssXMLoadEnvelopePoints(inFile, &xmI2.panningEnv))
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
661 {
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
662 JSSERROR(DMERR_FREAD, DMERR_FREAD,
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
663 "Could not read envelope point data for instrument #%d.\n", ninst);
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
664 }
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
665
1132
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
666 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
667 !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
668
1132
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
669 !jssXMLoadEnvelopeData(inFile, &xmI2.volumeEnv) ||
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
670 !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
671
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
672 !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
673 !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
674
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
675 !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
676 !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
677 !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
678 !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
679
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
680 !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
681 !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
682 {
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
683 JSSERROR(DMERR_FREAD, DMERR_FREAD,
1132
d4512925b4f9 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1131
diff changeset
684 "Could not read secondary instrument header part #2 for #%d.\n", ninst);
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
685 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
686
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
687 // 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
688 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
689 if (remainder > 0)
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
690 {
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
691 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
692 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
693 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
694
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
695 // 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
696 #ifndef JSS_LIGHT
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
697 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
698 #endif
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
699 jssXMConvertEnvelope(&einst->volumeEnv, &xmI2.volumeEnv, "vol", ninst);
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
700 jssXMConvertEnvelope(&einst->panningEnv, &xmI2.panningEnv, "pan", ninst);
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
701
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
702 switch (xmI2.vibratoType)
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
703 {
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
704 case 0: einst->vibratoType = jvibSine; break;
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
705 case 1: einst->vibratoType = jvibRamp; break;
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
706 case 2: einst->vibratoType = jvibSquare; break;
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
707 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
708 default:
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
709 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
710 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
711 "Invalid extinstrument vibrato type %d for inst #%d\n", ninst);
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
712 break;
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
713 }
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
714 einst->vibratoSweep = xmI2.vibratoSweep;
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
715 einst->vibratoDepth = xmI2.vibratoDepth;
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
716 einst->vibratoRate = xmI2.vibratoRate;
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
717 einst->fadeOut = xmI2.fadeOut;
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
718 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
719
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
720 // 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
721 for (i = 0; i < XM_MaxInstruments; i++)
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
722 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
723
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
724 // Read sample headers
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
725 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
726 {
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
727 if ((ret = jssXMLoadSampleInstrument(inFile, module, einst, ninst, nsample)) != DMERR_OK)
1130
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
728 return ret;
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
729 }
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
730
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
731 // 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
732 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
733 {
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
734 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
735 if (tmp >= 0 && tmp < xmI1.nsamples)
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
736 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
737 else
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
738 {
1175
165c673ee012 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1174
diff changeset
739 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
740 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
741 "Ext.instrument #%d sNumForNotes[%d] out of range (%d).\n",
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
742 ninst, i, tmp);
725e7caa43a0 Split instrument sample data loading to another function in XM loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
743 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745
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
746 // 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
747 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
748 {
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
749 if ((ret = jssXMLoadInstrumentSamples(inFile, module, einst, ninst)) != DMERR_OK)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
750 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
751 }
dc26df8b642c Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents: 1176
diff changeset
752
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
753 return DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
757 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
758 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
759 int index;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 for (index = 0; index < module->nextInstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 {
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
762 int result = jssXMLoadExtInstrument(inFile, index, module);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 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
764 JSSERROR(result, result, "Errors while reading instrument #%d\n", index);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765 }
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
766 return DMERR_OK;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
767 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
768
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
769
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
770 /* 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
771 */
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
772 int jssLoadXM(DMResource *inFile, JSSModule **ppModule, BOOL probe)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
773 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
774 JSSModule *module;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
775 XMHeader xmH;
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
776 int index, ret;
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
777
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
778 assert(ppModule != NULL);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
779 assert(inFile != NULL);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
780 *ppModule = NULL;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
781
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
782 // Try to get the XM-header
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
783 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
784 !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
785 !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
786 !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
787 !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
788 !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
789 !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
790 !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
791 !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
792 !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
793 !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
794 !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
795 !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
796 !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
797 return DMERR_FREAD;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
798
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
799
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
800 // 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
801 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
802 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
803 if (probe)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
804 return DMERR_NOT_SUPPORTED;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
805 else
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
806 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
807 "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
808 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
809
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
810 if (xmH.unUsed1A != 0x1a)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
811 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
812 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
813 "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
814 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
815
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
816 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
817 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
818 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
819 "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
820 xmH.norders, XM_MaxOrders);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
821 xmH.norders = XM_MaxOrders;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
822 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
823
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
824 if (xmH.norders == 0)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
825 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
826 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
827 "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
828 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
829
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
830 if (xmH.npatterns > XM_MaxPatterns)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
831 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
832 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
833 "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
834 xmH.npatterns, XM_MaxPatterns);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
835 xmH.npatterns = XM_MaxPatterns;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
836 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
837
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
838 if (xmH.npatterns == 0)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
839 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
840 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
841 "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
842 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
843
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
844 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
845 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
846 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
847 "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
848 xmH.nchannels, XM_MaxChannels);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
849 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
850
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
851 if (xmH.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
852 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
853 JSSWARNING(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
854 "Number of 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
855 xmH.ninstruments, XM_MaxInstruments);
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
856 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
857
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
858 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
859 {
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
860 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
861 "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
862 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
863 }
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
864
1160
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
865 switch (xmH.version)
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
866 {
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
867 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
868 case 0x0102:
1160
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
869 break;
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
870
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
871 default:
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
872 JSSWARNING(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
873 "Unsupported version of XM format 0x%04x.\n",
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
874 xmH.version);
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
875 }
b122ad2d3fbe Add XM format version check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
876
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
877 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
878 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
879 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
880 "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
881 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
882
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
883 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
884 {
92cee852a8af Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents: 1160
diff changeset
885 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
886 "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
887 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
888 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
889 }
92cee852a8af Check header size against the known values. Bail out if it's too small, and
Matti Hamalainen <ccr@tnsp.org>
parents: 1160
diff changeset
890
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
891 /* Okay, allocate a module structure
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
892 */
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
893 module = jssAllocateModule();
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
894 if (module == NULL)
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
895 {
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
896 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
897 "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
898 }
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
899 *ppModule = module;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
900
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
901
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
902 // Convert and check the header data
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
903 module->moduleType = jmdtXM;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
904 module->intVersion = xmH.version;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
905 #ifndef JSS_LIGHT
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
906 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
907 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
908 #endif
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
909 module->defSpeed = xmH.defSpeed;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
910 module->defTempo = xmH.defTempo;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
911 module->nextInstruments = xmH.ninstruments;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
912 module->ninstruments = 0;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
913 module->npatterns = xmH.npatterns;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
914 module->norders = xmH.norders;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
915 module->nchannels = xmH.nchannels;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
916 module->defFlags = jmdfStereo | jmdfFT2Replay;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
917 module->defRestartPos = xmH.defRestartPos;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
918
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
919 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
920 module->defFlags |= jmdfAmigaPeriods;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
921
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
922 // Setup the default pannings
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
923 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
924 module->defPanning[index] = jchPanMiddle;
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
925
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
926 // Load rest of the module
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
927 switch (xmH.version)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
928 {
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
929 case 0x0104:
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
930 if ((ret = jssXMLoadPatterns(inFile, module, &xmH)) != DMERR_OK)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
931 goto out;
1124
b8bfd9fbe1d9 Modularize the XM loader somewhat by splitting to more functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
932
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
933 if ((ret = jssXMLoadInstruments(inFile, module)) != DMERR_OK)
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
934 goto out;
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
935 break;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
936
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
937 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
938 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
939 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
940
dc26df8b642c Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents: 1176
diff changeset
941 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
942 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
943
dc26df8b642c Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents: 1176
diff changeset
944 // 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
945 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
946 {
dc26df8b642c Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents: 1176
diff changeset
947 JSSExtInstrument *einst = module->extInstruments[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
948 if ((ret = jssXMLoadInstrumentSamples(inFile, module, einst, index)) != 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
949 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
950 }
dc26df8b642c Some support for 0x0102 version of the XM format. Does not work fully yet,
Matti Hamalainen <ccr@tnsp.org>
parents: 1176
diff changeset
951 break;
1176
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
952 }
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
953
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
954 out:
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
955
afdbf62ce8ad Revamp instrument sample loading somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 1175
diff changeset
956 return ret;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
957 }