Mercurial > hg > dmlib
annotate jssplr.c @ 55:e0e470c3fc8e
Initial round of cleaning up the player code a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 01 Oct 2012 06:28:29 +0300 |
parents | ca0e00facb7b |
children | a33e47232161 |
rev | line source |
---|---|
0 | 1 /* |
2 * miniJSS - Module playing routines | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2006-2009 Tecnic Software productions (TNSP) | |
5 */ | |
6 #include "jssplr.h" | |
7 #include <string.h> | |
8 #include <stdlib.h> | |
9 | |
10 // FIXME!! FIX ME! | |
11 #include <math.h> | |
12 | |
13 /* Miscellaneous tables | |
14 */ | |
15 #define jmpNSineTable (256) | |
16 static int *jmpSineTable = NULL; | |
17 | |
18 | |
19 static const Sint16 jmpXMAmigaPeriodTab[13 * 8] = { | |
20 907, 900, 894, 887, 881, 875, 868, 862, 856, 850, 844, 838, | |
21 832, 826, 820, 814, 808, 802, 796, 791, 785, 779, 774, 768, | |
22 762, 757, 752, 746, 741, 736, 730, 725, 720, 715, 709, 704, | |
23 699, 694, 689, 684, 678, 675, 670, 665, 660, 655, 651, 646, | |
24 640, 636, 632, 628, 623, 619, 614, 610, 604, 601, 597, 592, | |
25 588, 584, 580, 575, 570, 567, 563, 559, 555, 551, 547, 543, | |
26 538, 535, 532, 528, 524, 520, 516, 513, 508, 505, 502, 498, | |
27 494, 491, 487, 484, 480, 477, 474, 470, 467, 463, 460, 457, | |
28 | |
29 453, 450, 447, 443, 440, 437, 434, 431 | |
30 }; | |
31 | |
32 | |
33 #define jmpNMODEffectTable (36) | |
34 static const char jmpMODEffectTable[jmpNMODEffectTable] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
35 | |
36 | |
37 /* Helper functions | |
38 */ | |
39 int jmpNoteToAmigaPeriod(int note, int finetune) | |
40 { | |
41 int tmp = (note + finetune + 8); | |
42 if (tmp < 0) tmp = 0; else | |
43 if (tmp > 103) tmp = 103; | |
44 return jmpXMAmigaPeriodTab[tmp]; | |
45 } | |
46 | |
47 | |
48 static int jmpGetPeriodFromNote(JSSPlayer *mp, int note, int finetune) | |
49 { | |
50 int res; | |
51 | |
52 if (JMPGETMODFLAGS(mp, jmdfAmigaPeriods)) | |
53 { | |
54 int mfinetune = finetune / 16, | |
55 mnote = (note % 12) * 8, | |
56 moctave = note / 12, | |
57 period1, period2; | |
58 | |
59 period1 = jmpNoteToAmigaPeriod(mnote, mfinetune); | |
60 | |
61 if (finetune < 0) | |
62 { | |
63 mfinetune--; | |
64 finetune = -finetune; | |
65 } else | |
66 mfinetune++; | |
67 | |
68 period2 = jmpNoteToAmigaPeriod(mnote, mfinetune); | |
69 | |
70 mfinetune = finetune & 15; | |
71 period1 *= (16 - mfinetune); | |
72 period2 *= mfinetune; | |
73 | |
74 res = ((period1 + period2) * 2) >> moctave; | |
75 | |
76 //fprintf(stderr, "jmpGetAmigaPeriod(%d, %d) = %d\n", note, finetune, res); | |
77 } | |
78 else | |
79 { | |
80 //fprintf(stderr, "jmpGetLinearPeriod(%d, %d) = %d\n", note, finetune, res); | |
81 //res = ((120 - note) << 6) - (finetune / 2); | |
82 res = 7680 - (note * 64) - (finetune / 2); | |
83 if (res < 1) res = 1; | |
84 } | |
85 | |
86 return res; | |
87 } | |
88 | |
89 | |
90 static void jmpCSetPitch(JSSPlayer *mp, int channel, int value) | |
91 { | |
92 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
93 assert(mp->device != NULL); |
0 | 94 |
95 if (value > 0) | |
96 { | |
97 if (JMPGETMODFLAGS(mp, jmdfAmigaPeriods)) | |
98 { | |
99 // Frequency = 8363*1712 / Period | |
100 //fprintf(stderr, "jmpCSetPitch::AMIGA(%d, %d)\n", channel, value); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
101 jvmSetFreq(mp->device, channel, 14317456.0f / (double) value); |
0 | 102 } |
103 else | |
104 { | |
105 // Frequency = Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4)) | |
106 //fprintf(stderr, "jmpCSetPitch::Linear(%d, %d)\n", channel, value); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
107 jvmSetFreq(mp->device, channel, |
0 | 108 8363.0f * pow(2.0f, (4608.0f - (double) value) / 768.0f)); |
109 } | |
110 } | |
111 } | |
112 | |
113 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
114 static void jmpCSetVolume(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int volume) |
0 | 115 { |
116 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
117 assert(mp->device != NULL); |
0 | 118 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
119 if (volume < mpMinVol) volume = mpMinVol; else |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
120 if (volume > mpMaxVol) volume = mpMaxVol; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
121 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
122 //fprintf(stderr, "chn %d: vol=%d, fad=%d, env=%d\n", channel, volume, chn->iCFadeOutVol, chn->iCVolEnv); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
123 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
124 jvmSetVolume(mp->device, channel, |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
125 (chn->iCFadeOutVol * chn->iCVolEnv * volume) / (16 * 65536)); |
0 | 126 } |
127 | |
128 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
129 static void jmpCSetPanning(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int panning) |
0 | 130 { |
131 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
132 assert(mp->device != NULL); |
0 | 133 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
134 jvmSetPan(mp->device, channel, |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
135 panning + (((chn->iCPanEnv - 32) * (128 - abs(panning - 128))) / 32)); |
0 | 136 } |
137 | |
138 | |
139 static void jmpCSetPosition(JSSPlayer * mp, int channel, int value) | |
140 { | |
141 assert(mp != NULL); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
142 assert(mp->device != NULL); |
0 | 143 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
144 jvmSetPos(mp->device, channel, value); |
0 | 145 } |
146 | |
147 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
148 static int jmpFindEnvPoint(JSSEnvelope * env, const int pos) |
0 | 149 { |
150 int i; | |
151 | |
152 for (i = 0; i < env->npoints - 1; i++) | |
153 { | |
154 if (env->points[i].frame <= pos && | |
155 env->points[i + 1].frame >= pos) | |
156 return i; | |
157 } | |
158 | |
159 return -1; | |
160 } | |
161 | |
162 | |
163 static void jmpExecEnvelope(JSSEnvelope * env, BOOL keyOff, int * frames, BOOL * doExec, int * result) | |
164 { | |
165 int currPoint, delta; | |
166 JSSEnvelopePoint *ipf1, *ipf2; | |
167 | |
168 // OK, find the current point based on frame | |
169 currPoint = jmpFindEnvPoint(env, *frames); | |
170 | |
171 // Check if the envelope has ended | |
172 if (currPoint < 0 && (env->flags & jenvfLooped) == 0) | |
173 { | |
174 *doExec = FALSE; | |
175 return; | |
176 } | |
177 | |
178 // Do the envelope looping here, if needed | |
179 if ((env->flags & jenvfLooped) && *frames >= env->points[env->loopE].frame) | |
180 { | |
181 currPoint = env->loopS; | |
182 *frames = env->points[currPoint].frame; | |
183 } | |
184 | |
185 // If the current point is OK, then process the envelope | |
186 if (currPoint >= 0) | |
187 { | |
188 // Linearly interpolate the value for given frame | |
189 ipf1 = &env->points[currPoint]; | |
190 ipf2 = &env->points[currPoint + 1]; | |
191 | |
192 delta = (ipf2->frame - ipf1->frame); | |
193 if (delta > 0) | |
194 *result = ipf1->value + ((ipf2->value - ipf1->value) * (*frames - ipf1->frame)) / delta; | |
195 else | |
196 *result = ipf1->value; | |
197 } | |
198 | |
199 // The frame counter IS processed even if the envelope is not! | |
200 if ((env->flags & jenvfSustain) && currPoint == env->sustain && | |
201 env->points[currPoint].frame == env->points[env->sustain].frame) { | |
202 if (keyOff) (*frames)++; | |
203 } else | |
204 (*frames)++; | |
205 } | |
206 | |
207 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
208 static void jmpProcessExtInstrument(JSSPlayer * mp, JSSPlayerChannel *chn, int channel) |
0 | 209 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
210 JSSExtInstrument *inst = chn->iCExtInstrument; |
0 | 211 |
212 // Get the instrument for envelope data | |
213 if (!inst) return; | |
214 | |
215 // Process the autovibrato | |
216 /* | |
217 FIXME fix me FIX me!!! todo. | |
218 */ | |
219 | |
220 // Process the volume envelope | |
221 if (inst->volumeEnv.flags & jenvfUsed) | |
222 { | |
223 // Process the instrument volume fadeout | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
224 if (chn->iCKeyOff && chn->iCFadeOutVol > 0 && inst->fadeOut > 0) |
0 | 225 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
226 int tmp = chn->iCFadeOutVol - inst->fadeOut; |
0 | 227 if (tmp < 0) tmp = 0; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
228 chn->iCFadeOutVol = tmp; |
0 | 229 |
230 JMPSETNDFLAGS(cdfNewVolume); | |
231 } | |
232 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
233 if (chn->iCVolEnv_Exec) |
0 | 234 { |
235 // Execute the volume envelope | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
236 jmpExecEnvelope(&(inst->volumeEnv), |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
237 chn->iCKeyOff, |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
238 &(chn->iCVolEnv_Frames), &(chn->iCVolEnv_Exec), |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
239 &(chn->iCVolEnv)); |
0 | 240 |
241 JMPSETNDFLAGS(cdfNewVolume); | |
242 } | |
243 } | |
244 else | |
245 { | |
246 // If the envelope is not used, set max volume | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
247 if (chn->iCVolEnv != mpMaxVol) |
0 | 248 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
249 chn->iCVolEnv = mpMaxVol; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
250 chn->iCFadeOutVol = mpMaxFadeoutVol; |
0 | 251 JMPSETNDFLAGS(cdfNewVolume); |
252 } | |
253 } | |
254 | |
255 // Process the panning envelope | |
256 if (inst->panningEnv.flags & jenvfUsed) | |
257 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
258 if (chn->iCPanEnv_Exec) |
0 | 259 { |
260 // Execute the panning envelope | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
261 jmpExecEnvelope(&(inst->panningEnv), chn->iCKeyOff, |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
262 &(chn->iCPanEnv_Frames), &(chn->iCPanEnv_Exec), |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
263 &(chn->iCPanEnv)); |
0 | 264 |
265 JMPSETNDFLAGS(cdfNewPanPos); | |
266 } | |
267 } | |
268 else | |
269 { | |
270 // If the envelope is not used, set center panning | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
271 if (chn->iCPanEnv != mpPanCenter) |
0 | 272 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
273 chn->iCPanEnv = mpPanCenter; |
0 | 274 JMPSETNDFLAGS(cdfNewPanPos); |
275 } | |
276 } | |
277 } | |
278 | |
279 | |
280 /* | |
281 * The player | |
282 */ | |
283 JSSPlayer *jmpInit(JSSMixer *pDevice) | |
284 { | |
285 JSSPlayer *mp; | |
286 | |
287 // Initialize global tables | |
288 if (jmpSineTable == NULL) | |
289 { | |
290 int i; | |
291 if ((jmpSineTable = dmMalloc(jmpNSineTable * sizeof(int))) == NULL) | |
292 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for sinus table.\n"); | |
293 | |
294 for (i = 0; i < 256; i++) | |
295 { | |
296 float f = ((float) i * M_PI * 2.0f) / 256.0f; | |
297 jmpSineTable[i] = (int) (sin(f) * 2048.0f); | |
298 } | |
299 } | |
300 | |
301 // Allocate a player structure | |
302 mp = dmMalloc0(sizeof(JSSPlayer)); | |
303 if (!mp) | |
304 JSSERROR(DMERR_MALLOC, NULL, "Could not allocate memory for player structure.\n"); | |
305 | |
306 // Set variables | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
307 mp->device = pDevice; |
0 | 308 #ifdef JSS_SUP_THREADS |
309 mp->mutex = dmCreateMutex(); | |
310 #endif | |
311 | |
312 return mp; | |
313 } | |
314 | |
315 | |
316 int jmpClose(JSSPlayer * mp) | |
317 { | |
318 if (mp == NULL) | |
319 return DMERR_NULLPTR; | |
320 | |
321 // Stop player | |
322 jmpStop(mp); | |
323 | |
324 // Deallocate resources | |
325 #ifdef JSS_SUP_THREADS | |
326 dmDestroyMutex(mp->mutex); | |
327 #endif | |
328 | |
329 // Clear structure | |
330 memset(mp, 0, sizeof(JSSPlayer)); | |
331 dmFree(mp); | |
332 | |
333 return DMERR_OK; | |
334 } | |
335 | |
336 | |
337 /* Reset the envelopes for given channel. | |
338 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
339 static void jmpResetEnvelopes(JSSPlayerChannel *chn) |
0 | 340 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
341 chn->iCPanEnv_Frames = chn->iCVolEnv_Frames = 0; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
342 chn->iCPanEnv_Exec = chn->iCVolEnv_Exec = TRUE; |
0 | 343 } |
344 | |
345 | |
346 /* Clear module player structure | |
347 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
348 void jmpClearChannel(JSSPlayerChannel *chn) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
349 { |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
350 memset(chn, 0, sizeof(JSSPlayerChannel)); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
351 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
352 chn->iCNote = jsetNotSet; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
353 chn->iCInstrumentN = jsetNotSet; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
354 chn->iCExtInstrumentN = jsetNotSet; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
355 chn->iCPanning = mpPanCenter; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
356 chn->iCPanEnv = mpPanCenter; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
357 } |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
358 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
359 |
0 | 360 void jmpClearPlayer(JSSPlayer * mp) |
361 { | |
362 int i; | |
363 assert(mp != NULL); | |
364 JSS_LOCK(mp); | |
365 | |
366 // Initialize general variables | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
367 mp->patternDelay = 0; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
368 mp->newRowSet = FALSE; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
369 mp->newOrderSet = FALSE; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
370 mp->tick = jsetNotSet; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
371 mp->row = 0; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
372 mp->lastPatLoopRow = 0; |
0 | 373 |
374 // Initialize channel data | |
375 for (i = 0; i < jsetNChannels; i++) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
376 jmpClearChannel(&mp->channels[i]); |
0 | 377 |
378 JSS_UNLOCK(mp); | |
379 } | |
380 | |
381 | |
382 /* Set module | |
383 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
384 void jmpSetModule(JSSPlayer * mp, JSSModule * module) |
0 | 385 { |
386 assert(mp != NULL); | |
387 JSS_LOCK(mp); | |
388 | |
389 jmpStop(mp); | |
390 jmpClearPlayer(mp); | |
391 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
392 mp->module = module; |
0 | 393 |
394 JSS_UNLOCK(mp); | |
395 } | |
396 | |
397 | |
398 /* Stop playing | |
399 */ | |
400 void jmpStop(JSSPlayer * mp) | |
401 { | |
402 assert(mp != NULL); | |
403 JSS_LOCK(mp); | |
404 | |
405 if (mp->isPlaying) | |
406 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
407 jvmRemoveCallback(mp->device); |
0 | 408 mp->isPlaying = FALSE; |
409 } | |
410 | |
411 JSS_UNLOCK(mp); | |
412 } | |
413 | |
414 | |
415 /* Resume playing | |
416 */ | |
417 void jmpResume(JSSPlayer * mp) | |
418 { | |
419 assert(mp != NULL); | |
420 JSS_LOCK(mp); | |
421 | |
422 if (!mp->isPlaying) | |
423 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
424 int result = jvmSetCallback(mp->device, jmpExec, (void *) mp); |
0 | 425 if (result != DMERR_OK) |
426 JSSERROR(result,, "Could not initialize callback for player.\n"); | |
427 | |
428 mp->isPlaying = TRUE; | |
429 } | |
430 | |
431 JSS_UNLOCK(mp); | |
432 } | |
433 | |
434 | |
435 /* Sets new order using given value as reference. | |
436 * Jumps over skip-points and invalid values, loops | |
437 * to first order if enabled. | |
438 */ | |
439 static void jmpSetNewOrder(JSSPlayer * mp, int order) | |
440 { | |
441 BOOL orderOK; | |
442 int pattern; | |
443 | |
444 pattern = jsetOrderEnd; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
445 mp->order = jsetNotSet; |
0 | 446 orderOK = FALSE; |
447 | |
448 while (!orderOK) | |
449 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
450 if (order < 0 || order >= mp->module->norders) |
0 | 451 { |
452 jmpStop(mp); | |
453 orderOK = TRUE; | |
454 } | |
455 else | |
456 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
457 pattern = mp->module->orderList[order]; |
0 | 458 if (pattern == jsetOrderSkip) |
459 { | |
460 order++; | |
461 } | |
462 else | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
463 if (pattern >= mp->module->npatterns || pattern == jsetOrderEnd) |
0 | 464 { |
465 jmpStop(mp); | |
466 orderOK = TRUE; | |
467 } | |
468 else | |
469 { | |
470 // All OK | |
471 orderOK = TRUE; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
472 mp->pattern = mp->module->patterns[pattern]; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
473 mp->npattern = pattern; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
474 mp->order = order; |
0 | 475 } |
476 } | |
477 } | |
478 } | |
479 | |
480 | |
481 /* Set new tempo-value of the player. | |
482 */ | |
483 void jmpSetTempo(JSSPlayer * mp, int tempo) | |
484 { | |
485 assert(mp != NULL); | |
486 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
487 assert(mp->device != NULL); |
0 | 488 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
489 mp->tempo = tempo; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
490 jvmSetCallbackFreq(mp->device, (tempo * 2) / 5); |
0 | 491 JSS_UNLOCK(mp); |
492 } | |
493 | |
494 | |
495 void jmpClearChannels(JSSPlayer * mp) | |
496 { | |
497 int i; | |
498 assert(mp != NULL); | |
499 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
500 assert(mp->device != NULL); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
501 assert(mp->module != NULL); |
0 | 502 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
503 for (i = 0; i < mp->module->nchannels; i++) |
0 | 504 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
505 jvmStop(mp->device, i); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
506 jvmClear(mp->device, i); |
0 | 507 } |
508 | |
509 JSS_UNLOCK(mp); | |
510 } | |
511 | |
512 | |
513 /* Starts playing module from a given ORDER. | |
514 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
515 int jmpPlayOrder(JSSPlayer * mp, int order) |
0 | 516 { |
517 int result; | |
518 assert(mp != NULL); | |
519 | |
520 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
521 assert(mp->module != NULL); |
0 | 522 |
523 // Stop if already playing | |
524 jmpStop(mp); | |
525 jmpClearChannels(mp); | |
526 | |
527 // Check starting order | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
528 if (order < 0 || order >= mp->module->norders) |
0 | 529 { |
530 JSS_UNLOCK(mp); | |
531 JSSERROR(DMERR_INVALID_ARGS, DMERR_INVALID_ARGS, "Invalid playing startorder given.\n"); | |
532 } | |
533 | |
534 // Initialize playing | |
535 jmpClearPlayer(mp); | |
536 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
537 jmpSetNewOrder(mp, order); |
0 | 538 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
539 if (mp->order == jsetNotSet) |
0 | 540 { |
541 JSS_UNLOCK(mp); | |
542 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
543 "Could not start playing from given order #%i\n", order); |
0 | 544 } |
545 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
546 mp->speed = mp->module->defSpeed; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
547 jmpSetTempo(mp, mp->module->defTempo); |
0 | 548 |
549 // Set callback | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
550 result = jvmSetCallback(mp->device, jmpExec, (void *) mp); |
0 | 551 if (result != DMERR_OK) |
552 { | |
553 JSS_UNLOCK(mp); | |
554 JSSERROR(result, result, "Could not initialize callback for player.\n"); | |
555 } | |
556 | |
557 mp->isPlaying = TRUE; | |
558 | |
559 JSS_UNLOCK(mp); | |
560 return 0; | |
561 } | |
562 | |
563 | |
564 /* Play given pattern | |
565 */ | |
566 int jmpPlayPattern(JSSPlayer * mp, int pattern) | |
567 { | |
568 int result; | |
569 assert(mp != NULL); | |
570 JSS_LOCK(mp); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
571 assert(mp->module != NULL); |
0 | 572 |
573 // Stop if already playing | |
574 jmpStop(mp); | |
575 jmpClearChannels(mp); | |
576 | |
577 // Initialize playing | |
578 jmpClearPlayer(mp); | |
579 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
580 mp->npattern = pattern; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
581 mp->speed = mp->module->defSpeed; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
582 jmpSetTempo(mp, mp->module->defTempo); |
0 | 583 |
584 // Set callback | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
585 result = jvmSetCallback(mp->device, jmpExec, (void *) mp); |
0 | 586 if (result != DMERR_OK) |
587 { | |
588 JSS_UNLOCK(mp); | |
589 JSSERROR(result, result, "Could not initialize callback for player.\n"); | |
590 } | |
591 | |
592 mp->isPlaying = TRUE; | |
593 | |
594 JSS_UNLOCK(mp); | |
595 return 0; | |
596 } | |
597 | |
598 | |
599 /* Set volume for given module channel. | |
600 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
601 static void jmpSetVolume(JSSPlayerChannel * chn, int channel, int volume) |
0 | 602 { |
603 // Check values | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
604 if (volume < mpMinVol) volume = mpMinVol; else |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
605 if (volume > mpMaxVol) volume = mpMaxVol; |
0 | 606 |
607 // Set the volume | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
608 chn->iCVolume = volume; |
0 | 609 JMPSETNDFLAGS(cdfNewVolume); |
610 } | |
611 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
612 #define jmpChangeVolume(Q, Z, X) jmpSetVolume(Q, Z, chn->iCVolume + (X)) |
0 | 613 |
614 | |
615 /* Change the pitch of given channel by ADelta. | |
616 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
617 static void jmpChangePitch(JSSPlayerChannel *chn, int channel, int delta) |
0 | 618 { |
619 int value; | |
620 | |
621 // Calculate new pitch and check it | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
622 value = chn->iCPitch + delta; |
0 | 623 if (value < 0) |
624 value = 0; | |
625 | |
626 // Set the new pitch | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
627 chn->iCPitch = value; |
0 | 628 JMPSETNDFLAGS(cdfNewPitch); |
629 } | |
630 | |
631 | |
632 /* Do a note portamento (pitch slide) effect for given module channel. | |
633 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
634 static void jmpDoPortamento(JSSPlayerChannel * chn, int channel) |
0 | 635 { |
636 // Check for zero parameter | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
637 if (chn->iLastPortaToNoteParam == 0) |
0 | 638 { |
639 JMPSETNDFLAGS(cdfNewPitch); | |
640 return; | |
641 } | |
642 | |
643 /* Slide the pitch of channel to the destination value | |
644 * with speed of iLastPortaToNoteParam[] * 4 and stop when it equals. | |
645 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
646 if (chn->iCPitch != chn->iLastPortaToNotePitch) |
0 | 647 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
648 if (chn->iCPitch < chn->iLastPortaToNotePitch) |
0 | 649 { |
650 // Increase pitch UP | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
651 jmpChangePitch(chn, channel, chn->iLastPortaToNoteParam * 4); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
652 if (chn->iCPitch > chn->iLastPortaToNotePitch) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
653 chn->iCPitch = chn->iLastPortaToNotePitch; |
0 | 654 } |
655 else | |
656 { | |
657 // Decrease pitch DOWN | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
658 jmpChangePitch(chn, channel, -(chn->iLastPortaToNoteParam * 4)); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
659 if (chn->iCPitch < chn->iLastPortaToNotePitch) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
660 chn->iCPitch = chn->iLastPortaToNotePitch; |
0 | 661 } |
662 } | |
663 } | |
664 | |
665 | |
666 /* Do a tremolo effect for given module channel. | |
667 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
668 static void jmpDoTremolo(JSSPlayer * mp, JSSPlayerChannel *chn, int channel) |
0 | 669 { |
670 int delta, pos, depth; | |
671 | |
672 // Check settings | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
673 if (chn->iTremoloDepth == 0 || chn->iTremoloSpeed == 0) |
0 | 674 return; |
675 | |
676 // Get position of tremolo waveform | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
677 pos = chn->iTremoloPos & 255; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
678 depth = chn->iTremoloDepth; |
0 | 679 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
680 switch (chn->iTremoloWC & 3) |
0 | 681 { |
682 case 0: // Sine-wave | |
683 delta = (jmpSineTable[pos] * depth) / 2048; | |
684 break; | |
685 | |
686 case 1: // Ramp down | |
687 delta = ((pos - 128) * depth) / 128; | |
688 break; | |
689 | |
690 case 2: // Square | |
691 delta = (((pos & 128) - 64) * depth) / 64; | |
692 break; | |
693 | |
694 default: | |
695 return; | |
696 } | |
697 | |
698 // Set the new volume | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
699 jmpCSetVolume(mp, chn, channel, chn->iCVolume + delta); |
0 | 700 |
701 // Advance tremolo waveform position | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
702 chn->iTremoloPos += chn->iTremoloSpeed; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
703 if (chn->iTremoloPos > 255) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
704 chn->iTremoloPos = 0; |
0 | 705 } |
706 | |
707 | |
708 /* Do a vibrato effect for given module channel. | |
709 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
710 static void jmpDoVibrato(JSSPlayer * mp, JSSPlayerChannel *chn, int channel) |
0 | 711 { |
712 int delta, pos, depth; | |
713 | |
714 // Check settings | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
715 if (chn->iVibratoDepth == 0 || chn->iVibratoSpeed == 0) |
0 | 716 return; |
717 | |
718 // Get position of vibrato waveform | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
719 pos = chn->iVibratoPos & 255; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
720 depth = chn->iVibratoDepth; |
0 | 721 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
722 switch (chn->iVibratoWC & 3) |
0 | 723 { |
724 case 0: // Sine-wave | |
725 delta = (jmpSineTable[pos] * depth) / 2048; | |
726 break; | |
727 | |
728 case 1: // Ramp down | |
729 delta = ((pos - 128) * depth) / 16; | |
730 break; | |
731 | |
732 case 2: // Square | |
733 delta = (((pos & 128) - 64) * depth) / 8; | |
734 break; | |
735 | |
736 default: | |
737 return; | |
738 } | |
739 | |
740 // Set the new frequency | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
741 jmpCSetPitch(mp, channel, chn->iCPitch + delta); |
0 | 742 |
743 // Advance vibrato waveform position | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
744 chn->iVibratoPos += chn->iVibratoSpeed; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
745 if (chn->iVibratoPos > 255) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
746 chn->iVibratoPos = 0; |
0 | 747 } |
748 | |
749 | |
750 /* Do a volume slide effect for given module channel. | |
751 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
752 static void jmpDoVolumeSlide(JSSPlayerChannel * chn, int channel, int param) |
0 | 753 { |
754 int paramX, paramY; | |
755 | |
756 JMPMAKEPARAM(param, paramX, paramY) | |
757 | |
758 if (paramY == 0) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
759 jmpChangeVolume(chn, channel, paramX); |
0 | 760 if (paramX == 0) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
761 jmpChangeVolume(chn, channel, -paramY); |
0 | 762 } |
763 | |
764 | |
765 /* Execute a pattern loop effect/command for given module channel. | |
766 * | |
767 * This routine works for most of the supported formats, as they | |
768 * use the 'standard' implementation ascending from MOD. However, | |
769 * here is included also a slightly kludgy implementation of the | |
770 * FT2 patloop bug. | |
771 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
772 static void jmpDoPatternLoop(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int paramY) |
0 | 773 { |
774 // Check what we need to do | |
775 if (paramY > 0) | |
776 { | |
777 // SBx/E6x loops 'x' times | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
778 if (chn->iPatLoopCount == 1) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
779 chn->iPatLoopCount = 0; |
0 | 780 else |
781 { | |
782 // Check if we need to set the count | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
783 if (chn->iPatLoopCount == 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
784 chn->iPatLoopCount = (paramY + 1); |
0 | 785 |
786 // Loop to specified row | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
787 chn->iPatLoopCount--; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
788 mp->newRow = chn->iPatLoopRow; |
0 | 789 mp->newRowSet = TRUE; |
790 } | |
791 } | |
792 else | |
793 { | |
794 // SB0/E60 sets the loop start point | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
795 chn->iPatLoopRow = mp->row; |
0 | 796 |
797 // This is here because of the infamous FT2 patloop bug | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
798 mp->lastPatLoopRow = mp->row; |
0 | 799 } |
800 } | |
801 | |
802 | |
803 /* Do arpeggio effect | |
804 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
805 static void jmpDoArpeggio(JSSPlayer * mp, JSSPlayerChannel *chn, int channel, int paramY, int paramX) |
0 | 806 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
807 JSSInstrument *tempInst = chn->iCInstrument; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
808 |
0 | 809 if (tempInst) |
810 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
811 int tmp = chn->iCNote; |
0 | 812 if (tmp == jsetNotSet || tmp == jsetNoteOff) return; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
813 switch (mp->tick & 3) |
0 | 814 { |
815 case 1: | |
816 tmp += paramX; | |
817 break; | |
818 case 2: | |
819 tmp += paramY; | |
820 break; | |
821 } | |
822 jmpCSetPitch(mp, channel, jmpGetPeriodFromNote(mp, tmp + tempInst->ERelNote, tempInst->EFineTune)); | |
823 } | |
824 } | |
825 | |
826 | |
827 /* | |
828 * Process pattern effects | |
829 */ | |
830 static void jmpProcessRowEffect(JSSPlayer * mp, int channel, JSSNote * currNote) | |
831 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
832 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 833 int param, paramX, paramY; |
834 char effect; | |
835 | |
836 param = currNote->param; | |
837 JMPMAKEPARAM(param, paramX, paramY); | |
838 JMPGETEFFECT(effect, currNote->effect); | |
839 | |
840 switch (effect) | |
841 { | |
842 case '0': // 0xy = Arpeggio | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
843 jmpDoArpeggio(mp, chn, channel, paramX, paramY); |
0 | 844 break; |
845 | |
846 case 'W': // Used widely in demo-music as MIDAS Sound System sync-command | |
847 case 'Q': // SoundTracker/OpenCP: Qxx = Set LP filter resonance | |
848 case 'Z': // SoundTracker/OpenCP: Zxx = Set LP filter cutoff freq | |
849 break; | |
850 | |
851 case '1': | |
852 case '2': // 1xy = Portamento Up, 2xy = Portamento Down : IMPL.VERIFIED | |
853 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
854 chn->iLastPortaParam = param; |
0 | 855 break; |
856 | |
857 case '3': // 3xy = Porta To Note | |
858 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
859 chn->iLastPortaToNoteParam = param; |
0 | 860 |
861 if (currNote->note != jsetNotSet && currNote->note != jsetNoteOff) { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
862 chn->iLastPortaToNotePitch = chn->iCPitch; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
863 chn->iCPitch = chn->iCOldPitch; |
0 | 864 JMPUNSETNDFLAGS(cdfNewPitch | cdfNewInstr | cdfNewPanPos); |
865 } | |
866 break; | |
867 | |
868 case '4': // 4xy = Vibrato : IMPL.VERIFIED | |
869 if (paramX) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
870 chn->iVibratoSpeed = paramX; |
0 | 871 |
872 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
873 chn->iVibratoDepth = paramY; |
0 | 874 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
875 if ((chn->iVibratoWC & 4) == 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
876 chn->iVibratoPos = 0; |
0 | 877 break; |
878 | |
879 case '5': // 5xy = Portamento + Volume Slide | |
880 case '6': // 6xy = Vibrato + Volume slide | |
881 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
882 chn->iLastVolSlideParam = param; |
0 | 883 break; |
884 | |
885 case '7': // 7xy = Tremolo | |
886 if (paramX) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
887 chn->iTremoloSpeed = paramX; |
0 | 888 |
889 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
890 chn->iTremoloDepth = paramY; |
0 | 891 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
892 if ((chn->iTremoloWC & 4) == 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
893 chn->iTremoloPos = 0; |
0 | 894 break; |
895 | |
896 case '8': // 8xx = Set Panning | |
897 JMPDEBUG("Set Panning used, UNIMPLEMENTED"); | |
898 break; | |
899 | |
900 case '9': // 9xx = Set Sample Offset : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
901 if (chn->iCNewDataFlags & cdfNewPitch) |
30 | 902 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
903 chn->iCPosition = param * 0x100; |
0 | 904 JMPSETNDFLAGS(cdfNewPos); |
905 } | |
906 break; | |
907 | |
908 case 'A': // Axy = Volume Slide : IMPL.VERIFIED | |
909 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
910 chn->iLastVolSlideParam = param; |
0 | 911 break; |
912 | |
913 case 'B': // Bxx = Pattern Jump : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
914 mp->newOrder = param; |
0 | 915 mp->newOrderSet = TRUE; |
916 mp->jumpFlag = TRUE; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
917 mp->lastPatLoopRow = 0; |
0 | 918 break; |
919 | |
920 case 'C': // Cxx = Set Volume : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
921 jmpSetVolume(chn, channel, param); |
0 | 922 break; |
923 | |
924 case 'D': // Dxx = Pattern Break : IMPL.VERIFIED | |
925 // Compute the new row | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
926 mp->newRow = (paramX * 10) + paramY; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
927 if (mp->newRow >= mp->pattern->nrows) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
928 mp->newRow = 0; |
0 | 929 |
930 mp->newRowSet = TRUE; | |
931 | |
932 // Now we do some tricky tests | |
933 if (!mp->breakFlag && !mp->jumpFlag) { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
934 mp->newOrder = mp->order + 1; |
0 | 935 mp->newOrderSet = TRUE; |
936 } | |
937 | |
938 mp->breakFlag = TRUE; | |
939 break; | |
940 | |
941 case 'E': // Exy = Special Effects | |
942 switch (paramX) { | |
943 case 0x00: // E0x - Set filter (NOT SUPPORTED) | |
944 JMPDEBUG("Set Filter used, UNSUPPORTED"); | |
945 break; | |
946 | |
947 case 0x01: // E1x - Fine Portamento Up | |
948 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
949 chn->iCLastFinePortamentoUpParam = paramY; |
0 | 950 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
951 jmpChangePitch(chn, channel, -(chn->iCLastFinePortamentoUpParam * 4)); |
0 | 952 break; |
953 | |
954 case 0x02: // E2x - Fine Portamento Down | |
955 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
956 chn->iCLastFinePortamentoDownParam = paramY; |
0 | 957 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
958 jmpChangePitch(chn, channel, (chn->iCLastFinePortamentoDownParam * 4)); |
0 | 959 break; |
960 | |
961 case 0x03: // E3x - Glissando Control (NOT SUPPORTED) | |
962 break; | |
963 | |
964 case 0x04: // E4x - Set Vibrato waveform | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
965 chn->iVibratoWC = paramY; |
0 | 966 break; |
967 | |
968 case 0x05: // E5x - Set Finetune | |
969 JMPDEBUG("Set Finetune used, UNIMPLEMENTED"); | |
970 break; | |
971 | |
972 case 0x06: // E6x - Set Pattern Loop | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
973 jmpDoPatternLoop(mp, chn, channel, paramY); |
0 | 974 break; |
975 | |
976 case 0x07: // E7x - Set Tremolo waveform | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
977 chn->iTremoloWC = paramY; |
0 | 978 break; |
979 | |
980 case 0x08: // E8x - Set Pan Position | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
981 chn->iCPanning = (paramY * 16); |
0 | 982 JMPSETNDFLAGS(cdfNewPanPos); |
983 break; | |
984 | |
985 case 0x09: // E9x - Retrig note | |
986 JMPDEBUG("Retrig Note used, UNIMPLEMENTED"); | |
987 break; | |
988 | |
989 case 0x0a: // EAx - Fine Volumeslide Up | |
990 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
991 chn->iCLastFineVolumeslideUpParam = paramY; |
0 | 992 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
993 jmpChangeVolume(chn, channel, chn->iCLastFineVolumeslideUpParam); |
0 | 994 break; |
995 | |
996 case 0x0b: // EBx - Fine Volumeslide Down | |
997 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
998 chn->iCLastFineVolumeslideDownParam = paramY; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
999 jmpChangeVolume(chn, channel, -(chn->iCLastFineVolumeslideDownParam)); |
0 | 1000 break; |
1001 | |
1002 case 0x0c: // ECx - Set Note Cut (NOT PROCESSED IN TICK0) | |
1003 break; | |
1004 | |
1005 case 0x0d: // EDx - Set Note Delay : IMPL.VERIFIED | |
1006 if (paramY > 0) | |
1007 { | |
1008 // Save the ND-flags, then clear | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1009 chn->iSaveNDFlags = chn->iCNewDataFlags; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1010 chn->iCNewDataFlags = 0; |
0 | 1011 // TODO .. does this only affect NOTE or also instrument? |
1012 } | |
1013 break; | |
1014 | |
1015 case 0x0e: // EEx - Set Pattern Delay : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1016 mp->patternDelay = paramY; |
0 | 1017 break; |
1018 | |
1019 case 0x0f: // EFx - Invert Loop (NOT SUPPORTED) | |
1020 JMPDEBUG("Invert Loop used, UNSUPPORTED"); | |
1021 break; | |
1022 | |
1023 default: | |
1024 JMPDEBUG("Unsupported special command used"); | |
1025 } | |
1026 break; | |
1027 | |
1028 case 'F': // Fxy = Set Speed / Tempo : IMPL.VERIFIED | |
1029 if (param > 0) | |
1030 { | |
1031 if (param < 0x20) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1032 mp->speed = param; |
0 | 1033 else |
1034 jmpSetTempo(mp, param); | |
1035 } | |
1036 break; | |
1037 | |
1038 case 'G': // Gxx = Global Volume | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1039 mp->globalVol = param; |
0 | 1040 JMPSETNDFLAGS(cdfNewGlobalVol); |
1041 break; | |
1042 | |
1043 | |
1044 case 'H': // Hxx = Global Volume Slide | |
1045 JMPDEBUG("Global Volume Slide used, UNIMPLEMENTED"); | |
1046 break; | |
1047 | |
1048 case 'K': // Kxx = Key-off (Same as key-off note) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1049 chn->iCKeyOff = TRUE; |
0 | 1050 break; |
1051 | |
1052 case 'L': // Lxx = Set Envelope Position | |
1053 JMPDEBUG("Set Envelope Position used, NOT verified with FT2"); | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1054 chn->iCPanEnv_Frames = param; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1055 chn->iCVolEnv_Frames = param; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1056 chn->iCPanEnv_Exec = TRUE; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1057 chn->iCVolEnv_Exec = TRUE; |
0 | 1058 break; |
1059 | |
1060 case 'R': // Rxy = Multi Retrig note | |
1061 JMPDEBUG("Multi Retrig Note used, UNIMPLEMENTED"); | |
1062 break; | |
1063 | |
1064 case 'T': // Txy = Tremor | |
1065 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1066 chn->iLastTremorParam = param; |
0 | 1067 break; |
1068 | |
1069 case 'X': // Xxy = Extra Fine Portamento | |
1070 switch (paramX) | |
1071 { | |
1072 case 0x01: // X1y - Extra Fine Portamento Up | |
1073 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1074 chn->iCLastExtraFinePortamentoUpParam = paramY; |
0 | 1075 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1076 jmpChangePitch(chn, channel, - chn->iCLastExtraFinePortamentoUpParam); |
0 | 1077 break; |
1078 | |
1079 case 0x02: // X2y - Extra Fine Portamento Down | |
1080 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1081 chn->iCLastExtraFinePortamentoDownParam = paramY; |
0 | 1082 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1083 jmpChangePitch(chn, channel, chn->iCLastExtraFinePortamentoUpParam); |
0 | 1084 break; |
1085 | |
1086 default: | |
1087 JMPDEBUG("Unsupported value in Extra Fine Portamento command!"); | |
1088 break; | |
1089 } | |
1090 break; | |
1091 | |
1092 default: | |
1093 JMPDEBUG("Unsupported effect"); | |
1094 break; | |
1095 } | |
1096 } | |
1097 | |
1098 | |
1099 static void jmpProcessNewRow(JSSPlayer * mp, int channel) | |
1100 { | |
1101 JSSNote *currNote; | |
1102 JSSExtInstrument *extInst = NULL; | |
1103 JSSInstrument *inst = NULL; | |
1104 BOOL newNote = FALSE; | |
1105 int tmp, paramX, paramY; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1106 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1107 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1108 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1109 |
1110 // Check for a new note/keyoff here | |
1111 if (currNote->note == jsetNoteOff) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1112 chn->iCKeyOff = TRUE; |
0 | 1113 else |
1114 if (currNote->note >= 0 && currNote->note <= 96) | |
1115 { | |
1116 // New note was set | |
1117 newNote = TRUE; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1118 chn->iCNote = currNote->note; |
0 | 1119 } |
1120 | |
1121 // Check for new instrument | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1122 if (currNote->instrument != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1123 { |
0 | 1124 /* Envelopes and ext.instrument fadeout are initialized always if |
1125 * new instrument is set, even if the instrument does not exist. | |
1126 */ | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1127 jmpResetEnvelopes(chn); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1128 chn->iCKeyOff = FALSE; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1129 chn->iCFadeOutVol = mpMaxFadeoutVol; |
0 | 1130 |
1131 // We save the instrument number here for later use | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1132 if (currNote->instrument >= 0 && currNote->instrument < mp->module->nextInstruments) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1133 chn->iCExtInstrumentN = currNote->instrument; |
0 | 1134 } |
1135 | |
1136 /* ONLY if newNote was SET NOW and ExtInstrument HAS BEEN set, we can | |
1137 * set new pitches, and other things... | |
1138 */ | |
1139 if (newNote) | |
1140 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1141 if (chn->iCExtInstrumentN != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1142 extInst = mp->module->extInstruments[chn->iCExtInstrumentN]; |
0 | 1143 else |
1144 extInst = NULL; | |
1145 | |
1146 if (extInst) | |
1147 { | |
1148 // Set instrument | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1149 int note = chn->iCNote; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1150 chn->iCExtInstrument = extInst; |
0 | 1151 |
1152 // We set new Instrument ONLY if NEW NOTE has been set | |
1153 if (note != jsetNotSet) | |
1154 { | |
1155 // Get instrument number | |
1156 tmp = extInst->sNumForNotes[note]; | |
1157 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1158 if (tmp >= 0 && tmp < mp->module->ninstruments) { |
0 | 1159 // Set the new instrument |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1160 inst = mp->module->instruments[tmp]; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1161 chn->iCInstrumentN = tmp; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1162 chn->iCInstrument = inst; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1163 chn->iCVolume = inst->volume; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1164 chn->iCPanning = inst->EPanning; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1165 chn->iCPosition = 0; |
0 | 1166 |
1167 // Set NDFlags | |
1168 JMPSETNDFLAGS(cdfNewInstr | cdfNewPos | cdfNewPanPos | cdfNewVolume); | |
1169 } | |
1170 } | |
1171 } | |
1172 } | |
1173 | |
1174 if (inst) | |
1175 { | |
1176 // Save old pitch for later use | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1177 chn->iCOldPitch = chn->iCPitch; |
0 | 1178 |
1179 // Compute new pitch | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1180 tmp = (chn->iCNote + inst->ERelNote); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1181 //fprintf(stderr, "HEH: %d + %d = %d\n", chn->iCNote, inst->ERelNote, tmp); |
0 | 1182 if (tmp < 0) |
1183 tmp = 0; | |
1184 else if (tmp > 119) | |
1185 tmp = 119; | |
1186 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1187 chn->iCPitch = jmpGetPeriodFromNote(mp, tmp, inst->EFineTune); |
0 | 1188 JMPSETNDFLAGS(cdfNewPitch); |
1189 } | |
1190 | |
1191 // Process the volume column | |
1192 JMPMAKEPARAM(currNote->volume, paramX, paramY); | |
1193 | |
1194 switch (paramX) | |
1195 { | |
1196 case 0x00: | |
1197 case 0x01: | |
1198 case 0x02: | |
1199 case 0x03: | |
1200 case 0x04: | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1201 jmpSetVolume(chn, channel, currNote->volume); |
0 | 1202 break; |
1203 | |
1204 case 0x07: // Dx = Fine Volumeslide Down : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1205 jmpChangeVolume(chn, channel, -paramY); |
0 | 1206 break; |
1207 | |
1208 case 0x08: // Ux = Fine Volumeslide Up : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1209 jmpChangeVolume(chn, channel, paramY); |
0 | 1210 break; |
1211 | |
1212 case 0x09: // Sx = Set vibrato speed : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1213 chn->iVibratoSpeed = paramY; |
0 | 1214 break; |
1215 | |
1216 case 0x0a: // Vx = Vibrato : IMPL.VERIFIED | |
1217 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1218 chn->iVibratoDepth = paramY; |
0 | 1219 break; |
1220 | |
1221 case 0x0e: // Mx = Porta To Note : IMPL.VERIFIED | |
1222 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1223 chn->iLastPortaToNoteParam = paramY; |
0 | 1224 |
1225 if (currNote->note != jsetNotSet && currNote->note != jsetNoteOff) { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1226 chn->iLastPortaToNotePitch = chn->iCPitch; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1227 chn->iCPitch = chn->iCOldPitch; |
0 | 1228 JMPUNSETNDFLAGS(cdfNewPitch | cdfNewInstr | cdfNewPanPos); |
1229 } | |
1230 break; | |
1231 } | |
1232 | |
1233 // ...And finally process the Normal effects | |
1234 if (currNote->effect != jsetNotSet) | |
1235 jmpProcessRowEffect(mp, channel, currNote); | |
1236 } | |
1237 | |
1238 | |
1239 static void jmpProcessEffects(JSSPlayer * mp, int channel) | |
1240 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1241 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1242 JSSNote *currNote; |
1243 int param, paramX, paramY, tmp; | |
1244 char effect; | |
1245 | |
1246 // Process the volume column effects | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1247 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1248 JMPMAKEPARAM(currNote->volume, paramX, paramY); |
1249 | |
1250 switch (paramX) | |
1251 { | |
1252 case 0x05: // -x = Volumeslide Down : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1253 jmpChangeVolume(chn, channel, -paramY); |
0 | 1254 break; |
1255 | |
1256 case 0x06: // +x = Volumeslide Down : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1257 jmpChangeVolume(chn, channel, paramY); |
0 | 1258 break; |
1259 | |
1260 case 0x0a: // Vx = Vibrato : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1261 jmpDoVibrato(mp, chn, channel); |
0 | 1262 break; |
1263 | |
1264 case 0x0e: // Mx = Porta To Note : IMPL.VERIFIED | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1265 jmpDoPortamento(chn, channel); |
0 | 1266 break; |
1267 } | |
1268 | |
1269 // ...And finally process the Normal effects | |
1270 if (currNote->effect == jsetNotSet) | |
1271 return; | |
1272 | |
1273 param = currNote->param; | |
1274 JMPMAKEPARAM(param, paramX, paramY); | |
1275 JMPGETEFFECT(effect, currNote->effect); | |
1276 | |
1277 switch (effect) | |
1278 { | |
1279 case '0': // 0xy = Arpeggio | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1280 jmpDoArpeggio(mp, chn, channel, paramX, paramY); |
0 | 1281 break; |
1282 | |
1283 case '1': // 1xy = Portamento Up | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1284 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1285 jmpChangePitch(chn, channel, -(chn->iLastPortaParam * 4)); |
0 | 1286 break; |
1287 | |
1288 case '2': // 2xy = Portamento Down | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1289 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1290 jmpChangePitch(chn, channel, (chn->iLastPortaParam * 4)); |
0 | 1291 break; |
1292 | |
1293 case '3': // 3xy = Porta To Note | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1294 jmpDoPortamento(chn, channel); |
0 | 1295 break; |
1296 | |
1297 case '4': // 4xy = Vibrato | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1298 jmpDoVibrato(mp, chn, channel); |
0 | 1299 break; |
1300 | |
1301 case '5': // 5xy = Portamento + Volume Slide | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1302 jmpDoPortamento(chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1303 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1304 break; |
1305 | |
1306 case '6': // 6xy = Vibrato + Volume Slide | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1307 jmpDoVibrato(mp, chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1308 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1309 break; |
1310 | |
1311 case '7': // 7xy = Tremolo | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1312 jmpDoTremolo(mp, chn, channel); |
0 | 1313 break; |
1314 | |
1315 case 'A': // Axy = Volume slide | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1316 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1317 break; |
1318 | |
1319 case 'E': // Exy = Special Effects | |
1320 switch (paramX) | |
1321 { | |
1322 case 0x0c: // ECx - Set Note Cut | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1323 if (mp->tick == paramY) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1324 jmpSetVolume(chn, channel, jsetMinVol); |
0 | 1325 break; |
1326 | |
1327 case 0x0d: // EDx - Set Note Delay | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1328 if (mp->tick == paramY) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1329 chn->iCNewDataFlags = chn->iSaveNDFlags; |
0 | 1330 break; |
1331 } | |
1332 break; | |
1333 | |
1334 case 'T': // Txy = Tremor | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1335 JMPMAKEPARAM(chn->iLastTremorParam, paramX, paramY) |
0 | 1336 paramX++; |
1337 paramY++; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1338 tmp = (chn->iTremorCount % (paramX + paramY)); |
0 | 1339 if (tmp < paramX) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1340 jmpCSetVolume(mp, chn, channel, chn->iCVolume); |
0 | 1341 else |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1342 jmpCSetVolume(mp, chn, channel, jsetMinVol); |
0 | 1343 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1344 chn->iTremorCount = (tmp + 1); |
0 | 1345 break; |
1346 } | |
1347 } | |
1348 | |
1349 | |
1350 /* This is the main processing callback-loop of a module player. | |
1351 * It processes the ticks, calling the needed jmpProcessNewRow() | |
1352 * and jmpProcessEffects() methods for processing the module playing. | |
1353 */ | |
1354 void jmpExec(void *pDEV, void *pMP) | |
1355 { | |
1356 JSSPlayer *mp; | |
1357 JSSMixer *dev; | |
1358 int channel, flags; | |
1359 | |
1360 // Check some things via assert() | |
1361 assert(pMP != NULL); | |
1362 mp = (JSSPlayer *) pMP; | |
1363 JSS_LOCK(mp); | |
1364 | |
1365 dev = (JSSMixer *) pDEV; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1366 assert(mp->device == dev); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1367 assert(mp->module != NULL); |
0 | 1368 |
1369 // Check if we are playing | |
1370 if (!mp->isPlaying) | |
1371 goto out; | |
1372 | |
1373 // Clear channel new data flags | |
1374 mp->jumpFlag = FALSE; | |
1375 mp->breakFlag = FALSE; | |
1376 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1377 for (channel = 0; channel < jsetNChannels; channel++) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1378 mp->channels[channel].iCNewDataFlags = 0; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1379 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1380 //fprintf(stderr, "1: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1381 |
1382 // Check for init-tick | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1383 if (mp->tick < 0) |
0 | 1384 { |
1385 // Initialize pattern | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1386 if (mp->order != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1387 jmpSetNewOrder(mp, mp->order); |
0 | 1388 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1389 mp->newRow = 0; |
0 | 1390 mp->newRowSet = TRUE; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1391 mp->tick = mp->speed; |
0 | 1392 } |
1393 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1394 //fprintf(stderr, "2: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1395 |
1396 // Check if we are playing | |
1397 if (!mp->isPlaying) | |
1398 goto out; | |
1399 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1400 assert(mp->pattern); |
0 | 1401 |
1402 // Update the tick | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1403 mp->tick++; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1404 if (mp->tick >= mp->speed) |
0 | 1405 { |
1406 // Re-init tick counter | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1407 mp->tick = 0; |
0 | 1408 |
1409 // Check pattern delay | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1410 if (mp->patternDelay > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1411 mp->patternDelay--; |
0 | 1412 else |
1413 { | |
1414 // New pattern row | |
1415 if (mp->newRowSet) | |
1416 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1417 mp->row = mp->newRow; |
0 | 1418 mp->newRowSet = FALSE; |
1419 } else | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1420 mp->row++; |
0 | 1421 |
1422 // Check for end of pattern | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1423 if (mp->row >= mp->pattern->nrows) |
0 | 1424 { |
1425 // Go to next order | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1426 if (mp->order != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1427 jmpSetNewOrder(mp, mp->order + 1); |
0 | 1428 else |
1429 mp->isPlaying = FALSE; | |
1430 | |
1431 // Check for FT2 quirks | |
1432 if (JMPGETMODFLAGS(mp, jmdfFT2Replay)) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1433 mp->row = mp->lastPatLoopRow; |
0 | 1434 else |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1435 mp->row = 0; |
0 | 1436 } |
1437 | |
1438 if (!mp->isPlaying) | |
1439 goto out; | |
1440 | |
1441 // Check current order | |
1442 if (mp->newOrderSet) | |
1443 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1444 jmpSetNewOrder(mp, mp->newOrder); |
0 | 1445 mp->newOrderSet = FALSE; |
1446 } | |
1447 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1448 //fprintf(stderr, "3: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1449 |
1450 if (!mp->isPlaying) | |
1451 goto out; | |
1452 | |
1453 // TICK #0: Process new row | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1454 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1455 jmpProcessNewRow(mp, channel); |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1456 } // patternDelay |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1457 } // tick |
0 | 1458 else |
1459 { | |
1460 // Implement FT2's pattern delay-effect: don't update effects while on patdelay | |
1461 if (!JMPGETMODFLAGS(mp, jmdfFT2Replay) || | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1462 (JMPGETMODFLAGS(mp, jmdfFT2Replay) && mp->patternDelay <= 0)) |
0 | 1463 { |
1464 // TICK n: Process the effects | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1465 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1466 jmpProcessEffects(mp, channel); |
1467 } | |
1468 } | |
1469 | |
1470 // Check if playing has stopped | |
1471 if (!mp->isPlaying) | |
1472 goto out; | |
1473 | |
1474 // Update player data to audio device/mixer | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1475 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1476 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1477 JSSPlayerChannel *chn = &mp->channels[channel]; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1478 |
0 | 1479 // Process extended instruments |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1480 jmpProcessExtInstrument(mp, chn, channel); |
0 | 1481 |
1482 // Check NDFlags and update channel data | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1483 flags = chn->iCNewDataFlags; |
0 | 1484 if (flags) |
1485 { | |
1486 // Check if we stop? | |
1487 if (flags & cdfStop) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1488 { |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1489 jvmStop(mp->device, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1490 } |
0 | 1491 else |
1492 { | |
1493 // No, handle other flags | |
1494 if (flags & cdfNewInstr) | |
1495 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1496 JSSInstrument *instr = chn->iCInstrument; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1497 if (instr != NULL) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1498 { |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1499 jvmSetSample(mp->device, channel, |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1500 instr->data, instr->size, |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1501 instr->loopS, instr->loopE, |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1502 instr->flags); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1503 } |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1504 jvmPlay(mp->device, channel); |
0 | 1505 } |
1506 | |
1507 if (flags & cdfNewPitch) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1508 jmpCSetPitch(mp, channel, chn->iCPitch); |
0 | 1509 |
1510 if (flags & cdfNewPos) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1511 jmpCSetPosition(mp, channel, chn->iCPosition); |
0 | 1512 |
1513 if (flags & cdfNewVolume) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1514 jmpCSetVolume(mp, chn, channel, chn->iCVolume); |
0 | 1515 |
1516 if (flags & cdfNewPanPos) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1517 jmpCSetPanning(mp, chn, channel, chn->iCPanning); |
0 | 1518 |
1519 if (flags & cdfNewGlobalVol) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1520 jvmSetGlobalVol(mp->device, mp->globalVol); |
0 | 1521 } |
1522 } | |
1523 } | |
1524 | |
1525 out: | |
1526 JSS_UNLOCK(mp); | |
1527 } |