annotate jssplr.c @ 181:879b2488340a

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