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