Mercurial > hg > dmlib
annotate jssplr.c @ 223:9fa8e9326d18
Implement effect Rxy - multi retrig note.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 08 Oct 2012 00:20:20 +0300 |
parents | 63be671823d3 |
children | 81f3993412ae |
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 0x0a: // EAx - Fine Volumeslide Up | |
976 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
977 chn->iCLastFineVolumeslideUpParam = paramY; |
0 | 978 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
979 jmpChangeVolume(chn, channel, chn->iCLastFineVolumeslideUpParam); |
0 | 980 break; |
981 | |
982 case 0x0b: // EBx - Fine Volumeslide Down | |
983 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
984 chn->iCLastFineVolumeslideDownParam = paramY; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
985 jmpChangeVolume(chn, channel, -(chn->iCLastFineVolumeslideDownParam)); |
0 | 986 break; |
987 | |
988 case 0x0c: // ECx - Set Note Cut (NOT PROCESSED IN TICK0) | |
989 break; | |
990 | |
991 case 0x0d: // EDx - Set Note Delay : IMPL.VERIFIED | |
992 if (paramY > 0) | |
993 { | |
994 // 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
|
995 chn->iSaveNDFlags = chn->newDataFlags; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
996 chn->newDataFlags = 0; |
0 | 997 // TODO .. does this only affect NOTE or also instrument? |
998 } | |
999 break; | |
1000 | |
1001 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
|
1002 mp->patternDelay = paramY; |
0 | 1003 break; |
1004 | |
1005 case 0x0f: // EFx - Invert Loop (NOT SUPPORTED) | |
1006 JMPDEBUG("Invert Loop used, UNSUPPORTED"); | |
1007 break; | |
1008 | |
1009 default: | |
1010 JMPDEBUG("Unsupported special command used"); | |
1011 } | |
1012 break; | |
1013 | |
1014 case 'F': // Fxy = Set Speed / Tempo : IMPL.VERIFIED | |
1015 if (param > 0) | |
1016 { | |
1017 if (param < 0x20) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1018 mp->speed = param; |
0 | 1019 else |
1020 jmpSetTempo(mp, param); | |
1021 } | |
1022 break; | |
1023 | |
1024 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
|
1025 mp->globalVol = param; |
0 | 1026 JMPSETNDFLAGS(cdfNewGlobalVol); |
1027 break; | |
1028 | |
1029 | |
1030 case 'H': // Hxx = Global Volume Slide | |
1031 JMPDEBUG("Global Volume Slide used, UNIMPLEMENTED"); | |
1032 break; | |
1033 | |
1034 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
|
1035 chn->keyOff = TRUE; |
0 | 1036 break; |
1037 | |
1038 case 'L': // Lxx = Set Envelope Position | |
1039 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
|
1040 chn->panningEnv.frame = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1041 chn->volumeEnv.frame = param; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1042 chn->panningEnv.exec = TRUE; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1043 chn->volumeEnv.exec = TRUE; |
0 | 1044 break; |
1045 | |
1046 case 'R': // Rxy = Multi Retrig note | |
223
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1047 if (paramX != 0) |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1048 chn->lastMultiRetrigParamX = paramX; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1049 if (paramY != 0) |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1050 chn->lastMultiRetrigParamY = paramY; |
0 | 1051 break; |
1052 | |
1053 case 'T': // Txy = Tremor | |
1054 if (param) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1055 chn->iLastTremorParam = param; |
0 | 1056 break; |
1057 | |
1058 case 'X': // Xxy = Extra Fine Portamento | |
1059 switch (paramX) | |
1060 { | |
1061 case 0x01: // X1y - Extra Fine Portamento Up | |
1062 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1063 chn->iCLastExtraFinePortamentoUpParam = paramY; |
0 | 1064 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1065 jmpChangePitch(chn, channel, - chn->iCLastExtraFinePortamentoUpParam); |
0 | 1066 break; |
1067 | |
1068 case 0x02: // X2y - Extra Fine Portamento Down | |
1069 if (paramY) | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1070 chn->iCLastExtraFinePortamentoDownParam = paramY; |
0 | 1071 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1072 jmpChangePitch(chn, channel, chn->iCLastExtraFinePortamentoUpParam); |
0 | 1073 break; |
1074 | |
1075 default: | |
1076 JMPDEBUG("Unsupported value in Extra Fine Portamento command!"); | |
1077 break; | |
1078 } | |
1079 break; | |
1080 | |
1081 default: | |
1082 JMPDEBUG("Unsupported effect"); | |
1083 break; | |
1084 } | |
1085 } | |
1086 | |
1087 | |
221
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1088 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
|
1089 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1090 if (chn->nextInstrument >= 0 && |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1091 chn->nextInstrument < mp->module->nextInstruments && |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1092 mp->module->extInstruments[chn->nextInstrument] != NULL) |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1093 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1094 chn->extInstrument = mp->module->extInstruments[chn->nextInstrument]; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1095 } |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1096 else |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1097 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1098 chn->extInstrument = NULL; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1099 chn->instrument = NULL; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1100 chn->ninstrument = jsetNotSet; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1101 } |
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 if (chn->extInstrument != NULL) |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1104 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1105 int tmp = chn->extInstrument->sNumForNotes[chn->note]; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1106 |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1107 if (tmp >= 0 && tmp < mp->module->ninstruments && |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1108 mp->module->instruments[tmp] != NULL) |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1109 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1110 if (chn->ninstrument != tmp) |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1111 JMPSETNDFLAGS(cdfNewInstr); |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1112 |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1113 chn->ninstrument = tmp; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1114 chn->instrument = mp->module->instruments[chn->ninstrument]; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1115 |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1116 if (newExtInstrument) |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1117 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1118 chn->volume = chn->instrument->volume; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1119 chn->panning = chn->instrument->EPanning; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1120 JMPSETNDFLAGS(cdfNewPanPos | cdfNewVolume); |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1121 } |
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 if (chn->instrument != NULL) |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1126 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1127 int tmp; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1128 JSSInstrument *inst = chn->instrument; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1129 |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1130 // Save old pitch for later use |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1131 chn->oldPitch = chn->pitch; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1132 |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1133 chn->position = 0; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1134 |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1135 // Compute new pitch |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1136 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
|
1137 chn->pitch = jmpGetPeriodFromNote(mp, tmp, inst->EFineTune); |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1138 JMPSETNDFLAGS(cdfNewPitch | cdfPlay | cdfNewPos); |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1139 } |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1140 else |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1141 { |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1142 chn->volume = 0; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1143 chn->panning = jchPanMiddle; |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1144 JMPSETNDFLAGS(cdfStop | cdfNewPanPos | cdfNewVolume); |
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1145 } |
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 |
0 | 1149 static void jmpProcessNewRow(JSSPlayer * mp, int channel) |
1150 { | |
1151 JSSNote *currNote; | |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1152 BOOL newNote = FALSE, newExtInstrument = FALSE; |
221
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1153 int paramX, paramY; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1154 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1155 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1156 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1157 |
1158 // Check for a new note/keyoff here | |
1159 if (currNote->note == jsetNoteOff) | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1160 chn->keyOff = TRUE; |
0 | 1161 else |
1162 if (currNote->note >= 0 && currNote->note <= 96) | |
1163 { | |
1164 newNote = TRUE; | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1165 chn->note = currNote->note; |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1166 chn->keyOff = FALSE; |
0 | 1167 } |
1168 | |
1169 // 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
|
1170 if (currNote->instrument != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1171 { |
0 | 1172 /* Envelopes and ext.instrument fadeout are initialized always if |
1173 * new instrument is set, even if the instrument does not exist. | |
1174 */ | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1175 jmpResetEnvelope(&chn->volumeEnv); |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1176 jmpResetEnvelope(&chn->panningEnv); |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1177 chn->keyOff = FALSE; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1178 chn->fadeOutVol = mpMaxFadeoutVol; |
0 | 1179 |
215
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1180 JMPSETNDFLAGS(cdfNewPanPos | cdfPlay | cdfNewVolume); |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1181 |
0 | 1182 // 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
|
1183 chn->nextInstrument = currNote->instrument; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1184 newExtInstrument = TRUE; |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1185 } |
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 if (newNote) |
5523ea253603
Possibly fix new note/instrument handling logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
214
diff
changeset
|
1188 { |
221
5c36aff80205
Factor note triggering to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
220
diff
changeset
|
1189 jmpTriggerNote(mp, chn, newExtInstrument); |
0 | 1190 } |
1191 | |
1192 // Process the volume column | |
1193 JMPMAKEPARAM(currNote->volume, paramX, paramY); | |
1194 | |
1195 switch (paramX) | |
1196 { | |
214 | 1197 case 0x0: |
1198 case 0x1: | |
1199 case 0x2: | |
1200 case 0x3: | |
1201 case 0x4: | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1202 jmpSetVolume(chn, channel, currNote->volume); |
0 | 1203 break; |
1204 | |
214 | 1205 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
|
1206 jmpChangeVolume(chn, channel, -paramY); |
0 | 1207 break; |
1208 | |
214 | 1209 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
|
1210 jmpChangeVolume(chn, channel, paramY); |
0 | 1211 break; |
1212 | |
214 | 1213 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
|
1214 chn->vibrato.speed = paramY; |
0 | 1215 break; |
1216 | |
214 | 1217 case 0xa: // Vx = Vibrato : IMPL.VERIFIED |
0 | 1218 if (paramY) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1219 chn->vibrato.depth = paramY; |
0 | 1220 break; |
1221 | |
214 | 1222 case 0xe: // Mx = Porta To Note : IMPL.VERIFIED |
0 | 1223 if (paramY) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1224 chn->iLastPortaToNoteParam = paramY; |
0 | 1225 |
175 | 1226 if (currNote->note != jsetNotSet && currNote->note != jsetNoteOff) |
1227 { | |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1228 chn->iLastPortaToNotePitch = chn->pitch; |
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1229 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
|
1230 JMPUNSETNDFLAGS(cdfNewPitch | cdfPlay); |
0 | 1231 } |
1232 break; | |
1233 } | |
1234 | |
1235 // ...And finally process the Normal effects | |
1236 if (currNote->effect != jsetNotSet) | |
1237 jmpProcessRowEffect(mp, channel, currNote); | |
1238 } | |
1239 | |
1240 | |
1241 static void jmpProcessEffects(JSSPlayer * mp, int channel) | |
1242 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1243 JSSPlayerChannel *chn = &(mp->channels[channel]); |
0 | 1244 JSSNote *currNote; |
1245 int param, paramX, paramY, tmp; | |
1246 char effect; | |
1247 | |
1248 // 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
|
1249 JMPGETNOTE(currNote, mp->row, channel); |
0 | 1250 JMPMAKEPARAM(currNote->volume, paramX, paramY); |
1251 | |
1252 switch (paramX) | |
1253 { | |
1254 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
|
1255 jmpChangeVolume(chn, channel, -paramY); |
0 | 1256 break; |
1257 | |
1258 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
|
1259 jmpChangeVolume(chn, channel, paramY); |
0 | 1260 break; |
1261 | |
1262 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
|
1263 jmpDoVibrato(mp, chn, channel); |
0 | 1264 break; |
1265 | |
1266 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
|
1267 jmpDoPortamento(chn, channel); |
0 | 1268 break; |
1269 } | |
1270 | |
1271 // ...And finally process the Normal effects | |
1272 if (currNote->effect == jsetNotSet) | |
1273 return; | |
1274 | |
1275 param = currNote->param; | |
1276 JMPMAKEPARAM(param, paramX, paramY); | |
1277 JMPGETEFFECT(effect, currNote->effect); | |
1278 | |
1279 switch (effect) | |
1280 { | |
1281 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
|
1282 jmpDoArpeggio(mp, chn, channel, paramX, paramY); |
0 | 1283 break; |
1284 | |
1285 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
|
1286 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1287 jmpChangePitch(chn, channel, -(chn->iLastPortaParam * 4)); |
0 | 1288 break; |
1289 | |
1290 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
|
1291 if (chn->iLastPortaParam > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1292 jmpChangePitch(chn, channel, (chn->iLastPortaParam * 4)); |
0 | 1293 break; |
1294 | |
1295 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
|
1296 jmpDoPortamento(chn, channel); |
0 | 1297 break; |
1298 | |
1299 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
|
1300 jmpDoVibrato(mp, chn, channel); |
0 | 1301 break; |
1302 | |
1303 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
|
1304 jmpDoPortamento(chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1305 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1306 break; |
1307 | |
1308 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
|
1309 jmpDoVibrato(mp, chn, channel); |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1310 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1311 break; |
1312 | |
1313 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
|
1314 jmpDoTremolo(mp, chn, channel); |
0 | 1315 break; |
1316 | |
1317 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
|
1318 jmpDoVolumeSlide(chn, channel, chn->iLastVolSlideParam); |
0 | 1319 break; |
1320 | |
1321 case 'E': // Exy = Special Effects | |
1322 switch (paramX) | |
1323 { | |
222
63be671823d3
Implement effect E9x - Retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
221
diff
changeset
|
1324 case 0x09: // E9x - Retrig note |
63be671823d3
Implement effect E9x - Retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
221
diff
changeset
|
1325 if (mp->tick == paramY) |
63be671823d3
Implement effect E9x - Retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
221
diff
changeset
|
1326 jmpTriggerNote(mp, chn, FALSE); |
63be671823d3
Implement effect E9x - Retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
221
diff
changeset
|
1327 break; |
63be671823d3
Implement effect E9x - Retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
221
diff
changeset
|
1328 |
0 | 1329 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
|
1330 if (mp->tick == paramY) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1331 jmpSetVolume(chn, channel, jsetMinVol); |
0 | 1332 break; |
1333 | |
1334 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
|
1335 if (mp->tick == paramY) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1336 chn->newDataFlags = chn->iSaveNDFlags; |
0 | 1337 break; |
1338 } | |
1339 break; | |
1340 | |
223
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1341 case 'R': // Rxy = Multi Retrig note |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1342 if (chn->lastMultiRetrigParamY != 0 && |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1343 (mp->tick % chn->lastMultiRetrigParamY) == 0) |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1344 { |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1345 BOOL change = TRUE; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1346 int volume = chn->volume; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1347 switch (chn->lastMultiRetrigParamX) |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1348 { |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1349 case 0x1: volume -= 1; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1350 case 0x2: volume -= 2; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1351 case 0x3: volume -= 4; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1352 case 0x4: volume -= 8; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1353 case 0x5: volume -= 16; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1354 case 0x6: volume = (volume * 2) / 3; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1355 case 0x7: volume /= 2; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1356 |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1357 case 0x9: volume += 1; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1358 case 0xA: volume += 2; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1359 case 0xB: volume += 4; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1360 case 0xC: volume += 8; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1361 case 0xD: volume += 16; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1362 case 0xE: volume = (volume * 3) / 2; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1363 case 0xF: volume *= 2; break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1364 default: change = FALSE; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1365 } |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1366 jmpTriggerNote(mp, chn, FALSE); |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1367 if (change) |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1368 { |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1369 chn->volume = dmClamp(volume, mpMinVol, mpMaxVol); |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1370 JMPSETNDFLAGS(cdfNewVolume); |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1371 } |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1372 } |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1373 break; |
9fa8e9326d18
Implement effect Rxy - multi retrig note.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1374 |
0 | 1375 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
|
1376 JMPMAKEPARAM(chn->iLastTremorParam, paramX, paramY) |
0 | 1377 paramX++; |
1378 paramY++; | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1379 tmp = (chn->iTremorCount % (paramX + paramY)); |
0 | 1380 if (tmp < paramX) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1381 jmpCSetVolume(mp, chn, channel, chn->volume, FALSE); |
0 | 1382 else |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1383 jmpCSetVolume(mp, chn, channel, jsetMinVol, FALSE); |
0 | 1384 |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1385 chn->iTremorCount = (tmp + 1); |
0 | 1386 break; |
1387 } | |
1388 } | |
1389 | |
1390 | |
1391 /* This is the main processing callback-loop of a module player. | |
1392 * It processes the ticks, calling the needed jmpProcessNewRow() | |
1393 * and jmpProcessEffects() methods for processing the module playing. | |
1394 */ | |
1395 void jmpExec(void *pDEV, void *pMP) | |
1396 { | |
1397 JSSPlayer *mp; | |
1398 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
|
1399 int channel; |
0 | 1400 |
1401 // Check some things via assert() | |
1402 mp = (JSSPlayer *) pMP; | |
1403 JSS_LOCK(mp); | |
1404 | |
1405 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
|
1406 |
0 | 1407 // Check if we are playing |
1408 if (!mp->isPlaying) | |
1409 goto out; | |
1410 | |
1411 // Clear channel new data flags | |
1412 mp->jumpFlag = FALSE; | |
1413 mp->breakFlag = FALSE; | |
1414 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1415 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
|
1416 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
|
1417 |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1418 //fprintf(stderr, "1: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1419 |
1420 // Check for init-tick | |
187 | 1421 if (mp->tick == jsetNotSet) |
0 | 1422 { |
1423 // Initialize pattern | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1424 mp->newRow = 0; |
0 | 1425 mp->newRowSet = TRUE; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1426 mp->tick = mp->speed; |
187 | 1427 mp->patternDelay = 0; |
0 | 1428 } |
1429 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1430 //fprintf(stderr, "2: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1431 |
1432 // Check if we are playing | |
1433 if (!mp->isPlaying) | |
1434 goto out; | |
1435 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1436 assert(mp->pattern); |
0 | 1437 |
1438 // Update the tick | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1439 mp->tick++; |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1440 if (mp->tick >= mp->speed) |
0 | 1441 { |
1442 // 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
|
1443 mp->tick = 0; |
0 | 1444 |
1445 // Check pattern delay | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1446 if (mp->patternDelay > 0) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1447 mp->patternDelay--; |
0 | 1448 else |
1449 { | |
1450 // New pattern row | |
1451 if (mp->newRowSet) | |
1452 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1453 mp->row = mp->newRow; |
0 | 1454 mp->newRowSet = FALSE; |
1455 } else | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1456 mp->row++; |
0 | 1457 |
1458 // 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
|
1459 if (mp->row >= mp->pattern->nrows) |
0 | 1460 { |
1461 // 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
|
1462 if (mp->order != jsetNotSet) |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1463 jmpSetNewOrder(mp, mp->order + 1); |
0 | 1464 else |
1465 mp->isPlaying = FALSE; | |
1466 | |
1467 // Check for FT2 quirks | |
1468 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
|
1469 mp->row = mp->lastPatLoopRow; |
0 | 1470 else |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1471 mp->row = 0; |
0 | 1472 } |
1473 | |
1474 if (!mp->isPlaying) | |
1475 goto out; | |
1476 | |
1477 // Check current order | |
1478 if (mp->newOrderSet) | |
1479 { | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1480 jmpSetNewOrder(mp, mp->newOrder); |
0 | 1481 mp->newOrderSet = FALSE; |
1482 } | |
1483 | |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1484 //fprintf(stderr, "3: tick=%d, order=%d, iPattern=%d, row=%d\n", mp->tick, mp->order, mp->npattern, mp->row); |
0 | 1485 |
1486 if (!mp->isPlaying) | |
1487 goto out; | |
1488 | |
1489 // 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
|
1490 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1491 jmpProcessNewRow(mp, channel); |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1492 } // patternDelay |
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1493 } // tick |
0 | 1494 else |
1495 { | |
1496 // Implement FT2's pattern delay-effect: don't update effects while on patdelay | |
1497 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
|
1498 (JMPGETMODFLAGS(mp, jmdfFT2Replay) && mp->patternDelay <= 0)) |
0 | 1499 { |
1500 // 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
|
1501 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1502 jmpProcessEffects(mp, channel); |
1503 } | |
1504 } | |
1505 | |
1506 // Check if playing has stopped | |
1507 if (!mp->isPlaying) | |
1508 goto out; | |
1509 | |
1510 // 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
|
1511 for (channel = 0; channel < mp->module->nchannels; channel++) |
0 | 1512 { |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1513 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
|
1514 int flags; |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1515 |
0 | 1516 // Process extended instruments |
61
a33e47232161
Silence some "unused parameter" warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1517 jmpProcessExtInstrument(chn, channel); |
0 | 1518 |
1519 // 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
|
1520 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
|
1521 if (!flags) |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1522 continue; |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1523 |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1524 // 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
|
1525 if (flags & cdfStop) |
0 | 1526 { |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1527 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
|
1528 } |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1529 else |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1530 { |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1531 // 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
|
1532 if (flags & cdfNewInstr) |
55
e0e470c3fc8e
Initial round of cleaning up the player code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
1533 { |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1534 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
|
1535 if (instr != NULL) |
0 | 1536 { |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1537 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
|
1538 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
|
1539 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
|
1540 instr->flags); |
0 | 1541 } |
180
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1542 } |
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1543 |
bc8019c38ba5
Refactoring of the note triggering and other player logic, fixes various
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
1544 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
|
1545 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
|
1546 |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1547 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
|
1548 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
|
1549 |
218 | 1550 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
|
1551 jvmSetFreq(mp->device, channel, chn->freq); |
0 | 1552 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1553 if (flags & cdfNewPos) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1554 jvmSetPos(mp->device, channel, chn->position); |
0 | 1555 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1556 if (flags & cdfNewVolume) |
196
dea742428ac6
Adjust volume ramping logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1557 jmpCSetVolume(mp, chn, channel, chn->volume, flags & (cdfNewInstr | cdfPlay)); |
0 | 1558 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1559 if (flags & cdfNewPanPos) |
183
a65f0c3deaa7
Some more player logic cleanups and variable renames.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
1560 jmpCSetPanning(mp, chn, channel, chn->panning); |
0 | 1561 |
144
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1562 if (flags & cdfNewGlobalVol) |
22e1be63f6af
Various improvements in XM replay: implement the 5ms volume fadein and
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
1563 jvmSetGlobalVol(mp->device, mp->globalVol); |
0 | 1564 } |
1565 } | |
1566 | |
1567 out: | |
1568 JSS_UNLOCK(mp); | |
1569 } |