annotate minijss/jloadjss.c @ 1118:de25e0f2b856

Fix sNumForNotes conversion/handling in JSSMOD loader and xm2jss.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Mar 2015 03:33:25 +0200
parents 97ecc0a9c21f
children e22d4ceb6414
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 - JSSMOD module loader
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2007-2009 Tecnic Software productions (TNSP)
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 #include "jssmod.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <string.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
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 #ifdef JM_SUP_PATMODE_ALL
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
11 # define JM_SUP_PATMODE_1 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
12 # define JM_SUP_PATMODE_2 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
13 # define JM_SUP_PATMODE_3 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
14 # define JM_SUP_PATMODE_4 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
15 # define JM_SUP_PATMODE_5 1
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
19 #define JSGETBUF(XV, XT) if (!dmf_read_str(inFile, XV, sizeof(XT))) return DMERR_OUT_OF_DATA
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
20 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
23 #if defined(JM_SUP_PATMODE_1) || defined(JM_SUP_PATMODE_3)
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
24 static int jssGetConvertedNote(DMResource *inFile, JSSNote *note)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 Uint8 tmp;
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 JSGETBYTE(&tmp);
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 if (tmp == 127)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 note->note = jsetNoteOff;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 else if (tmp == 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 note->note = jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 note->note = tmp - 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 note->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 note->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 note->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 note->param = (tmp == 0 && note->effect == jsetNotSet) ? jsetNotSet : tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 return DMERR_OK;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
54 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4)
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
55 static int jssGetCompressedNote(DMResource *inFile, JSSNote *note)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 Uint8 packb, tmp;
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 JSGETBYTE(&packb);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 if (packb & 0x80)
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 if (packb & COMP_NOTE)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 if (tmp == 127)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 note->note = jsetNoteOff;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 note->note = tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 if (packb & COMP_INSTRUMENT)
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 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 note->instrument = tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 if (packb & COMP_VOLUME)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 note->volume = tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
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 if (packb & COMP_EFFECT)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 note->effect = tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 note->param = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 if (packb & COMP_PARAM)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 note->param = tmp;
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 else
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 tmp = packb;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 if (tmp == 127)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 note->note = jsetNoteOff;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 else if (tmp == 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 note->note = jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 note->note = tmp - 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 note->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 note->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 note->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
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 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 note->param = (tmp == 0 && note->effect == jsetNotSet) ? jsetNotSet : tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
125 #ifdef JM_SUP_PATMODE_2
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
126 static int jssGetPatternCompHoriz(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel];
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
137 int res = jssGetCompressedNote(inFile, note);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 if (res != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n", row, channel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 return DMERR_OK;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
147 #ifdef JM_SUP_PATMODE_4
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
148 static int jssGetPatternCompVert(DMResource *inFile, JSSPattern *pattern)
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 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 for (row = 0; row < pattern->nrows; row++)
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 JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel];
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
159 int res = jssGetCompressedNote(inFile, note);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 if (res != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n", row, channel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
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 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
169 #ifdef JM_SUP_PATMODE_1
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
170 static int jssGetPatternRawHoriz(DMResource *inFile, JSSPattern *pattern)
0
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 int row, channel;
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 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 for (channel = 0; channel < pattern->nchannels; channel++)
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 JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel];
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
181 int res = jssGetConvertedNote(inFile, note);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 if (res != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n", row, channel);
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
191 #ifdef JM_SUP_PATMODE_3
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
192 static int jssGetPatternRawVert(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 int row, channel;
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 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 JSSNote *note = &pattern->data[(pattern->nchannels * row) + channel];
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
203 int res = jssGetConvertedNote(inFile, note);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 if (res != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n", row, channel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
213 #ifdef JM_SUP_PATMODE_5
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
214
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
215 #undef JSGETBYTE
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
216 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
217
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
218 #define JSFOREACHNOTE1 \
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
219 for (channel = 0; channel < pattern->nchannels; channel++) \
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
220 for (row = 0; row < pattern->nrows; row++) { \
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
221 JSSNote *note = pattern->data + (pattern->nchannels * row) + channel;
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
222
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
223 #define JSFOREACHNOTE2 }
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
224
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
225 static int jssGetPatternRawVertElem(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 int row, channel;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
228 Uint8 tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
233 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
234 JSGETBYTE(&tmp);
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
235 if (tmp == 0)
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
236 note->note = jsetNotSet;
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
237 else if (tmp == 127)
331
c200edce230d Oops, a silly typo in the JMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
238 note->note = jsetNoteOff;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
239 else
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
240 note->note = tmp - 1;
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
241 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
242
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
243 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
244 JSGETBYTE(&tmp);
338
cd57ba1130eb Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
245 note->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
246 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
247
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
248 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
249 JSGETBYTE(&tmp);
338
cd57ba1130eb Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
250 note->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
251 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
252
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
253 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
254 JSGETBYTE(&tmp);
338
cd57ba1130eb Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
255 note->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
256 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
257
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
258 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
259 JSGETBYTE(&tmp);
338
cd57ba1130eb Fixes and improvements in the JMOD saving and loading.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
260 note->param = (tmp == 0 && note->effect == jsetNotSet) ? jsetNotSet : tmp;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
261 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
262
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 #undef JSGETBUF
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 #undef JSGETBYTE
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 #define JSGETBUF(XV, XT) do { \
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
271 if (!dmf_read_str(inFile, XV, sizeof(XT))) \
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 JSSERROR(DMERR_OUT_OF_DATA, DMERR_OUT_OF_DATA, \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 "Out of data at getting " # XT " (%d bytes)\n", sizeof(XT)); \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 } while (0)
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
275 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 #ifdef JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 static void jssCopyEnvelope(JSSEnvelope *e, JSSMODEnvelope *je)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 e->flags = je->flags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 e->npoints = je->npoints;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 e->sustain = je->sustain;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 e->loopS = je->loopS;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 e->loopE = je->loopE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 for (i = 0; i < je->npoints; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 e->points[i].frame = je->points[i].frame;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 e->points[i].value = je->points[i].value;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
298 int jssLoadJSSMOD(DMResource *inFile, JSSModule **ppModule, BOOL probe)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 JSSModule *module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 JSSMODHeader jssH;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 int index;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 *ppModule = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 // Check the JSSMOD header
96
6bf5220fa47e Urgh .. use memset to silence some bogus GCC warnings about using
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
307 memset(&jssH, 0, sizeof(jssH));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 JSGETBUF(&jssH, JSSMODHeader);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 if (memcmp(jssH.idMagic, "JM", 2) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 {
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
312 if (probe)
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
313 return DMERR_NOT_SUPPORTED;
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
314 else
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
315 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
316 "Not a JSSMOD file, header signature mismatch!\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 if (jssH.idVersion != JSSMOD_VERSION)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 JSSERROR(DMERR_VERSION, DMERR_VERSION,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 "Unsupported version of JSSMOD 0x%4x, this version only supports 0x%4x!\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 jssH.idVersion, JSSMOD_VERSION);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 // Allocate the module
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 module = jssAllocateModule();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 if (module == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 "Could not allocate memory for module structure.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 *ppModule = module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 // Copy header information
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 module->norders = jssH.norders;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 module->npatterns = jssH.npatterns;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 module->nchannels = jssH.nchannels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 module->nextInstruments = jssH.nextInstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 module->ninstruments = jssH.ninstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 module->defFlags = jssH.defFlags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 module->intVersion = jssH.intVersion;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 module->defRestartPos = jssH.defRestartPos;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 module->defSpeed = jssH.defSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 module->defTempo = jssH.defTempo;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 // Get the orders list
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 for (index = 0; index < module->norders; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 Sint16 order;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 JSGETBUF(&order, Sint16);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 module->orderList[index] = order;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 // Parse the patterns
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 for (index = 0; index < module->npatterns; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 JSSMODPattern jssP;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 int result = DMERR_INVALID_DATA;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 // Get header and check size
96
6bf5220fa47e Urgh .. use memset to silence some bogus GCC warnings about using
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
362 memset(&jssP, 0, sizeof(jssP));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 JSGETBUF(&jssP, JSSMODPattern);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 // Allocate pattern
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 module->patterns[index] = jssAllocatePattern(jssP.nrows, module->nchannels);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 if (module->patterns[index] == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 "Could not allocate memory for pattern #%d.\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 // Get pattern data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 switch (jssH.patMode)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 #ifdef JM_SUP_PATMODE_1
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 case PATMODE_RAW_HORIZ:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
378 result = jssGetPatternRawHoriz(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 #ifdef JM_SUP_PATMODE_2
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 case PATMODE_COMP_HORIZ:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
383 result = jssGetPatternCompHoriz(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 #ifdef JM_SUP_PATMODE_3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 case PATMODE_RAW_VERT:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
388 result = jssGetPatternRawVert(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 #ifdef JM_SUP_PATMODE_4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 case PATMODE_COMP_VERT:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
393 result = jssGetPatternCompVert(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 #ifdef JM_SUP_PATMODE_5
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 case PATMODE_RAW_ELEM:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
398 result = jssGetPatternRawVertElem(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 "Unsupported pattern mode %d. Check compilation options.", jssH.patMode);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 if (result != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 JSSERROR(result, result, "Error in unpacking pattern #%i data\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 #ifdef JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 // Read extended instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 for (index = 0; index < module->nextInstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 JSSMODExtInstrument jssE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 JSSExtInstrument *einst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
96
6bf5220fa47e Urgh .. use memset to silence some bogus GCC warnings about using
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
421 memset(&jssE, 0, sizeof(jssE));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 JSGETBUF(&jssE, JSSMODExtInstrument);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 if ((einst = jssAllocateExtInstrument()) == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 "Could not allocate extended instrument structure #%i\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 module->extInstruments[index] = einst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 einst->nsamples = jssE.nsamples;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 einst->vibratoType = jssE.vibratoType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 einst->vibratoSweep = jssE.vibratoSweep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 einst->vibratoDepth = jssE.vibratoDepth;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 einst->vibratoRate = jssE.vibratoRate;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437 einst->fadeOut = jssE.fadeOut;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 for (i = 0; i < jsetNNotes; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 int snum = jssE.sNumForNotes[i];
1118
de25e0f2b856 Fix sNumForNotes conversion/handling in JSSMOD loader and xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
442 einst->sNumForNotes[i] = (snum > 0) ? snum - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 jssCopyEnvelope(&(einst->volumeEnv), &jssE.volumeEnv);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 jssCopyEnvelope(&(einst->panningEnv), &jssE.panningEnv);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 #ifdef JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 // Read sample instrument headers
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 for (index = 0; index < module->ninstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 JSSMODInstrument jssI;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 JSSInstrument *inst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
96
6bf5220fa47e Urgh .. use memset to silence some bogus GCC warnings about using
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
456 memset(&jssI, 0, sizeof(jssI));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 JSGETBUF(&jssI, JSSMODInstrument);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 if ((inst = jssAllocateInstrument()) == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 "Could not allocate instrument structure #%i\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 }
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 module->instruments[index] = inst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 inst->size = jssI.size;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 inst->loopS = jssI.loopS;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 inst->loopE = jssI.loopE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 inst->volume = jssI.volume;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 inst->flags = jssI.flags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 inst->C4BaseSpeed = jssI.C4BaseSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 inst->ERelNote = jssI.ERelNote;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 inst->EFineTune = jssI.EFineTune;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 inst->EPanning = jssI.EPanning;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 inst->hasData = jssI.hasData;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 inst->convFlags = jssI.convFlags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 #ifdef JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 // Read sample data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 for (index = 0; index < module->ninstruments; index++)
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 JSSInstrument *inst = module->instruments[index];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 if (inst && inst->hasData)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 size_t sz;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 // Calculate data size
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 if (inst->flags & jsf16bit)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 sz = inst->size * sizeof(Uint16);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 sz = inst->size * sizeof(Uint8);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 // Allocate
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 if ((inst->data = dmMalloc(sz)) == NULL)
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 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 "Could not allocate sample data #%d\n", index);
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 // Copy data
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
504 if (!dmf_read_str(inFile, inst->data, sz))
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
505 {
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
506 JSSERROR(DMERR_FREAD, DMERR_FREAD,
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
507 "Could not read sample data for #%d\n", index);
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
508 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 // Convert, if needed
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 if (inst->flags & jsf16bit)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 jssDecodeSample16(inst->data, inst->size, inst->convFlags);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 jssDecodeSample8(inst->data, inst->size, inst->convFlags);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
518 # warning Not including JSSMOD sample loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 #endif // JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
521 # warning Not including JSSMOD instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 #endif // JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
524 # warning Not including JSSMOD ext.instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 #endif // JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 }