1 
2 /*
3  *  Diverse Bristol audio routines.
4  *  Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5  *
6  *
7  *   This program is free software; you can redistribute it and/or modify
8  *   it under the terms of the GNU General Public License as published by
9  *   the Free Software Foundation; either version 3 of the License, or
10  *   (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with this program; if not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 
23 #include <fcntl.h>
24 
25 #include "brighton.h"
26 #include "brightonMini.h"
27 #include "brightoninternals.h"
28 
29 static int hammondB3Init();
30 static int hammondB3Configure();
31 static int hammondB3MidiCallback(brightonWindow *, int, int, float);
32 static int hammondB3Callback(brightonWindow *, int, int, float);
33 static int hammondB3destroy();
34 /*static int keyCallback(void *, int, int, float); */
35 /*static int modCallback(void *, int, int, float); */
36 static void doClick();
37 
38 static int dc = 0, shade_id;
39 
40 extern guimain global;
41 static guimain manual;
42 
43 #include "brightonKeys.h"
44 
45 #define FIRST_DEV 0
46 #define C_COUNT (35 + FIRST_DEV)
47 #define MEM_COUNT 16
48 #define VOL_COUNT 1
49 #define LESLIE_COUNT 2
50 #define OPTS_COUNT 40
51 
52 #define ACTIVE_DEVS (C_COUNT + OPTS_COUNT + VOL_COUNT + LESLIE_COUNT - 1)
53 #define DEVICE_COUNT (C_COUNT + OPTS_COUNT + VOL_COUNT + LESLIE_COUNT + MEM_COUNT)
54 
55 #define OPTS_PANEL 1
56 
57 #define DRAWBAR_START 9
58 
59 #define DEVICE_START FIRST_DEV
60 #define OPTS_START (DEVICE_START + C_COUNT)
61 #define VOL_START (OPTS_START + OPTS_COUNT)
62 #define LESLIE_START (VOL_START + VOL_COUNT)
63 #define MEM_START (LESLIE_START + LESLIE_COUNT)
64 
65 #define DISPLAY_PAN 4
66 #define DISPLAY_DEV (MEM_COUNT - 1)
67 
68 #define KEY_PANEL1 6
69 #define KEY_PANEL2 7
70 
71 #define RADIOSET_1 MEM_START
72 
73 /*
74  * This structure is for device definition. The structure is defined in
75  * include/brighton.h, further definitions in brighton/brightonDevtable.h and
76  * include/brightoninternals.h
77  *
78  *	typedef int (*brightonCallback)(int, float);
79  *	typedef struct BrightonLocations {
80  *		int device; 0=rotary, 1=scale, etc.
81  *		float relx, rely; relative position with regards to 1000 by 1000 window
82  *		float relw, relh; relative height.
83  *		int from, to;
84  *		brightonCallback callback; specific to this dev
85  *		char *image; bitmap. If zero take a device default.
86  *		int flags;
87  *	} brightonLocations;
88  *
89  * This example is for a hammondB3Bristol type synth interface.
90  */
91 #define SD1 28
92 #define SD2 50
93 
94 #define W1 20
95 #define L1 770
96 
97 #define R1 0
98 
99 #define Cm1 225
100 #define Cm2 (Cm1 + SD1)
101 
102 #define C1 290
103 #define C2 (C1 + SD1)
104 #define C3 (C2 + SD1)
105 #define C4 (C3 + SD1)
106 #define C5 (C4 + SD1)
107 #define C6 (C5 + SD1)
108 #define C7 (C6 + SD1)
109 #define C8 (C7 + SD1)
110 #define C9 (C8 + SD1)
111 
112 #define C11 556
113 #define C12 (C11 + SD1)
114 #define C13 (C12 + SD1)
115 #define C14 (C13 + SD1)
116 #define C15 (C14 + SD1)
117 #define C16 (C15 + SD1)
118 #define C17 (C16 + SD1)
119 #define C18 (C17 + SD1)
120 #define C19 (C18 + SD1)
121 
122 #define MC1 9
123 #define MC2 55
124 #define MC3 183
125 
126 #define MC4 810
127 #define MC5 (MC4 + SD2)
128 #define MC6 (MC5 + SD2)
129 #define MC7 (MC6 + SD2)
130 
131 #define MR1 360
132 #define MR2 650
133 #define MR3 700
134 
135 #define MW1 36
136 #define MW2 50
137 
138 #define MH1 525
139 #define MH2 200
140 
141 #include <brightondevflags.h>
142 
143 /*
144  * Drawbars were 0 to 7 due to encoding them in a single 7bit value - 3 bits
145  * were for gain and 4 bits required for the drawbar. This was always in need
146  * of a change and will implement it finally. It's actually quite trivial, it
147  * uses sequential encoding rather than reserving bits, the latter is too
148  * lossy.
149  */
150 static brightonLocations locations[C_COUNT] = {
151 	{"Lower Drawbar 16", BRIGHTON_HAMMOND, C1, R1, W1, L1, 0, 8, 0,
152 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
153 	{"Lower Drawbar 5 1/3", BRIGHTON_HAMMOND, C2, R1, W1, L1, 0, 8, 0,
154 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
155 	{"Lower Drawbar 8", BRIGHTON_HAMMOND, C3, R1, W1, L1, 0, 8, 0,
156 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
157 	{"Lower Drawbar 4", BRIGHTON_HAMMOND, C4, R1, W1, L1, 0, 8, 0,
158 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
159 	{"Lower Drawbar 2 2/3", BRIGHTON_HAMMOND, C5, R1, W1, L1, 0, 8, 0,
160 		"bitmaps/knobs/hammondblack.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
161 	{"Lower Drawbar 2", BRIGHTON_HAMMOND, C6, R1, W1, L1, 0, 8, 0,
162 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
163 	{"Lower Drawbar 1 3/5", BRIGHTON_HAMMOND, C7, R1, W1, L1, 0, 8, 0,
164 		"bitmaps/knobs/hammondblack.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
165 	{"Lower Drawbar 1 1/3", BRIGHTON_HAMMOND, C8, R1, W1, L1, 0, 8, 0,
166 		"bitmaps/knobs/hammondblack.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
167 	{"Lower Drawbar 1", BRIGHTON_HAMMOND, C9, R1, W1, L1, 0, 8, 0,
168 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
169 
170 	{"Upper Drawbar 16", BRIGHTON_HAMMOND, C11, R1, W1, L1, 0, 8, 0,
171 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
172 	{"Upper Drawbar 5 1/3", BRIGHTON_HAMMOND, C12, R1, W1, L1, 0, 8, 0,
173 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
174 	{"Upper Drawbar 8", BRIGHTON_HAMMOND, C13, R1, W1, L1, 0, 8, 0,
175 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
176 	{"Upper Drawbar 4", BRIGHTON_HAMMOND, C14, R1, W1, L1, 0, 8, 0,
177 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
178 	{"Upper Drawbar 2 2/3", BRIGHTON_HAMMOND, C15, R1, W1, L1, 0, 8, 0,
179 		"bitmaps/knobs/hammondblack.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
180 	{"Upper Drawbar 2", BRIGHTON_HAMMOND, C16, R1, W1, L1, 0, 8, 0,
181 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
182 	{"Upper Drawbar 1 3/5", BRIGHTON_HAMMOND, C17, R1, W1, L1, 0, 8, 0,
183 		"bitmaps/knobs/hammondblack.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
184 	{"Upper Drawbar 1 1/3", BRIGHTON_HAMMOND, C18, R1, W1, L1, 0, 8, 0,
185 		"bitmaps/knobs/hammondblack.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
186 	{"Upper Drawbar 1", BRIGHTON_HAMMOND, C19, R1, W1, L1, 0, 8, 0,
187 		"bitmaps/knobs/hammondwhite.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
188 
189 	/* 18 - switches, etc */
190 	{"Leslie", 2, MC1, MR1, MW1, MH1, 0, 1, 0,
191 		"bitmaps/buttons/rockersmooth.xpm",
192 		"bitmaps/buttons/rockersmoothd.xpm", 0},
193 	{"Reverb", 2, MC2, MR1, MW1, MH1, 0, 1, 0,
194 		"bitmaps/buttons/rockersmooth.xpm",
195 		"bitmaps/buttons/rockersmoothd.xpm", 0},
196 	{"VibraChorus", 0, MC2 + 57, MR1 + 70, MW1 + 10, MH1, 0, 6, 0, 0, 0, 0},
197 	{"Bright", 2, MC3, MR1, MW1, MH1, 0, 1, 0,
198 		"bitmaps/buttons/rockersmooth.xpm",
199 		"bitmaps/buttons/rockersmoothd.xpm", 0},
200 
201 	/* 22 - perc switches, etc */
202 	{"Perc 4", 2, MC4, MR1, MW1, MH1, 0, 1, 0,
203 		"bitmaps/buttons/rockersmooth.xpm",
204 		"bitmaps/buttons/rockersmoothd.xpm", 0},
205 	{"Perc 2 2/3", 2, MC5, MR1, MW1, MH1, 0, 1, 0,
206 		"bitmaps/buttons/rockersmooth.xpm",
207 		"bitmaps/buttons/rockersmoothd.xpm", 0},
208 	{"Perc Slow", 2, MC6, MR1, MW1, MH1, 0, 1, 0,
209 		"bitmaps/buttons/rockersmooth.xpm",
210 		"bitmaps/buttons/rockersmoothd.xpm", 0},
211 	{"Perc Soft", 2, MC7, MR1, MW1, MH1, 0, 1, 0,
212 		"bitmaps/buttons/rockersmooth.xpm",
213 		"bitmaps/buttons/rockersmoothd.xpm", 0},
214 
215 	/* 26 - Bass drawbars */
216 	{"Bass Drawbar 16", BRIGHTON_HAMMOND, Cm1, R1, W1, L1, 0, 8, 0,
217 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
218 	{"Bass Drawbar 8", BRIGHTON_HAMMOND, Cm2, R1, W1, L1, 0, 8, 0,
219 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_REVERSE|BRIGHTON_HSCALE},
220 
221 	/*
222 	 * 28 - Dummies. May one day extend the bass drawbar configuration as per
223 	 * some other emulations. It is extremely easy to do, just not convinved it
224 	 * really make sense.
225 	 */
226 	{"", BRIGHTON_HAMMOND, Cm2, R1, W1, L1, 0, 8, 0,
227 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
228 	{"", BRIGHTON_HAMMOND, Cm1, R1, W1, L1, 0, 8, 0,
229 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
230 	{"", BRIGHTON_HAMMOND, Cm2, R1, W1, L1, 0, 8, 0,
231 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
232 	{"", BRIGHTON_HAMMOND, Cm1, R1, W1, L1, 0, 8, 0,
233 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
234 	{"", BRIGHTON_HAMMOND, Cm2, R1, W1, L1, 0, 8, 0,
235 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
236 	{"", BRIGHTON_HAMMOND, Cm1, R1, W1, L1, 0, 8, 0,
237 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
238 	{"", BRIGHTON_HAMMOND, Cm2, R1, W1, L1, 0, 8, 0,
239 		"bitmaps/knobs/hammondbrown.xpm", 0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
240 };
241 
242 static brightonLocations volume[1] = {
243 	{"MasterVolume", 0, 125, 125, 750, 750, 0, 1, 0, 0, 0, 0},
244 };
245 
246 static brightonLocations leslie[2] = {
247 	{"Leslie On/Off", 2, 100, 600, 800, 200, 0, 1, 0,
248 		"bitmaps/buttons/sw3.xpm",
249 		"bitmaps/buttons/sw5.xpm", BRIGHTON_VERTICAL|BRIGHTON_NOSHADOW},
250 	{"", 2, 100, 100, 800, 200, 0, 1, 0,
251 	/*
252 	 * Use a slighly older rocker than the plastic white, looks mildly more
253 	 * authentic.
254 		"bitmaps/buttons/rockerwhite.xpm", 0, 0}
255 	 */
256 		"bitmaps/buttons/sw3.xpm",
257 		"bitmaps/buttons/sw5.xpm", BRIGHTON_VERTICAL|BRIGHTON_NOSHADOW}
258 };
259 
260 #define mR1 100
261 #define mR2 300
262 #define mR3 550
263 #define mR4 800
264 
265 #define mC1 50
266 #define mC2 213
267 #define mC3 376
268 #define mC4 539
269 #define mC5 705
270 
271 #define S4 100
272 #define S5 150
273 
274 static brightonLocations mem[MEM_COUNT] = {
275 	/* memories */
276 	{"", 2, mC5, mR4, S4, S5, 0, 1, 0,
277 		"bitmaps/buttons/pressoffg.xpm",
278 		"bitmaps/buttons/pressong.xpm", 0},
279 	{"", 2, mC1, mR3, S4, S5, 0, 1, 0,
280 		"bitmaps/buttons/pressoffg.xpm",
281 		"bitmaps/buttons/pressong.xpm", 0},
282 	{"", 2, mC2, mR3, S4, S5, 0, 1, 0,
283 		"bitmaps/buttons/pressoffg.xpm",
284 		"bitmaps/buttons/pressong.xpm", 0},
285 	{"", 2, mC3, mR3, S4, S5, 0, 1, 0,
286 		"bitmaps/buttons/pressoffg.xpm",
287 		"bitmaps/buttons/pressong.xpm", 0},
288 	{"", 2, mC4, mR3, S4, S5, 0, 1, 0,
289 		"bitmaps/buttons/pressoffg.xpm",
290 		"bitmaps/buttons/pressong.xpm", 0},
291 	{"", 2, mC5, mR3, S4, S5, 0, 1, 0,
292 		"bitmaps/buttons/pressoffg.xpm",
293 		"bitmaps/buttons/pressong.xpm", 0},
294 	{"", 2, mC1, mR4, S4, S5, 0, 1, 0,
295 		"bitmaps/buttons/pressoffg.xpm",
296 		"bitmaps/buttons/pressong.xpm", 0},
297 	{"", 2, mC2, mR4, S4, S5, 0, 1, 0,
298 		"bitmaps/buttons/pressoffg.xpm",
299 		"bitmaps/buttons/pressong.xpm", 0},
300 	{"", 2, mC3, mR4, S4, S5, 0, 1, 0,
301 		"bitmaps/buttons/pressoffg.xpm",
302 		"bitmaps/buttons/pressong.xpm", 0},
303 	{"", 2, mC4, mR4, S4, S5, 0, 1, 0,
304 		"bitmaps/buttons/pressoffg.xpm",
305 		"bitmaps/buttons/pressong.xpm", 0},
306 	/* midi U, D, Load, Save */
307 	{"", 2, mC1, mR2, S4, S5, 0, 1, 0,
308 		"bitmaps/buttons/pressoff.xpm",
309 		"bitmaps/buttons/presson.xpm", BRIGHTON_CHECKBUTTON},
310 	{"", 2, mC2, mR2, S4, S5, 0, 1, 0,
311 		"bitmaps/buttons/pressoff.xpm",
312 		"bitmaps/buttons/presson.xpm", BRIGHTON_CHECKBUTTON},
313 	{"", 2, mC4, mR2, S4, S5, 0, 1, 0,
314 		"bitmaps/buttons/pressoffg.xpm",
315 		"bitmaps/buttons/pressong.xpm", BRIGHTON_CHECKBUTTON},
316 	{"", 2, mC3, mR2, S4, S5, 0, 1, 0,
317 		"bitmaps/buttons/pressoffo.xpm",
318 		"bitmaps/buttons/pressono.xpm", BRIGHTON_CHECKBUTTON},
319 	{"", 2, mC5, mR2, S4, S5, 0, 1, 0,
320 		"bitmaps/buttons/pressoff.xpm",
321 		"bitmaps/buttons/presson.xpm", BRIGHTON_CHECKBUTTON},
322 	/* display */
323 	{"", 3, mC1, mR1, 750, 125, 0, 1, 0, 0, 0, 0},
324 };
325 
326 #define OD1 90
327 #define OD2 92
328 #define OD3 70
329 
330 #define OC1 65
331 #define OC2 (OC1 + OD1 + 50)
332 #define OC3 (OC2 + OD1)
333 #define OC4 (OC3 + OD1)
334 #define OC5 (OC4 + OD1)
335 #define OC6 (OC5 + OD1)
336 #define OC7 (OC6 + OD1)
337 #define OC8 (OC7 + OD1)
338 #define OC9 (OC8 + OD1)
339 #define OC10 (OC9 + OD1)
340 
341 #define OR1 23
342 #define OR2 (OR1 + OD2)
343 #define OR3 (OR2 + OD2)
344 #define OR4 (OR3 + OD2)
345 
346 #define OR5 (OR1 + 250)
347 #define OR6 (OR5 + 250)
348 #define OR7 (OR6 + 250)
349 
350 #define OS1 20
351 #define OS2 88
352 #define OS3 150
353 static brightonLocations opts[OPTS_COUNT] = {
354 	/* Leslie type - 26 */
355 	{"Leslie Separate", 2, OC1, OR1, OS1, OS2, 0, 1, 0,
356 		"bitmaps/buttons/pressoff.xpm",
357 		"bitmaps/buttons/presson.xpm", 0},
358 	{"Leslie Sync", 2, OC1, OR2, OS1, OS2, 0, 1, 0,
359 		"bitmaps/buttons/pressoff.xpm",
360 		"bitmaps/buttons/presson.xpm", 0},
361 	{"Leslie NoBass", 2, OC1, OR3, OS1, OS2, 0, 1, 0,
362 		"bitmaps/buttons/pressoff.xpm",
363 		"bitmaps/buttons/presson.xpm", 0},
364 	{"Leslie Break", 2, OC1, OR4, OS1, OS2, 0, 1, 0,
365 		"bitmaps/buttons/pressoffg.xpm",
366 		"bitmaps/buttons/pressong.xpm", 0},
367 	/* Leslie global - 30 */
368 	{"Leslie X-Over", 0, OC2, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreynew.xpm",
369 		0, BRIGHTON_NOSHADOW},
370 	{"Leslie Inertia", 0, OC3, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreynew.xpm",
371 		0, BRIGHTON_NOSHADOW},
372 	/* Leslie HS - 32 */
373 	{"Leslie HighFreq", 0, OC5, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreennew.xpm",
374 		0, BRIGHTON_NOSHADOW},
375 	{"Leslie HighDepth", 0, OC6, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreennew.xpm",
376 		0, BRIGHTON_NOSHADOW},
377 	{"Leslie HighPhase", 0, OC7, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreennew.xpm",
378 		0, BRIGHTON_NOSHADOW},
379 	/* Leslie global - 35 */
380 	{"Leslie Overdrive", 0, OC4, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobrednew.xpm",
381 		0, BRIGHTON_NOSHADOW},
382 	/* Leslie LS - 37 */
383 	{"Leslie LowFreq", 0, OC8, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobyellownew.xpm",
384 		0, BRIGHTON_NOSHADOW},
385 	{"Leslie LowDepth", 0, OC9, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobyellownew.xpm",
386 		0, BRIGHTON_NOSHADOW},
387 	{"Leslie LowPhase", 0, OC10, OR1, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobyellownew.xpm",
388 		0, BRIGHTON_NOSHADOW},
389 	/* VC Params - 40 */
390 	{"VibraChorus Phase", 0, OC2, OR5, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
391 		0, BRIGHTON_NOSHADOW},
392 	{"VibraChorus LC", 0, OC3, OR5, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
393 		0, BRIGHTON_NOSHADOW},
394 	{"VibraChorus Depth", 0, OC4, OR5, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
395 		0, BRIGHTON_NOSHADOW},
396 	/* Envelopes 43 */
397 	{"Perc Fast Decay", 0, OC2, OR6, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreynew.xpm",
398 		0, BRIGHTON_NOSHADOW},
399 	{"Perc Slow Decay", 0, OC3, OR6, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreynew.xpm",
400 		0, BRIGHTON_NOSHADOW},
401 	{"Perc Fast Attack", 0, OC5, OR6, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreynew.xpm",
402 		0, BRIGHTON_NOSHADOW},
403 	{"Perc Slow Attack", 0, OC6, OR6, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreynew.xpm",
404 		0, BRIGHTON_NOSHADOW},
405 	/* Diverse - 47 */
406 	{"Preacher", 2, OC1, OR7 - 10, OS1, OS2, 0, 1, 0,
407 		"bitmaps/buttons/pressoff.xpm",
408 		"bitmaps/buttons/presson.xpm", 0},
409 	{"Compression", 2, OC1, OR7 + OD2 - 10, OS1, OS2, 0, 1, 0,
410 		"bitmaps/buttons/pressoffg.xpm",
411 		"bitmaps/buttons/pressong.xpm", 0},
412 	{"Bright", 0, OC2, OR7, OS3, OS3, 0, 7, 0, "bitmaps/knobs/knobyellownew.xpm",
413 		0, BRIGHTON_NOSHADOW},
414 	{"Click", 0, OC3, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobrednew.xpm",
415 		0, BRIGHTON_NOSHADOW},
416 	{"Leslie T Phase", 0, OC10, OR5, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobyellownew.xpm",
417 		0, BRIGHTON_NOSHADOW},
418 	{"Damping", 0, OC4, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobyellownew.xpm",
419 		0, BRIGHTON_NOSHADOW},
420 	/* Hammond chorus phase delay 53 */
421 	{"VibraChorus PD", 0, OC5, OR5, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobgreynew.xpm",
422 		0, BRIGHTON_NOSHADOW},
423 /* Five reverb controls from 27 */
424 	{"Reverb Decay", 0, OC6, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
425 		0, BRIGHTON_NOSHADOW},
426 	{"Reverb Drive", 0, OC7, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
427 		0, BRIGHTON_NOSHADOW},
428 	{"Reverb Crossover", 0, OC8, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
429 		0, BRIGHTON_NOSHADOW},
430 	{"Reverb Feedback", 0, OC9, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
431 		0, BRIGHTON_NOSHADOW},
432 	{"Reverb Wet", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
433 		0, BRIGHTON_NOSHADOW},
434 
435 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
436 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
437 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
438 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
439 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
440 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
441 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
442 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
443 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
444 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
445 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
446 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
447 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
448 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
449 	{"", 0, OC10, OR7, OS3, OS3, 0, 1, 0, "bitmaps/knobs/knobbluenew.xpm",
450 		0, BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
451 };
452 
453 static int commonPreset = -1;
454 
455 static void
commonPresets(brightonWindow * win,guiSynth * synth,int index,float value)456 commonPresets(brightonWindow *win, guiSynth *synth, int index, float value)
457 {
458 	if (value == 0.0) {
459 		if (index != 23)
460 			commonPreset = -1;
461 		return;
462 	}
463 
464 	if (commonPreset != -1)
465 	{
466 		brightonEvent event;
467 
468 		event.command = BRIGHTON_PARAMCHANGE;
469 		event.type = BRIGHTON_FLOAT;
470 		event.value = 0;
471 
472 /*	printf("commonPresets(): %i %i\n", index, commonPreset); */
473 		if (index == 23)
474 		{
475 			if (brightonDoubleClick(dc))
476 				saveMemory(synth, "hammondB3", 0, synth->bank + synth->location,
477 					FIRST_DEV);
478 
479 			brightonParamChange(synth->win, KEY_PANEL2, index - 12, &event);
480 
481 			return;
482 		}
483 
484 		if (commonPreset < 12)
485 			/* Key release upper manual */
486 			brightonParamChange(synth->win, KEY_PANEL1, commonPreset, &event);
487 		else
488 			/* Key release lower manual, commonPreset - 12 */
489 			brightonParamChange(synth->win, KEY_PANEL2, commonPreset - 12,
490 				&event);
491 	}
492 
493 	synth->location = commonPreset = index;
494 
495 	loadMemory(synth, "hammondB3", 0, synth->bank + synth->location,
496 		C_COUNT, FIRST_DEV, 0);
497 }
498 
499 static int
umCallback(brightonWindow * win,int panel,int index,float value)500 umCallback(brightonWindow * win, int panel, int index, float value)
501 {
502 	guiSynth *synth = findSynth(global.synths, win);
503 
504 	if (global.libtest)
505 		return(0);
506 
507 	if (synth->flags & REQ_MIDI_DEBUG)
508 		printf("umCallback(%i, %i, %f)\n", global.libtest, index, value);
509 
510 	/*
511 	 * If the code from 0 to 11 then this will become the preset section and
512 	 * be used to load the first 24 memories.
513 	 */
514 	if (index < 12)
515 	{
516 /*		printf("umCallback(%x, %i, %i, %f): %i %i\n", synth, panel, index, */
517 /*			value, synth->transpose, global.controlfd); */
518 		commonPresets(win, synth, index, value);
519 		return(0);
520 	}
521 
522 	/*
523 	 * Want to send a note event, on or off, for this index + transpose.
524 	 */
525 	if (value)
526 		bristolMidiSendMsg(manual.controlfd, synth->midichannel,
527 			BRISTOL_EVENT_KEYON, 0, index + synth->transpose);
528 	else
529 		bristolMidiSendMsg(manual.controlfd, synth->midichannel,
530 			BRISTOL_EVENT_KEYOFF, 0, index + synth->transpose);
531 
532 	return(0);
533 }
534 
535 static int
lmCallback(brightonWindow * win,int panel,int index,float value)536 lmCallback(brightonWindow * win, int panel, int index, float value)
537 {
538 	guiSynth *synth = findSynth(global.synths, win);
539 
540 	if (global.libtest)
541 		return(0);
542 
543 	if (synth->flags & REQ_MIDI_DEBUG)
544 		printf("lmCallback(%i, %i, %f)\n", panel, index, value);
545 
546 	/*
547 	 * If the code from 0 to 11 then this will become the preset section and
548 	 * be used to load the first 24 memories.
549 	 */
550 	if (index < 12)
551 	{
552 /*		printf("lmCallback(%x, %i, %i, %f): %i %i\n", synth, panel, index, */
553 /*			value, synth->transpose, global.controlfd); */
554 
555 		commonPresets(win, synth, index + 12, value);
556 		return(0);
557 	}
558 
559 	/*
560 	 * Want to send a note event, on or off, for this index + transpose.
561 	 */
562 	if (value)
563 		bristolMidiSendMsg(manual.controlfd, synth->midichannel + 1,
564 			BRISTOL_EVENT_KEYON, 0, index + synth->transpose);
565 	else
566 		bristolMidiSendMsg(manual.controlfd, synth->midichannel + 1,
567 			BRISTOL_EVENT_KEYOFF, 0, index + synth->transpose);
568 
569 	return(0);
570 }
571 
572 static int
hammondB3destroy(brightonWindow * win)573 hammondB3destroy(brightonWindow *win)
574 {
575 	guiSynth *synth = findSynth(global.synths, win);
576 
577 	printf("hammondB3destroy(%p): %i\n", win, synth->midichannel);
578 
579 	/*
580 	 * Since we registered two synths, we now need to remove the upper
581 	 * manual.
582 	 */
583 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 127, 0,
584 		BRISTOL_EXIT_ALGO);
585 	bristolMidiSendMsg(global.controlfd, synth->sid, 127, 0,
586 		BRISTOL_EXIT_ALGO);
587 	return(0);
588 }
589 
590 int
b3PedalCallback(brightonWindow * win,int panel,int index,float value)591 b3PedalCallback(brightonWindow *win, int panel, int index, float value)
592 {
593 	guiSynth *synth = findSynth(global.synths, win);
594 
595 	if ((synth->flags & OPERATIONAL) == 0)
596 		return(0);
597 
598 	/*
599 	 * Want to send a note event, on or off, for this index + transpose.
600 	 */
601 	if (value > 0)
602 		bristolMidiSendMsg(global.controlfd, synth->midichannel + 1,
603 			BRISTOL_EVENT_KEYON, 0, index);
604 	else
605 		bristolMidiSendMsg(global.controlfd, synth->midichannel + 1,
606 			BRISTOL_EVENT_KEYOFF, 0, index);
607 
608 	return(0);
609 }
610 
611 /*
612  * This is a set of globals for the main window rendering. Again taken from
613  * include/brighton.h
614  */
615 brightonApp hammondB3App = {
616 	"hammondB3",
617 	0, /* no blueprint on wood background. */
618 	"bitmaps/textures/wood3.xpm",
619 	0, /* BRIGHTON_STRETCH, //flags */
620 	hammondB3Init,
621 	hammondB3Configure, /* 3 callbacks, unused? */
622 	hammondB3MidiCallback,
623 	hammondB3destroy,
624 	{-1, 0, 2, 2, 5, 175, 0, 0},
625 	765, 400, 0, 0,
626 	15,
627 	{
628 		{
629 			"HammondB3",
630 			"bitmaps/blueprints/hammondB3.xpm",
631 			"bitmaps/textures/metal5.xpm",
632 			0, /*BRIGHTON_STRETCH, // flags */
633 			0,
634 			0,
635 			hammondB3Callback,
636 			25, 122, 950, 238,
637 			C_COUNT,
638 			locations
639 		},
640 		{
641 			"Opts",
642 			"bitmaps/blueprints/hammondB3opts.xpm",
643 			"bitmaps/textures/wood3.xpm",
644 			0x020, /*BRIGHTON_STRETCH, // flags */
645 			0,
646 			0,
647 			hammondB3Callback,
648 			74, 357, 632, 440,
649 			/*70, 440, 470, 500, */
650 			OPTS_COUNT,
651 			opts
652 		},
653 		{
654 			"volume",
655 			0,
656 			"bitmaps/textures/metal5.xpm",
657 			0, /*BRIGHTON_STRETCH, // flags */
658 			0,
659 			0,
660 			hammondB3Callback,
661 			25, 427, 47, 89,
662 			1,
663 			volume
664 		},
665 		{
666 			"leslie",
667 			0,
668 			"bitmaps/textures/metal5.xpm",
669 			0, /*BRIGHTON_STRETCH, // flags */
670 			0,
671 			0,
672 			hammondB3Callback,
673 			30, 707, 40, 89,
674 			2,
675 			leslie
676 		},
677 		{
678 			"Memory",
679 			"bitmaps/blueprints/hammondB3mem.xpm",
680 			"bitmaps/textures/wood3.xpm",
681 			0x020, /*BRIGHTON_STRETCH, // flags */
682 			0,
683 			0,
684 			hammondB3Callback,
685 			704, 358, 270, 440,
686 			/*70, 440, 470, 500, */
687 			MEM_COUNT,
688 			mem
689 		},
690 		{
691 			"HammondB3bar",
692 			0,
693 			"bitmaps/textures/metal5.xpm",
694 			0, /*flags */
695 			0,
696 			0,
697 			0,
698 			25, 561, 950, 29,
699 			0,
700 			0
701 		},
702 		{
703 			"Keyboard",
704 			0,
705 			"bitmaps/newkeys/hkbg.xpm", /* flags */
706 			BRIGHTON_STRETCH,
707 			0,
708 			0,
709 			umCallback,
710 			70, 357, 878, 211,
711 			KEY_COUNT_6_OCTAVE,
712 			keys6hammond
713 		},
714 		{
715 			"Keyboard",
716 			0,
717 			"bitmaps/newkeys/hkbg.xpm", /* flags */
718 			BRIGHTON_STRETCH,
719 			0,
720 			0,
721 			lmCallback,
722 			74, 589, 870, 211,
723 			KEY_COUNT_6_OCTAVE,
724 			keys6hammond
725 		},
726 		{
727 			"Pedalboard",
728 			0,
729 			"bitmaps/textures/wood6.xpm",
730 			BRIGHTON_STRETCH,
731 			0,
732 			0,
733 			b3PedalCallback,
734 			260, 823, 500, 167,
735 			KEY_COUNT_PEDAL,
736 			pedalBoard
737 		},
738 		{
739 			"Wood Edge",
740 			0,
741 			"bitmaps/textures/wood.xpm",
742 			BRIGHTON_STRETCH|BRIGHTON_VERTICAL, /* flags */
743 			0,
744 			0,
745 			0,
746 			0, 0, 25, 813,
747 			0,
748 			0
749 		},
750 		{
751 			"Wood Edge",
752 			0,
753 			"bitmaps/textures/wood.xpm",
754 			BRIGHTON_STRETCH|BRIGHTON_VERTICAL, /*flags */
755 			0,
756 			0,
757 			0,
758 			975, 0, 25, 813,
759 			0,
760 			0
761 		},
762 		{
763 			"Wood",
764 			0,
765 			"bitmaps/textures/wood4.xpm",
766 			0,
767 			0,
768 			0,
769 			0,
770 			25, 24, 950, 57,
771 			0,
772 			0
773 		},
774 		{
775 			"Wood",
776 			0,
777 			"bitmaps/textures/wood4.xpm",
778 			BRIGHTON_STRETCH,
779 			0,
780 			0,
781 			0,
782 			25, 49, 950, 73,
783 			0,
784 			0
785 		},
786 		{
787 			"Wood",
788 			0,
789 			"bitmaps/textures/wood5.xpm",
790 			BRIGHTON_STRETCH, /*flags */
791 			0,
792 			0,
793 			0,
794 			25, 49, 950, 122,
795 			0,
796 			0
797 		},
798 		{
799 			"Pedalboard",
800 			0,
801 			"bitmaps/keys/vkbg.xpm",
802 			BRIGHTON_STRETCH,
803 			0,
804 			0,
805 			0,
806 			0, 813, 1000, 187,
807 			0,
808 			0
809 		},
810 	}
811 };
812 
813 static void
b3SendMsg(int fd,int chan,int c,int o,int v)814 b3SendMsg(int fd, int chan, int c, int o, int v)
815 {
816 /*printf("b3SendMsg(%i, %i, %i, %i, %i) [%i, %i]\n", fd, chan, c, o, v, */
817 /*global.controlfd, manual.controlfd); */
818 	bristolMidiSendMsg(global.controlfd, chan, c, o, v);
819 	bristolMidiSendMsg(manual.controlfd, chan + 1, c, o, v);
820 }
821 
822 static void
hammondB3Memory(guiSynth * synth,int fd,int chan,int c,int o,int v)823 hammondB3Memory(guiSynth *synth, int fd, int chan, int c, int o, int v)
824 {
825 	brightonEvent event;
826 
827 /*printf("hammondB3Memory(%i, %i)\n", c, o); */
828 
829 	if (synth->dispatch[RADIOSET_1].other2)
830 	{
831 		synth->dispatch[RADIOSET_1].other2 = 0;
832 		return;
833 	}
834 
835 	switch (c) {
836 		default:
837 		case 0:
838 			/*
839 			 * We want to make these into memory buttons. To do so we need to
840 			 * know what the last active button was, and deactivate its
841 			 * display, then send any message which represents the most
842 			 * recently configured value. Since this is a memory button we do
843 			 * not have much issue with the message, but we are concerned with
844 			 * the display.
845 			 */
846 			if (synth->dispatch[RADIOSET_1].other1 != -1)
847 			{
848 				synth->dispatch[RADIOSET_1].other2 = 1;
849 
850 				if (synth->dispatch[RADIOSET_1].other1 != o)
851 					event.value = 0;
852 				else
853 					event.value = 1;
854 
855 				brightonParamChange(synth->win, DISPLAY_PAN,
856 					synth->dispatch[RADIOSET_1].other1, &event);
857 			}
858 			synth->dispatch[RADIOSET_1].other1 = o;
859 
860 			if (synth->flags & BANK_SELECT) {
861 				if ((synth->bank * 10 + o * 10) >= 1000)
862 				{
863 					synth->location = o;
864 					synth->flags &= ~BANK_SELECT;
865 					if (loadMemory(synth, "hammondB3", 0,
866 						synth->bank + synth->location,
867 						synth->mem.active, FIRST_DEV, BRISTOL_STAT) < 0)
868 						displayPanelText(synth, "FRE",
869 							synth->bank + synth->location,
870 							DISPLAY_PAN, DISPLAY_DEV);
871 					else
872 						displayPanelText(synth, "PRG",
873 							synth->bank + synth->location,
874 							DISPLAY_PAN, DISPLAY_DEV);
875 				} else {
876 					synth->bank = synth->bank * 10 + o * 10;
877 					if (loadMemory(synth, "hammondB3", 0,
878 						synth->bank + synth->location,
879 						synth->mem.active, FIRST_DEV, BRISTOL_STAT) < 0)
880 						displayPanelText(synth, "FRE",
881 							synth->bank + synth->location,
882 							DISPLAY_PAN, DISPLAY_DEV);
883 					else
884 						displayPanelText(synth, "BANK",
885 							synth->bank + synth->location,
886 							DISPLAY_PAN, DISPLAY_DEV);
887 				}
888 			} else {
889 				synth->location = o;
890 				if (loadMemory(synth, "hammondB3", 0,
891 					synth->bank + synth->location,
892 					synth->mem.active, FIRST_DEV, BRISTOL_STAT) < 0)
893 					displayPanelText(synth, "FRE",
894 						synth->bank + synth->location,
895 						DISPLAY_PAN, DISPLAY_DEV);
896 				else
897 					displayPanelText(synth, "PRG",
898 						synth->bank + synth->location,
899 						DISPLAY_PAN, DISPLAY_DEV);
900 			}
901 			break;
902 		case 1:
903 			synth->flags |= MEM_LOADING;
904 			if (loadMemory(synth, "hammondB3", 0, synth->bank + synth->location,
905 				synth->mem.active, FIRST_DEV, 0) < 0)
906 				displayPanelText(synth, "FRE", synth->bank + synth->location,
907 					DISPLAY_PAN, DISPLAY_DEV);
908 			else
909 				displayPanelText(synth, "PRG", synth->bank + synth->location,
910 					DISPLAY_PAN, DISPLAY_DEV);
911 			synth->flags &= ~MEM_LOADING;
912 			synth->flags &= ~BANK_SELECT;
913 			break;
914 		case 2:
915 			saveMemory(synth, "hammondB3", 0, synth->bank + synth->location,
916 				FIRST_DEV);
917 			displayPanelText(synth, "PRG", synth->bank + synth->location,
918 				DISPLAY_PAN, DISPLAY_DEV);
919 			synth->flags &= ~BANK_SELECT;
920 			break;
921 		case 3:
922 			if (synth->flags & BANK_SELECT) {
923 				synth->flags &= ~BANK_SELECT;
924 				if (loadMemory(synth, "hammondB3", 0,
925 					synth->bank + synth->location,
926 					synth->mem.active, FIRST_DEV, BRISTOL_STAT) < 0)
927 					displayPanelText(synth, "FRE",
928 						synth->bank + synth->location,
929 						DISPLAY_PAN, DISPLAY_DEV);
930 				else
931 					displayPanelText(synth, "PRG",
932 						synth->bank + synth->location,
933 						DISPLAY_PAN, DISPLAY_DEV);
934 			} else {
935 				synth->bank = 0;
936 				displayPanelText(synth, "BANK", synth->bank, DISPLAY_PAN,
937 					DISPLAY_DEV);
938 				synth->flags |= BANK_SELECT;
939 			}
940 			break;
941 	}
942 /*	printf("	hammondB3Memory(B: %i L %i: %i)\n", */
943 /*		synth->bank, synth->location, o); */
944 }
945 
946 static void
hammondB3Midi(guiSynth * synth,int fd,int chan,int c,int o,int v)947 hammondB3Midi(guiSynth *synth, int fd, int chan, int c, int o, int v)
948 {
949 	int newchan;
950 /*	printf("hammondB3Midi(%i %i %i %i %i)\n", fd, chan, c, o, v); */
951 
952 	if ((synth->flags & OPERATIONAL) == 0)
953 		return;
954 
955 	if (c == 1) {
956 		if ((newchan = synth->midichannel - 1) < 0)
957 		{
958 			synth->midichannel = 0;
959 			return;
960 		}
961 	} else {
962 		/*
963 		 * On the upper side we need to reserve two midi channels
964 		 */
965 		if ((newchan = synth->midichannel + 1) >= 15)
966 		{
967 			synth->midichannel = 14;
968 			return;
969 		}
970 	}
971 
972 	/*
973 	 * Lower manual midi channel selection first
974 	 */
975 	bristolMidiSendMsg(manual.controlfd, synth->sid2,
976 		127, 0, (BRISTOL_MIDICHANNEL|newchan) + 1);
977 
978 	bristolMidiSendMsg(global.controlfd, synth->sid,
979 		127, 0, BRISTOL_MIDICHANNEL|newchan);
980 
981 	synth->midichannel = newchan;
982 
983 	displayPanelText(synth, "MIDI", synth->midichannel + 1,
984 		DISPLAY_PAN, DISPLAY_DEV);
985 
986 }
987 
988 /*
989  * For the sake of ease of use, links have been placed here to be called
990  * by any of the devices created. They would be better in some other file,
991  * perhaps with this as a dispatch.
992  *
993  * Param refers to the device index in the locations table given below.
994  */
995 static int
hammondB3Callback(brightonWindow * win,int panel,int index,float value)996 hammondB3Callback(brightonWindow * win, int panel, int index, float value)
997 {
998 	guiSynth *synth = findSynth(global.synths, win);
999 	int sendvalue;
1000 
1001 /*printf("hammondB3Callback(%i, %i, %f): %x\n", panel, index, value, synth); */
1002 
1003 	if (synth == 0)
1004 		return(0);
1005 
1006 	if ((index >= DEVICE_COUNT) || ((synth->flags & OPERATIONAL) == 0))
1007 		return(0);
1008 
1009 	if (hammondB3App.resources[panel].devlocn[index].to == 1.0)
1010 		sendvalue = value * (CONTROLLER_RANGE - 1);
1011 	else
1012 		sendvalue = value;
1013 
1014 	switch (panel) {
1015 		default:
1016 		case 0:
1017 			break;
1018 		case 1:
1019 			index += OPTS_START;
1020 			break;
1021 		case 2:
1022 			index += VOL_START;
1023 			break;
1024 		case 3:
1025 			index += LESLIE_START;
1026 			break;
1027 		case 4:
1028 			index += MEM_START;
1029 			break;
1030 	}
1031 /*printf("index is now %i, %i %i\n", index, DEVICE_COUNT, ACTIVE_DEVS); */
1032 
1033 	synth->mem.param[index] = value;
1034 
1035 	if ((!global.libtest) || (index >= ACTIVE_DEVS) || (index == 18))
1036 		synth->dispatch[index].routine(synth,
1037 			global.controlfd, synth->sid,
1038 			synth->dispatch[index].controller,
1039 			synth->dispatch[index].operator,
1040 			sendvalue);
1041 
1042 #ifdef DEBUG
1043 	else
1044 		printf("dispatch[%x,%i](%i, %i, %i, %i, %i)\n", synth, index,
1045 			global.controlfd, synth->sid,
1046 			synth->dispatch[index].controller,
1047 			synth->dispatch[index].operator,
1048 			sendvalue);
1049 #endif
1050 
1051 	return(0);
1052 }
1053 
1054 static void
hammondB3Passthrough(float value)1055 hammondB3Passthrough(float value)
1056 {
1057 /*	printf("hammondB3Passthrough\n"); */
1058 }
1059 
1060 static void
doVolume(guiSynth * synth)1061 doVolume(guiSynth *synth)
1062 {
1063 	b3SendMsg(global.controlfd, synth->sid, 0, 4,
1064 		(int) (synth->mem.param[VOL_START] * C_RANGE_MIN_1));
1065 	b3SendMsg(global.controlfd, synth->sid2, 0, 4,
1066 		(int) (synth->mem.param[VOL_START] * C_RANGE_MIN_1));
1067 	b3SendMsg(global.controlfd, synth->sid2, 3, 4,
1068 		(int) (synth->mem.param[VOL_START] * C_RANGE_MIN_1));
1069 }
1070 
1071 static void
doLMSlider(guiSynth * synth,int fd,int chan,int cont,int op,int value)1072 doLMSlider(guiSynth *synth, int fd, int chan, int cont, int op, int value)
1073 {
1074 	int slidervalue;
1075 
1076 /*printf("doLMSlider(%x, %i, %i, %i, %i, %i)\n", */
1077 /*synth, fd, chan, cont, op, value); */
1078 
1079 	slidervalue = cont * 9 + value;
1080 
1081 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 0, 2, slidervalue);
1082 }
1083 
1084 static void
doPedalSlider(guiSynth * synth,int fd,int chan,int cont,int op,int value)1085 doPedalSlider(guiSynth *synth, int fd, int chan, int cont, int op, int value)
1086 {
1087 	int slidervalue;
1088 
1089 	slidervalue = cont * 9 + value;
1090 
1091 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 3, 2, slidervalue);
1092 }
1093 
1094 static void
doDrawbar(guiSynth * synth,int fd,int chan,int cont,int op,int value)1095 doDrawbar(guiSynth *synth, int fd, int chan, int cont, int op, int value)
1096 {
1097 	int slidervalue;
1098 
1099 	/*printf("doDrawbar(%x, %i, %i, %i, %i, %i)\n", */
1100 	/*	synth, fd, chan, cont, op, value); */
1101 
1102 	slidervalue = cont * 9 + value;
1103 
1104 	bristolMidiSendMsg(global.controlfd, synth->sid, 0, 2, slidervalue);
1105 }
1106 
1107 static void
hammondB3Switch(guiSynth * id,int fd,int chan,int cont,int op,int value)1108 hammondB3Switch(guiSynth *id, int fd, int chan, int cont, int op, int value)
1109 {
1110 	brightonEvent event;
1111 
1112 /*	printf("hammondB3Switch(%x, %i, %i, %i, %i, %i)\n", */
1113 /*		id, fd, chan, cont, op, value); */
1114 
1115 	id->flags &= ~OPERATIONAL;
1116 	/*
1117 	 * If the sendvalue is zero, then withdraw the opts window, draw the
1118 	 * keyboard window, and vice versa.
1119 	 */
1120 	if (value == 0)
1121 	{
1122 		event.type = BRIGHTON_EXPOSE;
1123 		event.intvalue = 0;
1124 		brightonParamChange(id->win, 1, -1, &event);
1125 		event.intvalue = 0;
1126 		brightonParamChange(id->win, 4, -1, &event);
1127 		event.intvalue = 1;
1128 		brightonParamChange(id->win, 5, -1, &event);
1129 		event.intvalue = 1;
1130 		brightonParamChange(id->win, 6, -1, &event);
1131 		event.intvalue = 1;
1132 		brightonParamChange(id->win, 7, -1, &event);
1133 
1134 		shade_id = brightonPut(id->win,
1135 			"bitmaps/blueprints/hammondB3shade.xpm", 0, 0, id->win->width,
1136 				id->win->height);
1137 	} else {
1138 		brightonRemove(id->win, shade_id);
1139 
1140 		event.type = BRIGHTON_EXPOSE;
1141 		event.intvalue = 0;
1142 		brightonParamChange(id->win, 5, -1, &event);
1143 		event.intvalue = 0;
1144 		brightonParamChange(id->win, 6, -1, &event);
1145 		event.intvalue = 0;
1146 		brightonParamChange(id->win, 7, -1, &event);
1147 		event.intvalue = 1;
1148 		brightonParamChange(id->win, 1, -1, &event);
1149 		event.intvalue = 1;
1150 		brightonParamChange(id->win, 4, -1, &event);
1151 	}
1152 	id->flags |= OPERATIONAL;
1153 }
1154 
1155 static void
doVibra(guiSynth * synth,int fd,int chan,int cont,int op,int v)1156 doVibra(guiSynth *synth, int fd, int chan, int cont, int op, int v)
1157 {
1158 	/*
1159 	printf("doVibra(%i, %i, %i)\n", cont, op, v);
1160 	 * We get a value from 0 to 6.
1161 	 * 0 1 2 are vibra only, with speeds from the opts panel.
1162 	 * 3 is off
1163 	 * 4 5 6 are vibrachorus, with same respective speeds
1164 	 */
1165 	switch (op) {
1166 		case 0: /* Tap delay */
1167 			bristolMidiSendMsg(global.controlfd, synth->sid, 6, 0, v);
1168 			break;
1169 		case 1: /* Delay line progressive filtering */
1170 			bristolMidiSendMsg(global.controlfd, synth->sid, 6, 1, v);
1171 			break;
1172 		case 2:
1173 			doClick(synth);
1174 			if (v == 3) {
1175 				bristolMidiSendMsg(global.controlfd, synth->sid, 126, 0, 0);
1176 				return;
1177 			}
1178 			/*
1179 			 * Turn it on, set a depth and a VC.
1180 			 */
1181 			bristolMidiSendMsg(global.controlfd, synth->sid, 126, 0, 1);
1182 			if (v < 3) {
1183 				bristolMidiSendMsg(global.controlfd, synth->sid, 6, 2, 3 - v);
1184 				bristolMidiSendMsg(global.controlfd, synth->sid, 6, 4, 0);
1185 				return;
1186 			}
1187 			bristolMidiSendMsg(global.controlfd, synth->sid, 6, 2, v - 3);
1188 			bristolMidiSendMsg(global.controlfd, synth->sid, 6, 4, 1);
1189 			break;
1190 		case 3: /* Direct signal gain */
1191 			bristolMidiSendMsg(global.controlfd, synth->sid, 6, 3, v);
1192 			break;
1193 		case 4: /* Rate */
1194 			bristolMidiSendMsg(global.controlfd, synth->sid, 6, 5, v);
1195 			break;
1196 	}
1197 }
1198 
1199 #define LESLIE_ONOFF 18
1200 
1201 static void
doLeslieSpeed(guiSynth * synth)1202 doLeslieSpeed(guiSynth *synth)
1203 {
1204 	int speed, depth, phase;
1205 
1206 	if (synth->mem.param[LESLIE_ONOFF] == 0)
1207 	{
1208 		bristolMidiSendMsg(global.controlfd, synth->sid, 100, 7, 0);
1209 		return;
1210 	}
1211 
1212 	bristolMidiSendMsg(global.controlfd, synth->sid, 100, 4,
1213 		(int) (synth->mem.param[OPTS_START + 24] * C_RANGE_MIN_1));
1214 
1215 	/*
1216 	 * If we do not yet have another option, configure this as default
1217 	 */
1218 	if (synth->dispatch[OPTS_START + 1].other1 == 0)
1219 		synth->dispatch[OPTS_START + 1].other1 = 1;
1220 
1221 	bristolMidiSendMsg(global.controlfd, synth->sid, 100, 7,
1222 		(int) (synth->dispatch[OPTS_START + 1].other1));
1223 
1224 	if (synth->mem.param[LESLIE_START] == 0)
1225 	{
1226 		speed = synth->mem.param[OPTS_START + 6] * C_RANGE_MIN_1;
1227 		depth = synth->mem.param[OPTS_START + 7] * C_RANGE_MIN_1;
1228 		phase = synth->mem.param[OPTS_START + 8] * C_RANGE_MIN_1;
1229 	} else {
1230 		speed = synth->mem.param[OPTS_START + 10] * C_RANGE_MIN_1;
1231 		depth = synth->mem.param[OPTS_START + 11] * C_RANGE_MIN_1;
1232 		phase = synth->mem.param[OPTS_START + 12] * C_RANGE_MIN_1;
1233 	}
1234 	bristolMidiSendMsg(global.controlfd, synth->sid, 100, 0, speed);
1235 	bristolMidiSendMsg(global.controlfd, synth->sid, 100, 3, depth);
1236 	bristolMidiSendMsg(global.controlfd, synth->sid, 100, 2, phase);
1237 	bristolMidiSendMsg(global.controlfd, synth->sid, 100, 6,
1238 		(int) (synth->mem.param[OPTS_START + 4] * C_RANGE_MIN_1));
1239 	bristolMidiSendMsg(global.controlfd, synth->sid, 100, 1,
1240 		(int) (synth->mem.param[OPTS_START + 5] * C_RANGE_MIN_1));
1241 }
1242 
1243 static void
doReverbParam(guiSynth * synth,int fd,int chan,int cont,int op,int value)1244 doReverbParam(guiSynth *synth, int fd, int chan, int cont, int op, int value)
1245 {
1246 /*printf("doReverbParam(%i, %i, %i)\n", cont, op, value); */
1247 	if (op == 4)
1248 		bristolMidiSendMsg(global.controlfd, synth->sid, 101, 5, value);
1249 	bristolMidiSendMsg(global.controlfd, synth->sid, 101, op, value);
1250 }
1251 
1252 static void
doReverb(guiSynth * synth)1253 doReverb(guiSynth *synth)
1254 {
1255     if (synth->mem.param[DEVICE_START + 19] == 0)
1256 		bristolMidiSendMsg(global.controlfd, synth->sid, 101, 3, 0);
1257 	else
1258 		bristolMidiSendMsg(global.controlfd, synth->sid, 101, 3,
1259 			(int) (synth->mem.param[OPTS_START + 30] * C_RANGE_MIN_1));
1260 }
1261 
1262 static void
doDamping(guiSynth * synth,int fd,int chan,int cont,int op,int value)1263 doDamping(guiSynth *synth, int fd, int chan, int cont, int op, int value)
1264 {
1265 	bristolMidiSendMsg(global.controlfd, synth->sid, 0, 1, value);
1266 	bristolMidiSendMsg(global.controlfd, synth->sid2, 0, 1, value);
1267 }
1268 
1269 static void
doClick(guiSynth * synth)1270 doClick(guiSynth *synth)
1271 {
1272 	float scale = 1.0;
1273 
1274 	if (synth->mem.param[DEVICE_START + 20] != 3)
1275 		scale = 0.1;
1276 
1277 	/*
1278 	 * If we have VC enabled then reduce the click volume by half, otherwise
1279 	 * it is full strength.
1280 	 */
1281 	b3SendMsg(global.controlfd, synth->sid, 0, 6,
1282 		(int) (synth->mem.param[OPTS_START + 23] * C_RANGE_MIN_1 * scale));
1283 	b3SendMsg(global.controlfd, synth->sid2, 0, 6,
1284 		(int) (synth->mem.param[OPTS_START + 23] * C_RANGE_MIN_1 * scale));
1285 }
1286 
1287 static void
doPreacher(guiSynth * synth)1288 doPreacher(guiSynth *synth)
1289 {
1290 	if (synth->mem.param[OPTS_START + 20] == 0)
1291 	{
1292 		b3SendMsg(global.controlfd, synth->sid, 126, 3, 0);
1293 		b3SendMsg(global.controlfd, synth->sid, 0, 7, 0);
1294 		b3SendMsg(global.controlfd, synth->sid2, 0, 7, 0);
1295 		b3SendMsg(global.controlfd, synth->sid2, 3, 7, 0);
1296 	} else {
1297 		b3SendMsg(global.controlfd, synth->sid, 126, 3, 1);
1298 		b3SendMsg(global.controlfd, synth->sid, 0, 7, 1);
1299 		b3SendMsg(global.controlfd, synth->sid2, 0, 7, 1);
1300 		b3SendMsg(global.controlfd, synth->sid2, 3, 7, 1);
1301 	}
1302 }
1303 
1304 static void
doBright(guiSynth * synth)1305 doBright(guiSynth *synth)
1306 {
1307 /*printf("doBright()\n"); */
1308 	if (synth->mem.param[DEVICE_START + 21] == 0)
1309 	{
1310 		/*
1311 		 * Once to the hammond manager
1312 		 */
1313 		b3SendMsg(global.controlfd, synth->sid, 126, 1, 0);
1314 		/*
1315 		 * And to the sine oscillator
1316 		 */
1317 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 0);
1318 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 8);
1319 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 16);
1320 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 24);
1321 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 32);
1322 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 40);
1323 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 48);
1324 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 56);
1325 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 64);
1326 	} else {
1327 		b3SendMsg(global.controlfd, synth->sid, 126, 1,
1328 			(int) (synth->mem.param[OPTS_START + 22]));
1329 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 0 +
1330 			(int) (synth->mem.param[OPTS_START + 22]));
1331 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 8 +
1332 			(int) (synth->mem.param[OPTS_START + 22]));
1333 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 16 +
1334 			(int) (synth->mem.param[OPTS_START + 22]));
1335 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 24 +
1336 			(int) (synth->mem.param[OPTS_START + 22]));
1337 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 32 +
1338 			(int) (synth->mem.param[OPTS_START + 22]));
1339 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 40 +
1340 			(int) (synth->mem.param[OPTS_START + 22]));
1341 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 48 +
1342 			(int) (synth->mem.param[OPTS_START + 22]));
1343 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 56 +
1344 			(int) (synth->mem.param[OPTS_START + 22]));
1345 		b3SendMsg(global.controlfd, synth->sid, 0, 0, 64 +
1346 			(int) (synth->mem.param[OPTS_START + 22]));
1347 	}
1348 }
1349 
1350 static void
doCompress(guiSynth * synth)1351 doCompress(guiSynth *synth)
1352 {
1353 /*printf("doCompress()\n"); */
1354 	if (synth->mem.param[OPTS_START + 21] == 0)
1355 	{
1356 		b3SendMsg(global.controlfd, synth->sid, 126, 2, 0);
1357 	} else {
1358 		b3SendMsg(global.controlfd, synth->sid, 126, 2, 1);
1359 	}
1360 }
1361 
1362 static void
doGrooming(guiSynth * synth)1363 doGrooming(guiSynth *synth)
1364 {
1365 /*printf("doGrooming()\n"); */
1366 	if (synth->mem.param[DEVICE_START + 25] != 0)
1367 	{
1368 		b3SendMsg(global.controlfd, synth->sid, 1, 0,
1369 			(int) (synth->mem.param[OPTS_START + 18] * C_RANGE_MIN_1));
1370 	} else {
1371 		b3SendMsg(global.controlfd, synth->sid, 1, 0,
1372 			(int) (synth->mem.param[OPTS_START + 19] * C_RANGE_MIN_1));
1373 	}
1374 }
1375 
1376 static void
doPerc(guiSynth * synth)1377 doPerc(guiSynth *synth)
1378 {
1379 /*printf("doPerc()\n"); */
1380 	/*
1381 	 * 4 foot percussive
1382 	 */
1383 	if (synth->mem.param[DEVICE_START + 22] == 0)
1384 		bristolMidiSendMsg(global.controlfd, synth->sid, 0, 3, 24);
1385 	else
1386 		bristolMidiSendMsg(global.controlfd, synth->sid, 0, 3, 25);
1387 
1388 	/*
1389 	 * 2 1/3 foot percussive
1390 	 */
1391 	if (synth->mem.param[DEVICE_START + 23] == 0)
1392 		bristolMidiSendMsg(global.controlfd, synth->sid, 0, 3, 32);
1393 	else
1394 		bristolMidiSendMsg(global.controlfd, synth->sid, 0, 3, 33);
1395 
1396 	/*
1397 	 * Slow fast decay
1398 	 */
1399 	if (synth->mem.param[DEVICE_START + 24] == 0)
1400 		bristolMidiSendMsg(global.controlfd, synth->sid, 4, 1,
1401 			(int) (synth->mem.param[OPTS_START + 16] * C_RANGE_MIN_1));
1402 	else
1403 		bristolMidiSendMsg(global.controlfd, synth->sid, 4, 1,
1404 			(int) (synth->mem.param[OPTS_START + 17] * C_RANGE_MIN_1));
1405 }
1406 
1407 static void
hammondOption(guiSynth * synth,int fd,int chan,int cont,int op,int value)1408 hammondOption(guiSynth *synth, int fd, int chan, int cont, int op, int value)
1409 {
1410 	brightonEvent event;
1411 
1412 /*printf("hammondOption(%x, %i, %i, %i, %i, %i)\n", */
1413 /*	synth, fd, chan, cont, op, value); */
1414 
1415 	switch (cont) {
1416 		case OPTS_START:
1417 			/*
1418 			 * Rotation type. Send 100.7 becomes op;
1419 			 */
1420 			if ((synth->flags & MEM_LOADING) == 0)
1421 			{
1422 				if (synth->dispatch[OPTS_START].other2)
1423 				{
1424 					synth->dispatch[OPTS_START].other2 = 0;
1425 					return;
1426 				}
1427 				synth->dispatch[OPTS_START].other2 = 1;
1428 				if (synth->dispatch[OPTS_START].other1 >= 0)
1429 				{
1430 					event.command = BRIGHTON_PARAMCHANGE;
1431 					if (synth->dispatch[OPTS_START].other1 != (op - 1))
1432 						event.value = 0;
1433 					else
1434 						event.value = 1;
1435 					brightonParamChange(synth->win,
1436 						OPTS_PANEL, synth->dispatch[OPTS_START].other1, &event);
1437 				}
1438 			}
1439 
1440 			if (synth->mem.param[OPTS_START + op - 1] != 0)
1441 			{
1442 				synth->dispatch[OPTS_START].other1 = op - 1;
1443 				synth->dispatch[OPTS_START + 1].other1 = op;
1444 
1445 				if (synth->mem.param[LESLIE_ONOFF] == 0)
1446 					bristolMidiSendMsg(global.controlfd, chan, 100, 7, 0);
1447 				else {
1448 					bristolMidiSendMsg(global.controlfd, chan, 100, 7, op);
1449 					bristolMidiSendMsg(global.controlfd, chan, 100, 1,
1450 						(int) (synth->mem.param[OPTS_START + 5]
1451 							* C_RANGE_MIN_1));
1452 				}
1453 			}
1454 			break;
1455 		case OPTS_START + 3:
1456 			/*
1457 			 * Rotor break. Send 100.7 = 4 off, 100.7 = 5 on.
1458 			 */
1459 			if (value == 0)
1460 				bristolMidiSendMsg(global.controlfd, chan, 100, 7, 4);
1461 			else
1462 				bristolMidiSendMsg(global.controlfd, chan, 100, 7, 5);
1463 			break;
1464 		case OPTS_START + 4:
1465 		case OPTS_START + 5:
1466 		case OPTS_START + 6:
1467 		case OPTS_START + 7:
1468 		case OPTS_START + 8:
1469 		case OPTS_START + 10:
1470 		case OPTS_START + 11:
1471 		case OPTS_START + 12:
1472 			doLeslieSpeed(synth);
1473 			break;
1474 		case OPTS_START + 9:
1475 			/* overdrive */
1476 			bristolMidiSendMsg(global.controlfd, synth->sid, 100, 5,
1477 				(int) (synth->mem.param[OPTS_START + 9] * C_RANGE_MIN_1));
1478 			break;
1479 		case OPTS_START + 13:
1480 		case OPTS_START + 14:
1481 		case OPTS_START + 15:
1482 			doVibra(synth, fd, chan, cont, op, value);
1483 			break;
1484 		case OPTS_START + 16:
1485 		case OPTS_START + 17:
1486 			doPerc(synth);
1487 			break;
1488 		case OPTS_START + 18:
1489 		case OPTS_START + 19:
1490 			doGrooming(synth);
1491 			break;
1492 		case OPTS_START + 20:
1493 			doPreacher(synth);
1494 			break;
1495 		case OPTS_START + 21:
1496 			doCompress(synth);
1497 			break;
1498 		case OPTS_START + 22:
1499 			doBright(synth);
1500 			break;
1501 		case OPTS_START + 23:
1502 			doClick(synth);
1503 			break;
1504 		case OPTS_START + 24:
1505 			doLeslieSpeed(synth);
1506 			break;
1507 		case OPTS_START + 25:
1508 			doDamping(synth, fd, chan, cont, op, value);
1509 			break;
1510 /*		case OPTS_START + 26: */
1511 		default:
1512 			break;
1513 	}
1514 }
1515 
1516 /*
1517  * Any location initialisation required to run the callbacks. For bristol, this
1518  * will connect to the engine, and give it some base parameters.
1519  * May need to generate some application specific menus.
1520  * Will also then make specific requests to some of the devices to alter their
1521  * rendering.
1522  */
1523 static int
hammondB3Init(brightonWindow * win)1524 hammondB3Init(brightonWindow *win)
1525 {
1526 	guiSynth *synth = findSynth(global.synths, win);
1527 	dispatcher *dispatch;
1528 	int i;
1529 
1530 	if (synth == 0)
1531 	{
1532 		synth = findSynth(global.synths, 0);
1533 		if (synth == 0)
1534 		{
1535 			printf("cannot init\n");
1536 			return(0);
1537 		}
1538 	}
1539 
1540 	synth->win = win;
1541 
1542 	printf("Initialise the hammondB3 link to bristol: %p\n", synth->win);
1543 
1544 	synth->mem.param = (float *) brightonmalloc(DEVICE_COUNT * sizeof(float));
1545 	synth->mem.count = DEVICE_COUNT;
1546 	synth->mem.active = ACTIVE_DEVS;
1547 	synth->dispatch = (dispatcher *)
1548 		brightonmalloc(DEVICE_COUNT * sizeof(dispatcher));
1549 	dispatch = synth->dispatch;
1550 
1551 	if (!global.libtest)
1552 	{
1553 		if (synth->synthtype == BRISTOL_HAMMONDB3)
1554 		{
1555 			bcopy(&global, &manual, sizeof(guimain));
1556 			manual.home = 0;
1557 
1558 			synth->synthtype = BRISTOL_HAMMOND;
1559 			if ((synth->sid = initConnection(&global, synth)) < 0)
1560 				return(-1);
1561 
1562 			/*
1563 			 * send a hello, with a voice count, then request starting of the
1564 			 * synthtype. All of these will require an ACK, and we should wait
1565 			 * here and read that ack before proceeding with each next step.
1566 			 */
1567 			manual.flags |= BRISTOL_CONN_FORCE|BRIGHTON_NOENGINE;
1568 			manual.port = global.port;
1569 			manual.host = global.host;
1570 
1571 			synth->midichannel++;
1572 			synth->synthtype = BRISTOL_HAMMONDB3;
1573 			if ((synth->sid2 = initConnection(&manual, synth)) < 0)
1574 				return(-1);
1575 			synth->midichannel--;
1576 			global.manualfd = manual.controlfd;
1577 			global.manual = &manual;
1578 			manual.manual = &global;
1579 		} else {
1580 			if ((synth->sid2 = initConnection(&manual, synth)) < 0)
1581 				return(-1);
1582 		}
1583 	}
1584 
1585 	for (i = 0; i < DEVICE_COUNT; i++)
1586 	{
1587 		synth->dispatch[i].routine = (synthRoutine) hammondB3Passthrough;
1588 	}
1589 
1590 	/*
1591 	 * Put in the drawbar configurations, upper manual
1592 	 */
1593 	dispatch[0].routine =
1594 	dispatch[1].routine =
1595 	dispatch[2].routine =
1596 	dispatch[3].routine =
1597 	dispatch[4].routine =
1598 	dispatch[5].routine =
1599 	dispatch[6].routine =
1600 	dispatch[7].routine =
1601 	dispatch[8].routine = (synthRoutine) doLMSlider;
1602 
1603 	dispatch[0].controller = 0;
1604 	dispatch[1].controller = 1;
1605 	dispatch[2].controller = 2;
1606 	dispatch[3].controller = 3;
1607 	dispatch[4].controller = 4;
1608 	dispatch[5].controller = 5;
1609 	dispatch[6].controller = 6;
1610 	dispatch[7].controller = 7;
1611 	dispatch[8].controller = 8;
1612 
1613 	/*
1614 	 * Put in the drawbar configurations, upper manual
1615 	 */
1616 	dispatch[DRAWBAR_START].routine =
1617 	dispatch[DRAWBAR_START + 1].routine =
1618 	dispatch[DRAWBAR_START + 2].routine =
1619 	dispatch[DRAWBAR_START + 3].routine =
1620 	dispatch[DRAWBAR_START + 4].routine =
1621 	dispatch[DRAWBAR_START + 5].routine =
1622 	dispatch[DRAWBAR_START + 6].routine =
1623 	dispatch[DRAWBAR_START + 7].routine =
1624 	dispatch[DRAWBAR_START + 8].routine = (synthRoutine) doDrawbar;
1625 
1626 	dispatch[DRAWBAR_START].controller = 0;
1627 	dispatch[DRAWBAR_START + 1].controller = 1;
1628 	dispatch[DRAWBAR_START + 2].controller = 2;
1629 	dispatch[DRAWBAR_START + 3].controller = 3;
1630 	dispatch[DRAWBAR_START + 4].controller = 4;
1631 	dispatch[DRAWBAR_START + 5].controller = 5;
1632 	dispatch[DRAWBAR_START + 6].controller = 6;
1633 	dispatch[DRAWBAR_START + 7].controller = 7;
1634 	dispatch[DRAWBAR_START + 8].controller = 8;
1635 
1636 	/* Options controllers */
1637 	dispatch[OPTS_START].routine = (synthRoutine) hammondOption;
1638 	dispatch[OPTS_START].controller = OPTS_START;
1639 	dispatch[OPTS_START].operator = 1;
1640 	dispatch[OPTS_START + 1].routine = (synthRoutine) hammondOption;
1641 	dispatch[OPTS_START + 1].controller = OPTS_START;
1642 	dispatch[OPTS_START + 1].operator = 2;
1643 	dispatch[OPTS_START + 2].routine = (synthRoutine) hammondOption;
1644 	dispatch[OPTS_START + 2].controller = OPTS_START;
1645 	dispatch[OPTS_START + 2].operator = 3;
1646 	dispatch[OPTS_START].other1 = -1;
1647 	dispatch[OPTS_START].other2 = 0;
1648 	dispatch[OPTS_START + 3].routine = (synthRoutine) hammondOption;
1649 	dispatch[OPTS_START + 3].controller = OPTS_START + 3;
1650 
1651 	dispatch[OPTS_START + 4].routine = (synthRoutine) hammondOption;
1652 	dispatch[OPTS_START + 4].controller = OPTS_START + 4;
1653 	dispatch[OPTS_START + 5].routine = (synthRoutine) hammondOption;
1654 	dispatch[OPTS_START + 5].controller = OPTS_START + 5;
1655 	dispatch[OPTS_START + 6].routine = (synthRoutine) hammondOption;
1656 	dispatch[OPTS_START + 6].controller = OPTS_START + 6;
1657 	dispatch[OPTS_START + 7].routine = (synthRoutine) hammondOption;
1658 	dispatch[OPTS_START + 7].controller = OPTS_START + 7;
1659 	dispatch[OPTS_START + 8].routine = (synthRoutine) hammondOption;
1660 	dispatch[OPTS_START + 8].controller = OPTS_START + 8;
1661 	dispatch[OPTS_START + 9].routine = (synthRoutine) hammondOption;
1662 	dispatch[OPTS_START + 9].controller = OPTS_START + 9;
1663 	dispatch[OPTS_START + 10].routine = (synthRoutine) hammondOption;
1664 	dispatch[OPTS_START + 10].controller = OPTS_START + 10;
1665 	dispatch[OPTS_START + 11].routine = (synthRoutine) hammondOption;
1666 	dispatch[OPTS_START + 11].controller = OPTS_START + 11;
1667 	dispatch[OPTS_START + 12].routine = (synthRoutine) hammondOption;
1668 	dispatch[OPTS_START + 12].controller = OPTS_START + 12;
1669 
1670 	/* vibra */
1671 	dispatch[OPTS_START + 13].routine = (synthRoutine) hammondOption;
1672 	dispatch[OPTS_START + 13].controller = OPTS_START + 13;
1673 	dispatch[OPTS_START + 13].operator = 0;
1674 	dispatch[OPTS_START + 14].routine = (synthRoutine) hammondOption;
1675 	dispatch[OPTS_START + 14].controller = OPTS_START + 14;
1676 	dispatch[OPTS_START + 14].operator = 1;
1677 	dispatch[OPTS_START + 15].routine = (synthRoutine) hammondOption;
1678 	dispatch[OPTS_START + 15].controller = OPTS_START + 15;
1679 	dispatch[OPTS_START + 15].operator = 3;
1680 	dispatch[DEVICE_START + 20].controller = 6;
1681 	dispatch[DEVICE_START + 20].operator = 2;
1682 	dispatch[DEVICE_START + 20].routine = (synthRoutine) doVibra;
1683 
1684 	/* Percussives */
1685 	dispatch[OPTS_START + 16].routine = (synthRoutine) hammondOption;
1686 	dispatch[OPTS_START + 16].controller = OPTS_START + 16;
1687 	dispatch[OPTS_START + 17].routine = (synthRoutine) hammondOption;
1688 	dispatch[OPTS_START + 17].controller = OPTS_START + 17;
1689 	dispatch[22].routine = (synthRoutine) doPerc;
1690 	dispatch[23].routine = (synthRoutine) doPerc;
1691 	dispatch[24].routine = (synthRoutine) doPerc;
1692 
1693 	/* Soft attack - grooming */
1694 	dispatch[OPTS_START + 18].routine = (synthRoutine) hammondOption;
1695 	dispatch[OPTS_START + 18].controller = OPTS_START + 18;
1696 	dispatch[OPTS_START + 19].routine = (synthRoutine) hammondOption;
1697 	dispatch[OPTS_START + 19].controller = OPTS_START + 19;
1698 	dispatch[DEVICE_START + 25].routine = (synthRoutine) doGrooming;
1699 
1700 	/* Bass Drawbars */
1701 	dispatch[26].routine = dispatch[27].routine = (synthRoutine) doPedalSlider;
1702 	dispatch[26].controller = 0;
1703 	dispatch[27].controller = 1;
1704 
1705 	/* preacher */
1706 	dispatch[OPTS_START + 20].routine = (synthRoutine) doPreacher;
1707 	dispatch[OPTS_START + 20].controller = OPTS_START + 20;
1708 	dispatch[OPTS_START + 21].routine = (synthRoutine) hammondOption;
1709 	dispatch[OPTS_START + 21].controller = OPTS_START + 21;
1710 	dispatch[OPTS_START + 22].routine = (synthRoutine) hammondOption;
1711 	dispatch[OPTS_START + 22].controller = OPTS_START + 22;
1712 	dispatch[DEVICE_START + 21].routine = (synthRoutine) doBright;
1713 	dispatch[OPTS_START + 23].routine = (synthRoutine) hammondOption;
1714 	dispatch[OPTS_START + 23].controller = OPTS_START + 23;
1715 
1716 	/* reverb */
1717 	dispatch[OPTS_START + 24].routine = (synthRoutine) hammondOption;
1718 	dispatch[OPTS_START + 24].controller = OPTS_START + 24;
1719 	dispatch[OPTS_START + 25].routine = (synthRoutine) hammondOption;
1720 	dispatch[OPTS_START + 25].controller = OPTS_START + 25;
1721 /*	dispatch[OPTS_START + 26].routine = (synthRoutine) hammondOption; */
1722 	dispatch[OPTS_START + 26].controller = 6;
1723 	dispatch[OPTS_START + 26].operator = 4;
1724 	dispatch[OPTS_START + 26].routine = (synthRoutine) doVibra;
1725 
1726 	/* Reverb */
1727 	dispatch[OPTS_START + 27].controller = 101;
1728 	dispatch[OPTS_START + 27].operator = 0;
1729 	dispatch[OPTS_START + 27].routine = (synthRoutine) doReverbParam;
1730 	dispatch[OPTS_START + 28].controller = 101;
1731 	dispatch[OPTS_START + 28].operator = 1;
1732 	dispatch[OPTS_START + 28].routine = (synthRoutine) doReverbParam;
1733 	dispatch[OPTS_START + 29].controller = 101;
1734 	dispatch[OPTS_START + 29].operator = 2;
1735 	dispatch[OPTS_START + 29].routine = (synthRoutine) doReverbParam;
1736 	dispatch[OPTS_START + 30].controller = 101;
1737 	dispatch[OPTS_START + 30].operator = 3;
1738 	dispatch[OPTS_START + 30].routine = (synthRoutine) doReverbParam;
1739 	dispatch[OPTS_START + 31].controller = 101;
1740 	dispatch[OPTS_START + 31].operator = 4;
1741 	dispatch[OPTS_START + 31].routine = (synthRoutine) doReverbParam;
1742 	dispatch[DEVICE_START + 19].routine = (synthRoutine) doReverb;
1743 
1744 	dispatch[DEVICE_START + 18].routine = (synthRoutine) doLeslieSpeed;
1745 	dispatch[LESLIE_START].routine = (synthRoutine) doLeslieSpeed;
1746 
1747 	dispatch[VOL_START].routine = (synthRoutine) doVolume;
1748 
1749 	/* Memory/Midi buttons */
1750 	dispatch[MEM_START + 10].controller = 12;
1751 	dispatch[MEM_START + 10].operator = 0;
1752 
1753 	/*
1754 	 * These are for the memory radio buttons
1755 	 */
1756 	dispatch[MEM_START].other1 = 0;
1757 	dispatch[MEM_START].other2 = 0;
1758 
1759 	dispatch[MEM_START].operator = 0;
1760 	dispatch[MEM_START + 1].operator = 1;
1761 	dispatch[MEM_START + 2].operator = 2;
1762 	dispatch[MEM_START + 3].operator = 3;
1763 	dispatch[MEM_START + 4].operator = 4;
1764 	dispatch[MEM_START + 5].operator = 5;
1765 	dispatch[MEM_START + 6].operator = 6;
1766 	dispatch[MEM_START + 7].operator = 7;
1767 	dispatch[MEM_START + 8].operator = 8;
1768 	dispatch[MEM_START + 9].operator = 9;
1769 
1770 	dispatch[MEM_START].routine = dispatch[MEM_START + 1].routine =
1771 	dispatch[MEM_START + 2].routine = dispatch[MEM_START + 3].routine =
1772 	dispatch[MEM_START + 4].routine = dispatch[MEM_START + 5].routine =
1773 	dispatch[MEM_START + 6].routine = dispatch[MEM_START + 7].routine =
1774 	dispatch[MEM_START + 8].routine = dispatch[MEM_START + 9].routine =
1775 		(synthRoutine) hammondB3Memory;
1776 
1777 	/*
1778 	 * Mem load and save
1779 	 */
1780 	dispatch[MEM_START + 12].controller = 1;
1781 	dispatch[MEM_START + 13].controller = 2;
1782 	dispatch[MEM_START + 14].controller = 3;
1783 	dispatch[MEM_START + 12].routine = dispatch[MEM_START + 13].routine =
1784 		dispatch[MEM_START + 14].routine = (synthRoutine) hammondB3Memory;
1785 
1786 	/*
1787 	 * Midi up/down
1788 	 */
1789 	dispatch[MEM_START + 10].controller = 2;
1790 	dispatch[MEM_START + 11].controller = 1;
1791 	dispatch[MEM_START + 10].routine = dispatch[MEM_START + 11].routine =
1792 		(synthRoutine) hammondB3Midi;
1793 
1794 	bristolMidiSendMsg(global.controlfd, synth->sid, 1, 0, 0);
1795 	bristolMidiSendMsg(global.controlfd, synth->sid, 1, 1, 3);
1796 	bristolMidiSendMsg(global.controlfd, synth->sid, 1, 2, 16383);
1797 	bristolMidiSendMsg(global.controlfd, synth->sid, 1, 3, 400);
1798 	bristolMidiSendMsg(global.controlfd, synth->sid, 1, 4, 13000);
1799 	bristolMidiSendMsg(global.controlfd, synth->sid, 1, 5, 0);
1800 
1801 	bristolMidiSendMsg(global.controlfd, synth->sid, 12, 7, 1);
1802 	bristolMidiSendMsg(global.controlfd, synth->sid, 10, 0, 4);
1803 
1804 	bristolMidiSendMsg(global.controlfd, synth->sid, 3, 0, 0);
1805 	bristolMidiSendMsg(global.controlfd, synth->sid, 3, 1, 10);
1806 	bristolMidiSendMsg(global.controlfd, synth->sid, 3, 2, 13000);
1807 	bristolMidiSendMsg(global.controlfd, synth->sid, 3, 3, 400);
1808 	bristolMidiSendMsg(global.controlfd, synth->sid, 3, 4, 13000);
1809 	bristolMidiSendMsg(global.controlfd, synth->sid, 3, 5, 0);
1810 
1811 	bristolMidiSendMsg(global.controlfd, synth->sid, 4, 0, 2);
1812 	bristolMidiSendMsg(global.controlfd, synth->sid, 4, 1, 1200);
1813 	bristolMidiSendMsg(global.controlfd, synth->sid, 4, 2, 0);
1814 	bristolMidiSendMsg(global.controlfd, synth->sid, 4, 3, 20);
1815 	bristolMidiSendMsg(global.controlfd, synth->sid, 4, 4, 15500);
1816 	bristolMidiSendMsg(global.controlfd, synth->sid, 4, 5, 0);
1817 
1818 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 1, 0, 2);
1819 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 1, 1, 3);
1820 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 1, 2, 16383);
1821 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 1, 3, 1000);
1822 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 1, 4, 13000);
1823 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 1, 5, 0);
1824 
1825 	dispatch[LESLIE_START + 1].routine = (synthRoutine) hammondB3Switch;
1826 
1827 	return(0);
1828 }
1829 
1830 static int
hammondB3MidiCallback(brightonWindow * win,int controller,int value,float n)1831 hammondB3MidiCallback(brightonWindow *win, int controller, int value, float n)
1832 {
1833 	guiSynth *synth = findSynth(global.synths, win);
1834 
1835 	printf("midi callback: %x, %i\n", controller, value);
1836 
1837 	switch(controller)
1838 	{
1839 		case MIDI_PROGRAM:
1840 			printf("midi program: %x, %i\n", controller, value);
1841 			synth->location = value;
1842 			loadMemory(synth, "hammondB3", 0, synth->bank + synth->location,
1843 				synth->mem.active, FIRST_DEV, 0);
1844 			break;
1845 		case MIDI_BANK_SELECT:
1846 			printf("midi banksel: %x, %i\n", controller, value);
1847 			synth->bank = value;
1848 			break;
1849 	}
1850 	return(0);
1851 }
1852 
1853 /*
1854  * This will be called to make any routine specific parameters available.
1855  */
1856 static int
hammondB3Configure(brightonWindow * win)1857 hammondB3Configure(brightonWindow *win)
1858 {
1859 	guiSynth *synth = findSynth(global.synths, win);
1860 	brightonEvent event;
1861 
1862 	if (synth == 0)
1863 	{
1864 		printf("problems going operational\n");
1865 		return(-1);
1866 	}
1867 
1868 	if (synth->flags & OPERATIONAL)
1869 		return(0);
1870 
1871 	printf("going operational: %p, %p\n", synth, win);
1872 
1873 	synth->flags |= OPERATIONAL;
1874 	synth->keypanel = 6;
1875 	synth->keypanel2 = 7;
1876 	synth->transpose = 24;
1877 
1878 	synth->bank = 0;
1879 	synth->location = 0;
1880 
1881 	hammondB3Switch(synth, 0, 0, 0, 0, 1);
1882 	loadMemory(synth, "hammondB3", 0, 0, synth->mem.active, FIRST_DEV, 0);
1883 	hammondB3Switch(synth, 0, 0, 0, 0, 0);
1884 
1885 	/*
1886 	 * We also want to configure the mod wheel so that it is half way up, this
1887 	 * affects the speed of the leslie.
1888 	 */
1889 	if (global.libtest == 0)
1890 	{
1891 		bristolMidiControl(global.controlfd, synth->midichannel,
1892 			0, 1, C_RANGE_MIN_1 >> 1);
1893 		bristolMidiControl(global.controlfd, synth->midichannel + 1,
1894 			0, 1, C_RANGE_MIN_1 >> 1);
1895 		/*
1896 		 * And the expression (foot) pedal to full on as it governs the gain
1897 		 */
1898 		bristolMidiControl(global.controlfd, synth->midichannel,
1899 			0, 4, C_RANGE_MIN_1);
1900 		bristolMidiControl(global.controlfd, synth->midichannel + 1,
1901 			0, 4, C_RANGE_MIN_1);
1902 	}
1903 
1904 	synth->mem.param[LESLIE_ONOFF] = 1;
1905 
1906 	event.type = BRIGHTON_EXPOSE;
1907 	event.intvalue = 1;
1908 	brightonParamChange(synth->win, 8, -1, &event);
1909 
1910 /*	event.value = 1.0; */
1911 /*	brightonParamChange(synth->win, 1, 2, &event); */
1912 /*	brightonParamChange(synth->win, 1, 0, &event); */
1913 	configureGlobals(synth);
1914 
1915 	dc = brightonGetDCTimer(win->dcTimeout);
1916 
1917 	bristolMidiSendMsg(global.controlfd, synth->midichannel,
1918 		BRISTOL_EVENT_KEYON, 0, 10 + synth->transpose);
1919 	bristolMidiSendMsg(global.controlfd, synth->midichannel,
1920 		BRISTOL_EVENT_KEYOFF, 0, 10 + synth->transpose);
1921 
1922 	return(0);
1923 }
1924 
1925