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