Mercurial > hg > dmlib
annotate minijss/jssmod.h @ 1238:e8c99da451cd
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Mar 2015 18:14:03 +0200 |
parents | b8c9af10b7fd |
children | 22c71fa5698e |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Module structure and handling routines | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
1163 | 4 * (C) Copyright 2006-2015 Tecnic Software productions (TNSP) |
0 | 5 */ |
6 #ifndef JSSMOD_H | |
7 #define JSSMOD_H | |
8 | |
9 #include "jss.h" | |
10 #include "dmres.h" | |
11 | |
358 | 12 #ifdef __cplusplus |
13 extern "C" { | |
14 #endif | |
0 | 15 |
16 // Max data size definitions | |
1220 | 17 #define jsetMaxChannels (128) |
18 #define jsetMaxRows (16*1024) // Number of rows checked against | |
19 #define jsetMaxPatterns (1024) // Max patterns | |
1215
66c79bae8704
Bump up some maximum values for JSS module data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1210
diff
changeset
|
20 #define jsetMaxInstruments (1024) |
66c79bae8704
Bump up some maximum values for JSS module data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1210
diff
changeset
|
21 #define jsetMaxOrders (512) |
0 | 22 #define jsetNNotes (11 * 12) |
1220 | 23 #define jsetMinNote (0) // Smallest note number |
0 | 24 #define jsetMaxNote (jsetNNotes - 1) |
1220 | 25 #define jsetMaxEnvPoints (64) // Max number of envelope points |
0 | 26 |
27 // Instrument envelope flags | |
28 #define jenvfUsed (0x01) // Envelope is used | |
29 #define jenvfSustain (0x02) // Envelope has a sustain point (XM) or has sustain loop (IT) | |
30 #define jenvfLooped (0x04) // Envelope is looped | |
31 | |
32 // Instrument vibrato waveform types | |
33 #define jvibSine (0) | |
34 #define jvibRamp (1) | |
35 #define jvibSquare (2) | |
36 #define jvibRandom (3) | |
37 | |
38 // General stuff | |
39 #define jsetNoteOff (-2) | |
40 #define jsetOrderEnd (-1) | |
41 #define jsetOrderSkip (-2) | |
42 | |
43 | |
44 // General module flags | |
45 #define jmdfAmigaPeriods (0x0001) // Use non-linear periods (Amiga) | |
46 #define jmdfAmigaLimits (0x0002) // Use Amiga-styled valuelimits | |
47 #define jmdfStereo (0x0008) // Use stereo output, if possible | |
48 | |
49 #define jmdfFT2Replay (0x0010) // Use FT2 replaying bugs/features | |
50 #define jmdfST300Slides (0x0020) // Use Scream Tracker 3.00 slides | |
51 #define jmdfByteLStart (0x0040) // LStart is in BYTES instead of WORDS (MOD only) | |
52 | |
53 | |
54 // Module format types | |
55 enum JMDT | |
56 { | |
57 jmdtMOD = 1, | |
58 jmdtS3M, | |
59 jmdtXM, | |
60 jmdtIT | |
61 }; | |
62 | |
63 | |
64 // Bits for sample conversion routines | |
65 #define jsampDelta (0x01) | |
66 #define jsampFlipSign (0x02) | |
67 #define jsampSwapEndianess (0x04) | |
68 #define jsampSplit (0x08) | |
69 | |
1236 | 70 #define jsampHasData (0x80) // Special flag |
71 | |
0 | 72 |
73 // Internal instrument structure | |
74 typedef struct | |
75 { | |
49
033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
76 int size, // Length in units |
0 | 77 loopS, // Loop start position in units |
78 loopE; // Loop end position in units | |
79 int volume, // Volume [jsetMinVol...jsetMaxVol] | |
80 flags, // Flags - see jss.h jsfXXXX | |
81 C4BaseSpeed, // C4BaseSpeed | |
82 ERelNote, // Extended: Relative note value | |
83 EFineTune, // Extended: Fine-tune value | |
84 EPanning; // Extended: Panning | |
85 #ifndef JSS_LIGHT | |
86 char *desc; | |
87 #endif | |
88 void *data; // Sample data | |
89 | |
90 int convFlags; | |
91 } JSSInstrument; | |
92 | |
93 | |
94 // Envelope point structure | |
95 typedef struct | |
96 { | |
97 int frame, value; | |
98 } JSSEnvelopePoint; | |
99 | |
100 | |
101 // Envelope structure | |
102 typedef struct | |
103 { | |
104 int flags, | |
105 npoints, | |
106 sustain, | |
107 loopS, | |
108 loopE; | |
109 JSSEnvelopePoint points[jsetMaxEnvPoints]; | |
110 } JSSEnvelope; | |
111 | |
112 | |
113 // Extended instrument | |
114 typedef struct | |
115 { | |
116 #ifndef JSS_LIGHT | |
117 char *desc; | |
118 #endif | |
1178
f1bbac567942
Oops, forgot to commit this change to add the conversion table to
Matti Hamalainen <ccr@tnsp.org>
parents:
1163
diff
changeset
|
119 int nsamples, |
f1bbac567942
Oops, forgot to commit this change to add the conversion table to
Matti Hamalainen <ccr@tnsp.org>
parents:
1163
diff
changeset
|
120 sNumForNotes[jsetNNotes], |
f1bbac567942
Oops, forgot to commit this change to add the conversion table to
Matti Hamalainen <ccr@tnsp.org>
parents:
1163
diff
changeset
|
121 instConvTable[jsetNNotes]; |
0 | 122 JSSEnvelope volumeEnv, panningEnv; |
123 int vibratoType, | |
124 vibratoSweep, | |
125 vibratoDepth, | |
126 vibratoRate, | |
127 fadeOut; | |
128 } JSSExtInstrument; | |
129 | |
130 | |
131 // Internal pattern structures | |
132 typedef struct | |
133 { | |
134 int note, | |
135 instrument, | |
136 volume, | |
137 effect, | |
138 param; | |
139 } JSSNote; | |
140 | |
141 | |
142 typedef struct | |
143 { | |
144 int nrows, nchannels; | |
145 JSSNote *data; | |
146 } JSSPattern; | |
147 | |
148 | |
149 // Module structure | |
150 typedef struct | |
151 { | |
152 int moduleType; // Type of the module | |
153 char *moduleName; // Title/name | |
154 char *trackerName; // Tracker software name | |
155 int defSpeed, // Initial values | |
156 defTempo, | |
157 defFlags, | |
158 defRestartPos, | |
159 intVersion, // Format's internal version | |
160 nchannels, | |
161 ninstruments, | |
162 nextInstruments, | |
163 npatterns, | |
164 norders; | |
165 | |
166 int defPanning[jsetNChannels]; | |
167 int orderList[jsetMaxOrders]; | |
168 JSSPattern *patterns[jsetMaxPatterns + 1]; | |
169 JSSInstrument *instruments[jsetMaxInstruments]; | |
170 JSSExtInstrument *extInstruments[jsetMaxInstruments]; | |
171 | |
172 #ifdef JSS_SUP_THREADS | |
173 DMMutex *mutex; | |
174 #endif | |
175 | |
176 } JSSModule; | |
177 | |
178 | |
179 #ifdef JSS_SUP_JSSMOD | |
180 | |
1230 | 181 #define JSSMOD_VERSION (0x20) |
0 | 182 |
183 enum | |
184 { | |
185 PATMODE_RAW_HORIZ = 1, | |
186 PATMODE_COMP_HORIZ, | |
187 PATMODE_RAW_VERT, | |
188 PATMODE_COMP_VERT, | |
189 PATMODE_RAW_ELEM, | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
190 PATMODE_LAST |
0 | 191 }; |
192 | |
193 /* JSSMOD typedefs | |
194 */ | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
195 typedef struct __attribute__((__packed__)) |
0 | 196 { |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
197 char idMagic[2]; // "JM" |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
198 Uint8 idVersion; // 0x10 for 1.0, etc. |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
199 Uint16 |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
200 defFlags, // Flags field: see jmdf* flags |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
201 intVersion, // Internal version, format dependant |
0 | 202 norders, // Number of orders in orderlist |
203 npatterns, // Number of patterns | |
204 nextInstruments, // Number of extended instruments | |
205 ninstruments, // Number of sample-instruments | |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
206 defRestartPos; // Default restart position in orderlist |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
207 |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
208 Uint8 |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
209 nchannels, // Number of channels |
0 | 210 defSpeed, // Default speed (ticks/row) |
211 defTempo, // Default tempo (BPM) | |
212 patMode; // Pattern data format mode | |
213 | |
214 /* | |
215 - After this, norders long orders table will follow, of type: | |
216 Sint16 orderList[norders]; | |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
217 |
0 | 218 - Pattern data, format depends on patMode. |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
219 |
0 | 220 - Extended instruments (*) |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
221 |
0 | 222 - Sample instrument headers (*) |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
223 |
0 | 224 - Sample data (format depends) (*) |
1127
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
225 |
e22d4ceb6414
Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
226 (*) Items are optional and may have been omitted. Fields in the |
0 | 227 module and other headers are used to indicate if these items exist. |
228 */ | |
229 } JSSMODHeader; | |
230 | |
231 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
232 typedef struct __attribute__((__packed__)) |
0 | 233 { |
234 Uint16 frame, value; | |
235 } JSSMODEnvelopePoint; | |
236 | |
237 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
238 typedef struct __attribute__((__packed__)) |
0 | 239 { |
1229
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
240 Uint32 |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
241 flags, |
0 | 242 npoints, |
243 sustain, | |
244 loopS, | |
245 loopE; | |
246 JSSMODEnvelopePoint points[jsetMaxEnvPoints]; | |
247 } JSSMODEnvelope; | |
248 | |
249 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
250 typedef struct __attribute__((__packed__)) |
0 | 251 { |
1229
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
252 Uint8 nsamples, |
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
253 vibratoType; |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
254 Uint16 vibratoSweep, |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
255 vibratoDepth, |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
256 vibratoRate, |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
257 fadeOut; |
1229
dff0dfddaf0a
Change some JSSMOD struct member types.
Matti Hamalainen <ccr@tnsp.org>
parents:
1224
diff
changeset
|
258 Uint32 sNumForNotes[jsetNNotes]; // 32bit because internally we use global indices |
0 | 259 JSSMODEnvelope volumeEnv, panningEnv; |
260 } JSSMODExtInstrument; | |
261 | |
262 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
263 typedef struct __attribute__((__packed__)) |
0 | 264 { |
1236 | 265 Uint32 size, // Length in units |
0 | 266 loopS, // Loop start position in units |
267 loopE; // Loop end position in units | |
1236 | 268 Uint16 flags, // Flags - see jss.h jsfXXXX |
0 | 269 C4BaseSpeed, // C4BaseSpeed |
270 ERelNote, // Extended: Relative note value | |
271 EFineTune, // Extended: Fine-tune value | |
272 EPanning; // Extended: Panning | |
1236 | 273 Uint8 volume, // Volume [jsetMinVol...jsetMaxVol] |
274 convFlags; // Conversion flags .. jsampXXXX | |
275 // jsampHasData set if there is sample data | |
0 | 276 } JSSMODInstrument; |
277 | |
278 | |
1210
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
279 #define JM_COMP_NOTE (0x01) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
280 #define JM_COMP_INSTRUMENT (0x02) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
281 #define JM_COMP_VOLUME (0x04) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
282 #define JM_COMP_EFFECT (0x08) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
283 #define JM_COMP_PARAM (0x10) |
6b48bad13399
Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1209
diff
changeset
|
284 #define JM_COMP_ALL (JM_COMP_NOTE | JM_COMP_INSTRUMENT | JM_COMP_VOLUME | JM_COMP_EFFECT | JM_COMP_PARAM) |
0 | 285 |
286 | |
865
fc5bd0ccc260
Use struct packing and specific types for JSSMOD data.
Matti Hamalainen <ccr@tnsp.org>
parents:
796
diff
changeset
|
287 typedef struct __attribute__((__packed__)) |
0 | 288 { |
1221
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
289 Uint32 size; |
e0aa979e7188
Change sizes of some JSSMOD structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
1220
diff
changeset
|
290 Uint16 nrows; |
0 | 291 } JSSMODPattern; |
292 | |
293 #endif | |
294 | |
1216 | 295 |
0 | 296 #ifndef JSS_LIGHT |
948 | 297 char * jssASCIItoStr(const char *src, const char endByte, const size_t len); |
0 | 298 BOOL jssEncodeSample8(Uint8 *, const size_t, const int); |
299 BOOL jssEncodeSample16(Uint16 *, const size_t, const int); | |
300 #endif | |
1129
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
301 int jssDecodeSample8(Uint8 *, const size_t, const int); |
e466d10dae6d
Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents:
1127
diff
changeset
|
302 int jssDecodeSample16(Uint16 *, const size_t, const int); |
49
033c660c25f5
Restructure module playing, removing 8bit sample mixing (output can still be
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
303 int jssConvertModuleForPlaying(JSSModule *module); |
1231 | 304 |
0 | 305 JSSModule * jssAllocateModule(void); |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
306 int jssFreeModule(JSSModule * module); |
1238 | 307 |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
308 JSSPattern * jssAllocatePattern(const int nrows, const int nchannels); |
1224
e667710aee8e
Add functions jssFreeInstrument(), jssFreeExtInstrument() and jssFreePattern().
Matti Hamalainen <ccr@tnsp.org>
parents:
1223
diff
changeset
|
309 void jssFreePattern(JSSPattern *pattern); |
1238 | 310 |
0 | 311 JSSInstrument * jssAllocateInstrument(void); |
1224
e667710aee8e
Add functions jssFreeInstrument(), jssFreeExtInstrument() and jssFreePattern().
Matti Hamalainen <ccr@tnsp.org>
parents:
1223
diff
changeset
|
312 void jssFreeInstrument(JSSInstrument *inst); |
1238 | 313 |
0 | 314 JSSExtInstrument * jssAllocateExtInstrument(void); |
1224
e667710aee8e
Add functions jssFreeInstrument(), jssFreeExtInstrument() and jssFreePattern().
Matti Hamalainen <ccr@tnsp.org>
parents:
1223
diff
changeset
|
315 void jssFreeExtInstrument(JSSExtInstrument *inst); |
0 | 316 |
317 #ifdef JSS_SUP_XM | |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
318 int jssLoadXM(DMResource *file, JSSModule **pmodule, BOOL probe); |
0 | 319 #endif |
320 | |
321 #ifdef JSS_SUP_JSSMOD | |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
322 int jssLoadJSSMOD(DMResource *file, JSSModule **pmodule, BOOL probe); |
0 | 323 #endif |
324 | |
1223
82cc143cb7d2
Add function argument names to prototypes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1221
diff
changeset
|
325 |
358 | 326 #ifdef __cplusplus |
327 } | |
328 #endif | |
329 | |
0 | 330 #endif // JSSMOD_H |