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