annotate minijss/jloadxm.c @ 2509:0c0576544d41

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