1 #ifndef LIBXMP_PLAYER_H
2 #define LIBXMP_PLAYER_H
3 
4 #include "lfo.h"
5 
6 /* Quirk control */
7 #define HAS_QUIRK(x)	(m->quirk & (x))
8 
9 /* Channel flag control */
10 #define SET(f)		SET_FLAG(xc->flags,(f))
11 #define RESET(f) 	RESET_FLAG(xc->flags,(f))
12 #define TEST(f)		TEST_FLAG(xc->flags,(f))
13 
14 /* Persistent effect flag control */
15 #define SET_PER(f)	SET_FLAG(xc->per_flags,(f))
16 #define RESET_PER(f)	RESET_FLAG(xc->per_flags,(f))
17 #define TEST_PER(f)	TEST_FLAG(xc->per_flags,(f))
18 
19 /* Note flag control */
20 #define SET_NOTE(f)	SET_FLAG(xc->note_flags,(f))
21 #define RESET_NOTE(f)	RESET_FLAG(xc->note_flags,(f))
22 #define TEST_NOTE(f)	TEST_FLAG(xc->note_flags,(f))
23 
24 struct retrig_control {
25 	int s;
26 	int m;
27 	int d;
28 };
29 
30 /* The following macros are used to set the flags for each channel */
31 #define VOL_SLIDE	(1 << 0)
32 #define PAN_SLIDE	(1 << 1)
33 #define TONEPORTA	(1 << 2)
34 #define PITCHBEND	(1 << 3)
35 #define VIBRATO		(1 << 4)
36 #define TREMOLO		(1 << 5)
37 #define FINE_VOLS	(1 << 6)
38 #define FINE_BEND	(1 << 7)
39 #define OFFSET		(1 << 8)
40 #define TRK_VSLIDE	(1 << 9)
41 #define TRK_FVSLIDE	(1 << 10)
42 #define NEW_INS		(1 << 11)
43 #define NEW_VOL		(1 << 12)
44 #define VOL_SLIDE_2	(1 << 13)
45 #define NOTE_SLIDE	(1 << 14)
46 #define FINE_NSLIDE	(1 << 15)
47 #define NEW_NOTE	(1 << 16)
48 #define FINE_TPORTA	(1 << 17)
49 #define RETRIG		(1 << 18)
50 #define PANBRELLO	(1 << 19)
51 #define GVOL_SLIDE	(1 << 20)
52 #define TEMPO_SLIDE	(1 << 21)
53 #define VENV_PAUSE	(1 << 22)
54 #define PENV_PAUSE	(1 << 23)
55 #define FENV_PAUSE	(1 << 24)
56 #define FINE_VOLS_2	(1 << 25)
57 #define KEY_OFF		(1 << 26)	/* for IT release on envloop end */
58 #define TREMOR		(1 << 27)	/* for XM tremor */
59 
60 #define NOTE_FADEOUT	(1 << 0)
61 #define NOTE_RELEASE	(1 << 1)
62 #define NOTE_END	(1 << 2)
63 #define NOTE_CUT	(1 << 3)
64 #define NOTE_ENV_END	(1 << 4)
65 #define NOTE_SAMPLE_END	(1 << 5)
66 #define NOTE_SET	(1 << 6)	/* for IT portamento after keyoff */
67 #define NOTE_SUSEXIT	(1 << 7)	/* for delayed note release */
68 #define NOTE_KEY_CUT	(1 << 8)	/* note cut with XMP_KEY_CUT event */
69 #define NOTE_GLISSANDO	(1 << 9)
70 
71 #define IS_VALID_INSTRUMENT(x) ((uint32)(x) < mod->ins && mod->xxi[(x)].nsm > 0)
72 #define IS_VALID_INSTRUMENT_OR_SFX(x) (((uint32)(x) < mod->ins && mod->xxi[(x)].nsm > 0) || (smix->ins > 0 && (uint32)(x) < mod->ins + smix->ins))
73 
74 struct instrument_vibrato {
75 	int phase;
76 	int sweep;
77 };
78 
79 struct channel_data {
80 	int flags;		/* Channel flags */
81 	int per_flags;		/* Persistent effect channel flags */
82 	int note_flags;		/* Note release, fadeout or end */
83 	int note;		/* Note number */
84 	int key;		/* Key number */
85 	double period;		/* Amiga or linear period */
86 	double per_adj;		/* MED period/pitch adjustment factor hack */
87 	int finetune;		/* Guess what */
88 	int ins;		/* Instrument number */
89 	int old_ins;		/* Last instruemnt */
90 	int smp;		/* Sample number */
91 	int mastervol;		/* Master vol -- for IT track vol effect */
92 	int delay;		/* Note delay in frames */
93 	int keyoff;		/* Key off counter */
94 	int fadeout;		/* Current fadeout (release) value */
95 	int ins_fade;		/* Instrument fadeout value */
96 	int volume;		/* Current volume */
97 	int gvl;		/* Global volume for instrument for IT */
98 
99 	int rvv;		/* Random volume variation */
100 	int rpv;		/* Random pan variation */
101 
102 	uint8 split;		/* Split channel */
103 	uint8 pair;		/* Split channel pair */
104 
105 	int v_idx;		/* Volume envelope index */
106 	int p_idx;		/* Pan envelope index */
107 	int f_idx;		/* Freq envelope index */
108 
109 	int key_porta;		/* Key number for portamento target
110 				 * -- needed to handle IT portamento xpo */
111 	struct {
112 		struct lfo lfo;
113 		int memory;
114 	} vibrato;
115 
116 	struct {
117 		struct lfo lfo;
118 		int memory;
119 	} tremolo;
120 
121 #ifndef LIBXMP_CORE_DISABLE_IT
122 	struct {
123 		struct lfo lfo;
124 		int memory;
125 	} panbrello;
126 #endif
127 
128 	struct {
129         	int8 val[16];	/* 16 for Smaksak MegaArps */
130 		int size;
131 		int count;
132 		int memory;
133 	} arpeggio;
134 
135 	struct {
136 		struct lfo lfo;
137 		int sweep;
138 	} insvib;
139 
140 	struct {
141 		int val;
142 		int val2;	/* For fx9 bug emulation */
143 		int memory;
144 	} offset;
145 
146 	struct {
147 		int val;	/* Retrig value */
148 		int count;	/* Retrig counter */
149 		int type;	/* Retrig type */
150 	} retrig;
151 
152 	struct {
153 		uint8 up,down;	/* Tremor value */
154 		uint8 count;	/* Tremor counter */
155 		uint8 memory;	/* Tremor memory */
156 	} tremor;
157 
158 	struct {
159 		int slide;	/* Volume slide value */
160 		int fslide;	/* Fine volume slide value */
161 		int slide2;	/* Volume slide value */
162 		int memory;	/* Volume slide effect memory */
163 #ifndef LIBXMP_CORE_DISABLE_IT
164 		int fslide2;
165 		int memory2;	/* Volume slide effect memory */
166 #endif
167 	} vol;
168 
169 	struct {
170 		int up_memory;	/* Fine volume slide up memory (XM) */
171 		int down_memory;/* Fine volume slide up memory (XM) */
172 	} fine_vol;
173 
174 	struct {
175 		int slide;	/* Global volume slide value */
176 		int fslide;	/* Fine global volume slide value */
177 		int memory;	/* Global volume memory is saved per channel */
178 	} gvol;
179 
180 	struct {
181 		int slide;	/* Track volume slide value */
182 		int fslide;	/* Track fine volume slide value */
183 		int memory;	/* Track volume slide effect memory */
184 	} trackvol;
185 
186 	struct {
187 		int slide;	/* Frequency slide value */
188 		double fslide;	/* Fine frequency slide value */
189 		int memory;	/* Portamento effect memory */
190 	} freq;
191 
192 	struct {
193 		double target;	/* Target period for tone portamento */
194 		int dir;	/* Tone portamento up/down directionh */
195 		int slide;	/* Delta for tone portamento */
196 		int memory;	/* Tone portamento effect memory */
197 	} porta;
198 
199 	struct {
200 		int up_memory;	/* FT2 has separate memories for these */
201 		int down_memory;/* cases (see Porta-LinkMem.xm) */
202 	} fine_porta;
203 
204 	struct {
205 		int val;	/* Current pan value */
206 		int slide;	/* Pan slide value */
207 		int fslide;	/* Pan fine slide value */
208 		int memory;	/* Pan slide effect memory */
209 		int surround;	/* Surround channel flag */
210 	} pan;
211 
212 	struct {
213 		int speed;
214 		int count;
215 		int pos;
216 	} invloop;
217 
218 #ifndef LIBXMP_CORE_DISABLE_IT
219 	struct {
220 		int slide;	/* IT tempo slide */
221 	} tempo;
222 
223 	struct {
224 		int cutoff;	/* IT filter cutoff frequency */
225 		int resonance;	/* IT filter resonance */
226 		int envelope;	/* IT filter envelope */
227 	} filter;
228 
229 #endif
230 
231 #ifndef LIBXMP_CORE_PLAYER
232 	struct {
233 		int slide;	/* PTM note slide amount */
234 		int fslide;	/* OKT fine note slide amount */
235 		int speed;	/* PTM note slide speed */
236 		int count;	/* PTM note slide counter */
237 	} noteslide;
238 
239 	void *extra;
240 #endif
241 
242 	struct xmp_event delayed_event;
243 	int delayed_ins;	/* IT save instrument emulation */
244 
245 	int info_period;	/* Period */
246 	int info_pitchbend;	/* Linear pitchbend */
247 	int info_position;	/* Position before mixing */
248 	int info_finalvol;	/* Final volume including envelopes */
249 	int info_finalpan;	/* Final pan including envelopes */
250 };
251 
252 
253 void	libxmp_process_fx	(struct context_data *, struct channel_data *,
254 				 int, struct xmp_event *, int);
255 void	libxmp_filter_setup	(int, int, int, int*, int*, int *);
256 int	libxmp_read_event	(struct context_data *, struct xmp_event *, int);
257 
258 #endif /* LIBXMP_PLAYER_H */
259