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 #include <fcntl.h>
23 
24 #include "brighton.h"
25 #include "brightonMini.h"
26 #include "brightoninternals.h"
27 
28 #include "brightonSID2.h"
29 
30 static int sid2Init();
31 static int sid2Configure();
32 static int sid2Callback(brightonWindow *, int, int, float);
33 static int sid2ModCallback(brightonWindow *, int, int, float);
34 static int midiCallback(brightonWindow *, int, int, float);
35 static int sid2KeyCallback(brightonWindow *, int, int, float);
36 
37 extern guimain global;
38 
39 #include "brightonKeys.h"
40 
41 #define SYNTH_NAME synth->resources->name
42 
43 #define DEVICE_COUNT 254
44 #define ACTIVE_DEVS 229
45 #define MEM_START (ACTIVE_DEVS + 8) /* 8 are for globals */
46 
47 #define KEY_PANEL 1
48 #define MODS_PANEL 2
49 #define DISPLAY_DEV (DEVICE_COUNT - 1)
50 
51 static int dc, mbh = 0;
52 
53 /*
54  * This structure is for device definition. The structure is defined in
55  * include/brighton.h, further definitions in brighton/brightonDevtable.h and
56  * include/brightoninternals.h
57  *
58  *	typedef int (*brightonCallback)(int, float);
59  *	typedef struct BrightonLocations {
60  *		int device; 0=rotary, 1=scale, etc.
61  *		float relx, rely; relative position with regards to 1000 by 1000 window
62  *		float relw, relh; relative height.
63  *		int from, to;
64  *		brightonCallback callback; specific to this dev
65  *		char *image; bitmap. If zero take a device default.
66  *		int flags;
67  *	} brightonLocations;
68  *
69  * This example is for a sid2Bristol type synth interface.
70  */
71 
72 /*
73  * GUI needs the following:
74  *
75  * 	Modes:
76  *
77  * 		Mono
78  * 		Poly-H
79  * 		Poly-V
80  * 		Voice ALL/1/2/3/4/5
81  *
82  * 	Voice-3 PolyMod section to include LFO option, touch, destination.
83  *
84  * 		PolyMod needs:
85  *
86  * 			On/off		button (No)
87  * 			LFO			button
88  * 			Tracking	button (LFO frequency)
89  * 			Tracking	button (ENV gain)
90  * 			Tracking	button (Voice gain)
91  * 			Legato		button
92  * 			PPM			button
93  *
94  * 			OSC Routing - 6 bus volumes, touch
95  * 			ENV Routing - 6 bus volumes, touch
96  * 			Prod Routing- 6 bus volumes, touch
97  *
98  * 	LFO-1
99  *
100  * 		Remove noise
101  * 		Stack waveforms
102  * 		Legato Env
103  *
104  * 	LFO-2 MonoMods -> S&H. Product.
105  *
106  * 	No Arpeggiator
107  *
108  * 	Add in analogue parameters:
109  * 		S/N, Detune, DC/Bias, Leakage, tune/trans, volume.
110  * 		perhaps leave out DC Bias?
111  *
112  * 	Filter: cutoff, res, pole mix, volume+touch, pan.
113  *
114  * Want to have 6 mod busses. The mono mods will be routed to them, the poly
115  * mods also, then the busses can be directed to destinations with routing
116  * buttons. Internally these should be mod routes per chip, presentation may
117  * be distinct - PPM switch:
118  * 	PPM off - MMods to all, PolyMods to self
119  * 	PPM on - MMods to any, PolyMods to any
120  *
121  * Add stereo panning for voices. Add global volume, global tuning. There are
122  * also some voice controls I need to add.
123  *
124  * FIX:
125  * 	Velocity opion per voice - could be in PolyMods?
126  * 	Keyboard ranging per voice (and arpeggiate?)
127  * 	Pan - per voice or Mono/All use slightly different positioning +/-
128  *
129  * To send so many voice and routing messages will probably need to either
130  * notify engine of which voice is under control or use different controller
131  * id from 100 for example.
132  */
133 
134 /* SID2-1 */
135 #define V1R1 50
136 #define V1R2 125
137 #define V1R3 250
138 
139 #define VD1 36
140 #define VD2 22
141 #define VD3 2
142 
143 #define VBW1 28
144 #define VBW2 10
145 #define VBW3 45
146 
147 #define VBH1 30
148 #define VBH2 70
149 #define VBH3 235
150 #define VBH4 200
151 
152 #define V1C1 25
153 #define V1C2 (V1C1 + VD1)
154 #define V1C3 (V1C2 + VD1)
155 #define V1C4 (V1C3 + VD1)
156 #define V1C1b (V1C1 + VD3)
157 #define V1C2b (V1C2 + VD3)
158 #define V1C3b (V1C3 + VD3)
159 #define V1C4b (V1C4 + VD3)
160 #define V1C5 (V1C4 + VD1 + 15)
161 #define V1C6 (V1C5 + VD2)
162 #define V1C7 (V1C6 + VD2)
163 #define V1C8 (V1C7 + VD2)
164 
165 #define V2C1 (V1C8 + VD2 + VD1)
166 #define V2C2 (V2C1 + VD1)
167 #define V2C3 (V2C2 + VD1)
168 #define V2C4 (V2C3 + VD1)
169 #define V2C1b (V2C1 + VD3)
170 #define V2C2b (V2C2 + VD3)
171 #define V2C3b (V2C3 + VD3)
172 #define V2C4b (V2C4 + VD3)
173 #define V2C5 (V2C4 + VD1 + 15)
174 #define V2C6 (V2C5 + VD2)
175 #define V2C7 (V2C6 + VD2)
176 #define V2C8 (V2C7 + VD2)
177 
178 #define V3C1 (V2C8 + VD2 + VD1)
179 #define V3C2 (V3C1 + VD1)
180 #define V3C3 (V3C2 + VD1)
181 #define V3C4 (V3C3 + VD1)
182 #define V3C1b (V3C1 + VD3)
183 #define V3C2b (V3C2 + VD3)
184 #define V3C3b (V3C3 + VD3)
185 #define V3C4b (V3C4 + VD3)
186 #define V3C5 (V3C4 + VD1 + 15)
187 #define V3C6 (V3C5 + VD2)
188 #define V3C7 (V3C6 + VD2)
189 #define V3C8 (V3C7 + VD2)
190 
191 #define FC1 (V3C8 + VD2 + VD1)
192 #define FC2 (FC1 + VD1)
193 #define FC3 (FC2 + VD1)
194 #define FC1b (FC1 + VD3)
195 #define FC2b (FC2 + VD3)
196 #define FC3b (FC3 + VD3)
197 
198 /* SID2-2 Mods */
199 #define S2R0 460
200 #define S2R1 (S2R0 + 30) //630
201 #define S2R2 (S2R1 + 30) //675
202 #define S2R3 (S2R2 + 50) //750
203 #define S2R4 (S2R3 + 50) //825
204 
205 /* SID2-2 Mods */
206 #define S2R5 760
207 #define S2R6 (S2R5 + 30) //630
208 #define S2R7 (S2R6 + 30) //675
209 #define S2R8 (S2R7 + 50) //750
210 #define S2R9 (S2R8 + 50) //825
211 
212 #define S2C0 700
213 #define S2C1 20
214 #define S2C1b (S2C1 + VD1/2)
215 #define S2C2 (S2C1 + VD1)
216 #define S2C2b (S2C1 + VD1 + VD1/2)
217 #define S2C3 (S2C2 + VD1)
218 #define S2C3b (S2C3 + VD1/2)
219 #define S2C4 (S2C3 + VD1)
220 #define S2C5 (S2C4 + VD1 + VD2)
221 #define S2C6 (S2C5 + VD1)
222 
223 #define S2C7 (S2C5 + VD1)
224 #define S2C8 (S2C7 + VD1)
225 #define S2C8b (S2C8 + VD1)
226 #define S2C9 (S2C8b + VD2)
227 #define S2C10 (S2C9 + VD2)
228 #define S2C11 (S2C10 + VD2)
229 #define S2C12 (S2C11 + VD2)
230 
231 #define S2C13 (S2C12 + VD1 + 10)
232 #define S2C14 (S2C13 + VD1/2)
233 #define S2C15 (S2C13 + VD1)
234 
235 #define S2C16 730 //(S2C15 + VD1 + VD2)
236 #define S2C17 (S2C16 + VD1)
237 #define S2C18 (S2C17 + VD1)
238 #define S2C19 (S2C18 + VD1)
239 #define S2C20 (S2C19 + VD1)
240 #define S2C21 (S2C20 + VD1)
241 #define S2C22 (S2C21 + VD1)
242 #define S2C23 (S2C22 + VD1 + 10)
243 
244 #define S3C0 730
245 #define S3C1 (S3C0 + 40)
246 #define S3C2 (S3C1 + 45)
247 #define S3C3 (S3C2 + 45)
248 #define S3C4 (S3C3 + 40)
249 #define S3C5 (S3C4 + 50)
250 
251 #define SRD1 34
252 
253 #define SRC0 450
254 #define SRC1 (SRC0 + SRD1)
255 #define SRC2 (SRC1 + SRD1)
256 #define SRC3 (SRC2 + SRD1)
257 #define SRC4 (SRC3 + SRD1)
258 #define SRC5 (SRC4 + SRD1)
259 #define SRC6 (SRC5 + SRD1)
260 
261 #define SRR0 (S2R5-35)
262 #define SRR1 (S2R5)
263 #define SRR2 (S2R5+35)
264 #define SRR3 (S2R5+70)
265 #define SRR4 (S2R5+105)
266 #define SRR5 (S2R5+140)
267 #define SRR6 (S2R5+175)
268 
269 static
270 brightonLocations modwheel[5] = {
271 	{"", BRIGHTON_MODWHEEL, 0, 0, 390, 1000, 0, 1, 0,
272 		"bitmaps/knobs/modwheel.xpm", 0,
273 		BRIGHTON_HSCALE|BRIGHTON_NOSHADOW|BRIGHTON_NOTCH},
274 	{"", 2, 500, 50, 500, 130, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
275 		"bitmaps/buttons/sidbon.xpm", 0},
276 	{"", 2, 500, 306, 500, 130, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
277 		"bitmaps/buttons/sidbon.xpm", 0},
278 	{"", 2, 500, 562, 500, 130, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
279 		"bitmaps/buttons/sidbon.xpm", 0},
280 	{"", 2, 500, 820, 500, 130, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
281 		"bitmaps/buttons/sidbongreen.xpm", 0},
282 };
283 
284 static
285 brightonLocations locations[DEVICE_COUNT] = {
286 	/*
287 	 * Three voices with same parameterisation, roughly
288 	 * Tri/Ramp/Square/Noise Buttons
289 	 * RM/SYNC/Mute/Routing(Multi global) Buttons
290 	 * PW/Tune/transpose(/Glide?) - Pots
291 	 * Att/Dec/Sust/Rel - Sliders
292 	 */
293 	{"", 2, V1C1, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
294 		"bitmaps/buttons/sidbon.xpm", 0},
295 	{"", 2, V1C2, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
296 		"bitmaps/buttons/sidbon.xpm", 0},
297 	{"", 2, V1C3, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
298 		"bitmaps/buttons/sidbon.xpm", 0},
299 	{"", 2, V1C4, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
300 		"bitmaps/buttons/sidbon.xpm", 0},
301 	{"", 0, V1C1b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0, 0},
302 	{"", 0, V1C2b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0,
303 		BRIGHTON_NOTCH},
304 	{"", 0, V1C3b, V1R2, VBW3, VBH2, 0, 24,0, "bitmaps/knobs/knobred.xpm", 0, 0},
305 	{"", 0, V1C4b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0, 0},
306 	{"", 2, V1C1, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
307 		"bitmaps/buttons/sidbon.xpm", 0},
308 	{"", 2, V1C2, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
309 		"bitmaps/buttons/sidbon.xpm", 0},
310 	{"", 2, V1C3, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
311 		"bitmaps/buttons/sidbon.xpm", 0},
312 	{"", 2, V1C4, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
313 		"bitmaps/buttons/sidbon.xpm", 0},
314 	{"", 1, V1C5, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
315 		0, 0},
316 	{"", 1, V1C6, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
317 		0, 0},
318 	{"", 1, V1C7, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
319 		0, 0},
320 	{"", 1, V1C8, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
321 		0, 0},
322 
323 	/* Voice 2 - 16 */
324 	{"", 2, V2C1, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
325 		"bitmaps/buttons/sidbon.xpm", 0},
326 	{"", 2, V2C2, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
327 		"bitmaps/buttons/sidbon.xpm", 0},
328 	{"", 2, V2C3, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
329 		"bitmaps/buttons/sidbon.xpm", 0},
330 	{"", 2, V2C4, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
331 		"bitmaps/buttons/sidbon.xpm", 0},
332 	{"", 0, V2C1b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0,0},
333 	{"", 0, V2C2b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0,
334 		BRIGHTON_NOTCH},
335 	{"", 0, V2C3b, V1R2, VBW3, VBH2, 0, 24, 0, "bitmaps/knobs/knobred.xpm",0,0},
336 	{"", 0, V2C4b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0,0},
337 	{"", 2, V2C1, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
338 		"bitmaps/buttons/sidbon.xpm", 0},
339 	{"", 2, V2C2, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
340 		"bitmaps/buttons/sidbon.xpm", 0},
341 	{"", 2, V2C3, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
342 		"bitmaps/buttons/sidbon.xpm", 0},
343 	{"", 2, V2C4, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
344 		"bitmaps/buttons/sidbon.xpm", 0},
345 	{"", 1, V2C5, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
346 		0, 0},
347 	{"", 1, V2C6, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
348 		0, 0},
349 	{"", 1, V2C7, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
350 		0, 0},
351 	{"", 1, V2C8, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
352 		0, 0},
353 
354 	/* Voice 3 - 32 */
355 	{"", 2, V3C1, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
356 		"bitmaps/buttons/sidbon.xpm", 0},
357 	{"", 2, V3C2, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
358 		"bitmaps/buttons/sidbon.xpm", 0},
359 	{"", 2, V3C3, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
360 		"bitmaps/buttons/sidbon.xpm", 0},
361 	{"", 2, V3C4, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
362 		"bitmaps/buttons/sidbon.xpm", 0},
363 	{"", 0, V3C1b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0,0},
364 	{"", 0, V3C2b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0,
365 		BRIGHTON_NOTCH},
366 	{"", 0, V3C3b, V1R2, VBW3, VBH2, 0, 24, 0, "bitmaps/knobs/knobred.xpm",0,0},
367 	{"", 0, V3C4b, V1R2, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm", 0,0},
368 	{"", 2, V3C1, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
369 		"bitmaps/buttons/sidbon.xpm", 0},
370 	{"", 2, V3C2, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
371 		"bitmaps/buttons/sidbon.xpm", 0},
372 	{"", 2, V3C3, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
373 		"bitmaps/buttons/sidbon.xpm", 0},
374 	{"", 2, V3C4, V1R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
375 		"bitmaps/buttons/sidbon.xpm", 0},
376 	{"", 1, V3C5, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
377 		0, 0},
378 	{"", 1, V3C6, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
379 		0, 0},
380 	{"", 1, V3C7, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
381 		0, 0},
382 	{"", 1, V3C8, V1R1, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
383 		0, 0},
384 
385 	/* Filter - 48 */
386 	{"", 2, FC1, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
387 		"bitmaps/buttons/sidbon.xpm", 0},
388 	{"", 2, FC2, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
389 		"bitmaps/buttons/sidbon.xpm", 0},
390 	{"", 2, FC3, V1R1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
391 		"bitmaps/buttons/sidbon.xpm", 0},
392 	{"", 0, FC1b, V1R2-24, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm",
393 		0, 0},
394 	{"", 0, FC2b, V1R2-24, VBW3, VBH2, 0, 15,0, "bitmaps/knobs/knobred.xpm",
395 		0, 0},
396 	{"", 0, FC3b, V1R2-24, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobred.xpm",
397 		0, 0},
398 	{"", 2, FC3, V1R3-50, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
399 		"bitmaps/buttons/sidbon.xpm", 0},
400 	{"", 2, FC3, V1R3+4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
401 		"bitmaps/buttons/sidbon.xpm", 0},
402 
403 	/* Pan and VoiceVolume */
404 	{"", 0,  FC1b, V1R3 - 45, VBW3, VBH2, 0, 15, 0,
405 		"bitmaps/knobs/knobyellow.xpm", 0, 0},
406 	{"", 0,  FC2b, V1R3 - 45, VBW3, VBH2, 0, 15, 0,
407 		"bitmaps/knobs/knobyellow.xpm", 0, 0},
408 
409 	/* 58 - Polymods */
410 	{"", 2, SRC0, S2R0-80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
411 		"bitmaps/buttons/sidbon.xpm", 0},
412 	{"", 2, SRC1, S2R0-80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
413 		"bitmaps/buttons/sidbon.xpm", 0},
414 	{"", 2, SRC2, S2R0-80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
415 		"bitmaps/buttons/sidbon.xpm", 0},
416 	{"", 2, SRC3, S2R0-80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
417 		"bitmaps/buttons/sidbon.xpm", 0},
418 	{"", 2, SRC4, S2R0-80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
419 		"bitmaps/buttons/sidbon.xpm", 0},
420 	{"", 2, SRC5, S2R0-80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
421 		"bitmaps/buttons/sidbon.xpm", 0},
422 	{"", 2, SRC6, S2R0-80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
423 		"bitmaps/buttons/sidbon.xpm", 0},
424 
425 	/* 65 */
426 	{"", 0, SRC0, S2R0-0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
427 		0, 0},
428 	{"", 0, SRC1, S2R0-0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
429 		0, 0},
430 	{"", 0, SRC2, S2R0-0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
431 		0, 0},
432 	{"", 0, SRC3, S2R0-0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
433 		0, 0},
434 	{"", 0, SRC4, S2R0-0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
435 		0, 0},
436 	{"", 0, SRC5, S2R0-0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
437 		0, 0},
438 	{"", 2, SRC6, S2R0+20, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
439 		"bitmaps/buttons/sidbon.xpm", 0},
440 
441 	/* 72 */
442 	{"", 0, SRC0, S2R2+23, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
443 		0, 0},
444 	{"", 0, SRC1, S2R2+23, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
445 		0, 0},
446 	{"", 0, SRC2, S2R2+23, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
447 		0, 0},
448 	{"", 0, SRC3, S2R2+23, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
449 		0, 0},
450 	{"", 0, SRC4, S2R2+23, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
451 		0, 0},
452 	{"", 0, SRC5, S2R2+23, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
453 		0, 0},
454 	{"", 2, SRC6, S2R2+43, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
455 		"bitmaps/buttons/sidbon.xpm", 0},
456 
457 	/* 79 */
458 	{"", 0, SRC0, S2R4, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
459 		0, 0},
460 	{"", 0, SRC1, S2R4, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
461 		0, 0},
462 	{"", 0, SRC2, S2R4, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
463 		0, 0},
464 	{"", 0, SRC3, S2R4, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
465 		0, 0},
466 	{"", 0, SRC4, S2R4, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
467 		0, 0},
468 	{"", 0, SRC5, S2R4, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
469 		0, 0},
470 	{"", 2, SRC6, S2R4+20, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
471 		"bitmaps/buttons/sidbon.xpm", 0},
472 
473 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
474 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
475 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
476 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
477 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
478 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
479 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
480 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
481 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
482 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
483 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
484 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
485 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
486 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
487 
488 	/* 86 - mod routing change to 6 lots of 7 destinations */
489 	{"", 2, SRC0, SRR1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
490 		"bitmaps/buttons/sidbon.xpm", 0},
491 	{"", 2, SRC0, SRR2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
492 		"bitmaps/buttons/sidbon.xpm", 0},
493 	{"", 2, SRC0, SRR3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
494 		"bitmaps/buttons/sidbon.xpm", 0},
495 	{"", 2, SRC0, SRR4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
496 		"bitmaps/buttons/sidbon.xpm", 0},
497 	{"", 2, SRC0, SRR5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
498 		"bitmaps/buttons/sidbon.xpm", 0},
499 	{"", 2, SRC0, SRR6, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
500 		"bitmaps/buttons/sidbon.xpm", 0},
501 
502 	{"", 2, SRC1, SRR1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
503 		"bitmaps/buttons/sidbon.xpm", 0},
504 	{"", 2, SRC1, SRR2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
505 		"bitmaps/buttons/sidbon.xpm", 0},
506 	{"", 2, SRC1, SRR3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
507 		"bitmaps/buttons/sidbon.xpm", 0},
508 	{"", 2, SRC1, SRR4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
509 		"bitmaps/buttons/sidbon.xpm", 0},
510 	{"", 2, SRC1, SRR5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
511 		"bitmaps/buttons/sidbon.xpm", 0},
512 	{"", 2, SRC1, SRR6, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
513 		"bitmaps/buttons/sidbon.xpm", 0},
514 
515 	{"", 2, SRC2, SRR1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
516 		"bitmaps/buttons/sidbon.xpm", 0},
517 	{"", 2, SRC2, SRR2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
518 		"bitmaps/buttons/sidbon.xpm", 0},
519 	{"", 2, SRC2, SRR3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
520 		"bitmaps/buttons/sidbon.xpm", 0},
521 	{"", 2, SRC2, SRR4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
522 		"bitmaps/buttons/sidbon.xpm", 0},
523 	{"", 2, SRC2, SRR5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
524 		"bitmaps/buttons/sidbon.xpm", 0},
525 	{"", 2, SRC2, SRR6, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
526 		"bitmaps/buttons/sidbon.xpm", 0},
527 
528 	{"", 2, SRC3, SRR1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
529 		"bitmaps/buttons/sidbon.xpm", 0},
530 	{"", 2, SRC3, SRR2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
531 		"bitmaps/buttons/sidbon.xpm", 0},
532 	{"", 2, SRC3, SRR3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
533 		"bitmaps/buttons/sidbon.xpm", 0},
534 	{"", 2, SRC3, SRR4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
535 		"bitmaps/buttons/sidbon.xpm", 0},
536 	{"", 2, SRC3, SRR5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
537 		"bitmaps/buttons/sidbon.xpm", 0},
538 	{"", 2, SRC3, SRR6, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
539 		"bitmaps/buttons/sidbon.xpm", 0},
540 
541 	{"", 2, SRC4, SRR1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
542 		"bitmaps/buttons/sidbon.xpm", 0},
543 	{"", 2, SRC4, SRR2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
544 		"bitmaps/buttons/sidbon.xpm", 0},
545 	{"", 2, SRC4, SRR3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
546 		"bitmaps/buttons/sidbon.xpm", 0},
547 	{"", 2, SRC4, SRR4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
548 		"bitmaps/buttons/sidbon.xpm", 0},
549 	{"", 2, SRC4, SRR5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
550 		"bitmaps/buttons/sidbon.xpm", 0},
551 	{"", 2, SRC4, SRR6, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
552 		"bitmaps/buttons/sidbon.xpm", 0},
553 
554 	{"", 2, SRC5, SRR1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
555 		"bitmaps/buttons/sidbon.xpm", 0},
556 	{"", 2, SRC5, SRR2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
557 		"bitmaps/buttons/sidbon.xpm", 0},
558 	{"", 2, SRC5, SRR3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
559 		"bitmaps/buttons/sidbon.xpm", 0},
560 	{"", 2, SRC5, SRR4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
561 		"bitmaps/buttons/sidbon.xpm", 0},
562 	{"", 2, SRC5, SRR5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
563 		"bitmaps/buttons/sidbon.xpm", 0},
564 	{"", 2, SRC5, SRR6, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
565 		"bitmaps/buttons/sidbon.xpm", 0},
566 
567 	{"", 2, SRC6, SRR1, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
568 		"bitmaps/buttons/sidbon.xpm", 0},
569 	{"", 2, SRC6, SRR2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
570 		"bitmaps/buttons/sidbon.xpm", 0},
571 	{"", 2, SRC6, SRR3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
572 		"bitmaps/buttons/sidbon.xpm", 0},
573 	{"", 2, SRC6, SRR4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
574 		"bitmaps/buttons/sidbon.xpm", 0},
575 	{"", 2, SRC6, SRR5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
576 		"bitmaps/buttons/sidbon.xpm", 0},
577 	{"", 2, SRC6, SRR6, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
578 		"bitmaps/buttons/sidbon.xpm", 0},
579 
580 	/*
581 	 * MODS: 135
582 	 *
583 	 */
584 	/*
585 	 * Key Mode:
586 	 * 	First three radio: Mono, Poly-H, Poly-V
587 	 * 	6 voice selectors: All/1/2/3/4/5
588 	 */
589 	{"", 2, S3C0, S2R0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
590 		"bitmaps/buttons/sidbon.xpm", 0},
591 	{"", 2, S3C0, S2R0+40, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
592 		"bitmaps/buttons/sidbon.xpm", 0},
593 	{"", 2, S3C0, S2R0+80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
594 		"bitmaps/buttons/sidbon.xpm", 0},
595 
596 	{"", 2, S3C0, S2R0+160, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
597 		"bitmaps/buttons/sidbon.xpm", 0},
598 
599 	{"", 2, S3C1, S2R0+0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
600 		"bitmaps/buttons/sidbon.xpm", 0},
601 	{"", 2, S3C1, S2R0+40, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
602 		"bitmaps/buttons/sidbon.xpm", 0},
603 	{"", 2, S3C1, S2R0+80, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
604 		"bitmaps/buttons/sidbon.xpm", 0},
605 	{"", 2, S3C1, S2R0+120, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
606 		"bitmaps/buttons/sidbon.xpm", 0},
607 	{"", 2, S3C1, S2R0+160, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
608 		"bitmaps/buttons/sidbon.xpm", 0},
609 
610 	/* Mods - 144 */
611 	{"", 0, S2C1, S2R1, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
612 		0, 0},
613 	{"", 0, S2C3, S2R1, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
614 		0, 0},
615 	{"", 2, S2C1, S2R4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
616 		"bitmaps/buttons/sidbon.xpm", 0},
617 	{"", 2, S2C2, S2R4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
618 		"bitmaps/buttons/sidbon.xpm", 0},
619 	{"", 2, S2C3, S2R4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
620 		"bitmaps/buttons/sidbon.xpm", 0},
621 	{"", 2, S2C4, S2R4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
622 		"bitmaps/buttons/sidbon.xpm", 0},
623 
624 	/* 150 - bus selections */
625 	{"", 2, S2C5, S2R0+0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
626 		"bitmaps/buttons/sidbon.xpm", 0},
627 	{"", 2, S2C5, S2R0+35, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
628 		"bitmaps/buttons/sidbon.xpm", 0},
629 	{"", 2, S2C5, S2R0+70, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
630 		"bitmaps/buttons/sidbon.xpm", 0},
631 	{"", 2, S2C5, S2R0+105, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
632 		"bitmaps/buttons/sidbon.xpm", 0},
633 	{"", 2, S2C5, S2R0+140, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
634 		"bitmaps/buttons/sidbon.xpm", 0},
635 	{"", 2, S2C5, S2R0+175, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
636 		"bitmaps/buttons/sidbon.xpm", 0},
637 
638 	/* 156 - Mod Touch control */
639 	{"", 2, S2C2, S2R2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
640 		"bitmaps/buttons/sidbon.xpm", 0},
641 	{"", 2, S2C4, S2R2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
642 		"bitmaps/buttons/sidbon.xpm", 0},
643 
644 	/* 158 - Env mods */
645 	{"", 2, S2C7, S2R0+0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
646 		"bitmaps/buttons/sidbon.xpm", 0},
647 	{"", 2, S2C7, S2R0+35, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
648 		"bitmaps/buttons/sidbon.xpm", 0},
649 	{"", 2, S2C7, S2R0+70, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
650 		"bitmaps/buttons/sidbon.xpm", 0},
651 	{"", 2, S2C7, S2R0+105, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
652 		"bitmaps/buttons/sidbon.xpm", 0},
653 	{"", 2, S2C7, S2R0+140, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
654 		"bitmaps/buttons/sidbon.xpm", 0},
655 	{"", 2, S2C7, S2R0+175, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
656 		"bitmaps/buttons/sidbon.xpm", 0},
657 
658 	/* 166 - Mod Env */
659 	{"", 1, S2C8b, S2R0, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
660 		0, 0},
661 	{"", 1, S2C9, S2R0, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
662 		0, 0},
663 	{"", 1, S2C10, S2R0, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
664 		0, 0},
665 	{"", 1, S2C11, S2R0, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
666 		0, 0},
667 	{"", 1, S2C12, S2R0, VBW2, VBH4, 0, 1, 0, "bitmaps/buttons/polywhiteV.xpm",
668 		0, 0},
669 	{"", 2, S2C8, S2R0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
670 		"bitmaps/buttons/sidbon.xpm", 0},
671 	{"", 2, S2C8, S2R4, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
672 		"bitmaps/buttons/sidbon.xpm", 0},
673 
674 	/* 173 - 2nd Mods */
675 	{"", 0, S2C1, S2R6, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
676 		0, 0},
677 	{"", 0, S2C3, S2R6, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobgreen.xpm",
678 		0, 0},
679 	{"", 2, S2C1, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
680 		"bitmaps/buttons/sidbon.xpm", 0},
681 	{"", 2, S2C2, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
682 		"bitmaps/buttons/sidbon.xpm", 0},
683 	{"", 2, S2C3, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
684 		"bitmaps/buttons/sidbon.xpm", 0},
685 	{"", 2, S2C4, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
686 		"bitmaps/buttons/sidbon.xpm", 0},
687 
688 	/* 179 */
689 	{"", 2, S2C5, S2R5+00, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
690 		"bitmaps/buttons/sidbon.xpm", 0},
691 	{"", 2, S2C5, S2R5+35, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
692 		"bitmaps/buttons/sidbon.xpm", 0},
693 	{"", 2, S2C5, S2R5+70, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
694 		"bitmaps/buttons/sidbon.xpm", 0},
695 	{"", 2, S2C5, S2R5+105, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
696 		"bitmaps/buttons/sidbon.xpm", 0},
697 	{"", 2, S2C5, S2R5+140, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
698 		"bitmaps/buttons/sidbon.xpm", 0},
699 	{"", 2, S2C5, S2R5+175, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
700 		"bitmaps/buttons/sidbon.xpm", 0},
701 
702 	/* 185 - Mod Touch control */
703 	{"", 2, S2C2, S2R5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
704 		"bitmaps/buttons/sidbon.xpm", 0},
705 	{"", 2, S2C2, S2R7, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
706 		"bitmaps/buttons/sidbon.xpm", 0},
707 	{"", 2, S2C4, S2R5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
708 		"bitmaps/buttons/sidbon.xpm", 0},
709 	{"", 2, S2C4, S2R7, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
710 		"bitmaps/buttons/sidbon.xpm", 0},
711 
712 	/* 189 - Env mods */
713 	{"", 2, S2C7, S2R5+00, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
714 		"bitmaps/buttons/sidbon.xpm", 0},
715 	{"", 2, S2C7, S2R5+35, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
716 		"bitmaps/buttons/sidbon.xpm", 0},
717 	{"", 2, S2C7, S2R5+70, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
718 		"bitmaps/buttons/sidbon.xpm", 0},
719 	{"", 2, S2C7, S2R5+105, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
720 		"bitmaps/buttons/sidbon.xpm", 0},
721 	{"", 2, S2C7, S2R5+140, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
722 		"bitmaps/buttons/sidbon.xpm", 0},
723 	{"", 2, S2C7, S2R5+175, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
724 		"bitmaps/buttons/sidbon.xpm", 0},
725 
726 	/* 195 - Mod Env */
727 	{"", 1, S2C8b, S2R5, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
728 		0, 0},
729 	{"", 1, S2C9, S2R5, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
730 		0, 0},
731 	{"", 1, S2C10, S2R5, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
732 		0, 0},
733 	{"", 1, S2C11, S2R5, VBW2, VBH4, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
734 		0, 0},
735 	{"", 1, S2C12, S2R5, VBW2, VBH4, 0, 1, 0, "bitmaps/buttons/polywhiteV.xpm",
736 		0, 0},
737 	{"", 2, S2C8, S2R5, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
738 		"bitmaps/buttons/sidbon.xpm", 0},
739 	{"", 2, S2C8, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
740 		"bitmaps/buttons/sidbon.xpm", 0},
741 
742 	/* 202 - Dummies for voice /modes, etc */
743 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
744 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
745 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
746 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
747 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
748 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
749 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
750 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
751 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
752 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
753 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
754 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
755 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
756 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
757 
758 	{"", 2, 0, 0, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm", 0,
759 		BRIGHTON_WITHDRAWN|BRIGHTON_NOSHADOW},
760 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
761 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
762 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
763 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
764 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
765 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
766 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
767 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
768 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
769 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
770 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
771 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
772 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
773 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
774 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
775 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
776 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
777 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
778 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
779 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
780 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
781 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
782 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
783 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
784 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
785 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
786 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
787 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
788 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
789 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
790 
791 	/*
792 	 * This will shadow the version of the memory. Existing memories will have
793 	 * a zero in here (0.40) ones saved by this release (0.40.2) will have a
794 	 * 1 in there, this allows the GUI to adjust the keymode parameter.
795 	 */
796 #warning this index has changed
797 #define M_VERS 223
798 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
799 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
800 
801 	/* ??? - These shadow the mod panel */
802 #warning this index has changed too
803 #define M_SHAD 224
804 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
805 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
806 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
807 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
808 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
809 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
810 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
811 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
812 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
813 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
814 
815 	/* 229 - Globals - not saved in memories */
816 	{"", 0, S3C2, S2R0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobblue.xpm",
817 		0, 0},
818 	{"", 0, S3C2, S2R3, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobblue.xpm",
819 		0, 0},
820 	{"", 0, S3C3, S2R0, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobblue.xpm",
821 		0, 0},
822 	{"", 0, S3C3, S2R3, VBW3, VBH2, 0, 1, 0, "bitmaps/knobs/knobblue.xpm",
823 		0, 0},
824 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
825 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
826 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
827 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
828 	{"", 1, 0, 0, VBW2, VBH3, 0, 15, 0, "bitmaps/buttons/polywhiteV.xpm",
829 		0, BRIGHTON_NOSHADOW|BRIGHTON_WITHDRAWN},
830 
831 	/* 236 - Master Vol */
832 	{"", 0, S3C4, S2R1+20, VBW3, VBH2+30, 0, 1, 0,
833 		"bitmaps/knobs/knob.xpm", 0, 0},
834 
835 	/* Memories 237 - first 8 digits */
836 	{"", 2, S2C17, S2R8, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
837 		"bitmaps/buttons/sidbongreen.xpm", 0},
838 	{"", 2, S2C18, S2R8, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
839 		"bitmaps/buttons/sidbongreen.xpm", 0},
840 	{"", 2, S2C19, S2R8, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
841 		"bitmaps/buttons/sidbongreen.xpm", 0},
842 	{"", 2, S2C20, S2R8, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
843 		"bitmaps/buttons/sidbongreen.xpm", 0},
844 
845 	{"", 2, S2C17, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
846 		"bitmaps/buttons/sidbongreen.xpm", 0},
847 	{"", 2, S2C18, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
848 		"bitmaps/buttons/sidbongreen.xpm", 0},
849 	{"", 2, S2C19, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
850 		"bitmaps/buttons/sidbongreen.xpm", 0},
851 	{"", 2, S2C20, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
852 		"bitmaps/buttons/sidbongreen.xpm", 0},
853 
854 	/* Then load/save */
855 	{"", 2, S2C16, S2R8, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
856 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
857 	{"", 2, S2C16, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
858 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
859 
860 	/* Then Bank, down, up, find */
861 	{"", 2, S2C21, S2R8, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
862 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
863 	{"", 2, S2C22, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
864 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
865 	{"", 2, S2C22, S2R8, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
866 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
867 	{"", 2, S2C21, S2R9, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
868 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
869 
870 	/* Midi */
871 	{"", 2, S3C5, S2R2, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
872 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
873 	{"", 2, S3C5, S2R3, VBW1, VBH1, 0, 1, 0, "bitmaps/buttons/sidb.xpm",
874 		"bitmaps/buttons/sidbon.xpm", BRIGHTON_CHECKBUTTON},
875 
876 	/* Done */
877 
878 	{"", 3, S2C17, S2R6, 175, 45, 0, 1, 0, 0,
879 		"bitmaps/images/alphadisplay3.xpm", 0}
880 
881 };
882 
883 /*
884  * This is a set of globals for the main window rendering. Again taken from
885  * include/brighton.h
886  * Hm, the bit-1 was black, and the bit 99 was in various builds including a
887  * white one, but also a black one and a black one with wood panels. I would
888  * like the black one with wood panels, so that will have to be the bit-1, the
889  * bit-99 will be white with thin metal panels.
890  */
891 brightonApp sid2App = {
892 	"melbourne",
893 	0, /* no blueprint on wood background. */
894 	"bitmaps/textures/metal1.xpm",
895 	//"bitmaps/textures/p8b.xpm",
896 	BRIGHTON_STRETCH,
897 	sid2Init,
898 	sid2Configure, /* 3 callbacks, unused? */
899 	midiCallback,
900 	destroySynth,
901 	{1, 100, 2, 2, 5, 520, 0, 0},
902 	1000, 450, 0, 0,
903 	3, /* panels */
904 	{
905 		{
906 			"Sid800",
907 			"bitmaps/blueprints/sid2.xpm",
908 			"bitmaps/textures/metal1.xpm",
909 			BRIGHTON_STRETCH, /* flags */
910 			0,
911 			0,
912 			sid2Callback,
913 			25, 16, 950, 720,
914 			DEVICE_COUNT,
915 			locations
916 		},
917 		{
918 			"Keyboard",
919 			0,
920 			"bitmaps/newkeys/nkbg.xpm",
921 			0x020|BRIGHTON_STRETCH,
922 			0,
923 			0,
924 			sid2KeyCallback,
925 			90, 760, 893, 230,
926 			KEY_COUNT_5OCTAVE,
927 			keysprofile2
928 		},
929 		{
930 			"mods",
931 			"bitmaps/buttons/blue.xpm",
932 			"bitmaps/textures/metal1.xpm",
933 			0,
934 			0,
935 			0,
936 			sid2ModCallback,
937 			32, 780, 50, 170,
938 			5,
939 			modwheel
940 		},
941 	}
942 };
943 
944 /*
945  * We really want to just use one midi channel and let the midi library decide
946  * that we have multiple synths on the channel with their own split points.
947  * The lower layer should define the midi channel, split point and transpose
948  * of upper layer.
949  */
950 static int
sid2KeyCallback(brightonWindow * win,int panel,int index,float value)951 sid2KeyCallback(brightonWindow *win, int panel, int index, float value)
952 {
953 	guiSynth *synth = findSynth(global.synths, win);
954 
955 	if (global.libtest)
956 		return(0);
957 
958 	/*
959 	 * So we have a single key event and two MIDI channels. Just send the
960 	 * event on both channels, no need to be difficult about it since if this
961 	 * was a split configuration the library filters out the events.
962 	 */
963 	if (value) {
964 		bristolMidiSendMsg(global.controlfd, synth->midichannel,
965 			BRISTOL_EVENT_KEYON, 0, index + synth->transpose);
966 	} else {
967 		bristolMidiSendMsg(global.controlfd, synth->midichannel,
968 			BRISTOL_EVENT_KEYOFF, 0, index + synth->transpose);
969 	}
970 
971 	return(0);
972 }
973 
974 /*
975  * At this point we have loaded a memory so we need to send those actual new
976  * parameters to the engine. This is an issue for MIDI program load, perhaps
977  * we should consid2er dual load above memory 74 as per the original?
978  *
979  * The path of least resistance here is to scan through the the memory table
980  * incrementing the input selector and delivering the memory value to the
981  * data entry pot.....
982  */
983 static void
loadMemoryShim(guiSynth * synth)984 loadMemoryShim(guiSynth *synth)
985 {
986 	brightonEvent event;
987 
988 	/* We need to force some exclusion on LFO mods and Mode */
989 	synth->dispatch[173].other1 =
990 		synth->mem.param[173] != 0? 0:
991 			synth->mem.param[174] != 0? 1:
992 				synth->mem.param[175] != 0? 2:
993 						synth->mem.param[176] != 0? 3: 0;
994 
995 	/* We need to force some exclusion on LFO mods and Mode */
996 	synth->dispatch[146].other1 =
997 		synth->mem.param[146] != 0? 0:
998 			synth->mem.param[147] != 0? 1:
999 				synth->mem.param[148] != 0? 2:
1000 						synth->mem.param[149] != 0? 3: 0;
1001 
1002 		synth->dispatch[135].other1 =
1003 			synth->mem.param[135] != 0? 0:
1004 				synth->mem.param[136] != 0? 1:
1005 					synth->mem.param[137] != 0? 2: 0;
1006 
1007 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 5,
1008 		synth->dispatch[135].other1);
1009 
1010 	/* Set up the trigger options */
1011 
1012 	/* Then we can look at the mod panel options */
1013 	event.type = BRISTOL_FLOAT;
1014 	event.value = synth->mem.param[111];
1015 	brightonParamChange(synth->win, MODS_PANEL, 1, &event);
1016 	event.value = synth->mem.param[112];
1017 	brightonParamChange(synth->win, MODS_PANEL, 2, &event);
1018 	event.value = synth->mem.param[113];
1019 	brightonParamChange(synth->win, MODS_PANEL, 3, &event);
1020 	event.value = synth->mem.param[114];
1021 	brightonParamChange(synth->win, MODS_PANEL, 4, &event);
1022 
1023 	/* And we should enforce mod waveform */
1024 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 66,
1025 		synth->mem.param[146] == 0?0:1);
1026 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 67,
1027 		synth->mem.param[147] == 0?0:1);
1028 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 68,
1029 		synth->mem.param[149] == 0?0:1);
1030 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 69,
1031 		synth->mem.param[149] == 0?0:1);
1032 	if (synth->mem.param[146] != 0)
1033 		bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 66, 1);
1034 
1035 	/* And we should enforce mod waveform */
1036 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 66,
1037 		synth->mem.param[173] == 0?0:1);
1038 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 67,
1039 		synth->mem.param[174] == 0?0:1);
1040 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 68,
1041 		synth->mem.param[175] == 0?0:1);
1042 	bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 69,
1043 		synth->mem.param[176] == 0?0:1);
1044 	if (synth->mem.param[173] != 0)
1045 		bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 66, 1);
1046 
1047 	/* See if we have to force memory variables */
1048 	if (synth->mem.param[70] != 0)
1049 	{
1050 		int i;
1051 
1052 		for (i = 0; i < 20; i++)
1053 		{
1054 			event.value = synth->mem.param[i];
1055 			brightonParamChange(synth->win, 0, i, &event);
1056 			brightonParamChange(synth->win, 0, i + 20, &event);
1057 			brightonParamChange(synth->win, 0, i + 40, &event);
1058 		}
1059 	}
1060 }
1061 
1062 static void
loadMemoryMidiShim(guiSynth * synth,int from)1063 loadMemoryMidiShim(guiSynth *synth, int from)
1064 {
1065 	loadMemory(synth, SYNTH_NAME, 0, synth->bank * 10 + from,
1066 		synth->mem.active, 0, BRISTOL_FORCE);
1067 	loadMemoryShim(synth);
1068 }
1069 
1070 static int
midiCallback(brightonWindow * win,int controller,int value,float n)1071 midiCallback(brightonWindow *win, int controller, int value, float n)
1072 {
1073 	guiSynth *synth = findSynth(global.synths, win);
1074 
1075 	switch(controller)
1076 	{
1077 		case MIDI_PROGRAM:
1078 			if (synth->mem.param[87] == 0)
1079 				return(0);
1080 			/*
1081 			 * We should accept 0..74 as lower layer and above that as dual
1082 			 * loading requests.
1083 			 */
1084 			printf("midi program: %x, %i\n", controller, value);
1085 			synth->location = value;
1086 			loadMemoryMidiShim(synth, synth->location);
1087 			break;
1088 		case MIDI_BANK_SELECT:
1089 			printf("midi banksel: %x, %i\n", controller, value);
1090 			synth->bank = value;
1091 			break;
1092 	}
1093 	return(0);
1094 }
1095 
1096 static int
sid2MidiNull(void * synth,int fd,int chan,int c,int o,int v)1097 sid2MidiNull(void *synth, int fd, int chan, int c, int o, int v)
1098 {
1099 	if (global.libtest)
1100 		printf("This is a null callback on %i id %i\n", c, o);
1101 
1102 	return(0);
1103 }
1104 
1105 static int vexclude = 0;
1106 
1107 /*
1108  * Typically this should just do what sid2MidiShim does, send the parameter to
1109  * the target however in mode Poly-1 all voices need to have the same set of
1110  * parameters. This really means the GUI needs to replicate the parameter
1111  * changes all voice params. There are many ways to do this, the coolest is
1112  * actually to redistribute the requests, ganging the controls.
1113  */
1114 static void
sid2VoiceShim(guiSynth * synth,int fd,int chan,int c,int o,int v)1115 sid2VoiceShim(guiSynth *synth, int fd, int chan, int c, int o, int v)
1116 {
1117 	brightonEvent event;
1118 	int off1 = 20, off2 = 40;
1119 
1120 	if (synth->mem.param[70] != 0)
1121 	{
1122 		if (vexclude)
1123 			return;
1124 
1125 		event.value = synth->mem.param[o - 10];
1126 
1127 		vexclude = 1;
1128 
1129 		/* Find out what parameters we need to use */
1130 		if (o >= 50)
1131 		{
1132 			off1 = -40;
1133 			off2 = -20;
1134 		} else if (o >= 30) {
1135 			off1 = -20;
1136 			off2 = 20;
1137 		}
1138 
1139 		/* Update the displays */
1140 		brightonParamChange(synth->win, synth->panel, o - 10 + off1, &event);
1141 		brightonParamChange(synth->win, synth->panel, o - 10 + off2, &event);
1142 
1143 		vexclude = 0;
1144 
1145 		/* Send the messages for the other voices */
1146 		bristolMidiSendMsg(fd, synth->sid2, c, o + off1, v);
1147 		bristolMidiSendMsg(fd, synth->sid2, c, o + off2, v);
1148 	}
1149 	bristolMidiSendMsg(fd, synth->sid2, c, o, v);
1150 }
1151 
1152 static void
sid2MidiShim(guiSynth * synth,int fd,int chan,int c,int o,int v)1153 sid2MidiShim(guiSynth *synth, int fd, int chan, int c, int o, int v)
1154 {
1155 	bristolMidiSendMsg(fd, synth->sid2, c, o, v);
1156 }
1157 
1158 static void
sid2LFOWave(guiSynth * synth,int fd,int chan,int c,int o,int v)1159 sid2LFOWave(guiSynth *synth, int fd, int chan, int c, int o, int v)
1160 {
1161 	brightonEvent event;
1162 
1163 	event.value = 1.0;
1164 	event.type = BRISTOL_FLOAT;
1165 
1166 	if (synth->flags & MEM_LOADING)
1167 		return;
1168 	if ((synth->flags & OPERATIONAL) == 0)
1169 		return;
1170 
1171 	if (synth->dispatch[146].other2)
1172 	{
1173 		synth->dispatch[146].other2 = 0;
1174 		return;
1175 	}
1176 
1177 	/*
1178 	 * We want to make these into memory buttons. To do so we need to
1179 	 * know what the last active button was, and deactivate its
1180 	 * display, then send any message which represents the most
1181 	 * recently configured value. Since this is a memory button we do
1182 	 * not have much issue with the message, but we are concerned with
1183 	 * the display.
1184 	 */
1185 	if (synth->dispatch[146].other1 != -1)
1186 	{
1187 		synth->dispatch[146].other2 = 1;
1188 
1189 		if (synth->dispatch[146].other1 != o)
1190 			event.value = 0;
1191 		else
1192 			event.value = 1;
1193 
1194 		brightonParamChange(synth->win, synth->panel,
1195 			synth->dispatch[146].other1 + 146, &event);
1196 		bristolMidiSendMsg(fd, synth->sid2, 126,
1197 			66 + synth->dispatch[146].other1, 0);
1198 	}
1199 	synth->dispatch[146].other1 = o;
1200 
1201 	bristolMidiSendMsg(fd, synth->sid2, 126, 66 + o, 1);
1202 }
1203 
1204 static int mode = -1;
1205 
1206 static void
sid2Mode(guiSynth * synth,int fd,int chan,int c,int o,int v)1207 sid2Mode(guiSynth *synth, int fd, int chan, int c, int o, int v)
1208 {
1209 	brightonEvent event;
1210 	int i, sv;
1211 
1212 	event.value = 1.0;
1213 	event.type = BRISTOL_FLOAT;
1214 
1215 	if (synth->flags & MEM_LOADING)
1216 		return;
1217 	if ((synth->flags & OPERATIONAL) == 0)
1218 		return;
1219 
1220 	if (synth->dispatch[135].other2)
1221 	{
1222 		synth->dispatch[135].other2 = 0;
1223 		return;
1224 	}
1225 
1226 	/*
1227 	 * We want to make these into memory buttons. To do so we need to
1228 	 * know what the last active button was, and deactivate its
1229 	 * display, then send any message which represents the most
1230 	 * recently configured value. Since this is a memory button we do
1231 	 * not have much issue with the message, but we are concerned with
1232 	 * the display.
1233 	 */
1234 	if (synth->dispatch[135].other1 != -1)
1235 	{
1236 		synth->dispatch[135].other2 = 1;
1237 
1238 		if (synth->dispatch[135].other1 != o)
1239 			event.value = 0;
1240 		else
1241 			event.value = 1;
1242 
1243 		brightonParamChange(synth->win, synth->panel,
1244 			synth->dispatch[135].other1 + 135, &event);
1245 	}
1246 	synth->dispatch[135].other1 = o;
1247 
1248 	bristolMidiSendMsg(fd, synth->sid2, 126, 5, o);
1249 
1250 	/*
1251 	 * This code would sync all the voice parameters as we enter Poly-1 however
1252 	 * that is always desirable. We should either sync the engine parameters
1253 	 * to voice-3 entering Poly-1 and reset them to GUI parameters on exit,
1254 	 * or do nothing.
1255 	 */
1256 	if (synth->mem.param[70] != 0)
1257 	{
1258 		/*
1259 		 * Sync voices in engine
1260 		 */
1261 		if (mode != 1)
1262 			for (i = 0; i < 20; i++)
1263 			{
1264 				if (sid2App.resources[0].devlocn[i].to == 1)
1265 					sv = synth->mem.param[i+40] * C_RANGE_MIN_1;
1266 				else
1267 					sv = synth->mem.param[i+40];
1268 
1269 				bristolMidiSendMsg(fd, synth->sid2, 126, i + 10, sv);
1270 				bristolMidiSendMsg(fd, synth->sid2, 126, i + 30, sv);
1271 			}
1272 	} else {
1273 		if (mode == 1)
1274 			for (i = 0; i < 60; i++)
1275 			{
1276 				event.value = synth->mem.param[i];
1277 				brightonParamChange(synth->win, synth->panel, i, &event);
1278 			}
1279 	}
1280 
1281 	mode = o;
1282 }
1283 
1284 static void
sid2Memory(guiSynth * synth,int fd,int chan,int c,int o,int v)1285 sid2Memory(guiSynth *synth, int fd, int chan, int c, int o, int v)
1286 {
1287 	brightonEvent event;
1288 	int bank = synth->bank;
1289 	int location = synth->location;
1290 
1291 	event.value = 1.0;
1292 	event.type = BRISTOL_FLOAT;
1293 
1294 	if (synth->flags & MEM_LOADING)
1295 		return;
1296 	if ((synth->flags & OPERATIONAL) == 0)
1297 		return;
1298 
1299 	if (synth->dispatch[MEM_START].other2)
1300 	{
1301 		synth->dispatch[MEM_START].other2 = 0;
1302 		return;
1303 	}
1304 
1305 	switch (c) {
1306 		default:
1307 		case 0:
1308 			/*
1309 			 * We want to make these into memory buttons. To do so we need to
1310 			 * know what the last active button was, and deactivate its
1311 			 * display, then send any message which represents the most
1312 			 * recently configured value. Since this is a memory button we do
1313 			 * not have much issue with the message, but we are concerned with
1314 			 * the display.
1315 			 */
1316 			if (synth->dispatch[MEM_START].other1 != -1)
1317 			{
1318 				synth->dispatch[MEM_START].other2 = 1;
1319 
1320 				if (synth->dispatch[MEM_START].other1 != o)
1321 					event.value = 0;
1322 				else
1323 					event.value = 1;
1324 
1325 				brightonParamChange(synth->win, synth->panel,
1326 					synth->dispatch[MEM_START].other1 + MEM_START - 1, &event);
1327 			}
1328 			synth->dispatch[MEM_START].other1 = o;
1329 
1330 			if (synth->flags & BANK_SELECT) {
1331 				if ((synth->bank * 10 + o) >= 100)
1332 				{
1333 					synth->location = o;
1334 					synth->flags &= ~BANK_SELECT;
1335 
1336 					if (loadMemory(synth, SYNTH_NAME, 0,
1337 						synth->bank * 10 + synth->location, synth->mem.active,
1338 							0, BRISTOL_STAT) < 0)
1339 						displayText(synth, "FREE MEM",
1340 							synth->bank * 10 + synth->location, DISPLAY_DEV);
1341 					else
1342 						displayText(synth, "PROGRAM",
1343 							synth->bank * 10 + synth->location, DISPLAY_DEV);
1344 				} else {
1345 					synth->bank = synth->bank * 10 + o;
1346 					displayText(synth, "BANK",
1347 						synth->bank * 10 + synth->location, DISPLAY_DEV);
1348 				}
1349 			} else {
1350 				if (synth->bank < 1)
1351 					synth->bank = 1;
1352 				synth->location = o;
1353 				if (loadMemory(synth, SYNTH_NAME, 0,
1354 					synth->bank * 10 + synth->location, synth->mem.active,
1355 						0, BRISTOL_STAT) < 0)
1356 					displayText(synth, "FREE MEM",
1357 						synth->bank * 10 + synth->location, DISPLAY_DEV);
1358 				else
1359 					displayText(synth, "PROGRAM",
1360 						synth->bank * 10 + synth->location, DISPLAY_DEV);
1361 			}
1362 			break;
1363 		case 1:
1364 			if (synth->bank < 1)
1365 				synth->bank = 1;
1366 			if (synth->location == 0)
1367 				synth->location = 1;
1368 			if (loadMemory(synth, SYNTH_NAME, 0,
1369 				synth->bank * 10 + synth->location,
1370 				synth->mem.active, 0, BRISTOL_FORCE) < 0)
1371 				displayText(synth, "FREE MEM",
1372 					synth->bank * 10 + synth->location, DISPLAY_DEV);
1373 			else {
1374 				loadMemoryShim(synth);
1375 				displayText(synth, "PROGRAM",
1376 					synth->bank * 10 + synth->location, DISPLAY_DEV);
1377 			}
1378 			synth->flags &= ~BANK_SELECT;
1379 
1380 			/* Doubleclick on load will toggle debugging */
1381 			if (brightonDoubleClick(dc) != 0)
1382 				bristolMidiSendMsg(fd, synth->sid2, 126, 4, 1);
1383 
1384 			break;
1385 		case 2:
1386 			if (synth->bank < 1)
1387 				synth->bank = 1;
1388 			if (synth->location == 0)
1389 				synth->location = 1;
1390 			if (brightonDoubleClick(dc) != 0)
1391 			{
1392 				synth->mem.param[M_VERS] = 1.0;
1393 				saveMemory(synth, SYNTH_NAME, 0,
1394 					synth->bank * 10 + synth->location, 0);
1395 				displayText(synth, "PROGRAM",
1396 					synth->bank * 10 + synth->location, DISPLAY_DEV);
1397 				synth->flags &= ~BANK_SELECT;
1398 			}
1399 			break;
1400 		case 3:
1401 			if (synth->flags & BANK_SELECT) {
1402 				synth->flags &= ~BANK_SELECT;
1403 				if (loadMemory(synth, SYNTH_NAME, 0,
1404 					synth->bank * 10 + synth->location, synth->mem.active,
1405 						0, BRISTOL_STAT) < 0)
1406 					displayText(synth, "FREE MEM",
1407 						synth->bank * 10 + synth->location, DISPLAY_DEV);
1408 				else
1409 					displayText(synth, "PROGRAM",
1410 						synth->bank * 10 + synth->location, DISPLAY_DEV);
1411 			} else {
1412 				synth->bank = 0;
1413 				displayText(synth, "BANK", synth->bank, DISPLAY_DEV);
1414 				synth->flags |= BANK_SELECT;
1415 			}
1416 			break;
1417 		case 4:
1418 			if (--location < 1) {
1419 				location = 8;
1420 				if (--bank < 1)
1421 					bank = 88;
1422 			}
1423 			while (loadMemory(synth, SYNTH_NAME, 0, bank * 10 + location,
1424 				synth->mem.active, 0, BRISTOL_STAT) < 0)
1425 			{
1426 				if (--location < 1) {
1427 					location = 8;
1428 					if (--bank < 1)
1429 						bank = 88;
1430 				}
1431 				if ((bank * 10 + location)
1432 					== (synth->bank * 10 + synth->location))
1433 					break;
1434 			}
1435 			displayText(synth, "PROGRAM", bank * 10 + location, DISPLAY_DEV);
1436 			synth->bank = bank;
1437 			synth->location = location;
1438 			loadMemory(synth, SYNTH_NAME, 0, bank * 10 + location,
1439 				synth->mem.active, 0, BRISTOL_FORCE);
1440 			loadMemoryShim(synth);
1441 			brightonParamChange(synth->win, 0,
1442 				MEM_START - 1 + synth->location, &event);
1443 			break;
1444 		case 5:
1445 			if (++location > 8) {
1446 				location = 1;
1447 				if (++bank > 88)
1448 					bank = 1;
1449 			}
1450 			while (loadMemory(synth, SYNTH_NAME, 0, bank * 10 + location,
1451 				synth->mem.active, 0, BRISTOL_STAT) < 0)
1452 			{
1453 				if (++location > 8) {
1454 					location = 1;
1455 					if (++bank > 88)
1456 						bank = 1;
1457 				}
1458 				if ((bank * 10 + location)
1459 					== (synth->bank * 10 + synth->location))
1460 					break;
1461 			}
1462 			displayText(synth, "PROGRAM", bank * 10 + location, DISPLAY_DEV);
1463 			synth->bank = bank;
1464 			synth->location = location;
1465 			loadMemory(synth, SYNTH_NAME, 0, bank * 10 + location,
1466 				synth->mem.active, 0, BRISTOL_FORCE);
1467 			loadMemoryShim(synth);
1468 			brightonParamChange(synth->win, 0,
1469 				MEM_START - 1 + synth->location, &event);
1470 			break;
1471 		case 6:
1472 			/* Find the next free mem */
1473 			if (++location > 8) {
1474 				location = 1;
1475 				if (++bank > 88)
1476 					bank = 1;
1477 			}
1478 
1479 			while (loadMemory(synth, SYNTH_NAME, 0, bank * 10 + location,
1480 				synth->mem.active, 0, BRISTOL_STAT) >= 0)
1481 			{
1482 				if (++location > 8) {
1483 					location = 1;
1484 					if (++bank > 88)
1485 						bank = 1;
1486 				}
1487 				if ((bank * 10 + location)
1488 					== (synth->bank * 10 + synth->location))
1489 					break;
1490 			}
1491 
1492 			if (loadMemory(synth, SYNTH_NAME, 0, bank * 10 + location,
1493 				synth->mem.active, 0, BRISTOL_STAT) >= 0)
1494 				displayText(synth, "PROGRAM",
1495 					bank * 10 + location, DISPLAY_DEV);
1496 			else
1497 				displayText(synth, "FREE MEM",
1498 					bank * 10 + location, DISPLAY_DEV);
1499 
1500 			synth->bank = bank;
1501 			synth->location = location;
1502 			brightonParamChange(synth->win, 0,
1503 				MEM_START - 1 + synth->location, &event);
1504 			break;
1505 	}
1506 }
1507 
1508 static int
sid2ModCallback(brightonWindow * win,int panel,int index,float value)1509 sid2ModCallback(brightonWindow *win, int panel, int index, float value)
1510 {
1511 	guiSynth *synth = findSynth(global.synths, win);
1512 	brightonEvent event;
1513 
1514 	event.type = BRISTOL_FLOAT;
1515 	synth->mem.param[M_SHAD + index] = value;
1516 
1517 	switch (index) {
1518 		case 0:
1519 			/* Wheel - we don't send pitch, just mod */
1520 			bristolMidiControl(global.controlfd, synth->midichannel,
1521 				0, 1, ((int) (value * (C_RANGE_MIN_1 - 1))) >> 7);
1522 			break;
1523 		case 1:
1524 			/* Pitch select - these should actually just flag the engine */
1525 			bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 100,
1526 				value == 0?0:1);
1527 			break;
1528 		case 2:
1529 			/* LFO Select - these should actually just flag the engine */
1530 			bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 98,
1531 				value == 0?0:1);
1532 			if ((synth->mem.param[M_SHAD + index] = value) == 0)
1533 				return(0);
1534 
1535 			bristolMidiControl(global.controlfd, synth->midichannel, 0, 1,
1536 				((int) (synth->mem.param[M_SHAD] * (C_RANGE_MIN_1 - 1))) >> 7);
1537 			break;
1538 		case 3:
1539 			/* ENV Select - these should actually just flag the engine */
1540 			bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 99,
1541 				value == 0?0:1);
1542 			if ((synth->mem.param[M_SHAD + index] = value) == 0)
1543 				return(0);
1544 
1545 			bristolMidiControl(global.controlfd, synth->midichannel, 0, 1,
1546 				((int) (synth->mem.param[M_SHAD] * (C_RANGE_MIN_1 - 1))) >> 7);
1547 			break;
1548 		case 4:
1549 			/* Center spring */
1550 			if (value == 0)
1551 				win->app->resources[panel].devlocn[0].flags &= ~BRIGHTON_CENTER;
1552 			else {
1553 				win->app->resources[panel].devlocn[0].flags |= BRIGHTON_CENTER;
1554 				/* And centre the control */
1555 				event.value = 0.5;
1556 				brightonParamChange(synth->win, panel, 0, &event);
1557 			}
1558 			break;
1559 	};
1560 
1561 	return(0);
1562 }
1563 
1564 /*
1565  * For the sake of ease of use, links have been placed here to be called
1566  * by any of the devices created. They would be better in some other file,
1567  * perhaps with this as a dispatch.
1568  *
1569  * Param refers to the device index in the locations table given below.
1570  */
1571 static int
sid2Callback(brightonWindow * win,int panel,int index,float value)1572 sid2Callback(brightonWindow *win, int panel, int index, float value)
1573 {
1574 	guiSynth *synth = findSynth(global.synths, win);
1575 	int sendvalue;
1576 
1577 	if (global.libtest)
1578 		printf("sid2Callback(%i, %i, %f)\n", panel, index, value);
1579 
1580 	if (synth == 0)
1581 		return(0);
1582 
1583 	if ((index >= DEVICE_COUNT) || ((synth->flags & OPERATIONAL) == 0))
1584 		return(0);
1585 
1586 	if ((index >= 111) && (index <= 114))
1587 		return(sid2ModCallback(win, MODS_PANEL, index - M_SHAD, value));
1588 
1589 	if (sid2App.resources[0].devlocn[index].to == 1)
1590 		sendvalue = value * C_RANGE_MIN_1;
1591 	else
1592 		sendvalue = value;
1593 
1594 	synth->mem.param[index] = value;
1595 
1596 //	if (index < 100)
1597 		synth->dispatch[index].routine(synth,
1598 			global.controlfd, synth->sid2,
1599 			synth->dispatch[index].controller,
1600 			synth->dispatch[index].operator,
1601 			sendvalue);
1602 
1603 	return(0);
1604 }
1605 
1606 static void
sid2MidiChannel(guiSynth * synth,int fd,int chan,int c,int o,int v)1607 sid2MidiChannel(guiSynth *synth, int fd, int chan, int c, int o, int v)
1608 {
1609 	if ((c == 0) && (++synth->midichannel > 15))
1610 		synth->midichannel = 15;
1611 	else if ((c == 1) && (--synth->midichannel < 0))
1612 		synth->midichannel = 0;
1613 
1614 	displayText(synth, "MIDI CHAN", synth->midichannel + 1, DISPLAY_DEV);
1615 
1616 	if (global.libtest)
1617 		return;
1618 
1619 	bristolMidiSendMsg(global.controlfd, synth->sid2,
1620 		127, 0, BRISTOL_MIDICHANNEL|synth->midichannel);
1621 }
1622 
1623 /*
1624  * Any location initialisation required to run the callbacks. For bristol, this
1625  * will connect to the engine, and give it some base parameters.
1626  * May need to generate some application specific menus.
1627  * Will also then make specific requests to some of the devices to alter their
1628  * rendering.
1629  */
1630 static int
sid2Init(brightonWindow * win)1631 sid2Init(brightonWindow *win)
1632 {
1633 	guiSynth *synth = findSynth(global.synths, win);
1634 	dispatcher *dispatch;
1635 	int i;
1636 
1637 	if (synth == 0)
1638 	{
1639 		synth = findSynth(global.synths, 0);
1640 		if (synth == 0)
1641 		{
1642 			printf("cannot init\n");
1643 			return(0);
1644 		}
1645 	}
1646 
1647 	synth->win = win;
1648 
1649 	printf("Initialise the sid2 link to bristol: %p\n", synth->win);
1650 
1651 	synth->mem.param = (float *) brightonmalloc(DEVICE_COUNT * sizeof(float));
1652 	synth->mem.count = DEVICE_COUNT;
1653 	synth->mem.active = ACTIVE_DEVS;
1654 	synth->dispatch = (dispatcher *)
1655 		brightonmalloc(DEVICE_COUNT * sizeof(dispatcher));
1656 	dispatch = synth->dispatch;
1657 
1658 	/*
1659 	 * We really want to have three connection mechanisms. These should be
1660 	 *	1. Unix named sockets.
1661 	 *	2. UDP sockets (actually implements TCP unfortunately).
1662 	 *	3. MIDI pipe.
1663 	 */
1664 	if (!global.libtest)
1665 	{
1666 		if ((synth->sid2 = initConnection(&global, synth)) < 0)
1667 			return(-1);
1668 	}
1669 
1670 	for (i = 0; i < DEVICE_COUNT; i++)
1671 	{
1672 		synth->dispatch[i].routine = (synthRoutine) sid2MidiNull;
1673 		synth->dispatch[i].controller = i;
1674 		synth->dispatch[i].operator = i;
1675 	}
1676 
1677 	/* Voice 1 */
1678 	dispatch[0].controller = 126;
1679 	dispatch[0].operator = 10;
1680 	dispatch[0].routine = (synthRoutine) sid2VoiceShim;
1681 	dispatch[1].controller = 126;
1682 	dispatch[1].operator = 11;
1683 	dispatch[1].routine = (synthRoutine) sid2VoiceShim;
1684 	dispatch[2].controller = 126;
1685 	dispatch[2].operator = 12;
1686 	dispatch[2].routine = (synthRoutine) sid2VoiceShim;
1687 	dispatch[3].controller = 126;
1688 	dispatch[3].operator = 13;
1689 	dispatch[3].routine = (synthRoutine) sid2VoiceShim;
1690 	/* PW, tune, transpose, glide */
1691 	dispatch[4].controller = 126;
1692 	dispatch[4].operator = 14;
1693 	dispatch[4].routine = (synthRoutine) sid2VoiceShim;
1694 	dispatch[5].controller = 126;
1695 	dispatch[5].operator = 15;
1696 	dispatch[5].routine = (synthRoutine) sid2VoiceShim;
1697 	dispatch[6].controller = 126;
1698 	dispatch[6].operator = 16;
1699 	dispatch[6].routine = (synthRoutine) sid2VoiceShim;
1700 	dispatch[7].controller = 126;
1701 	dispatch[7].operator = 17;
1702 	dispatch[7].routine = (synthRoutine) sid2VoiceShim;
1703 	/* RM/sync/mute/route */
1704 	dispatch[8].controller = 126;
1705 	dispatch[8].operator = 18;
1706 	dispatch[8].routine = (synthRoutine) sid2VoiceShim;
1707 	dispatch[9].controller = 126;
1708 	dispatch[9].operator = 19;
1709 	dispatch[9].routine = (synthRoutine) sid2VoiceShim;
1710 	dispatch[10].controller = 126;
1711 	dispatch[10].operator = 20;
1712 	dispatch[10].routine = (synthRoutine) sid2VoiceShim;
1713 	dispatch[11].controller = 126;
1714 	dispatch[11].operator = 21;
1715 	dispatch[11].routine = (synthRoutine) sid2VoiceShim;
1716 	/* Env */
1717 	dispatch[12].controller = 126;
1718 	dispatch[12].operator = 22;
1719 	dispatch[12].routine = (synthRoutine) sid2VoiceShim;
1720 	dispatch[13].controller = 126;
1721 	dispatch[13].operator = 23;
1722 	dispatch[13].routine = (synthRoutine) sid2VoiceShim;
1723 	dispatch[14].controller = 126;
1724 	dispatch[14].operator = 24;
1725 	dispatch[14].routine = (synthRoutine) sid2VoiceShim;
1726 	dispatch[15].controller = 126;
1727 	dispatch[15].operator = 25;
1728 	dispatch[15].routine = (synthRoutine) sid2VoiceShim;
1729 
1730 	/* Voice 2 */
1731 	dispatch[16].controller = 126;
1732 	dispatch[16].operator = 30;
1733 	dispatch[16].routine = (synthRoutine) sid2VoiceShim;
1734 	dispatch[17].controller = 126;
1735 	dispatch[17].operator = 31;
1736 	dispatch[17].routine = (synthRoutine) sid2VoiceShim;
1737 	dispatch[18].controller = 126;
1738 	dispatch[18].operator = 32;
1739 	dispatch[18].routine = (synthRoutine) sid2VoiceShim;
1740 	dispatch[19].controller = 126;
1741 	dispatch[19].operator = 33;
1742 	dispatch[19].routine = (synthRoutine) sid2VoiceShim;
1743 	/* PW, tune, transpose, glide */
1744 	dispatch[20].controller = 126;
1745 	dispatch[20].operator = 34;
1746 	dispatch[20].routine = (synthRoutine) sid2VoiceShim;
1747 	dispatch[21].controller = 126;
1748 	dispatch[21].operator = 35;
1749 	dispatch[21].routine = (synthRoutine) sid2VoiceShim;
1750 	dispatch[22].controller = 126;
1751 	dispatch[22].operator = 36;
1752 	dispatch[22].routine = (synthRoutine) sid2VoiceShim;
1753 	dispatch[23].controller = 126;
1754 	dispatch[23].operator = 37;
1755 	dispatch[23].routine = (synthRoutine) sid2VoiceShim;
1756 	/* RM/sync/mute/route */
1757 	dispatch[24].controller = 126;
1758 	dispatch[24].operator = 38;
1759 	dispatch[24].routine = (synthRoutine) sid2VoiceShim;
1760 	dispatch[25].controller = 126;
1761 	dispatch[25].operator = 39;
1762 	dispatch[25].routine = (synthRoutine) sid2VoiceShim;
1763 	dispatch[26].controller = 126;
1764 	dispatch[26].operator = 40;
1765 	dispatch[26].routine = (synthRoutine) sid2VoiceShim;
1766 	dispatch[27].controller = 126;
1767 	dispatch[27].operator = 41;
1768 	dispatch[27].routine = (synthRoutine) sid2VoiceShim;
1769 	/* Env */
1770 	dispatch[28].controller = 126;
1771 	dispatch[28].operator = 42;
1772 	dispatch[28].routine = (synthRoutine) sid2VoiceShim;
1773 	dispatch[29].controller = 126;
1774 	dispatch[29].operator = 43;
1775 	dispatch[29].routine = (synthRoutine) sid2VoiceShim;
1776 	dispatch[30].controller = 126;
1777 	dispatch[30].operator = 44;
1778 	dispatch[30].routine = (synthRoutine) sid2VoiceShim;
1779 	dispatch[31].controller = 126;
1780 	dispatch[31].operator = 45;
1781 	dispatch[31].routine = (synthRoutine) sid2VoiceShim;
1782 
1783 	/* Voice 3 */
1784 	dispatch[32].controller = 126;
1785 	dispatch[32].operator = 50;
1786 	dispatch[32].routine = (synthRoutine) sid2VoiceShim;
1787 	dispatch[33].controller = 126;
1788 	dispatch[33].operator = 51;
1789 	dispatch[33].routine = (synthRoutine) sid2VoiceShim;
1790 	dispatch[34].controller = 126;
1791 	dispatch[34].operator = 52;
1792 	dispatch[34].routine = (synthRoutine) sid2VoiceShim;
1793 	dispatch[35].controller = 126;
1794 	dispatch[35].operator = 53;
1795 	dispatch[35].routine = (synthRoutine) sid2VoiceShim;
1796 	/* PW, tune, transpose, glide */
1797 	dispatch[36].controller = 126;
1798 	dispatch[36].operator = 54;
1799 	dispatch[36].routine = (synthRoutine) sid2VoiceShim;
1800 	dispatch[37].controller = 126;
1801 	dispatch[37].operator = 55;
1802 	dispatch[37].routine = (synthRoutine) sid2VoiceShim;
1803 	dispatch[38].controller = 126;
1804 	dispatch[38].operator = 56;
1805 	dispatch[38].routine = (synthRoutine) sid2VoiceShim;
1806 	dispatch[49].controller = 126;
1807 	dispatch[39].operator = 57;
1808 	dispatch[39].routine = (synthRoutine) sid2VoiceShim;
1809 	/* RM/sync/mute/route */
1810 	dispatch[40].controller = 126;
1811 	dispatch[40].operator = 58;
1812 	dispatch[40].routine = (synthRoutine) sid2VoiceShim;
1813 	dispatch[41].controller = 126;
1814 	dispatch[41].operator = 59;
1815 	dispatch[41].routine = (synthRoutine) sid2VoiceShim;
1816 	dispatch[42].controller = 126;
1817 	dispatch[42].operator = 60;
1818 	dispatch[42].routine = (synthRoutine) sid2VoiceShim;
1819 	dispatch[43].controller = 126;
1820 	dispatch[43].operator = 61;
1821 	dispatch[43].routine = (synthRoutine) sid2VoiceShim;
1822 	/* Env */
1823 	dispatch[44].controller = 126;
1824 	dispatch[44].operator = 62;
1825 	dispatch[44].routine = (synthRoutine) sid2VoiceShim;
1826 	dispatch[45].controller = 126;
1827 	dispatch[45].operator = 63;
1828 	dispatch[45].routine = (synthRoutine) sid2VoiceShim;
1829 	dispatch[46].controller = 126;
1830 	dispatch[46].operator = 64;
1831 	dispatch[46].routine = (synthRoutine) sid2VoiceShim;
1832 	dispatch[47].controller = 126;
1833 	dispatch[47].operator = 65;
1834 	dispatch[47].routine = (synthRoutine) sid2VoiceShim;
1835 
1836 	/* Filter */
1837 	dispatch[48].controller = 126;
1838 	dispatch[48].operator = 70;
1839 	dispatch[48].routine = (synthRoutine) sid2MidiShim;
1840 	dispatch[49].controller = 126;
1841 	dispatch[49].operator = 71;
1842 	dispatch[49].routine = (synthRoutine) sid2MidiShim;
1843 	dispatch[50].controller = 126;
1844 	dispatch[50].operator = 72;
1845 	dispatch[50].routine = (synthRoutine) sid2MidiShim;
1846 	/* Cutoff/res/OBmix */
1847 	dispatch[51].controller = 126;
1848 	dispatch[51].operator = 73;
1849 	dispatch[51].routine = (synthRoutine) sid2MidiShim;
1850 	dispatch[52].controller = 126;
1851 	dispatch[52].operator = 74;
1852 	dispatch[52].routine = (synthRoutine) sid2MidiShim;
1853 	dispatch[53].controller = 126;
1854 	dispatch[53].operator = 75;
1855 	dispatch[53].routine = (synthRoutine) sid2MidiShim;
1856 	dispatch[54].controller = 126;
1857 	dispatch[54].operator = 76;
1858 	dispatch[54].routine = (synthRoutine) sid2MidiShim;
1859 
1860 	/* Multi and master vol */
1861 	dispatch[67].controller = 126;
1862 	dispatch[67].operator = 2;
1863 	dispatch[67].routine = (synthRoutine) sid2MidiShim;
1864 	dispatch[68].controller = 126;
1865 	dispatch[68].operator = 3;
1866 	dispatch[68].routine = (synthRoutine) sid2MidiShim;
1867 
1868 	dispatch[135].operator = 0;
1869 	dispatch[136].operator = 1;
1870 	dispatch[137].operator = 2;
1871 	dispatch[135].routine = dispatch[136].routine = dispatch[137].routine
1872 		= (synthRoutine) sid2Mode;
1873 
1874 	/* Mod freq, gain and waveform */
1875 	dispatch[74].controller = 126;
1876 	dispatch[74].operator = 77;
1877 	dispatch[74].routine = (synthRoutine) sid2MidiShim;
1878 	dispatch[75].controller = 126;
1879 	dispatch[75].operator = 78;
1880 	dispatch[75].routine = (synthRoutine) sid2MidiShim;
1881 	dispatch[146].operator = 0;
1882 	dispatch[147].operator = 1;
1883 	dispatch[148].operator = 2;
1884 	dispatch[149].operator = 3;
1885 	dispatch[146].routine = dispatch[147].routine = dispatch[148].routine =
1886 		dispatch[149].routine = (synthRoutine) sid2LFOWave;
1887 
1888 	/* Then we have the routing buttons, TBD */
1889 	dispatch[80].controller = 126;
1890 	dispatch[80].operator = 79;
1891 	dispatch[80].routine = (synthRoutine) sid2MidiShim;
1892 	dispatch[81].controller = 126;
1893 	dispatch[81].operator = 80;
1894 	dispatch[81].routine = (synthRoutine) sid2MidiShim;
1895 	dispatch[82].controller = 126;
1896 	dispatch[82].operator = 81;
1897 	dispatch[82].routine = (synthRoutine) sid2MidiShim;
1898 	dispatch[83].controller = 126;
1899 	dispatch[83].operator = 82;
1900 	dispatch[83].routine = (synthRoutine) sid2MidiShim;
1901 	dispatch[84].controller = 126;
1902 	dispatch[84].operator = 83;
1903 	dispatch[84].routine = (synthRoutine) sid2MidiShim;
1904 	dispatch[85].controller = 126;
1905 	dispatch[85].operator = 84;
1906 	dispatch[85].routine = (synthRoutine) sid2MidiShim;
1907 	dispatch[86].controller = 126;
1908 	dispatch[86].operator = 85;
1909 	dispatch[86].routine = (synthRoutine) sid2MidiShim;
1910 	dispatch[87].controller = 126;
1911 	dispatch[87].operator = 101;
1912 	dispatch[87].routine = (synthRoutine) sid2MidiShim;
1913 	dispatch[88].controller = 126;
1914 	dispatch[88].operator = 102;
1915 	dispatch[88].routine = (synthRoutine) sid2MidiShim;
1916 
1917 	dispatch[95].controller = 126;
1918 	dispatch[95].operator = 89;
1919 	dispatch[95].routine = (synthRoutine) sid2MidiShim;
1920 	dispatch[96].controller = 126;
1921 	dispatch[96].operator = 90;
1922 	dispatch[96].routine = (synthRoutine) sid2MidiShim;
1923 	dispatch[97].controller = 126;
1924 	dispatch[97].operator = 91;
1925 	dispatch[97].routine = (synthRoutine) sid2MidiShim;
1926 	dispatch[98].controller = 126;
1927 	dispatch[98].operator = 92;
1928 	dispatch[98].routine = (synthRoutine) sid2MidiShim;
1929 	dispatch[99].controller = 126;
1930 	dispatch[99].operator = 86;
1931 	dispatch[99].routine = (synthRoutine) sid2MidiShim;
1932 	dispatch[100].controller = 126;
1933 	dispatch[100].operator = 87;
1934 	dispatch[100].routine = (synthRoutine) sid2MidiShim;
1935 	dispatch[101].controller = 126;
1936 	dispatch[101].operator = 88;
1937 	dispatch[101].routine = (synthRoutine) sid2MidiShim;
1938 
1939 	/* Env mod */
1940 	dispatch[102].controller = 126;
1941 	dispatch[102].operator = 93;
1942 	dispatch[102].routine = (synthRoutine) sid2MidiShim;
1943 	dispatch[103].controller = 126;
1944 	dispatch[103].operator = 94;
1945 	dispatch[103].routine = (synthRoutine) sid2MidiShim;
1946 	dispatch[104].controller = 126;
1947 	dispatch[104].operator = 95;
1948 	dispatch[104].routine = (synthRoutine) sid2MidiShim;
1949 	dispatch[105].controller = 126;
1950 	dispatch[105].operator = 96;
1951 	dispatch[105].routine = (synthRoutine) sid2MidiShim;
1952 	dispatch[106].controller = 126;
1953 	dispatch[106].operator = 97;
1954 	dispatch[106].routine = (synthRoutine) sid2MidiShim;
1955 	dispatch[107].controller = 126;
1956 	dispatch[107].operator = 103;
1957 	dispatch[107].routine = (synthRoutine) sid2MidiShim;
1958 
1959 	/* Arpeggiator */
1960 	dispatch[115].controller = 126;
1961 	dispatch[115].operator = 6;
1962 	dispatch[115].routine = (synthRoutine) sid2MidiShim;
1963 	dispatch[116].controller = 126;
1964 	dispatch[116].operator = 7;
1965 	dispatch[116].routine = (synthRoutine) sid2MidiShim;
1966 	dispatch[117].controller = 126;
1967 	dispatch[117].operator = 8;
1968 	dispatch[117].routine = (synthRoutine) sid2MidiShim;
1969 
1970 	/* Memory and MIDI */
1971 	dispatch[MEM_START + 0].operator = 1;
1972 	dispatch[MEM_START + 1].operator = 2;
1973 	dispatch[MEM_START + 2].operator = 3;
1974 	dispatch[MEM_START + 3].operator = 4;
1975 	dispatch[MEM_START + 4].operator = 5;
1976 	dispatch[MEM_START + 5].operator = 6;
1977 	dispatch[MEM_START + 6].operator = 7;
1978 	dispatch[MEM_START + 7].operator = 8;
1979 
1980 	dispatch[MEM_START + 8].controller = 1;
1981 	dispatch[MEM_START + 9].controller = 2;
1982 	dispatch[MEM_START + 10].controller = 3;
1983 	dispatch[MEM_START + 11].controller = 4;
1984 	dispatch[MEM_START + 12].controller = 5;
1985 	dispatch[MEM_START + 13].controller = 6;
1986 
1987 	dispatch[MEM_START + 0].routine =
1988 		dispatch[MEM_START + 1].routine =
1989 		dispatch[MEM_START + 2].routine =
1990 		dispatch[MEM_START + 3].routine =
1991 		dispatch[MEM_START + 4].routine =
1992 		dispatch[MEM_START + 5].routine =
1993 		dispatch[MEM_START + 6].routine =
1994 		dispatch[MEM_START + 7].routine =
1995 		dispatch[MEM_START + 8].routine =
1996 		dispatch[MEM_START + 9].routine =
1997 		dispatch[MEM_START + 10].routine =
1998 		dispatch[MEM_START + 11].routine =
1999 		dispatch[MEM_START + 12].routine =
2000 		dispatch[MEM_START + 13].routine = (synthRoutine) sid2Memory;
2001 
2002 	dispatch[132].controller = 0;
2003 	dispatch[133].controller = 1;
2004 	dispatch[132].routine = dispatch[133].routine
2005 		= (synthRoutine) sid2MidiChannel;
2006 
2007 	/* Osc-1 settings */
2008 
2009 	/* Env settings */
2010 
2011 	/* Filter */
2012 
2013 	dispatch[MEM_START].other1 = 1;
2014 	dispatch[135].other1 = 0;
2015 	dispatch[146].other1 = 0;
2016 	dispatch[173].other1 = 0;
2017 
2018 	return(0);
2019 }
2020 
2021 /*
2022  * This will be called to make any routine specific parameters available.
2023  */
2024 static int
sid2Configure(brightonWindow * win)2025 sid2Configure(brightonWindow *win)
2026 {
2027 	guiSynth *synth = findSynth(global.synths, win);
2028 	brightonEvent event;
2029 
2030 	if (synth == 0)
2031 	{
2032 		printf("problems going operational\n");
2033 		return(-1);
2034 	}
2035 
2036 	if (synth->location == 0) {
2037 		synth->bank = 1;
2038 		synth->location = 1;
2039 	} else if (synth->location > 0) {
2040 		mbh = (synth->location / 100) * 100;
2041 		if ((synth->bank = synth->location / 10) > 10)
2042 			synth->bank = synth->bank % 10;
2043 		if (((synth->location = synth->location % 10) == 0)
2044 			|| (synth->location > 8))
2045 			synth->location = 1;
2046 	}
2047 
2048 	if (synth->flags & OPERATIONAL)
2049 		return(0);
2050 
2051 	printf("going operational\n");
2052 
2053 	synth->flags |= OPERATIONAL;
2054 	synth->keypanel = 1;
2055 	synth->keypanel2 = -1;
2056 	synth->transpose = 24;
2057 
2058 	brightonPut(win,
2059 		"bitmaps/blueprints/melbourneshade.xpm", 0, 0, win->width, win->height);
2060 
2061 	/*
2062 	 * Hm. This is a hack for a few bits of bad rendering of a keyboard. Only
2063 	 * occurs on first paint, so we suppress the first paint, and then request
2064 	 * an expose here.
2065 	 */
2066 	event.type = BRIGHTON_EXPOSE;
2067 	event.intvalue = 1;
2068 	brightonParamChange(synth->win, KEY_PANEL, -1, &event);
2069 
2070 	/* Push some mod panel defaults */
2071 	event.type = BRISTOL_FLOAT;
2072 	event.value = 1;
2073 	brightonParamChange(synth->win, MODS_PANEL, 1, &event);
2074 	brightonParamChange(synth->win, MODS_PANEL, 2, &event);
2075 	brightonParamChange(synth->win, MODS_PANEL, 4, &event);
2076 	configureGlobals(synth);
2077 
2078 	/*
2079 	 * First memory location
2080 	 */
2081 	event.value = 1.0;
2082 	brightonParamChange(synth->win, 0, MEM_START + synth->location-1, &event);
2083 	brightonParamChange(synth->win, 0, 135, &event);
2084 	brightonParamChange(synth->win, 0, 146, &event);
2085 	brightonParamChange(synth->win, 0, 173, &event);
2086 
2087 	loadMemory(synth, SYNTH_NAME, 0, synth->bank * 10 + synth->location,
2088 		synth->mem.active, 0, BRISTOL_FORCE);
2089 	loadMemoryShim(synth);
2090 
2091 	event.value = 0.505;
2092 	brightonParamChange(synth->win, MODS_PANEL, 0, &event);
2093 
2094 	synth->dispatch[MEM_START].other1 = synth->location;
2095 
2096 	dc = brightonGetDCTimer(1000000);
2097 
2098 	return(0);
2099 }
2100 
2101