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 "bristolarpeggiation.h"
29 
30 static int jupiterInit();
31 static int jupiterConfigure();
32 static int jupiterCallback(brightonWindow *, int, int, float);
33 static int midiCallback(brightonWindow *, int, int, float);
34 static void jupiterSetSplit(guiSynth *);
35 static void jupiterSetVoices(guiSynth *);
36 
37 extern guimain global;
38 static guimain manual;
39 
40 static float *pcache;
41 static float *scache;
42 
43 #define MODE_SINGLE	0
44 #define MODE_SPLIT	1
45 #define MODE_LAYER	2
46 
47 static int debuglevel = 0;
48 static int setsplit = 0;
49 static int mode = MODE_SINGLE;
50 static int seqLearn = 0, chordLearn = 0;
51 
52 static void jupiterSetSplit(guiSynth *);
53 static int jupiterKeyCallback(brightonWindow *, int, int, float);
54 
55 #include "brightonKeys.h"
56 
57 /*
58  * These are a pair of double click timers and mw is a memory weighting to
59  * scale the 64 available memories into banks of banks
60  */
61 static int dc1, mw = 0;
62 
63 #define DEVICE_COUNT 134
64 #define LAYER_DEVS 65 /* 65 voice devices */
65 #define REAL_DEVS 92 /* 65 layer + 14 mod + 9 dummy + 4 reserved */
66 #define ACTIVE_DEVS (REAL_DEVS + 9) /* 19 arpeg/mode buttons */
67 #define MEM_MGT (ACTIVE_DEVS + 5)
68 #define MIDI_MGT (MEM_MGT + 18)
69 #define FUNCTION (MIDI_MGT + 3)
70 #define KEY_HOLD 7
71 #define CHORUS 32
72 
73 #define PATCH_BUTTONS MEM_MGT
74 #define BANK_BUTTONS (MEM_MGT + 9)
75 #define LOAD_BUTTON (MEM_MGT + 8)
76 
77 #define KEY_PANEL 1
78 #define MODS_PANEL 2
79 
80 /* For dual load options */
81 #define MY_MEM (REAL_DEVS - 1)
82 #define MEM_LINK (REAL_DEVS - 2)
83 #define SPLIT_POINT (REAL_DEVS - 3)
84 #define FUNCTION_SAVE (REAL_DEVS - 4)
85 
86 #define MOD_ENABLE 94
87 
88 #define ARPEG_RANGE 53
89 #define ARPEG_MODE 57
90 #define POLY_MODE 61
91 #define SEQ_MODE (DEVICE_COUNT - 6)
92 
93 #define HOLD_LOWER (REAL_DEVS)
94 #define MOD_LOWER (REAL_DEVS + 2)
95 #define MOD_UPPER (REAL_DEVS + 3)
96 #define MODE_DUAL (REAL_DEVS + 4)
97 #define KEY_MODE MODE_DUAL
98 
99 #define PANEL_SELECT (ACTIVE_DEVS + 4)
100 
101 #define DISPLAY_DEV (DEVICE_COUNT - 5)
102 
103 /*
104  * This structure is for device definition. The structure is defined in
105  * include/brighton.h, further definitions in brighton/brightonDevtable.h and
106  * include/brightoninternals.h
107  *
108  *	typedef int (*brightonCallback)(int, float);
109  *	typedef struct BrightonLocations {
110  *		int device; 0=rotary, 1=scale, etc.
111  *		float relx, rely; relative position with regards to 1000 by 1000 window
112  *		float relw, relh; relative height.
113  *		int from, to;
114  *		brightonCallback callback; specific to this dev
115  *		char *image; bitmap. If zero take a device default.
116  *		int flags;
117  *	} brightonLocations;
118  *
119  * This example is for a jupiterBristol type synth interface.
120  */
121 #define D3 80
122 #define BR1 300
123 #define BR2 BR1 + D3
124 #define BR3 BR2 + D3
125 #define BR4 BR3 + D3
126 
127 #define MBR2 BR4
128 #define MBR1 MBR2 - 100
129 #define MBR3 MBR2 + 100
130 #define MBR4 MBR3 + 100
131 
132 #define R2 390
133 #define R1 (R2 + 130)
134 #define R3 (R2 + 100)
135 #define R4 650
136 
137 #define JR1 90
138 #define JR2 JR1 - 20
139 #define JR3 JR1 - 30
140 
141 #define RB1 430
142 #define RB2 (RB1 + JR3 + 2)
143 #define RB3 (RB2 + JR3 + 2)
144 #define RB4 (RB3 + JR3 + 2)
145 #define RB5 (RB4 + JR3 + 2)
146 
147 #define D1 (980 / 41)
148 #define D2 (D1 + 11)
149 
150 #define C1 (13)
151 #define C2 (C1 + D2)
152 #define C3 (C2 + D2)
153 #define C4 (C3 + D1)
154 #define C5 (C4 + D1)
155 #define C6 (C5 + D1 - 6)
156 #define C7 (C6 + D2 - 3)
157 #define C8 (C7 + D2 - 1)
158 #define C9 (C8 + D1 - 6)
159 #define C10 (C9 + D1 - 7)
160 #define C10a (C9 + D1 + 22)
161 #define C11 (C10 + D1 + 22)
162 #define C12 (C11 + D1)
163 #define C13 (C12 + D1 - 5)
164 #define C13a (C12 + D1 + 14)
165 #define C14 (C13 + D1 + 9)
166 #define C15 (C14 + D2 - 9)
167 #define C16 (C15 + D2 + 2)
168 #define C17 (C16 + D1 + 0)
169 #define C18 (C17 + D1 - 6)
170 #define C19 (C18 + D2 - 3)
171 #define C20 (C19 + D2 - 2)
172 #define C21 (C20 + D2)
173 #define C22 (C21 + D2)
174 #define C23 (C22 + D1)
175 #define C24 (C23 + D1 - 6)
176 #define C25 (C24 + D1 - 8)
177 #define C26 (C25 + D1 + 2)
178 #define C27 (C26 + D1 - 2)
179 #define C28 (C27 + D1 - 4)
180 #define C29 (C28 + D1 - 6)
181 #define C30 (C29 + D1 - 1)
182 #define C31 (C30 + D1 - 6)
183 #define C32 (C31 + D1)
184 #define C33 (C32 + D1 - 6)
185 #define C34 (C33 + D1 - 6)
186 #define C35 (C34 + D1 - 7)
187 #define C36 (C35 + D1 - 2)
188 #define C37 (C36 + D1 - 4)
189 #define C38 (C37 + D1)
190 #define C39 (C38 + D1 - 6)
191 #define C40 (C39 + D1 - 6)
192 #define C41 (C40 + D1 - 7)
193 #define C42 (C41 + D1 - 2)
194 
195 #define W1 12
196 #define L1 310
197 
198 #define S2 120
199 
200 #define BS1 17
201 #define BS2 100
202 #define BS3 125
203 #define BS4 15
204 #define BS5 160
205 
206 /* Selector buttons */
207 #define JBS 14
208 #define JBH 80
209 #define JBD 18
210 #define JBD2 8
211 #define JBD3 17
212 #define JBD4 5
213 
214 #define JBC1 60
215 #define JBC2 (JBC1 + JBD + JBD2)
216 #define JBC3 (JBC2 + JBD3)
217 #define JBC4 (JBC3 + JBD3)
218 #define JBC5 (JBC4 + JBD3)
219 #define JBC6 (JBC5 + JBD3 + JBD4)
220 #define JBC7 (JBC6 + JBD3)
221 #define JBC8 (JBC7 + JBD3)
222 #define JBC9 (JBC8 + JBD3)
223 #define JBC9a (JBC9 + JBD3 + JBD4)
224 #define JBC10 (JBC9a + JBD + JBD4 - 3)
225 #define JBC11 (JBC10 + JBD)
226 #define JBC12 (JBC11 + JBD)
227 #define JBC13 (JBC12 + JBD)
228 
229 /* #define JBC14 (JBC13 + JBD + JBD2) */
230 #define JBC14 (326)
231 #define JBC15 (JBC14 + JBD)
232 #define JBC16 (JBC15 + JBD + JBD2)
233 #define JBC17 (JBC16 + JBD)
234 #define JBC18 (JBC17 + JBD)
235 #define JBC19 (JBC18 + JBD)
236 #define JBC20 (JBC19 + JBD)
237 #define JBC20_2 (JBC20 + JBD + JBD2)
238 /* Second half of buttons */
239 #define JBC21 (JBC1 + 512)
240 #define JBC22 (JBC21 + JBD)
241 #define JBC23 (JBC22 + JBD)
242 #define JBC24 (JBC23 + JBD)
243 #define JBC25 (JBC24 + JBD)
244 #define JBC26 (JBC25 + JBD)
245 #define JBC27 (JBC26 + JBD)
246 #define JBC28 (JBC27 + JBD)
247 #define JBC29 (JBC28 + JBD + JBD2)
248 #define JBC30 (JBC29 + JBD)
249 #define JBC31 (JBC30 + JBD)
250 #define JBC32 (JBC31 + JBD)
251 #define JBC33 (JBC32 + JBD)
252 #define JBC34 (JBC33 + JBD)
253 #define JBC35 (JBC34 + JBD)
254 #define JBC36 (JBC35 + JBD)
255 #define JBC37 (JBC36 + JBD + JBD2 - 2)
256 #define JBC38 (JBC37 + JBD + 4)
257 #define JBC39 (JBC38 + JBD + JBD2)
258 #define JBC40 (JBC39 + JBD)
259 #define JBC41 (JBC40 + JBD)
260 #define JBC42 (JBC41 + JBD)
261 
262 #define JBCD (JBC1 + 440)
263 
264 /* 42 lines controls, 43rd in button line, then 41 buttons plus display */
265 static brightonLocations locations[DEVICE_COUNT] = {
266 	/* 0 - LFO */
267 	{"LFO-Rate", 1, C5, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
268 		BRIGHTON_HALFSHADOW},
269 	{"LFO-Delay", 1, C6, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
270 		BRIGHTON_HALFSHADOW},
271 	{"LFO-Waveform", 0, C7 - 4, R1, JR1, JR1, 0, 3, 0, "bitmaps/knobs/knob1.xpm", 0,
272 		BRIGHTON_STEPPED},
273 	/* 3 - mods */
274 	{"Mod-LFO-lvl", 1, C8, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
275 		BRIGHTON_HALFSHADOW},
276 	{"Mod-Env-lvl", 1, C9, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
277 		BRIGHTON_HALFSHADOW},
278 	{"Mod-Osc1/2", 2, C10, R1 - 20, 10, JR2 + 35, 0, 2, 0, 0,
279 		0, BRIGHTON_NOSHADOW|BRIGHTON_THREEWAY},
280 
281 	{"Mod-PWM", 1, C11, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
282 		BRIGHTON_HALFSHADOW},
283 
284 	/* PWM */
285 	{"ModPWM-EnvLFO", 2, C12, R1, 10, JR2, 0, 1.01, 0, "bitmaps/buttons/sw1.xpm",
286 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
287 	{"Mod-XMod", 1, C13, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
288 		BRIGHTON_HALFSHADOW},
289 	/*
290 	 * Transpose - replace with 4 buttons as multiselectors, this one and
291 	 * three more in the 'free' section - 9
292 	 */
293 	{"VCO1-2'", 2, C14 + 2, RB1, 11, JR3, 0, 1, 0,
294 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
295 	{"VCA1-4'", 2, C14 + 2, RB2, 11, JR3, 0, 1, 0,
296 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
297 	{"VCA1-8'", 2, C14 + 2, RB3, 11, JR3, 0, 1, 0,
298 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
299 	{"VCA1-16'", 2, C14 + 2, RB4, 11, JR3, 0, 1, 0,
300 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
301 
302 	/*
303 	 * Waveform buttons - 13
304 	 */
305 	{"VCO1-Tri", 2, C15 + 4, RB1, 11, JR3, 0, 1, 0,
306 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
307 	{"VCO1-Ramp", 2, C15 + 4, RB2, 11, JR3, 0, 1, 0,
308 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
309 	{"VCO1-Pulse", 2, C15 + 4, RB3, 11, JR3, 0, 1, 0,
310 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
311 	{"VCO1-Square", 2, C15 + 4, RB4, 11, JR3, 0, 1, 0,
312 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
313 
314 	/* Sync, sub - 17 */
315 	{"VCO-Sync", 2, C16, R1 - 20, 10, JR2 + 35, 0, 2, 0, 0,
316 		0, BRIGHTON_NOSHADOW|BRIGHTON_THREEWAY},
317 	{"VCO2-Sub", 2, C17, R1, 10, JR2, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
318 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
319 
320 	/*
321 	 * 4 transpose buttons for OSC-2. They were 5 however we already have one
322 	 * button for sub wave - 19.
323 	 */
324 	{"VCO2-2'", 2, C18 + 1, RB1, 11, JR3, 0, 1, 0,
325 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
326 	{"VCO2-4'", 2, C18 + 1, RB2, 11, JR3, 0, 1, 0,
327 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
328 	{"VCO2-8'", 2, C18 + 1, RB3, 11, JR3, 0, 1, 0,
329 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
330 	{"VCO2-16'", 2, C18 + 1, RB4, 11, JR3, 0, 1, 0,
331 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
332 
333 	{"VCO2-Tune", 0, C19, R1, JR1, JR1, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0,
334 		BRIGHTON_NOTCH},
335 
336 	/*
337 	 * Waveform buttons - 24
338 	 */
339 	{"VCO2-Tri", 2, C20 + 0, RB1, 11, JR3, 0, 1, 0,
340 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
341 	{"VCO2-Ramp", 2, C20 + 0, RB2, 11, JR3, 0, 1, 0,
342 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
343 	{"VCO2-Pulse", 2, C20 + 0, RB3, 11, JR3, 0, 1, 0,
344 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
345 	{"VCO2-Noise", 2, C20 + 0, RB4, 11, JR3, 0, 1, 0,
346 		"bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0},
347 
348 	/* Mix, HPF - 28 */
349 	{"Mix Osc1/2", 0, C21, R1, JR1, JR1, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0,
350 		BRIGHTON_NOTCH},
351 	{"HPF", 1, C22, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
352 		BRIGHTON_HALFSHADOW},
353 
354 	/* Filter - 30 */
355 	{"VCF-Cutoff", 1, C23, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
356 		BRIGHTON_HALFSHADOW},
357 	{"VCF-Resonance", 1, C24, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
358 		BRIGHTON_HALFSHADOW},
359 	{"VCF-Mode", 2, C25, R1 - 20, 10, JR2 + 35, 0, 2, 0, 0,
360 		0, BRIGHTON_NOSHADOW|BRIGHTON_THREEWAY},
361 	{"VCF-EnvLvl", 1, C26, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
362 		BRIGHTON_HALFSHADOW},
363 	{"VCF-EnvSel", 2, C27, R1, 10, JR2, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
364 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
365 	{"VCF-LFO", 1, C28, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
366 		BRIGHTON_HALFSHADOW},
367 	{"VCF-KBD", 1, C29, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
368 		BRIGHTON_HALFSHADOW},
369 
370 	/* AMP - 37 */
371 	{"VCA-Env", 1, C30, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
372 		BRIGHTON_HALFSHADOW},
373 	{"VCA-LFO", 1, C31 - 1, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
374 		BRIGHTON_HALFSHADOW},
375 /*
376 	{"", 1, C31 + 1, R1 - 38, 5, JR2 + 75, 0, 3, 0,
377 		"bitmaps/buttons/klunk3.xpm", 0, 0},
378 */
379 
380 	/* ADSR1 - 39 */
381 	{"ADSR1-Attack", 1, C32 + 1, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
382 		BRIGHTON_HALFSHADOW},
383 	{"ADSR1-Decay", 1, C33, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
384 		BRIGHTON_HALFSHADOW},
385 	{"ADSR1-Sustain", 1, C34, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
386 		BRIGHTON_HALFSHADOW},
387 	{"ADSR1-Release", 1, C35, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
388 		BRIGHTON_HALFSHADOW},
389 	{"ADSR1-Kbd", 1, C36 - 6, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
390 		BRIGHTON_HALFSHADOW},
391 /*
392 	{"", 2, C36, R1, 10, JR2, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
393 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
394 */
395 	{"ADSR1-+/-", 2, C37 + 1, R1, 10, JR2, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
396 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
397 
398 	/* ADSR1 - 45 */
399 	{"ADSR2-Attack", 1, C38 + 1, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
400 		BRIGHTON_HALFSHADOW},
401 	{"ADSR2-Decay", 1, C39, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
402 		BRIGHTON_HALFSHADOW},
403 	{"ADSR2-Sustain", 1, C40, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
404 		BRIGHTON_HALFSHADOW},
405 	{"ADSR2-Release", 1, C41, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
406 		BRIGHTON_HALFSHADOW},
407 	{"ADSR2-Kdb", 1, C42 - 6, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
408 		BRIGHTON_HALFSHADOW},
409 /*
410 	{"", 2, C42, R1, 10, JR2, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
411 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
412 */
413 
414 	/* PWM, XMOD env - 50 */
415 	{"Mod-Osc-PW", 1, C10a, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
416 		BRIGHTON_HALFSHADOW},
417 	{"Mod-XMod-Lvl", 2, C13a, R1, 10, JR2, 0, 1.01, 0, "bitmaps/buttons/sw1.xpm",
418 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
419 	/* Layer Pan */
420 	{"Layer Pan", 0, C2, R2 + 50, JR1, JR1, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0,
421 		BRIGHTON_NOTCH},
422 
423 	/* Arpeg range - 53 */
424 	{"Arpeg 1 Oct", 2, JBC2, 800, JBS, JBH, 0, 4, 0,
425 		"bitmaps/buttons/jbo.xpm",
426 		"bitmaps/buttons/jboo.xpm", 0},
427 	{"Arpeg 2 Oct", 2, JBC3, 800, JBS, JBH, 0, 4, 0,
428 		"bitmaps/buttons/jbo.xpm",
429 		"bitmaps/buttons/jboo.xpm", 0},
430 	{"Arpeg 3 Oct", 2, JBC4, 800, JBS, JBH, 0, 4, 0,
431 		"bitmaps/buttons/jbo.xpm",
432 		"bitmaps/buttons/jboo.xpm", 0},
433 	{"Arpeg 4 Oct", 2, JBC5, 800, JBS, JBH, 0, 4, 0,
434 		"bitmaps/buttons/jbo.xpm",
435 		"bitmaps/buttons/jboo.xpm", 0},
436 
437 	/* Arpeg mode - 57 */
438 	{"Arpeg Mode Up", 2, JBC6, 800, JBS, JBH, 0, 4, 0,
439 		"bitmaps/buttons/jby.xpm",
440 		"bitmaps/buttons/jbyo.xpm", 0},
441 	{"Arpeg Mode Down", 2, JBC7, 800, JBS, JBH, 0, 4, 0,
442 		"bitmaps/buttons/jby.xpm",
443 		"bitmaps/buttons/jbyo.xpm", 0},
444 	{"Arpeg Mode UpDn", 2, JBC8, 800, JBS, JBH, 0, 4, 0,
445 		"bitmaps/buttons/jby.xpm",
446 		"bitmaps/buttons/jbyo.xpm", 0},
447 	{"Arpeg Mode Rand", 2, JBC9, 800, JBS, JBH, 0, 4, 0,
448 		"bitmaps/buttons/jby.xpm",
449 		"bitmaps/buttons/jbyo.xpm", 0},
450 
451 	/* Key assign mode - 61 */
452 	{"Mode Solo", 2, JBC10, 800, JBS, JBH, 0, 4, 0,
453 		"bitmaps/buttons/jbw.xpm",
454 		"bitmaps/buttons/jbwo.xpm", 0},
455 	{"Mode Uni", 2, JBC11, 800, JBS, JBH, 0, 4, 0,
456 		"bitmaps/buttons/jbw.xpm",
457 		"bitmaps/buttons/jbwo.xpm", 0},
458 	{"Mode Poly1", 2, JBC12, 800, JBS, JBH, 0, 4, 0,
459 		"bitmaps/buttons/jbw.xpm",
460 		"bitmaps/buttons/jbwo.xpm", 0},
461 	{"Mode Poly2", 2, JBC13, 800, JBS, JBH, 0, 4, 0,
462 		"bitmaps/buttons/jbw.xpm",
463 		"bitmaps/buttons/jbwo.xpm", 0},
464 
465 	/* Holders - 15 for mods panel - 65 */
466 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
467 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
468 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
469 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
470 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
471 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
472 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
473 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
474 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
475 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
476 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
477 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
478 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
479 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
480 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
481 
482 	/*
483 	 * Dummies - 8 from 80
484 	 */
485 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
486 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
487 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
488 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
489 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
490 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
491 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
492 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
493 
494 	/*
495 	 * These are reserved already for two memory links, split point and function
496 	 * settings. From 88
497 	 */
498 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
499 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
500 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
501 	{"", 0, 0, 0, JBH, JBH, 0, 1, 0, 0, 0, BRIGHTON_WITHDRAWN},
502 
503 	/*
504 	 * Total of 65 layer controls - 0 to 49 plus 30 dummies, 14 of which are
505 	 * used by the mod panel.
506 	 *
507 	 * The above will be replicated per layer, the rest will be global to the
508 	 * whole synth.
509 	 */
510 
511 	/*
512 	 * 92 - Second row Hold up/down
513 	 */
514 	{"Hold Lower", 2, JBC14, 800, JBS, JBH, 0, 4, 0,
515 		"bitmaps/buttons/jbg.xpm",
516 		"bitmaps/buttons/jbgo.xpm", 0},
517 	{"Hold Upper", 2, JBC15, 800, JBS, JBH, 0, 4, 0,
518 		"bitmaps/buttons/jbg.xpm",
519 		"bitmaps/buttons/jbgo.xpm", 0},
520 
521 	/* layer mod enable - 94 */
522 	{"Mod Layer 1", 2, JBC19, 800, JBS, JBH, 0, 1, 0,
523 		"bitmaps/buttons/jbb2.xpm",
524 		"bitmaps/buttons/jbb2o.xpm", 0},
525 	{"Mod Layer 2", 2, JBC20, 800, JBS, JBH, 0, 1, 0,
526 		"bitmaps/buttons/jbb2.xpm",
527 		"bitmaps/buttons/jbb2o.xpm", 0},
528 
529 	/* Dual/Split/Layer - 96 */
530 	{"Dual", 2, JBC16, 800, JBS, JBH, 0, 4, 0,
531 		"bitmaps/buttons/jbb1.xpm",
532 		"bitmaps/buttons/jbb1o.xpm", 0},
533 	{"Split", 2, JBC17, 800, JBS, JBH, 0, 4, 0,
534 		"bitmaps/buttons/jbb1.xpm",
535 		"bitmaps/buttons/jbb1o.xpm", 0},
536 	{"All", 2, JBC18, 800, JBS, JBH, 0, 4, 0,
537 		"bitmaps/buttons/jbb1.xpm",
538 		"bitmaps/buttons/jbb1o.xpm", 0},
539 
540 	/*
541 	 * The preceeding parameters are unique per synth and need to be loaded
542 	 * from different memory files? Alternatively just load the mem and let
543 	 * the last loaded parameters be active for the following ones:
544 	 *
545 	 * From 99:
546 	 *
547 	 * These are global to both layers - Vol/Balance/Arpeg rate and clock
548 	 *
549 	 * It could be worthwhile having the arpeggiator clock within the memory?
550 	 */
551 	{"Arpeg Rate", 1, C3, R2, W1, L1, 0, 1, 0, "bitmaps/knobs/sliderblack4.xpm", 0,
552 		BRIGHTON_HALFSHADOW},
553 	{"Arpeg Int/Ext", 2, C4, R1, 10, JR2, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
554 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
555 	/* Volume and Balance 101 and 102 */
556 	{"MasterVolume", 0, C1, R2 + 50, JR1, JR1, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0, 0},
557 	{"LayerBalance", 0, C1 +18, R1 +30, JR1, JR1, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0,
558 		BRIGHTON_NOTCH},
559 
560 	/* Second row, tuning - 103 */
561 	{"MasterTuning", 0, 15, 800, JR1, JR1, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0,
562 		BRIGHTON_NOTCH},
563 	{"Tune", 2, JBC1, 800, JBS, JBH, 0, 4, 0,
564 		"bitmaps/buttons/jbr.xpm",
565 		"bitmaps/buttons/jbro.xpm", BRIGHTON_CHECKBUTTON},
566 
567 	/* Panel switch - 105 */
568 	{"LayerSelect", 2, JBC20_2, 800, JBS, JBH, 0, 1, 0,
569 		"bitmaps/buttons/jbb2.xpm",
570 		"bitmaps/buttons/jbb2o.xpm", 0},
571 
572 	/* Second half - memories and MIDI, not saved - 106 */
573 	{"", 2, JBC21, 800, JBS, JBH, 0, 1, 0,
574 		"bitmaps/buttons/jbw.xpm",
575 		"bitmaps/buttons/jbwo.xpm", 0},
576 	{"", 2, JBC22, 800, JBS, JBH, 0, 1, 0,
577 		"bitmaps/buttons/jbw.xpm",
578 		"bitmaps/buttons/jbwo.xpm", 0},
579 	{"", 2, JBC23, 800, JBS, JBH, 0, 1, 0,
580 		"bitmaps/buttons/jbw.xpm",
581 		"bitmaps/buttons/jbwo.xpm", 0},
582 	{"", 2, JBC24, 800, JBS, JBH, 0, 1, 0,
583 		"bitmaps/buttons/jbw.xpm",
584 		"bitmaps/buttons/jbwo.xpm", 0},
585 	{"", 2, JBC25, 800, JBS, JBH, 0, 1, 0,
586 		"bitmaps/buttons/jbw.xpm",
587 		"bitmaps/buttons/jbwo.xpm", 0},
588 	{"", 2, JBC26, 800, JBS, JBH, 0, 1, 0,
589 		"bitmaps/buttons/jbw.xpm",
590 		"bitmaps/buttons/jbwo.xpm", 0},
591 	{"", 2, JBC27, 800, JBS, JBH, 0, 1, 0,
592 		"bitmaps/buttons/jbw.xpm",
593 		"bitmaps/buttons/jbwo.xpm", 0},
594 	{"", 2, JBC28, 800, JBS, JBH, 0, 1, 0,
595 		"bitmaps/buttons/jbw.xpm",
596 		"bitmaps/buttons/jbwo.xpm", 0},
597 
598 	/* Load */
599 	{"", 2, JBC37, 800, JBS, JBH, 0, 1, 0,
600 		"bitmaps/buttons/jbg.xpm",
601 		"bitmaps/buttons/jbgo.xpm", BRIGHTON_CHECKBUTTON},
602 
603 	{"", 2, JBC29, 800, JBS, JBH, 0, 1, 0,
604 		"bitmaps/buttons/jbo.xpm",
605 		"bitmaps/buttons/jboo.xpm", 0},
606 	{"", 2, JBC30, 800, JBS, JBH, 0, 1, 0,
607 		"bitmaps/buttons/jbo.xpm",
608 		"bitmaps/buttons/jboo.xpm", 0},
609 	{"", 2, JBC31, 800, JBS, JBH, 0, 1, 0,
610 		"bitmaps/buttons/jbo.xpm",
611 		"bitmaps/buttons/jboo.xpm", 0},
612 	{"", 2, JBC32, 800, JBS, JBH, 0, 1, 0,
613 		"bitmaps/buttons/jbo.xpm",
614 		"bitmaps/buttons/jboo.xpm", 0},
615 	{"", 2, JBC33, 800, JBS, JBH, 0, 1, 0,
616 		"bitmaps/buttons/jby.xpm",
617 		"bitmaps/buttons/jbyo.xpm", 0},
618 	{"", 2, JBC34, 800, JBS, JBH, 0, 1, 0,
619 		"bitmaps/buttons/jby.xpm",
620 		"bitmaps/buttons/jbyo.xpm", 0},
621 	{"", 2, JBC35, 800, JBS, JBH, 0, 1, 0,
622 		"bitmaps/buttons/jby.xpm",
623 		"bitmaps/buttons/jbyo.xpm", 0},
624 	{"", 2, JBC36, 800, JBS, JBH, 0, 1, 0,
625 		"bitmaps/buttons/jby.xpm",
626 		"bitmaps/buttons/jbyo.xpm", 0},
627 
628 	/* Save */
629 	{"", 2, JBC38, 800, JBS, JBH, 0, 1, 0,
630 		"bitmaps/buttons/jbr.xpm",
631 		"bitmaps/buttons/jbro.xpm", BRIGHTON_CHECKBUTTON},
632 
633 	/* MIDI */
634 	{"", 2, JBC39, 800, JBS, JBH, 0, 1, 0,
635 		"bitmaps/buttons/jbb1.xpm",
636 		"bitmaps/buttons/jbb1o.xpm", BRIGHTON_CHECKBUTTON},
637 	{"", 2, JBC40, 800, JBS, JBH, 0, 1, 0,
638 		"bitmaps/buttons/jbb1.xpm",
639 		"bitmaps/buttons/jbb1o.xpm", BRIGHTON_CHECKBUTTON},
640 	{"", 2, JBC41, 800, JBS, JBH, 0, 1, 0,
641 		"bitmaps/buttons/jbb2.xpm",
642 		"bitmaps/buttons/jbb2o.xpm", BRIGHTON_CHECKBUTTON},
643 
644 	/* Fn */
645 	{"", 2, JBC42, 800, JBS, JBH, 0, 1, 0,
646 		"bitmaps/buttons/jbb2.xpm",
647 		"bitmaps/buttons/jbb2o.xpm", 0},
648 
649 	{"", 2, JBC9a, 800, JBS, JBH, 0, 4, 0,
650 		"bitmaps/buttons/jby.xpm",
651 		"bitmaps/buttons/jbyo.xpm", 0},
652 
653 	/* RED LED display */
654 	{"", 8, JBCD,				813, JBS - 2, JBH - 8, 0, 9, 0, 0, 0, 0},
655 	{"", 8, JBS + JBCD - 2,		813, JBS - 2, JBH - 8, 0, 9, 0, 0, 0, 0},
656 	{"", 8, JBS * 2 + JBCD + 2, 813, JBS - 2, JBH - 8, 0, 9, 0, 0, 0, 0},
657 	{"", 8, JBS * 3 + JBCD + 1 ,813, JBS - 2, JBH - 8, 0, 9, 0, 0, 0, 0},
658 
659 	{"", 3, JBCD, 818, 75, 55, 0, 1, 0, 0,
660 		"bitmaps/images/alphadisplay3.xpm", BRIGHTON_WITHDRAWN},
661 };
662 
663 /*
664  * Mod panel
665  */
666 static brightonLocations jmods[15] = {
667 	{"", 1, 75, 395, 70, 505, 0, 1, 0, "bitmaps/knobs/sliderblack5.xpm", 0, 0},
668 	{"", 1, 175, 395, 70, 505, 0, 1, 0, "bitmaps/knobs/sliderblack5.xpm", 0, 0},
669 	{"", 1, 275, 395, 70, 505, 0, 1, 0, "bitmaps/knobs/sliderblack5.xpm", 0, 0},
670 	{"", 1, 375, 395, 70, 505, 0, 1, 0, "bitmaps/knobs/sliderblack5.xpm", 0, 0},
671 	{"", 2, 50, 150, 60, 160, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
672 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
673 	{"", 2, 115, 150, 60, 160, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
674 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
675 	{"", 2, 185, 150, 60, 160, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
676 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
677 	{"", 2, 285, 150, 60, 160, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
678 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
679 	{"", 2, 385, 150, 60, 160, 0, 1, 0, "bitmaps/buttons/sw1.xpm",
680 		"bitmaps/buttons/sw2.xpm", BRIGHTON_NOSHADOW},
681 	{"", 0, 580, 130, 195, 195, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0, 0},
682 	{"", 0, 780, 130, 195, 195, 0, 1, 0, "bitmaps/knobs/knob1.xpm", 0, 0},
683 	{"", 2, 820, 400, 60, 200, 0, 2, 0,
684 		0, 0, BRIGHTON_THREEWAY|BRIGHTON_NOSHADOW},
685 	{"", 2, 550, 400, 60, 200, 0, 2, 0,
686 		0, 0, BRIGHTON_THREEWAY|BRIGHTON_NOSHADOW},
687 	{"", 2, 690, 400, 60, 200, 0, 2, 0,
688 		0, 0, BRIGHTON_THREEWAY|BRIGHTON_NOSHADOW},
689 /*
690 	{"", 2, 550, 460, 190, 130, 0, 1, 0, "bitmaps/buttons/touchnlw.xpm",
691 		"bitmaps/buttons/touchnlw.xpm", 0},
692 */
693 	{"", 1, 520, 715, 500, 100, 0, 1, 0, "bitmaps/knobs/knob8.xpm", 0,
694 		BRIGHTON_VERTICAL|BRIGHTON_CENTER|BRIGHTON_NOSHADOW|BRIGHTON_REVERSE},
695 };
696 
697 static int
jupiterDestroySynth(brightonWindow * win)698 jupiterDestroySynth(brightonWindow *win)
699 {
700 	guiSynth *synth = findSynth(global.synths, win);
701 
702 	/*
703 	 * Since we registered two synths, we now need to remove the upper
704 	 * manual.
705 	 */
706 	bristolMidiSendMsg(manual.controlfd, synth->sid2, 127, 0,
707 		BRISTOL_EXIT_ALGO);
708 	bristolMidiSendMsg(global.controlfd, synth->sid, 127, 0,
709 		BRISTOL_EXIT_ALGO);
710 	return(0);
711 }
712 
713 /*
714  * This is a set of globals for the main window rendering. Again taken from
715  * include/brighton.h
716  */
717 brightonApp jupiterApp = {
718 	"jupiter8",
719 	0,
720 	"bitmaps/textures/metal4.xpm",
721 	0,
722 	jupiterInit,
723 	jupiterConfigure, /* 3 callbacks, unused? */
724 	midiCallback,
725 	jupiterDestroySynth,
726 	{8, 50, 32, 2, 5, 520, 0, 0},
727 	900, 350, 0, 0,
728 	5,
729 	{
730 		{
731 			"Jupiter",
732 			"bitmaps/blueprints/jupiter.xpm",
733 			"bitmaps/textures/metal6.xpm",
734 			BRIGHTON_STRETCH, /* flags */
735 			0,
736 			0,
737 			jupiterCallback,
738 			5, 30, 990, 670,
739 			DEVICE_COUNT,
740 			locations
741 		},
742 		{
743 			"Keyboard",
744 			0,
745 			"bitmaps/newkeys/kbg.xpm", /* flags */
746 			0x020|BRIGHTON_STRETCH,
747 			0,
748 			0,
749 			jupiterKeyCallback,
750 			180, 695, 810, 300,
751 			KEY_COUNT,
752 			keysprofile
753 		},
754 		{
755 			"Mods",
756 			"bitmaps/blueprints/jupitermods.xpm",
757 			"bitmaps/textures/metal6.xpm", /* flags */
758 			BRIGHTON_STRETCH,
759 			0,
760 			0,
761 			jupiterCallback,
762 			5, 695, 175, 300,
763 			15,
764 			jmods
765 		},
766 		{
767 			"Metal Edge",
768 			0,
769 			"bitmaps/textures/metal5.xpm",
770 			BRIGHTON_STRETCH|BRIGHTON_VERTICAL, /* flags */
771 			0,
772 			0,
773 			0,
774 			0, 0, 5, 1000,
775 			0,
776 			0
777 		},
778 		{
779 			"Metal Edge",
780 			0,
781 			"bitmaps/textures/metal5.xpm",
782 			BRIGHTON_STRETCH|BRIGHTON_VERTICAL, /* flags */
783 			0,
784 			0,
785 			0,
786 			995, 0, 5, 1000,
787 			0,
788 			0
789 		},
790 	}
791 };
792 
793 static int
jupiterDebug(guiSynth * synth,int level)794 jupiterDebug(guiSynth *synth, int level)
795 {
796 	if (debuglevel >= level)
797 		return(1);
798 	return(0);
799 }
800 
801 static void
jupiterSeqInsert(guiSynth * synth,int note)802 jupiterSeqInsert(guiSynth *synth, int note)
803 {
804 	arpeggiatorMemory *seq = (arpeggiatorMemory *) synth->seq1.param;
805 
806 	if (synth->mem.param[PANEL_SELECT] != 0) {
807 printf("	Learning on upper layer\n");
808 		seq = (arpeggiatorMemory *) synth->seq2.param;
809 	}
810 
811 	if (seq->s_max == 0)
812 		seq->s_dif = note + synth->transpose;
813 
814 	seq->sequence[(int) (seq->s_max)] =
815 		(float) (note + synth->transpose - seq->s_dif);
816 
817 	if (jupiterDebug(synth, 0))
818 		printf("Seq put %i into %i\n", (int) seq->sequence[(int) (seq->s_max)],
819 			(int) (seq->s_max));
820 
821 	if ((seq->s_max += 1) >= BRISTOL_SEQ_MAX)
822 		seq->s_max = BRISTOL_SEQ_MAX;
823 }
824 
825 static void
jupiterChordInsert(guiSynth * synth,int note)826 jupiterChordInsert(guiSynth *synth, int note)
827 {
828 	arpeggiatorMemory *seq = (arpeggiatorMemory *) synth->seq1.param;
829 
830 	if (synth->mem.param[HOLD_LOWER] == 0)
831 		seq = (arpeggiatorMemory *) synth->seq2.param;
832 
833 	if (seq->c_count == 0)
834 		seq->c_dif = note + synth->transpose;
835 
836 	seq->chord[(int) (seq->c_count)]
837 		= (float) (note + synth->transpose - seq->c_dif);
838 
839 	if (jupiterDebug(synth, 0))
840 		printf("Chord put %i into %i\n", (int) seq->chord[(int) (seq->c_count)],
841 			(int) (seq->c_count));
842 
843 	if ((seq->c_count += 1) >= BRISTOL_CHORD_MAX)
844 		seq->c_count = BRISTOL_CHORD_MAX;
845 }
846 
847 static int
jupiterKeyCallback(brightonWindow * win,int panel,int index,float value)848 jupiterKeyCallback(brightonWindow *win, int panel, int index, float value)
849 {
850 	guiSynth *synth = findSynth(global.synths, win);
851 
852 	if (setsplit != 0) {
853 		if (jupiterDebug(synth, 1))
854 			printf("setSplit at %i\n", index);
855 		synth->mem.param[SPLIT_POINT] = index;
856 		jupiterSetSplit(synth);
857 	}
858 
859 	if ((chordLearn) && (value != 0))
860 		jupiterChordInsert(synth, index);
861 
862 	if ((seqLearn) && (value != 0))
863 		jupiterSeqInsert(synth, index);
864 
865 	if (global.libtest)
866 		return(0);
867 
868 	if (jupiterDebug(synth, 2))
869 		printf("keyCallback(%i)\n", index);
870 
871 	/*
872 	 * Want to send a note event, on or off, for this index + transpose.
873 	 */
874 	if (value)
875 		bristolMidiSendMsg(global.controlfd, synth->midichannel,
876 			BRISTOL_EVENT_KEYON, 0, index + synth->transpose);
877 	else
878 		bristolMidiSendMsg(global.controlfd, synth->midichannel,
879 			BRISTOL_EVENT_KEYOFF, 0, index + synth->transpose);
880 
881 	return(0);
882 }
883 
884 static void
jupiterDualSend(guiSynth * synth,int fd,int c,int o,int v)885 jupiterDualSend(guiSynth *synth, int fd, int c, int o, int v)
886 {
887 	bristolMidiSendMsg(global.controlfd, synth->sid, c, o, v);
888 	bristolMidiSendMsg(global.controlfd, synth->sid2, c, o, v);
889 }
890 
891 static void
midiRelease(guiSynth * synth,int fd,int chan,int c,int o,int v)892 midiRelease(guiSynth *synth, int fd, int chan, int c, int o, int v)
893 {
894 	if (jupiterDebug(synth, 1))
895 		printf("midiRelease()\n");
896 
897 	if (!global.libtest)
898 	{
899 		/*
900 		 * Midi release is ALL notes, ALL synths. If this behaviour (in the
901 		 * engine) changes we may need to put in an all_notes_off on the
902 		 * second manual as well.
903 		 */
904 		bristolMidiSendMsg(fd, synth->sid, 127, 0,
905 			BRISTOL_ALL_NOTES_OFF);
906 	}
907 }
908 
909 static void
modPanelFix(brightonWindow * win,guiSynth * synth)910 modPanelFix(brightonWindow *win, guiSynth *synth)
911 {
912 	int i;
913 	brightonEvent event;
914 
915 	event.type = BRIGHTON_FLOAT;
916 
917 	for (i = 0; i < 14; i++)
918 	{
919 		event.value = synth->mem.param[LAYER_DEVS + i];
920 		brightonParamChange(win, MODS_PANEL, i, &event);
921 	}
922 }
923 
924 static int
midiCallback(brightonWindow * win,int controller,int value,float n)925 midiCallback(brightonWindow *win, int controller, int value, float n)
926 {
927 	guiSynth *synth = findSynth(global.synths, win);
928 
929 	if (jupiterDebug(synth, 1))
930 		printf("midi callback: %x, %i\n", controller, value);
931 
932 	switch(controller)
933 	{
934 		case MIDI_PROGRAM:
935 			if (jupiterDebug(synth, 2))
936 				printf("midi program: %x, %i\n", controller, value);
937 			synth->location = value;
938 			loadMemory(synth, "jupiter8", 0, synth->bank + synth->location,
939 				synth->mem.active, 0, 0);
940 			modPanelFix(win, synth);
941 			break;
942 		case MIDI_BANK_SELECT:
943 			if (jupiterDebug(synth, 2))
944 				printf("midi banksel: %x, %i\n", controller, value);
945 			synth->bank = value + 10;
946 			loadMemory(synth, "jupiter8", 0, synth->bank + synth->location,
947 				synth->mem.active, 0, 0);
948 			modPanelFix(win, synth);
949 			break;
950 	}
951 	return(0);
952 }
953 
954 static int
jupiterMidiSendMsg(guiSynth * synth,int fd,int chan,int c,int o,int v)955 jupiterMidiSendMsg(guiSynth *synth, int fd, int chan, int c, int o, int v)
956 {
957 	if (jupiterDebug(synth, 5))
958 		printf("%i, %i, %i\n", c, o, v);
959 
960 	if (synth->mem.param[PANEL_SELECT] != 0)
961 		bristolMidiSendMsg(fd, synth->sid2, c, o, v);
962 	else
963 		bristolMidiSendMsg(fd, synth->sid, c, o, v);
964 	return(0);
965 }
966 
967 static void
jupiterSetDisplay(guiSynth * synth)968 jupiterSetDisplay(guiSynth *synth)
969 {
970 	brightonEvent event;
971 
972 	if (jupiterDebug(synth, 3))
973 		printf("jupiterSetDisplay(%f, %f)\n",
974 			synth->mem.param[MY_MEM], synth->mem.param[MEM_LINK]);
975 
976 	event.type = BRIGHTON_FLOAT;
977 
978 	/*
979 	 * Load will set the displays and nothing else, they will always point to
980 	 * the active patches.
981 	 *
982 	 * The buttons selections should come from the layer select or from being
983 	 * pressed themselves.
984 	 */
985 	if (synth->mem.param[PANEL_SELECT] != 0) {
986 		event.value = ((int) synth->mem.param[MY_MEM]) / 10;
987 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 2, &event);
988 		event.value = ((int) synth->mem.param[MY_MEM]) % 10;
989 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 3, &event);
990 
991 		event.value = ((int) synth->mem.param[MEM_LINK]) / 10;
992 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 0, &event);
993 		event.value = ((int) synth->mem.param[MEM_LINK]) % 10;
994 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 1, &event);
995 	} else {
996 		event.value = ((int) synth->mem.param[MY_MEM]) / 10;
997 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 0, &event);
998 		event.value = ((int) synth->mem.param[MY_MEM]) % 10;
999 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 1, &event);
1000 
1001 		event.value = ((int) synth->mem.param[MEM_LINK]) / 10;
1002 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 2, &event);
1003 		event.value = ((int) synth->mem.param[MEM_LINK]) % 10;
1004 		brightonParamChange(synth->win, 0, DISPLAY_DEV + 3, &event);
1005 	}
1006 }
1007 
1008 static int exclude = 0;
1009 static int fPmask = 0x00;
1010 static int fBmask = 0x00;
1011 
1012 typedef struct FArray {
1013 	int c;
1014 	int o;
1015 } farray;
1016 
1017 static struct {
1018 	farray pFuncs[8];
1019 	farray bFuncs[8];
1020 } functions = {
1021 	{
1022 		{7, 6}, /* Env-1 rezero, condition, attack tracking. */
1023 		{7, 7},
1024 		{7, 8},
1025 		{9, 6}, /* Env-2 rezero, condition, attack tracking. */
1026 		{9, 7},
1027 		{9, 8},
1028 		{126, 31}, /* Noise per layer */
1029 		{10, 1} /* White/Pink */
1030 	},
1031 	{
1032 		{126, 29}, /* LFO-1 uni */
1033 		{0, 1}, /* LFO-1 uni */
1034 		{2, 5}, /* LFO-1 gain velocity tracking */
1035 		{BRISTOL_ARPEGGIATOR, BRISTOL_ARPEG_TRIGGER}, /* Arpeggiator retrig */
1036 		{127, 33}, /* LFO Touch Sense */
1037 		{127, 115}, /* NRP enable */
1038 		{127, 116}, /* MIDI Debug */
1039 		{127, 117} /* Internal debug */
1040 	}
1041 };
1042 
1043 static int width;
1044 
1045 static void
jupiterFunctionKey(guiSynth * synth,int fd,int chan,int c,int o,int v)1046 jupiterFunctionKey(guiSynth *synth, int fd, int chan, int c, int o, int v)
1047 {
1048 	int i;
1049 	brightonEvent event;
1050 
1051 	if (jupiterDebug(synth, 1))
1052 		printf("jupiterFunctionKey(%i, %i, %i)\n", c, o, v);
1053 
1054 	if (synth->win->width != width)
1055 	{
1056 		brightonPut(synth->win, "bitmaps/blueprints/jupitershade.xpm", 0, 0,
1057 			synth->win->width, synth->win->height);
1058 		width = synth->win->width;
1059 	}
1060 
1061 	if (exclude == 1)
1062 		return;
1063 
1064 	if ((c == 2) && (v != 0))
1065 	{
1066 		/*
1067 		 * Turn on any active function keys. TBD.
1068 		 */
1069 		exclude = 1;
1070 		event.type = BRIGHTON_FLOAT;
1071 		for (i = 0; i < 8; i++) {
1072 			event.value = fPmask & (1 << i);
1073 			brightonParamChange(synth->win, 0, MEM_MGT + i, &event);
1074 			event.value = fBmask & (1 << i);
1075 			brightonParamChange(synth->win, 0, MEM_MGT + 9 + i, &event);
1076 		}
1077 		exclude = 0;
1078 	}
1079 
1080 	if ((c == 2) && (v == 0))
1081 	{
1082 		/*
1083 		 * Turning off - clear all the buttons and stuff the memory value
1084 		 */
1085 		exclude = 1;
1086 
1087 		event.type = BRIGHTON_FLOAT;
1088 		event.value = 0;
1089 
1090 		for (i = 0; i < 8; i++) {
1091 			brightonParamChange(synth->win, 0, MEM_MGT + i, &event);
1092 			brightonParamChange(synth->win, 0, MEM_MGT + 9 + i, &event);
1093 		}
1094 
1095 		/*
1096 		 * set the buttons according to the display digits
1097 		 */
1098 		if (synth->mem.param[PANEL_SELECT] == 0) {
1099 			event.value = 1.0;
1100 			i = synth->mem.param[DISPLAY_DEV + 0] - 1;
1101 			brightonParamChange(synth->win, 0, MEM_MGT + 9 + i, &event);
1102 			i = synth->mem.param[DISPLAY_DEV + 1] - 1;
1103 			brightonParamChange(synth->win, 0, MEM_MGT + i, &event);
1104 		} else {
1105 			event.value = 1.0;
1106 			i = synth->mem.param[DISPLAY_DEV + 3] - 1;
1107 			brightonParamChange(synth->win, 0, MEM_MGT + i, &event);
1108 			i = synth->mem.param[DISPLAY_DEV + 2] - 1;
1109 			brightonParamChange(synth->win, 0, MEM_MGT + 9 + i, &event);
1110 		}
1111 
1112 		exclude = 0;
1113 	}
1114 
1115 	/*
1116 	 * The functions will be on, or off. We could consider how to make them
1117 	 * continuous however we don't really have a data entry pot we could
1118 	 * reasonably consider using. We should also consider that using just a
1119 	 * set of bits as a mask makes them easy to save.
1120 	 */
1121 	if (c == 0) {
1122 		if (v != 0)
1123 			/*
1124 			 * Prog functions on, keep mask to track them.
1125 			 */
1126 			fPmask |= 0x01 << o;
1127 		if (v == 0)
1128 			/*
1129 			 * Prog functions off.
1130 			 */
1131 			fPmask &= ~(0x01 << o);
1132 
1133 		if (jupiterDebug(synth, 1)) {
1134 			if (v != 0)
1135 				printf("call f(p): %i, %i ON\n",
1136 					functions.pFuncs[o].c,
1137 					functions.pFuncs[o].o);
1138 			else
1139 				printf("call f(p): %i, %i OFF\n",
1140 					functions.pFuncs[o].c,
1141 					functions.pFuncs[o].o);
1142 		}
1143 
1144 		if (exclude == 0)
1145 			jupiterDualSend(synth, synth->sid,
1146 				functions.pFuncs[o].c, functions.pFuncs[o].o, v);
1147 
1148 		return;
1149 	}
1150 
1151 	if (c == 1) {
1152 		if (v != 0)
1153 			/*
1154 			 * Prog functions on, keep mask to track them.
1155 			 */
1156 			fBmask |= 0x01 << o;
1157 		if (v == 0)
1158 			/*
1159 			 * Prog functions off.
1160 			 */
1161 			fBmask &= ~(0x01 << o);
1162 
1163 		if (jupiterDebug(synth, 1)) {
1164 			if (v != 0)
1165 				printf("call f(p): %i, %i ON\n",
1166 					functions.bFuncs[o].c,
1167 					functions.bFuncs[o].o);
1168 			else
1169 				printf("call f(b): %i, %i OFF\n",
1170 					functions.bFuncs[o].c,
1171 					functions.bFuncs[o].o);
1172 		}
1173 
1174 		/* LFO-2 (mods) keyboard control */
1175 		if (o == 4) {
1176 			if (v != 0)
1177 				v = 1;
1178 
1179 			/* LFO sync, LFO frequency tracking KBD, Env tracking */
1180 			jupiterDualSend(synth, synth->sid, 1, 1, v);
1181 			jupiterDualSend(synth, synth->sid, 1, 2, v);
1182 			jupiterDualSend(synth, synth->sid, 3, 5, v);
1183 
1184 			return;
1185 		}
1186 
1187 		/* NRP Enable */
1188 		if (o == 5) {
1189 			if (v != 0)
1190 				v = 1;
1191 			if (!global.libtest) {
1192 				bristolMidiSendNRP(global.controlfd, synth->sid,
1193 					BRISTOL_NRP_ENABLE_NRP, v);
1194 				bristolMidiSendNRP(global.controlfd, synth->sid2,
1195 					BRISTOL_NRP_ENABLE_NRP, v);
1196 			}
1197 			return;
1198 		}
1199 
1200 		/* Midi debug */
1201 		if (o == 6) {
1202 			if (v != 0)
1203 				v = 1;
1204 			if (!global.libtest) {
1205 				bristolMidiSendNRP(global.controlfd, synth->sid,
1206 					BRISTOL_NRP_DEBUG, v);
1207 				bristolMidiSendNRP(global.controlfd, synth->sid2,
1208 					BRISTOL_NRP_DEBUG, v);
1209 			}
1210 			return;
1211 		}
1212 
1213 		/* Internal debug */
1214 		if (o == 7) {
1215 			debuglevel = v;
1216 			return;
1217 		}
1218 
1219 		if (exclude == 0) {
1220 			jupiterDualSend(synth, synth->sid,
1221 				functions.bFuncs[o].c, functions.bFuncs[o].o, v);
1222 		}
1223 
1224 		return;
1225 	}
1226 }
1227 
1228 static void
jupiterSetFuncs(guiSynth * synth)1229 jupiterSetFuncs(guiSynth *synth)
1230 {
1231 	int i;
1232 
1233 	for (i = 0; i < 8; i++)
1234 		jupiterFunctionKey(synth, global.controlfd, synth->sid,
1235 			0, i, fPmask & (1 << i));
1236 	for (i = 0; i < 8; i++)
1237 		jupiterFunctionKey(synth, global.controlfd, synth->sid,
1238 			1, i, fBmask & (1 << i));
1239 }
1240 
1241 static void
jupiterButtonPanel(guiSynth * synth,int fd,int chan,int c,int o,int v)1242 jupiterButtonPanel(guiSynth *synth, int fd, int chan, int c, int o, int v)
1243 {
1244 	brightonEvent event;
1245 
1246 	event.type = BRIGHTON_FLOAT;
1247 
1248 	if (jupiterDebug(synth, 1))
1249 		printf("jupiterButtonPanel(%i, %i, %i)\n", c, o, v);
1250 
1251 	if (synth->mem.param[FUNCTION] != 0)
1252 		return(jupiterFunctionKey(synth, fd, chan, c, o, v));
1253 
1254 	switch (c) {
1255 		case 0:
1256 			/* patch selector */
1257 			if (jupiterDebug(synth, 2))
1258 				printf("memory\n");
1259 			/*
1260 			 * Force exclusion
1261 			 */
1262 			if (synth->dispatch[MEM_MGT + c].other2)
1263 			{
1264 				synth->dispatch[MEM_MGT + c].other2 = 0;
1265 				return;
1266 			}
1267 			if (synth->dispatch[MEM_MGT + c].other1 != -1)
1268 			{
1269 				synth->dispatch[MEM_MGT + c].other2 = 1;
1270 
1271 				if (synth->dispatch[MEM_MGT + c].other1 != MEM_MGT + o)
1272 					event.value = 0;
1273 				else
1274 					event.value = 1;
1275 
1276 				brightonParamChange(synth->win, synth->panel,
1277 					synth->dispatch[MEM_MGT + c].other1, &event);
1278 			}
1279 			synth->dispatch[MEM_MGT + c].other1 = MEM_MGT + o;
1280 
1281 			synth->location = o + 1;
1282 
1283 			break;
1284 		case 1:
1285 			/* Bank selector */
1286 			if (jupiterDebug(synth, 2))
1287 				printf("bank\n");
1288 			/*
1289 			 * Force exclusion
1290 			 */
1291 			if (synth->dispatch[MEM_MGT + c].other2)
1292 			{
1293 				synth->dispatch[MEM_MGT + c].other2 = 0;
1294 				return;
1295 			}
1296 			if (synth->dispatch[MEM_MGT + c].other1 != -1)
1297 			{
1298 				synth->dispatch[MEM_MGT + c].other2 = 1;
1299 
1300 				if (synth->dispatch[MEM_MGT + c].other1 != MEM_MGT + o + 9)
1301 					event.value = 0;
1302 				else
1303 					event.value = 1;
1304 
1305 				brightonParamChange(synth->win, synth->panel,
1306 					synth->dispatch[MEM_MGT + c].other1, &event);
1307 			}
1308 			synth->dispatch[MEM_MGT + c].other1 = MEM_MGT + o + 9;
1309 
1310 			synth->bank = (o + 1) * 10;
1311 
1312 			break;
1313 	}
1314 }
1315 
1316 /*
1317  * All the synth->second stuff is seriously painful. We are going to remove
1318  * it all and go for a single layer with backing stores. Panel switch will be
1319  * responsible for those two stores.
1320  */
1321 static void
jupiterPanelSwitch(guiSynth * synth,int fd,int chan,int c,int o,int v)1322 jupiterPanelSwitch(guiSynth *synth, int fd, int chan, int c, int o, int v)
1323 {
1324 	brightonEvent event;
1325 	int i, mymem, mylink;
1326 
1327 	mymem = synth->mem.param[MY_MEM];
1328 	mylink = synth->mem.param[MEM_LINK];
1329 
1330 	if (jupiterDebug(synth, 1))
1331 		printf("jupiterPanelSwitch(%i, %i, %i) %f\n", c, o, v,
1332 			synth->mem.param[PANEL_SELECT]);
1333 
1334 	if (jupiterDebug(synth, 5)) {
1335 		int i;
1336 
1337 		for (i = 0; i < LAYER_DEVS; i+= 8)
1338 			printf("%f %f %f %f %f %f %f %f\n",
1339 				pcache[i], pcache[i + 1], pcache[i + 2], pcache[i + 3],
1340 				pcache[i + 4], pcache[i + 5], pcache[i + 6], pcache[i + 7]);
1341 		printf("\n");
1342 		for (i = 0; i < LAYER_DEVS; i+= 8)
1343 			printf("%f %f %f %f %f %f %f %f\n",
1344 				scache[i], scache[i + 1], scache[i + 2], scache[i + 3],
1345 				scache[i + 4], scache[i + 5], scache[i + 6], scache[i + 7]);
1346 	}
1347 
1348 	/*
1349 	 * Copy from either the p or s cache into the synth then request updating
1350 	 * the whole shebang.
1351 	 */
1352 	if (v != 0)
1353 	{
1354 		if (jupiterDebug(synth, 1))
1355 			printf("converge secondary layer\n");
1356 
1357 		/*
1358 		 * Save pcache, copy in the scache
1359 		 */
1360 		bcopy(synth->mem.param, pcache, LAYER_DEVS * sizeof(float));
1361 
1362 		if (jupiterDebug(synth, 3))
1363 			printf("PS: my mem is %f, will be %f\n",
1364 				synth->mem.param[MY_MEM], synth->mem.param[MEM_LINK]);
1365 
1366 		event.type = BRIGHTON_FLOAT;
1367 		for (i = 0; i < LAYER_DEVS; i++)
1368 		{
1369 			event.value = scache[i];
1370 			brightonParamChange(synth->win, 0, i, &event);
1371 		}
1372 	} else {
1373 		if (jupiterDebug(synth, 1))
1374 			printf("converge primary layer\n");
1375 
1376 		/*
1377 		 * Save scache, copy in the pcache
1378 		 */
1379 		bcopy(synth->mem.param, scache, LAYER_DEVS * sizeof(float));
1380 
1381 		if (jupiterDebug(synth, 3))
1382 			printf("PS: my mem is %f, will be %f\n",
1383 				synth->mem.param[MY_MEM], synth->mem.param[MEM_LINK]);
1384 
1385 		event.type = BRIGHTON_FLOAT;
1386 		for (i = 0; i < LAYER_DEVS; i++)
1387 		{
1388 			event.value = pcache[i];
1389 			brightonParamChange(synth->win, 0, i, &event);
1390 		}
1391 	}
1392 
1393 	synth->mem.param[MY_MEM] = mylink;
1394 	synth->mem.param[MEM_LINK] = mymem;
1395 
1396 	event.type = BRIGHTON_FLOAT;
1397 	event.value = 1.0;
1398 	if (((i = (mylink / 10) - 1) >= 0) && (i < 8))
1399 		brightonParamChange(synth->win, 0, BANK_BUTTONS + i, &event);
1400 	event.type = BRIGHTON_FLOAT;
1401 	event.value = 1.0;
1402 	if (((i = (mylink % 10) - 1) >= 0) && (i < 8))
1403 		brightonParamChange(synth->win, 0, PATCH_BUTTONS + i, &event);
1404 
1405 	if (jupiterDebug(synth, 5)) {
1406 		int i;
1407 
1408 		for (i = 0; i < LAYER_DEVS; i+= 8)
1409 			printf("%f %f %f %f %f %f %f %f\n",
1410 				pcache[i], pcache[i + 1], pcache[i + 2], pcache[i + 3],
1411 				pcache[i + 4], pcache[i + 5], pcache[i + 6], pcache[i + 7]);
1412 		printf("\n");
1413 		for (i = 0; i < LAYER_DEVS; i+= 8)
1414 			printf("%f %f %f %f %f %f %f %f\n",
1415 				scache[i], scache[i + 1], scache[i + 2], scache[i + 3],
1416 				scache[i + 4], scache[i + 5], scache[i + 6], scache[i + 7]);
1417 	}
1418 
1419 	jupiterSetDisplay(synth);
1420 }
1421 
1422 static void
jupiterMemory(guiSynth * synth,int fd,int chan,int c,int o,int v)1423 jupiterMemory(guiSynth *synth, int fd, int chan, int c, int o, int v)
1424 {
1425 	if (synth->flags & MEM_LOADING)
1426 		return;
1427 
1428 	if ((synth->flags & OPERATIONAL) == 0)
1429 		return;
1430 
1431 	if (jupiterDebug(synth, 1))
1432 		printf("jupiterMemory(%i, %i, %i)\n", c, o, v);
1433 
1434 	switch (c) {
1435 		case 2:
1436 			/* Memory load */
1437 			if (jupiterDebug(synth, 2))
1438 				printf("load\n");
1439 
1440 			/*
1441 			 * Changed some of the original logic here. Rather than load all
1442 			 * parameters on a first load, then just the layer devs on a double
1443 			 * click we are only ever going to load the layer devs unless we
1444 			 * double click, then we load everything including peer layer if
1445 			 * configured. If there is no peer layer then we should put the
1446 			 * emulation into mode All and potentially put it into Poly-1 if
1447 			 * it was in Solo.
1448 			 *
1449 			 * This code should also invistigate how to load some arpeggiator
1450 			 * information, automated if possible into the library.
1451 			 */
1452 			if (brightonDoubleClick(dc1)) {
1453 				brightonEvent event;
1454 				int mymem, mylink;
1455 				int flags = BRISTOL_SEQLOAD|BRISTOL_SEQFORCE;
1456 
1457 				if (synth->mem.param[PANEL_SELECT] != 0)
1458 					flags |= BRISTOL_SID2;
1459 
1460 				/*
1461 				 * Do a full load of my memory, fix any mod panel controls,
1462 				 * set up the function masks and activate them.
1463 				 */
1464 				if (loadMemory(synth, "jupiter8", 0,
1465 					synth->bank + synth->location + mw,
1466 					synth->mem.active, 0, flags) >= 0)
1467 				{
1468 					if (jupiterDebug(synth, 2))
1469 						printf("am %2.0f (%i), peer layer loading %2.0f\n",
1470 							synth->mem.param[MY_MEM],
1471 							synth->bank + synth->location,
1472 							synth->mem.param[MEM_LINK]);
1473 
1474 					modPanelFix(synth->win, synth);
1475 
1476 					fBmask = ((int) synth->mem.param[FUNCTION_SAVE]) >> 8;
1477 					fPmask = ((int) synth->mem.param[FUNCTION_SAVE]) & 0x00ff;
1478 
1479 					if (jupiterDebug(synth, 4))
1480 						printf("loading functions %x %x from %x\n",
1481 							fBmask, fPmask,
1482 							(int) synth->mem.param[FUNCTION_SAVE]);
1483 
1484 					jupiterSetFuncs(synth);
1485 				} else
1486 					return;
1487 
1488 				/*
1489 				 * Build our links and also set our display values.
1490 				 */
1491 				mymem = synth->mem.param[MY_MEM]
1492 					= synth->bank + synth->location;
1493 
1494 				flags = BRISTOL_SEQLOAD|BRISTOL_SEQFORCE;
1495 
1496 				/*
1497 				 * Take a peek at the peer memory to see if one is configured.
1498 				 * If there is one and we have split/double selected then load
1499 				 * it and activate the splits, etc.
1500 				 */
1501 				if ((mylink = synth->mem.param[MEM_LINK]) >= 0)
1502 				{
1503 					event.type = BRIGHTON_FLOAT;
1504 					event.value = 1.0 - synth->mem.param[PANEL_SELECT];
1505 					brightonParamChange(synth->win, 0, PANEL_SELECT, &event);
1506 
1507 					/*
1508 					 * This should actually have happened due to the fully
1509 					 * loaded memory.
1510 					jupiterSetSplit(synth);
1511 					jupiterSetVoices(synth);
1512 					 */
1513 
1514 					if (jupiterDebug(synth, 2))
1515 						printf("dual load %i (%i), peer layer is %2.0f\n",
1516 							mylink,
1517 							synth->bank + synth->location,
1518 							synth->mem.param[MEM_LINK]);
1519 
1520 					if (synth->mem.param[PANEL_SELECT] != 0)
1521 						flags |= BRISTOL_SID2;
1522 
1523 					loadMemory(synth, "jupiter8", 0,
1524 						mylink + mw, LAYER_DEVS, 0, flags);
1525 
1526 					synth->mem.param[MY_MEM] = mylink;
1527 					synth->mem.param[MEM_LINK] = mymem;
1528 				} else {
1529 					/*
1530 					 * Clear any dual/split state
1531 					 */
1532 					event.type = BRIGHTON_FLOAT;
1533 					event.value = 1.0;
1534 
1535 					/* Set 'All' state */
1536 					brightonParamChange(synth->win, 0, KEY_MODE + 2, &event);
1537 					/* Set 'Poly-1' state */
1538 					brightonParamChange(synth->win, 0, POLY_MODE + 2, &event);
1539 				}
1540 			} else {
1541 				int link = synth->mem.param[MEM_LINK];
1542 
1543 				if (jupiterDebug(synth, 1))
1544 					printf("Single load %i of %i params\n",
1545 						synth->bank + synth->location + mw, LAYER_DEVS);
1546 
1547 				loadMemory(synth, "jupiter8", 0,
1548 					synth->bank + synth->location + mw,
1549 					LAYER_DEVS, 0, 0);
1550 
1551 				if (jupiterDebug(synth, 1))
1552 					printf("am %2.0f (%i), no peer layer loading (%2.0f)\n",
1553 						synth->mem.param[MY_MEM],
1554 						synth->bank + synth->location,
1555 						synth->mem.param[MEM_LINK]);
1556 
1557 				/*
1558 				 * Build our links and also set our display values.
1559 				 */
1560 				synth->mem.param[MY_MEM] = synth->bank + synth->location;
1561 				synth->mem.param[MEM_LINK] = link;
1562 
1563 			}
1564 			break;
1565 		case 3:
1566 			/* Memory save */
1567 			if (brightonDoubleClick(dc1)) {
1568 				if (jupiterDebug(synth, 2))
1569 					printf("save\n");
1570 
1571 				if (synth->flags & MEM_LOADING)
1572 					return;
1573 
1574 				/*
1575 				 * I have my memory setup, I need to make sure that my linked
1576 				 * memory is correct. The linked in memory changes by layer but
1577 				 * the panel switch should have taken care of that.
1578 				 */
1579 				synth->mem.param[MY_MEM] = synth->bank + synth->location;
1580 
1581 				if (synth->mem.param[PANEL_SELECT] != 0)
1582 					synth->mem.param[MEM_LINK]
1583 						= synth->mem.param[DISPLAY_DEV + 0] * 10
1584 						+ synth->mem.param[DISPLAY_DEV + 1];
1585 				else
1586 					synth->mem.param[MEM_LINK]
1587 						= synth->mem.param[DISPLAY_DEV + 2] * 10
1588 						+ synth->mem.param[DISPLAY_DEV + 3];
1589 
1590 				if (jupiterDebug(synth, 4))
1591 					printf("saving functions %x %x\n", fBmask, fPmask);
1592 
1593 				synth->mem.param[FUNCTION_SAVE] = (fBmask << 8) + fPmask;
1594 
1595 				saveMemory(synth, "jupiter8", 0,
1596 					synth->bank + synth->location + mw, 0);
1597 
1598 				if (synth->mem.param[PANEL_SELECT] != 0)
1599 					saveSequence(synth, "jupiter8",
1600 						synth->bank + synth->location + mw, BRISTOL_SID2);
1601 				else
1602 					saveSequence(synth, "jupiter8",
1603 						synth->bank + synth->location + mw, 0);
1604 
1605 				if (jupiterDebug(synth, 1))
1606 					printf("	am %2.0f (%i), peer layer saved %2.0f\n",
1607 						synth->mem.param[MY_MEM],
1608 						synth->bank + synth->location,
1609 						synth->mem.param[MEM_LINK]);
1610 			}
1611 			break;
1612 	}
1613 
1614 	if (synth->mem.param[PANEL_SELECT] == 0) {
1615 		synth->mem.param[DISPLAY_DEV + 0]
1616 			= ((int) synth->mem.param[MY_MEM]) / 10;
1617 		synth->mem.param[DISPLAY_DEV + 1]
1618 			= ((int) synth->mem.param[MY_MEM]) % 10;
1619 		synth->mem.param[DISPLAY_DEV + 2]
1620 			= ((int) synth->mem.param[MEM_LINK]) / 10;
1621 		synth->mem.param[DISPLAY_DEV + 3]
1622 			= ((int) synth->mem.param[MEM_LINK]) % 10;
1623 	} else {
1624 		synth->mem.param[DISPLAY_DEV + 0]
1625 			= ((int) synth->mem.param[MEM_LINK]) / 10;
1626 		synth->mem.param[DISPLAY_DEV + 1]
1627 			= ((int) synth->mem.param[MEM_LINK]) % 10;
1628 		synth->mem.param[DISPLAY_DEV + 2]
1629 			= ((int) synth->mem.param[MY_MEM]) / 10;
1630 		synth->mem.param[DISPLAY_DEV + 3]
1631 			= ((int) synth->mem.param[MY_MEM]) % 10;
1632 	}
1633 
1634 /*
1635 printf("am showing %1.0f %1.0f, %1.0f %1.0f from %1.0f %1.0f (%1.0f)\n",
1636 synth->mem.param[DISPLAY_DEV + 0],
1637 synth->mem.param[DISPLAY_DEV + 1],
1638 synth->mem.param[DISPLAY_DEV + 2],
1639 synth->mem.param[DISPLAY_DEV + 3],
1640 synth->mem.param[MY_MEM],
1641 synth->mem.param[MEM_LINK],
1642 synth->mem.param[PANEL_SELECT]);
1643 */
1644 
1645 	/*
1646 	 * Load will set the displays and nothing else, they will alsways point to
1647 	 * the active patches.
1648 	 *
1649 	 * The buttons selections should come from the layer select or from being
1650 	 * pressed themselves.
1651 	 */
1652 	jupiterSetDisplay(synth);
1653 }
1654 
1655 static void
jupiterMidi(guiSynth * synth,int fd,int chan,int c,int o,int v)1656 jupiterMidi(guiSynth *synth, int fd, int chan, int c, int o, int v)
1657 {
1658 	int newchan;
1659 
1660 	if ((synth->flags & OPERATIONAL) == 0)
1661 		return;
1662 
1663 	if (c == 1) {
1664 		if ((newchan = synth->midichannel - 1) < 0)
1665 			newchan = synth->midichannel = 0;
1666 	} else {
1667 		/*
1668 		 * This is a little incorrect - if we are layered then we can go to
1669 		 * midi channel 15.
1670 		 */
1671 		if ((newchan = synth->midichannel + 1) >= 14)
1672 			newchan = synth->midichannel = 14;
1673 	}
1674 
1675 	if (global.libtest == 0)
1676 	{
1677 		bristolMidiSendMsg(global.controlfd, synth->sid2,
1678 			127, 0, (BRISTOL_MIDICHANNEL|newchan) + 1);
1679 		bristolMidiSendMsg(global.controlfd, synth->sid,
1680 			127, 0, BRISTOL_MIDICHANNEL|newchan);
1681 	}
1682 
1683 	synth->midichannel = newchan;
1684 }
1685 
1686 /*
1687  * For the sake of ease of use, links have been placed here to be called
1688  * by any of the devices created. They would be better in some other file,
1689  * perhaps with this as a dispatch.
1690  *
1691  * Param refers to the device index in the locations table given below.
1692  */
1693 static int
jupiterCallback(brightonWindow * win,int panel,int index,float value)1694 jupiterCallback(brightonWindow * win, int panel, int index, float value)
1695 {
1696 	guiSynth *synth = findSynth(global.synths, win);
1697 	int sendvalue;
1698 
1699 	if ((synth == 0) || (synth->flags & SUPPRESS))
1700 		return(0);
1701 
1702 	if (jupiterDebug(synth, 2))
1703 		printf("jupiterCallback(%i, %i, %f)\n", panel, index, value);
1704 
1705 	if ((index >= DEVICE_COUNT) || ((synth->flags & OPERATIONAL) == 0))
1706 		return(0);
1707 
1708 	if (panel == 2) {
1709 		index += LAYER_DEVS;
1710 		sendvalue = value * C_RANGE_MIN_1;
1711 	} else {
1712 		if (jupiterApp.resources[0].devlocn[index].to == 1)
1713 			sendvalue = value * C_RANGE_MIN_1;
1714 		else
1715 			sendvalue = value;
1716 	}
1717 
1718 	/*
1719 	 * If the index is less than LAYER_DEVS then write the value to the desired
1720 	 * layer only, otherwise write the value to both/top layers?
1721 	 */
1722 	synth->mem.param[index] = value;
1723 
1724 	synth->dispatch[index].routine(synth,
1725 		global.controlfd, synth->sid,
1726 		synth->dispatch[index].controller,
1727 		synth->dispatch[index].operator,
1728 		sendvalue);
1729 
1730 	return(0);
1731 }
1732 
1733 /*
1734  * The Jupiter does not actually have a sequencer feature, just the arpeggiator
1735  * and chording.
1736  */
1737 static void
jupiterSeqMode(guiSynth * synth,int fd,int chan,int c,int o,int v)1738 jupiterSeqMode(guiSynth *synth, int fd, int chan, int c, int o, int v)
1739 {
1740 	brightonEvent event;
1741 	int sid = synth->sid;
1742 
1743 	if (jupiterDebug(synth, 1))
1744 		printf("jupiterSeqMode(%i, %i)\n", c, v);
1745 
1746 	event.type = BRIGHTON_FLOAT;
1747 
1748 	if (synth->mem.param[PANEL_SELECT] == 0)
1749 		sid = synth->sid;
1750 	else
1751 		sid = synth->sid2;
1752 
1753 	if (synth->mem.param[FUNCTION] != 0)
1754 	{
1755 		if  (v != 0) {
1756 			if ((synth->flags & OPERATIONAL) == 0)
1757 				return;
1758 			if (synth->flags & MEM_LOADING)
1759 				return;
1760 
1761 			if (jupiterDebug(synth, 0))
1762 				printf("Arpeg learn mode requested %x\n",  synth->flags);
1763 
1764 			if (synth->seq1.param == NULL)
1765 				loadSequence(&synth->seq1, "jupiter8", 0, 0);
1766 			if (synth->seq2.param == NULL)
1767 				loadSequence(&synth->seq2, "jupiter8", 0, BRISTOL_SID2);
1768 
1769 			seqLearn = 1;
1770 
1771 			/* Reset the counter */
1772 			if (synth->mem.param[PANEL_SELECT] == 0)
1773 				synth->seq1.param[0] = 0;
1774 			else
1775 				synth->seq2.param[0] = 0;
1776 
1777 			/*
1778 			 * Stop the arpeggiator and send a learn request
1779 			 */
1780 			bristolMidiSendMsg(global.controlfd, sid,
1781 				BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_ENABLE, 0);
1782 			bristolMidiSendMsg(global.controlfd, sid,
1783 				BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_RESEQ, 1);
1784 		} else {
1785 			/*
1786 			 * Stop the learning process
1787 			 */
1788 			seqLearn = 0;
1789 			bristolMidiSendMsg(global.controlfd, sid,
1790 				BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_RESEQ, 0);
1791 		}
1792 
1793 		return;
1794 	}
1795 
1796 	if (seqLearn == 1) {
1797 		/*
1798 		 * This is a button press during the learning sequence, in which case
1799 		 * it needs to be terminated.
1800 		 */
1801 		seqLearn = 0;
1802 		bristolMidiSendMsg(global.controlfd, sid,
1803 			BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_RESEQ, 0);
1804 	}
1805 
1806 	if (v != 0)
1807 	{
1808 		bristolMidiSendMsg(global.controlfd, sid,
1809 			BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_DIR, o);
1810 		/* And enable it */
1811 		bristolMidiSendMsg(global.controlfd, sid,
1812 			BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_ENABLE, 1);
1813 
1814 		return;
1815 	} else {
1816 		/*
1817 		 * OK, the value is zero. If this is the same controller going off
1818 		 * then disable the arpeggiator, otherwise do nothing.
1819 		 */
1820 		if (synth->dispatch[ARPEG_MODE].other1 == c)
1821 			bristolMidiSendMsg(global.controlfd, sid,
1822 				BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_ENABLE, 0);
1823 		return;
1824 	}
1825 }
1826 
1827 static void
jupiterArpegRate(guiSynth * synth,int fd,int chan,int c,int o,int v)1828 jupiterArpegRate(guiSynth *synth, int fd, int chan, int c, int o, int v)
1829 {
1830 	/*
1831 	 * We need a shim since this needs to go to both SEQ and ARPEG and both
1832 	 * layers (as we only have a single controller).
1833 	 */
1834 	bristolMidiSendMsg(global.controlfd, synth->sid,
1835 		BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_RATE, v);
1836 	bristolMidiSendMsg(global.controlfd, synth->sid,
1837 		BRISTOL_ARPEGGIATOR, BRISTOL_ARPEG_RATE, v);
1838 
1839 	bristolMidiSendMsg(global.controlfd, synth->sid2,
1840 		BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_RATE, v);
1841 	bristolMidiSendMsg(global.controlfd, synth->sid2,
1842 		BRISTOL_ARPEGGIATOR, BRISTOL_ARPEG_RATE, v);
1843 }
1844 
1845 static void
jupiterArpegMode(guiSynth * synth,int fd,int chan,int c,int o,int v)1846 jupiterArpegMode(guiSynth *synth, int fd, int chan, int c, int o, int v)
1847 {
1848 	brightonEvent event;
1849 	int sid = synth->sid;
1850 
1851 	/*
1852 	 * Force exclusion
1853 	 */
1854 	if (synth->dispatch[ARPEG_MODE].other2)
1855 	{
1856 		synth->dispatch[ARPEG_MODE].other2 = 0;
1857 		return;
1858 	}
1859 
1860 	if (jupiterDebug(synth, 1))
1861 		printf("jupiterArpegMode(%i, %i)\n", c, v);
1862 
1863 	event.type = BRIGHTON_FLOAT;
1864 
1865 	if (synth->mem.param[PANEL_SELECT] == 0)
1866 		sid = synth->sid;
1867 	else
1868 		sid = synth->sid2;
1869 
1870 	if (v != 0)
1871 	{
1872 		if (synth->dispatch[ARPEG_MODE].other1 != -1)
1873 		{
1874 			synth->dispatch[ARPEG_MODE].other2 = 1;
1875 
1876 			if (synth->dispatch[ARPEG_MODE].other1 != c)
1877 				event.value = 0;
1878 			else
1879 				event.value = 1;
1880 
1881 			brightonParamChange(synth->win, synth->panel,
1882 				synth->dispatch[ARPEG_MODE].other1, &event);
1883 		}
1884 		synth->dispatch[ARPEG_MODE].other1 = c;
1885 
1886 		bristolMidiSendMsg(global.controlfd, sid,
1887 			BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_DIR, o);
1888 		bristolMidiSendMsg(global.controlfd, sid,
1889 			BRISTOL_ARPEGGIATOR, BRISTOL_ARPEG_DIR, o);
1890 		/* And enable it */
1891 		bristolMidiSendMsg(global.controlfd, sid,
1892 			BRISTOL_ARPEGGIATOR, BRISTOL_ARPEG_ENABLE, 1);
1893 
1894 		return;
1895 	}
1896 
1897 	/*
1898 	 * If we are going off then disable the arpeggiator, otherwise set the
1899 	 * mode and start it.
1900 	 */
1901 	if ((v == 0) && (synth->dispatch[ARPEG_MODE].other1 == c))
1902 		/*
1903 		 * OK, the value is zero. If this is the same controller going off
1904 		 * then disable the arpeggiator, otherwise do nothing.
1905 		 */
1906 		bristolMidiSendMsg(global.controlfd, sid,
1907 			BRISTOL_ARPEGGIATOR, BRISTOL_ARPEG_ENABLE, 0);
1908 }
1909 
1910 static void
jupiterArpegRange(guiSynth * synth,int fd,int chan,int c,int o,int v)1911 jupiterArpegRange(guiSynth *synth, int fd, int chan, int c, int o, int v)
1912 {
1913 	brightonEvent event;
1914 	int sid;
1915 
1916 	if (jupiterDebug(synth, 1))
1917 		printf("jupiterArpegRange(%i, %i) %i\n", c, o, v);
1918 
1919 	event.type = BRIGHTON_FLOAT;
1920 
1921 	/*
1922 	 * Force exclusion
1923 	 */
1924 	if (synth->dispatch[ARPEG_RANGE].other2)
1925 	{
1926 		synth->dispatch[ARPEG_RANGE].other2 = 0;
1927 		return;
1928 	}
1929 
1930 	if (v == 0)
1931 	{
1932 		if (synth->dispatch[ARPEG_RANGE].other1 == c)
1933 		{
1934 			event.value = 1;
1935 			brightonParamChange(synth->win, synth->panel, c, &event);
1936 		}
1937 		return;
1938 	}
1939 
1940 	if (synth->dispatch[ARPEG_RANGE].other1 != -1)
1941 	{
1942 		synth->dispatch[ARPEG_RANGE].other2 = 1;
1943 
1944 		if (synth->dispatch[ARPEG_RANGE].other1 != c)
1945 			event.value = 0;
1946 		else
1947 			event.value = 1;
1948 
1949 		brightonParamChange(synth->win, 0,
1950 			synth->dispatch[ARPEG_RANGE].other1, &event);
1951 	}
1952 	synth->dispatch[ARPEG_RANGE].other1 = c;
1953 
1954 	/*
1955 	 * Then do whatever
1956 	 */
1957 	if (synth->mem.param[PANEL_SELECT] == 0)
1958 		sid = synth->sid;
1959 	else
1960 		sid = synth->sid2;
1961 
1962 	bristolMidiSendMsg(global.controlfd, sid,
1963 		BRISTOL_ARPEGGIATOR, BRISTOL_SEQ_RANGE, o);
1964 	bristolMidiSendMsg(global.controlfd, sid,
1965 		BRISTOL_ARPEGGIATOR, BRISTOL_ARPEG_RANGE, o);
1966 
1967 	return;
1968 }
1969 
1970 static void
jupiterSetVoices(guiSynth * synth)1971 jupiterSetVoices(guiSynth *synth)
1972 {
1973 	int sid;
1974 
1975 	/*
1976 	 * If we are in 'All' mode then sid is for lower layer only, otherwise
1977 	 * we need to look at the layer selection.
1978 	 */
1979 	if (synth->mem.param[KEY_MODE + 2] != 0)
1980 		sid = synth->sid;
1981 	else if (synth->mem.param[PANEL_SELECT] == 0)
1982 		sid = synth->sid;
1983 	else
1984 		sid = synth->sid2;
1985 
1986 	/*
1987 	 * Take a peek at the Poly and Key modes to set either:
1988 	 *
1989 	 *	Solo:	1 voice
1990 	 *	Uni:	Unify:
1991 	 *		All:	all voices else half
1992 	 *	Poly:	clear unison:
1993 	 *		All:	all voices else half
1994 	 */
1995 	if (synth->mem.param[POLY_MODE] != 0) {
1996 		/*
1997 		 * Solo. One voice no Unison.
1998 		 */
1999 		bristolMidiSendMsg(global.controlfd, sid, BRISTOL_ARPEGGIATOR,
2000 			BRISTOL_ARPEG_POLY_2, 0);
2001 		bristolMidiSendMsg(global.controlfd, sid, 126, 2, 2);
2002 		bristolMidiSendMsg(global.controlfd, sid, 126, 7, 0);
2003 	} else if (synth->mem.param[POLY_MODE + 1] != 0) {
2004 		/*
2005 		 * Unison all voices
2006 		 */
2007 		bristolMidiSendMsg(global.controlfd, sid, BRISTOL_ARPEGGIATOR,
2008 			BRISTOL_ARPEG_POLY_2, 0);
2009 		if (synth->mem.param[KEY_MODE + 2] != 0)
2010 			bristolMidiSendMsg(global.controlfd, sid, 126, 2, 1);
2011 		else
2012 			bristolMidiSendMsg(global.controlfd, sid, 126, 2, 0);
2013 		bristolMidiSendMsg(global.controlfd, sid, 126, 7, 1);
2014 	} else if (synth->mem.param[POLY_MODE + 2] != 0) {
2015 		/*
2016 		 * Poly-1
2017 		 */
2018 		bristolMidiSendMsg(global.controlfd, sid, BRISTOL_ARPEGGIATOR,
2019 			BRISTOL_ARPEG_POLY_2, 0);
2020 		if (synth->mem.param[KEY_MODE + 2] != 0)
2021 			bristolMidiSendMsg(global.controlfd, sid, 126, 2, 1);
2022 		else
2023 			bristolMidiSendMsg(global.controlfd, sid, 126, 2, 0);
2024 		bristolMidiSendMsg(global.controlfd, sid, 126, 7, 0);
2025 	} else if (synth->mem.param[POLY_MODE + 3] != 0) {
2026 		/*
2027 		 * Poly-2 is not operational at the moment. Configure as per Poly-1
2028 		 */
2029 		if (synth->mem.param[KEY_MODE + 2] != 0) {
2030 			bristolMidiSendMsg(global.controlfd, sid, 126, 2, 1);
2031 		} else {
2032 			bristolMidiSendMsg(global.controlfd, sid, 126, 2, 0);
2033 		}
2034 		bristolMidiSendMsg(global.controlfd, sid, BRISTOL_ARPEGGIATOR,
2035 			BRISTOL_ARPEG_POLY_2, 1);
2036 	}
2037 }
2038 
2039 /*
2040  * This may have to move to within the Layer parameters since assuming the JP-8
2041  * was the same as the JP6 and MKS-80 these were accorded to each layer.
2042  *
2043  * We could leave that for later study since the JP-8 arpeggiator was officially
2044  * only on the lower layer - the JP-6 and MKS-80 could have them on either
2045  * layer so we may move all these arpeggiator and key modes into the layer
2046  * parameters.
2047  */
2048 static void
jupiterUniPoly(guiSynth * synth,int fd,int chan,int c,int o,int v)2049 jupiterUniPoly(guiSynth *synth, int fd, int chan, int c, int o, int v)
2050 {
2051 	brightonEvent event;
2052 
2053 	if (jupiterDebug(synth, 2))
2054 		printf("jupiterUniPoly(%i, %i)\n", c, v);
2055 
2056 	event.type = BRIGHTON_FLOAT;
2057 	/*
2058 	 * Force exclusion
2059 	 */
2060 	if (synth->dispatch[POLY_MODE].other2)
2061 	{
2062 		synth->dispatch[POLY_MODE].other2 = 0;
2063 		return;
2064 	}
2065 
2066 	if (v == 0)
2067 	{
2068 		if (synth->dispatch[POLY_MODE].other1 == c)
2069 		{
2070 			event.value = 1;
2071 			brightonParamChange(synth->win, synth->panel, c, &event);
2072 		} else
2073 			return;
2074 	}
2075 	if (synth->dispatch[POLY_MODE].other1 != -1)
2076 	{
2077 		synth->dispatch[POLY_MODE].other2 = 1;
2078 
2079 		if (synth->dispatch[POLY_MODE].other1 != c)
2080 			event.value = 0;
2081 		else
2082 			event.value = 1;
2083 
2084 		brightonParamChange(synth->win, synth->panel,
2085 			synth->dispatch[POLY_MODE].other1, &event);
2086 	}
2087 
2088 	synth->dispatch[POLY_MODE].other1 = c;
2089 
2090 	if (v == 0)
2091 		return;
2092 
2093 	/*
2094 	 * Do what needs to be done
2095 	 */
2096 	switch (o) {
2097 		case 0:
2098 			if (jupiterDebug(synth, 1))
2099 				printf("Solo Mode\n");
2100 			/*
2101 			 * Set single voice, no uni
2102 			 */
2103 			jupiterSetVoices(synth);
2104 			break;
2105 		case 1:
2106 			if (jupiterDebug(synth, 1))
2107 				printf("Uni Mode\n");
2108 			/*
2109 			 * Set X voices depending on mode, unison all of them
2110 			 */
2111 			jupiterSetVoices(synth);
2112 			break;
2113 		case 2:
2114 			if (jupiterDebug(synth, 1))
2115 				printf("Poly-1 Mode\n");
2116 			/*
2117 			 * Set X voices depending on mode, no Unison
2118 			 */
2119 			jupiterSetVoices(synth);
2120 			break;
2121 		case 3:
2122 			if (jupiterDebug(synth, 1))
2123 				printf("Poly-2 Mode\n");
2124 			/*
2125 			 * Not implemented
2126 			 */
2127 			jupiterSetVoices(synth);
2128 			break;
2129 	}
2130 
2131 	return;
2132 }
2133 
2134 static void
jupiterSetSplit(guiSynth * synth)2135 jupiterSetSplit(guiSynth *synth)
2136 {
2137 	int lsp, usp;
2138 
2139 	if (jupiterDebug(synth, 1))
2140 		printf("setSplit: %i\n", (int) synth->mem.param[SPLIT_POINT]);
2141 
2142 	if (mode == MODE_SINGLE)
2143 		/* We could consider clearing any splitpoints here as well */
2144 		return;
2145 
2146 	/*
2147 	 * Find and apply split points
2148 	 * We need to consider DE-121 for multiple splits.
2149 	 */
2150 	if (mode == MODE_SPLIT) {
2151 		lsp = synth->mem.param[SPLIT_POINT] + synth->transpose;
2152 		usp = lsp + 1;
2153 	} else {
2154 		lsp = 127;
2155 		usp = 0;
2156 	}
2157 
2158 	if (global.libtest == 0) {
2159 		bristolMidiSendMsg(global.controlfd, synth->sid, 127, 0,
2160 			BRISTOL_HIGHKEY|lsp);
2161 		bristolMidiSendMsg(global.controlfd, synth->sid2, 127, 0,
2162 			BRISTOL_LOWKEY|usp);
2163 	}
2164 
2165 	setsplit = 0;
2166 }
2167 
2168 /*
2169  * Dual, split and layer. One button needs to be on constantly
2170  */
2171 static void
jupiterKeyMode(guiSynth * synth,int fd,int chan,int c,int o,int v)2172 jupiterKeyMode(guiSynth *synth, int fd, int chan, int c, int o, int v)
2173 {
2174 	brightonEvent event;
2175 
2176 	if (jupiterDebug(synth, 1))
2177 		printf("jupiterKeyMode(%i, %i)\n", c, v);
2178 
2179 	event.type = BRIGHTON_FLOAT;
2180 	/*
2181 	 * Force exclusion
2182 	 */
2183 	if (synth->dispatch[KEY_MODE].other2)
2184 	{
2185 		synth->dispatch[KEY_MODE].other2 = 0;
2186 		return;
2187 	}
2188 
2189 	if (v == 0)
2190 	{
2191 		if (synth->dispatch[KEY_MODE].other1 == c)
2192 		{
2193 			event.value = 1;
2194 			brightonParamChange(synth->win, synth->panel, c, &event);
2195 		} else
2196 			return;
2197 	}
2198 
2199 	if (synth->dispatch[KEY_MODE].other1 != -1)
2200 	{
2201 		synth->dispatch[KEY_MODE].other2 = 1;
2202 
2203 		if (synth->dispatch[KEY_MODE].other1 != c)
2204 			event.value = 0;
2205 		else
2206 			event.value = 1;
2207 
2208 		brightonParamChange(synth->win, synth->panel,
2209 			synth->dispatch[KEY_MODE].other1, &event);
2210 	}
2211 
2212 	synth->dispatch[KEY_MODE].other1 = c;
2213 
2214 	/*
2215 	 * Do what needs to be done
2216 	 */
2217 	switch (o) {
2218 		case 0:
2219 			if (jupiterDebug(synth, 1))
2220 				printf("Dual mode\n");
2221 			mode = MODE_DUAL;
2222 
2223 			/*
2224 			 * Configure split points to cover whole keyboard, halve notes on
2225 			 * lower layer or 1 if Solo.
2226 			 */
2227 			bristolMidiSendMsg(fd, synth->sid, 126, 2, 0);
2228 
2229 			if (global.libtest == 0) {
2230 				bristolMidiSendMsg(global.controlfd, synth->sid,
2231 					127, 0, BRISTOL_HIGHKEY|127);
2232 				bristolMidiSendMsg(global.controlfd, synth->sid2,
2233 					127, 0, BRISTOL_LOWKEY|0);
2234 			}
2235 			jupiterSetVoices(synth);
2236 			break;
2237 		case 1:
2238 			if (jupiterDebug(synth, 1))
2239 				printf("Split mode\n");
2240 			mode = MODE_SPLIT;
2241 
2242 			/*
2243 			 * Configure split points to cover whole keyboard, halve notes on
2244 			 * lower layer or 1 if Solo.. If double click then clear splitpoint
2245 			 * until next key.
2246 			 */
2247 			bristolMidiSendMsg(fd, synth->sid, 126, 2, 0);
2248 
2249 			if (brightonDoubleClick(dc1)) {
2250 				if (synth->flags & MEM_LOADING)
2251 					return;
2252 
2253 				if (jupiterDebug(synth, 1))
2254 					printf("Split mode\n");
2255 
2256 				synth->mem.param[SPLIT_POINT] = 0;
2257 				setsplit = 1;
2258 				return;
2259 			}
2260 			jupiterSetSplit(synth);
2261 			jupiterSetVoices(synth);
2262 			break;
2263 		case 2:
2264 			if (jupiterDebug(synth, 1))
2265 				printf("All mode\n");
2266 			mode = MODE_SINGLE;
2267 
2268 			/*
2269 			 * Move upper split out of range, increase notes on lower layer
2270 			 * or 1 if Solo.
2271 			 */
2272 			bristolMidiSendMsg(fd, synth->sid, 126, 2, 1);
2273 
2274 			if (global.libtest == 0) {
2275 				bristolMidiSendMsg(global.controlfd, synth->sid,
2276 					127, 0, BRISTOL_HIGHKEY|127);
2277 				bristolMidiSendMsg(global.controlfd, synth->sid2,
2278 					127, 0, BRISTOL_LOWKEY|127);
2279 			}
2280 			jupiterSetVoices(synth);
2281 			break;
2282 	}
2283 
2284 	return;
2285 }
2286 
2287 static void
jupiterBend(guiSynth * synth,int fd,int chan,int c,int o,int v)2288 jupiterBend(guiSynth *synth, int fd, int chan, int c, int o, int v)
2289 {
2290 	if (jupiterDebug(synth, 4))
2291 		printf("bend %i\n", v);
2292 	if (global.libtest == 0)
2293 		bristolMidiControl(global.controlfd, synth->midichannel, 0, 1, v >> 7);
2294 }
2295 
2296 static void
jupiterGlide(guiSynth * synth,int fd,int chan,int c,int o,int v)2297 jupiterGlide(guiSynth *synth, int fd, int chan, int c, int o, int v)
2298 {
2299 	if (jupiterDebug(synth, 4))
2300 		printf("glide %i %f to %i/%i\n", v, synth->mem.param[LAYER_DEVS + 11],
2301 			synth->sid, synth->sid2);
2302 
2303 	/*
2304 	 * Glide can be up/off/on, which I don't like (since it is in the memory)
2305 	 * and may go for up/both/lower instead.
2306 	 */
2307 	if (synth->mem.param[LAYER_DEVS + 11] == 2) {
2308 		/*
2309 		 * Upper only
2310 		 */
2311 		bristolMidiSendMsg(global.controlfd, synth->sid, 126, 0, 0);
2312 		bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 0,
2313 			(int) (synth->mem.param[LAYER_DEVS + 10] * C_RANGE_MIN_1));
2314 	} else if (synth->mem.param[LAYER_DEVS + 11] == 1) {
2315 		/*
2316 		 * Both
2317 		 */
2318 		bristolMidiSendMsg(global.controlfd, synth->sid, 126, 0,
2319 			(int) (synth->mem.param[LAYER_DEVS + 10] * C_RANGE_MIN_1));
2320 		bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 0,
2321 			(int) (synth->mem.param[LAYER_DEVS + 10] * C_RANGE_MIN_1));
2322 	} else {
2323 		/*
2324 		 * Lower
2325 		 */
2326 		bristolMidiSendMsg(global.controlfd, synth->sid, 126, 0,
2327 			(int) (synth->mem.param[LAYER_DEVS + 10] * C_RANGE_MIN_1));
2328 		bristolMidiSendMsg(global.controlfd, synth->sid2, 126, 0, 0);
2329 	}
2330 }
2331 
2332 static void
jupiterLFODelay(guiSynth * synth,int fd,int chan,int c,int o,int v)2333 jupiterLFODelay(guiSynth *synth, int fd, int chan, int c, int o, int v)
2334 {
2335 	if (jupiterDebug(synth, 4))
2336 		printf("LFODelay %i\n", v);
2337 
2338 	jupiterDualSend(synth, synth->sid, 3, 0, v);
2339 }
2340 
2341 static void
jupiterUME(guiSynth * synth,int sid,int chan,int c,int o,int v)2342 jupiterUME(guiSynth *synth, int sid, int chan, int c, int o, int v)
2343 {
2344 	if (o == 40)
2345 		bristolMidiSendMsg(global.controlfd, synth->sid, c, 40, v);
2346 	else
2347 		bristolMidiSendMsg(global.controlfd, synth->sid2, c, 40, v);
2348 }
2349 
2350 /*
2351  * This is a conditional dual send, it first checks for the Mod enable flags
2352  * before sending the codes.
2353  */
2354 static void
jupiterDSM(guiSynth * synth,int sid,int c,int o,int v)2355 jupiterDSM(guiSynth *synth, int sid, int c, int o, int v)
2356 {
2357 	if (--v < 0)
2358 		v = 0;
2359 
2360 	bristolMidiSendMsg(global.controlfd, synth->sid, c, o, v);
2361 	bristolMidiSendMsg(global.controlfd, synth->sid2, c, o, v);
2362 }
2363 
2364 static void
jupiterLFOVCF(guiSynth * synth,int fd,int chan,int c,int o,int v)2365 jupiterLFOVCF(guiSynth *synth, int fd, int chan, int c, int o, int v)
2366 {
2367 	float depth;
2368 
2369 	if (jupiterDebug(synth, 4))
2370 		printf("LFOVCF %i\n", v);
2371 
2372 	depth = synth->mem.param[LAYER_DEVS + 3];
2373 
2374 	if (synth->mem.param[LAYER_DEVS + 8] != 0)
2375 		jupiterDSM(synth, synth->sid, 126, 27, depth * C_RANGE_MIN_1);
2376 	else
2377 		jupiterDSM(synth, synth->sid, 126, 27, 0); // VCF
2378 }
2379 
2380 static void
jupiterLFOVCO(guiSynth * synth,int fd,int chan,int c,int o,int v)2381 jupiterLFOVCO(guiSynth *synth, int fd, int chan, int c, int o, int v)
2382 {
2383 	float depth;
2384 
2385 	if (jupiterDebug(synth, 4))
2386 		printf("LFOVCO %i\n", v);
2387 
2388 	depth = synth->mem.param[LAYER_DEVS + 2];
2389 
2390 	if (synth->mem.param[LAYER_DEVS + 7] != 0)
2391 		jupiterDSM(synth, synth->sid, 126, 26, depth * C_RANGE_MIN_1);
2392 	else
2393 		jupiterDSM(synth, synth->sid, 126, 26, 0); // VCF
2394 }
2395 
2396 static void
jupiterBendVCF(guiSynth * synth,int fd,int chan,int c,int o,int v)2397 jupiterBendVCF(guiSynth *synth, int fd, int chan, int c, int o, int v)
2398 {
2399 	float depth;
2400 
2401 	if (jupiterDebug(synth, 4))
2402 		printf("BendVCF %i\n", v);
2403 
2404 	depth = synth->mem.param[LAYER_DEVS + 1];
2405 
2406 	if (synth->mem.param[LAYER_DEVS + 6] != 0)
2407 		jupiterDSM(synth, synth->sid, 126, 25, depth * C_RANGE_MIN_1);
2408 	else
2409 		jupiterDSM(synth, synth->sid, 126, 25, 0); // VCF
2410 }
2411 
2412 static void
jupiterBendVCO(guiSynth * synth,int fd,int chan,int c,int o,int v)2413 jupiterBendVCO(guiSynth *synth, int fd, int chan, int c, int o, int v)
2414 {
2415 	float depth;
2416 
2417 	if (jupiterDebug(synth, 4))
2418 		printf("BendVCO %i\n", v);
2419 
2420 	/*
2421 	 * We expect 3 operators here, they are depth of bend plus direction.
2422 	 * 65 = VCO, 70 = VCO1, 71 = VCO2.
2423 	 */
2424 	depth = synth->mem.param[LAYER_DEVS];
2425 
2426 	if (synth->mem.param[LAYER_DEVS + 4] != 0)
2427 		jupiterDSM(synth, synth->sid, 126, 23, depth * C_RANGE_MIN_1);
2428 	else
2429 		jupiterDSM(synth, synth->sid, 126, 23, 0); // VCO 1 level;
2430 
2431 	if (synth->mem.param[LAYER_DEVS + 5] != 0)
2432 		jupiterDSM(synth, synth->sid, 126, 24, depth * C_RANGE_MIN_1);
2433 	else
2434 		jupiterDSM(synth, synth->sid, 126, 24, 0); // VCO 2 level;
2435 }
2436 
2437 static void
jupiterVolume(guiSynth * synth,int fd,int chan,int c,int o,int v)2438 jupiterVolume(guiSynth *synth, int fd, int chan, int c, int o, int v)
2439 {
2440 	float volume = synth->mem.param[101];
2441 	float balance = synth->mem.param[102];
2442 
2443 	if (jupiterDebug(synth, 4))
2444 		printf("Volume %i\n", v);
2445 
2446 	/*
2447 	 * We have to consider layer balance and volume here, they multiply out.
2448 	 * These are linear controls. They may become constand power curves but
2449 	 * that reponse is not too great.
2450 	 */
2451 	bristolMidiSendMsg(fd, synth->sid, 126, 3,
2452 		(int) (volume * (1.0 - balance) * C_RANGE_MIN_1));
2453 	bristolMidiSendMsg(fd, synth->sid2, 126, 3,
2454 		(int) (volume * balance * C_RANGE_MIN_1));
2455 }
2456 
2457 static void
jupiterPW(guiSynth * synth,int fd,int chan,int c,int o,int v)2458 jupiterPW(guiSynth *synth, int fd, int chan, int c, int o, int v)
2459 {
2460 	if (jupiterDebug(synth, 4))
2461 		printf("PW %i\n", v);
2462 
2463 	jupiterMidiSendMsg(synth, fd, chan, 4, 7, v);
2464 	jupiterMidiSendMsg(synth, fd, chan, 5, 7, v);
2465 }
2466 
2467 static void
jupiterLFOwave(guiSynth * synth,int fd,int chan,int c,int o,int v)2468 jupiterLFOwave(guiSynth *synth, int fd, int chan, int c, int o, int v)
2469 {
2470 	jupiterMidiSendMsg(synth, fd, chan, 126, 12 + v, 1);
2471 }
2472 
2473 static void
jupiterTranspose(guiSynth * synth,int fd,int chan,int c,int o,int v)2474 jupiterTranspose(guiSynth *synth, int fd, int chan, int c, int o, int v)
2475 {
2476 	if (v > 2)
2477 		v = 2;
2478 
2479 	if (c == 0)
2480 	{
2481 		if (jupiterDebug(synth, 2))
2482 			printf("lower transpose %i\n", (v - 1) * 12);
2483 		bristolMidiSendMsg(global.controlfd, synth->sid, 127, 0,
2484 			BRISTOL_TRANSPOSE + ((v - 1) * 12));
2485 	} else {
2486 		if (jupiterDebug(synth, 2))
2487 			printf("upper transpose %i\n", (v - 1) * 12);
2488 		bristolMidiSendMsg(global.controlfd, synth->sid2, 127, 0,
2489 			BRISTOL_TRANSPOSE + ((v - 1) * 12));
2490 	}
2491 }
2492 
2493 static void
jupiterChord(guiSynth * synth,int fd,int chan,int c,int o,int v)2494 jupiterChord(guiSynth *synth, int fd, int chan, int c, int o, int v)
2495 {
2496 	int sid = synth->sid;
2497 
2498 	if (jupiterDebug(synth, 1))
2499 		printf("Chord request: %i\n", v);
2500 
2501 	if (c == 81)
2502 		sid = synth->sid2;
2503 
2504 	if (synth->mem.param[FUNCTION] != 0)
2505 	{
2506 		if  (v != 0)
2507 		{
2508 			if ((synth->flags & OPERATIONAL) == 0)
2509 				return;
2510 			if (synth->flags & MEM_LOADING)
2511 				return;
2512 
2513 			if (synth->seq1.param == NULL)
2514 				loadSequence(&synth->seq1, "jupiter8", 0, 0);
2515 			if (synth->seq2.param == NULL)
2516 				loadSequence(&synth->seq2, "jupiter8", 0, BRISTOL_SID2);
2517 
2518 			chordLearn = 1;
2519 
2520 			if (jupiterDebug(synth, 0))
2521 				printf("Chord learn requested %x\n",  synth->flags);
2522 
2523 			if (c == 81)
2524 				synth->seq2.param[1] = 0;
2525 			else
2526 				synth->seq1.param[1] = 0;
2527 
2528 			/*
2529 			 * This is to start a re-seq of the chord.
2530 			 */
2531 			bristolMidiSendMsg(global.controlfd, sid,
2532 				BRISTOL_ARPEGGIATOR, BRISTOL_CHORD_ENABLE, 0);
2533 			bristolMidiSendMsg(global.controlfd, sid,
2534 				BRISTOL_ARPEGGIATOR, BRISTOL_CHORD_RESEQ, 1);
2535 		} else {
2536 			chordLearn = 0;
2537 			bristolMidiSendMsg(global.controlfd, sid,
2538 				BRISTOL_ARPEGGIATOR, BRISTOL_CHORD_RESEQ, 0);
2539 		}
2540 
2541 		return;
2542 	}
2543 
2544 	if (chordLearn == 1) {
2545 		/*
2546 		 * This is a button press during the learning sequence, in which case
2547 		 * it needs to be terminated.
2548 		 */
2549 		chordLearn = 0;
2550 		bristolMidiSendMsg(global.controlfd, sid,
2551 			BRISTOL_ARPEGGIATOR, BRISTOL_CHORD_RESEQ, 0);
2552 	}
2553 
2554 	bristolMidiSendMsg(global.controlfd, sid,
2555 		BRISTOL_ARPEGGIATOR, BRISTOL_CHORD_ENABLE, v);
2556 }
2557 
2558 static void
jupiterFilter(guiSynth * synth,int fd,int chan,int c,int o,int v)2559 jupiterFilter(guiSynth *synth, int fd, int chan, int c, int o, int v)
2560 {
2561 	int sid;
2562 
2563 	if ((synth->mem.param[PANEL_SELECT] == 0) || (mode == MODE_SINGLE))
2564 		sid = synth->sid;
2565 	else
2566 		sid = synth->sid2;
2567 
2568 	/*
2569 	 * The preferred filter is the Houvilainen however as of 0.20.8 this only
2570 	 * does LPF. For the HPF and BPF we have to revert back to the previous
2571 	 * chaimberlains
2572 	 */
2573 	switch (v) {
2574 		case 0: /* LP - 24 dB */
2575 			bristolMidiSendMsg(global.controlfd, sid, 6, 4, 4);
2576 			bristolMidiSendMsg(global.controlfd, sid, 6, 6, 0);
2577 			break;
2578 		case 1:
2579 			bristolMidiSendMsg(global.controlfd, sid, 6, 4, 0);
2580 			bristolMidiSendMsg(global.controlfd, sid, 6, 6, 1);
2581 			break;
2582 		case 2:
2583 			bristolMidiSendMsg(global.controlfd, sid, 6, 4, 0);
2584 			bristolMidiSendMsg(global.controlfd, sid, 6, 6, 2);
2585 			break;
2586 	}
2587 }
2588 
2589 static void
jupiterGlobalTune(guiSynth * synth,int fd,int chan,int c,int o,int v)2590 jupiterGlobalTune(guiSynth *synth, int fd, int chan, int c, int o, int v)
2591 {
2592 	/*
2593 	 * Configures all the tune settings to zero (ie, 0.5).
2594 	 *
2595 	 * 14 is the fine tune of osc-2. 12 and 13 are also potentials here but
2596 	 * they are more associated with sound than tuning. 74 is global tuning.
2597 	 */
2598 	bristolMidiSendMsg(global.controlfd, synth->sid, c, o, v);
2599 	bristolMidiSendMsg(global.controlfd, synth->sid2, c, o, v);
2600 }
2601 
2602 static void
jupiterTune(guiSynth * synth,int fd,int chan,int c,int o,int v)2603 jupiterTune(guiSynth *synth, int fd, int chan, int c, int o, int v)
2604 {
2605 	brightonEvent event;
2606 
2607 	/*
2608 	 * Configures all the tune settings to zero (ie, 0.5).
2609 	 *
2610 	 * 14 is the fine tune of osc-2. 12 and 13 are also potentials here but
2611 	 * they are more associated with sound than tuning. 74 is global tuning.
2612 	 */
2613 	event.type = BRIGHTON_FLOAT;
2614 	event.value = 0.5;
2615 	brightonParamChange(synth->win, synth->panel, 23, &event);
2616 	brightonParamChange(synth->win, synth->panel, 103, &event);
2617 }
2618 
2619 /*
2620  * Any location initialisation required to run the callbacks. For bristol, this
2621  * will connect to the engine, and give it some base parameters.
2622  * May need to generate some application specific menus.
2623  * Will also then make specific requests to some of the devices to alter their
2624  * rendering.
2625  */
2626 static int
jupiterInit(brightonWindow * win)2627 jupiterInit(brightonWindow *win)
2628 {
2629 	guiSynth *synth = findSynth(global.synths, win);
2630 	dispatcher *dispatch;
2631 	int i;
2632 
2633 	if (synth == 0)
2634 	{
2635 		synth = findSynth(global.synths, 0);
2636 		if (synth == 0)
2637 		{
2638 			printf("cannot init\n");
2639 			return(0);
2640 		}
2641 	}
2642 
2643 	synth->win = win;
2644 
2645 	printf("Initialise the jupiter link to bristol: %p\n", synth->win);
2646 
2647 	synth->mem.param = (float *) brightonmalloc(DEVICE_COUNT * sizeof(float));
2648 	synth->mem.count = DEVICE_COUNT;
2649 	synth->mem.active = ACTIVE_DEVS;
2650 	synth->dispatch = (dispatcher *)
2651 		brightonmalloc(DEVICE_COUNT * sizeof(dispatcher));
2652 	dispatch = synth->dispatch;
2653 
2654 	synth->second = brightonmalloc(sizeof(guiSynth));
2655 	bcopy(synth, ((guiSynth *) synth->second), sizeof(guiSynth));
2656 	((guiSynth *) synth->second)->mem.param =
2657 		(float *) brightonmalloc(DEVICE_COUNT * sizeof(float));
2658 	((guiSynth *) synth->second)->mem.count = DEVICE_COUNT;
2659 	((guiSynth *) synth->second)->mem.active = ACTIVE_DEVS;
2660 	((guiSynth *) synth->second)->dispatch = synth->dispatch;
2661 
2662 	/* If we have a default voice count then limit it */
2663 	if (synth->voices == BRISTOL_VOICECOUNT) {
2664 		synth->voices = 8;
2665 		((guiSynth *) synth->second)->voices = 4;
2666 	} else
2667 		((guiSynth *) synth->second)->voices = synth->voices >> 1;
2668 
2669 	pcache = (float *) brightonmalloc(LAYER_DEVS * sizeof(float));
2670 	scache = (float *) brightonmalloc(LAYER_DEVS * sizeof(float));
2671 
2672 	/*
2673 	 * We really want to have three connection mechanisms. These should be
2674 	 *	1. Unix named sockets.
2675 	 *	2. UDP sockets.
2676 	 *	3. MIDI pipe.
2677 	 */
2678 	if (!global.libtest)
2679 	{
2680 		int v = synth->voices;
2681 
2682 		bcopy(&global, &manual, sizeof(guimain));
2683 
2684 		if ((synth->sid = initConnection(&global, synth)) < 0)
2685 			return(-1);
2686 
2687 		/*
2688 		 * We have to tweak the voicecount as we use the same synth definition
2689 		 * to request the second layer
2690 		 */
2691 		synth->voices = synth->voices >> 1;
2692 		manual.flags |= BRISTOL_CONN_FORCE|BRIGHTON_NOENGINE;
2693 		manual.port = global.port;
2694 		manual.host = global.host;
2695 
2696 		if ((synth->sid2 = initConnection(&manual, synth)) < 0)
2697 			return(-1);
2698 
2699 		global.manualfd = manual.controlfd;
2700 		global.manual = &manual;
2701 		manual.manual = &global;
2702 
2703 		synth->voices = v;
2704 	}
2705 
2706 	for (i = 0; i < DEVICE_COUNT; i++)
2707 	{
2708 		/* Default all controllers to send a message that is ignored */
2709 		synth->dispatch[i].controller = 126;
2710 		synth->dispatch[i].operator = 101;
2711 		synth->dispatch[i].routine = (synthRoutine) jupiterMidiSendMsg;
2712 	}
2713 
2714 	/* LFO-1 rate and delay */
2715 	dispatch[0].controller = 0;
2716 	dispatch[0].operator = 0;
2717 	dispatch[1].controller = 2;
2718 	dispatch[1].operator = 0;
2719 	dispatch[2].routine = (synthRoutine) jupiterLFOwave;
2720 
2721 	/* Mods */
2722 	dispatch[3].controller = 126;
2723 	dispatch[3].operator = 9;
2724 	dispatch[4].controller = 126;
2725 	dispatch[4].operator = 10;
2726 	dispatch[5].controller = 126;
2727 	dispatch[5].operator = 11;
2728 
2729 	dispatch[6].controller = 126;
2730 	dispatch[6].operator = 16;
2731 	dispatch[7].controller = 126;
2732 	dispatch[7].operator = 17;
2733 
2734 	/* VCO-1 */
2735 	dispatch[8].controller = 126;
2736 	dispatch[8].operator = 8;
2737 	dispatch[9].controller = 4;
2738 	dispatch[9].operator = 3;
2739 	dispatch[10].controller = 4;
2740 	dispatch[10].operator = 2;
2741 	dispatch[11].controller = 4;
2742 	dispatch[11].operator = 1;
2743 	dispatch[12].controller = 4;
2744 	dispatch[12].operator = 0;
2745 	dispatch[13].controller = 4;
2746 	dispatch[13].operator = 4;
2747 	dispatch[14].controller = 4;
2748 	dispatch[14].operator = 5;
2749 	dispatch[15].controller = 4;
2750 	dispatch[15].operator = 6;
2751 	dispatch[16].controller = 4;
2752 	dispatch[16].operator = 11;
2753 	dispatch[17].controller = 126;
2754 	dispatch[17].operator = 38; /* Sync */
2755 
2756 	/* VCO-2 */
2757 	dispatch[18].controller = 5;
2758 	dispatch[18].operator = 12;
2759 	dispatch[19].controller = 5;
2760 	dispatch[19].operator = 3;
2761 	dispatch[20].controller = 5;
2762 	dispatch[20].operator = 2;
2763 	dispatch[21].controller = 5;
2764 	dispatch[21].operator = 1;
2765 	dispatch[22].controller = 5;
2766 	dispatch[22].operator = 0;
2767 
2768 	dispatch[23].controller = 5;
2769 	dispatch[23].operator = 9;
2770 
2771 	dispatch[24].controller = 5;
2772 	dispatch[24].operator = 4;
2773 	dispatch[25].controller = 5;
2774 	dispatch[25].operator = 5;
2775 	dispatch[26].controller = 5;
2776 	dispatch[26].operator = 6;
2777 
2778 	/* Noise */
2779 	dispatch[27].controller = 126;
2780 	dispatch[27].operator = 5;
2781 
2782 	/* MIX */
2783 	dispatch[28].controller = 126;
2784 	dispatch[28].operator = 6;
2785 
2786 	/* HPF */
2787 	dispatch[29].controller = 11;
2788 	dispatch[29].operator = 0;
2789 
2790 	/* VCF */
2791 	dispatch[30].controller = 6;
2792 	dispatch[30].operator = 0;
2793 	dispatch[31].controller = 6;
2794 	dispatch[31].operator = 1;
2795 	dispatch[32].controller = 6; /* Filter type - make this LP/HP */
2796 	dispatch[32].operator = 6;
2797 	dispatch[32].routine = (synthRoutine) jupiterFilter;
2798 	dispatch[33].controller = 126;
2799 	dispatch[33].operator = 18; /* Env amount */
2800 	dispatch[34].controller = 126;
2801 	dispatch[34].operator = 19; /* Env 1/2 */
2802 	dispatch[35].controller = 126;
2803 	dispatch[35].operator = 20; /* LFO amount */
2804 	dispatch[36].controller = 6;
2805 	dispatch[36].operator = 3; /* KBD */
2806 
2807 	/* Amp */
2808 	dispatch[37].controller = 126;
2809 	dispatch[37].operator = 21; /* Env to amp */
2810 	dispatch[38].controller = 126;
2811 	dispatch[38].operator = 22; /* LFO to AMP */
2812 
2813 	/* ADSR-1 */
2814 	dispatch[39].controller = 7;
2815 	dispatch[39].operator = 0;
2816 	dispatch[40].controller = 7;
2817 	dispatch[40].operator = 1;
2818 	dispatch[41].controller = 7;
2819 	dispatch[41].operator = 2;
2820 	dispatch[42].controller = 7;
2821 	dispatch[42].operator = 3;
2822 	dispatch[43].controller = 7;
2823 	dispatch[43].operator = 5; /* Velocity tracking */
2824 	dispatch[44].controller = 126;
2825 	dispatch[44].operator = 39; /* Env Invert */
2826 
2827 	/* ADSR-2 */
2828 	dispatch[45].controller = 9;
2829 	dispatch[45].operator = 0;
2830 	dispatch[46].controller = 9;
2831 	dispatch[46].operator = 1;
2832 	dispatch[47].controller = 9;
2833 	dispatch[47].operator = 2;
2834 	dispatch[48].controller = 9;
2835 	dispatch[48].operator = 3;
2836 	dispatch[49].controller = 9;
2837 	dispatch[49].operator = 5; /* Velocity tracking */
2838 	/* PW Both Osc */
2839 	dispatch[50].controller = 9;
2840 	dispatch[50].operator = 5; /* PW */
2841 	dispatch[50].routine = (synthRoutine) jupiterPW;
2842 	dispatch[51].controller = 126;
2843 	dispatch[51].operator = 30; /* XMOD env */
2844 	/* Pan */
2845 	dispatch[52].controller = 126;
2846 	dispatch[52].operator = 4; /* Layer panning */
2847 
2848 	dispatch[53].controller = 53;
2849 	dispatch[53].operator = 0;
2850 	dispatch[53].routine = (synthRoutine) jupiterArpegRange;
2851 	dispatch[54].controller = 54;
2852 	dispatch[54].operator = 1;
2853 	dispatch[54].routine = (synthRoutine) jupiterArpegRange;
2854 	dispatch[55].controller = 55;
2855 	dispatch[55].operator = 2;
2856 	dispatch[55].routine = (synthRoutine) jupiterArpegRange;
2857 	dispatch[56].controller = 56;
2858 	dispatch[56].operator = 3;
2859 	dispatch[56].routine = (synthRoutine) jupiterArpegRange;
2860 
2861 	dispatch[57].controller = 57;
2862 	dispatch[57].operator = 2; // 0 is down will be
2863 	dispatch[57].routine = (synthRoutine) jupiterArpegMode;
2864 	dispatch[58].controller = 58;
2865 	dispatch[58].operator = 0; // 1 is up/down
2866 	dispatch[58].routine = (synthRoutine) jupiterArpegMode;
2867 	dispatch[59].controller = 59;
2868 	dispatch[59].operator = 1; // 2 is up
2869 	dispatch[59].routine = (synthRoutine) jupiterArpegMode;
2870 	dispatch[60].controller = 60;
2871 	dispatch[60].operator = 3;
2872 	dispatch[60].routine = (synthRoutine) jupiterArpegMode;
2873 
2874 	/* Uni, Solo, Poly 1&2 */
2875 	dispatch[61].controller = 61;
2876 	dispatch[61].operator = 0;
2877 	dispatch[61].routine = (synthRoutine) jupiterUniPoly;
2878 	dispatch[62].controller = 62;
2879 	dispatch[62].operator = 1;
2880 	dispatch[62].routine = (synthRoutine) jupiterUniPoly;
2881 	dispatch[63].controller = 63;
2882 	dispatch[63].operator = 2;
2883 	dispatch[63].routine = (synthRoutine) jupiterUniPoly;
2884 	dispatch[64].controller = 64;
2885 	dispatch[64].operator = 3;
2886 	dispatch[64].routine = (synthRoutine) jupiterUniPoly;
2887 
2888 	/* Layer Devs were 65 - start with Bend to VCO */
2889 	dispatch[LAYER_DEVS + 0].controller = 0;
2890 	dispatch[LAYER_DEVS + 0].operator = 0;
2891 	dispatch[LAYER_DEVS + 0].routine = (synthRoutine) jupiterBendVCO;
2892 	dispatch[LAYER_DEVS + 4].controller = 0;
2893 	dispatch[LAYER_DEVS + 4].operator = 1;
2894 	dispatch[LAYER_DEVS + 4].routine = (synthRoutine) jupiterBendVCO;
2895 	dispatch[LAYER_DEVS + 5].controller = 0;
2896 	dispatch[LAYER_DEVS + 5].operator = 2;
2897 	dispatch[LAYER_DEVS + 5].routine = (synthRoutine) jupiterBendVCO;
2898 
2899 	/* Bend to VCF */
2900 	dispatch[LAYER_DEVS + 1].controller = 0;
2901 	dispatch[LAYER_DEVS + 1].operator = 0;
2902 	dispatch[LAYER_DEVS + 1].routine = (synthRoutine) jupiterBendVCF;
2903 	dispatch[LAYER_DEVS + 6].controller = 0;
2904 	dispatch[LAYER_DEVS + 6].operator = 0;
2905 	dispatch[LAYER_DEVS + 6].routine = (synthRoutine) jupiterBendVCF;
2906 
2907 	/* LFO to VC) */
2908 	dispatch[LAYER_DEVS + 2].controller = 0;
2909 	dispatch[LAYER_DEVS + 2].operator = 0;
2910 	dispatch[LAYER_DEVS + 2].routine = (synthRoutine) jupiterLFOVCO;
2911 	dispatch[LAYER_DEVS + 7].controller = 0;
2912 	dispatch[LAYER_DEVS + 7].operator = 0;
2913 	dispatch[LAYER_DEVS + 7].routine = (synthRoutine) jupiterLFOVCO;
2914 
2915 	/* LFO to VCF */
2916 	dispatch[LAYER_DEVS + 3].controller = 0;
2917 	dispatch[LAYER_DEVS + 3].operator = 0;
2918 	dispatch[LAYER_DEVS + 3].routine = (synthRoutine) jupiterLFOVCF;
2919 	dispatch[LAYER_DEVS + 8].controller = 0;
2920 	dispatch[LAYER_DEVS + 8].operator = 0;
2921 	dispatch[LAYER_DEVS + 8].routine = (synthRoutine) jupiterLFOVCF;
2922 
2923 	dispatch[LAYER_DEVS + 9].routine = (synthRoutine) jupiterLFODelay;
2924 	dispatch[LAYER_DEVS + 10].routine = (synthRoutine) jupiterGlide;
2925 	dispatch[LAYER_DEVS + 11].routine = (synthRoutine) jupiterGlide;
2926 
2927 	dispatch[LAYER_DEVS + 12].controller = 0;
2928 	dispatch[LAYER_DEVS + 12].routine = (synthRoutine) jupiterTranspose;
2929 	dispatch[LAYER_DEVS + 13].controller = 1;
2930 	dispatch[LAYER_DEVS + 13].routine = (synthRoutine) jupiterTranspose;
2931 
2932 	dispatch[LAYER_DEVS + 14].controller = 0;
2933 	dispatch[LAYER_DEVS + 14].operator = 2;
2934 	dispatch[LAYER_DEVS + 14].routine = (synthRoutine) jupiterBend;
2935 
2936 	/* Hold/Chord */
2937 	dispatch[92].controller = BRISTOL_ARPEGGIATOR;
2938 	dispatch[92].operator = BRISTOL_CHORD_ENABLE;
2939 	dispatch[92].routine = (synthRoutine) jupiterChord;
2940 	dispatch[93].controller = BRISTOL_ARPEGGIATOR;
2941 	dispatch[93].operator = BRISTOL_CHORD_ENABLE;
2942 	dispatch[93].routine = (synthRoutine) jupiterChord;
2943 
2944 	dispatch[MOD_ENABLE].controller = 126;
2945 	dispatch[MOD_ENABLE].operator = 40;
2946 	dispatch[MOD_ENABLE].routine = (synthRoutine) jupiterUME;
2947 	dispatch[MOD_ENABLE + 1].controller = 126;
2948 	dispatch[MOD_ENABLE + 1].operator = 41;
2949 	dispatch[MOD_ENABLE + 1].routine = (synthRoutine) jupiterUME;
2950 
2951 	/* Dual, split, layer */
2952 	dispatch[96].controller = 96;
2953 	dispatch[96].operator = 0;
2954 	dispatch[96].routine = (synthRoutine) jupiterKeyMode;
2955 	dispatch[97].controller = 97;
2956 	dispatch[97].operator = 1;
2957 	dispatch[97].routine = (synthRoutine) jupiterKeyMode;
2958 	dispatch[98].controller = 98;
2959 	dispatch[98].operator = 2;
2960 	dispatch[98].routine = (synthRoutine) jupiterKeyMode;
2961 
2962 	/* Volume/Balance */
2963 	dispatch[101].controller = 126;
2964 	dispatch[101].operator = 3;
2965 	dispatch[101].routine = (synthRoutine) jupiterVolume;
2966 	dispatch[102].controller = 126; /* This is not pan rather layer balance */
2967 	dispatch[102].operator = 4;
2968 	dispatch[102].routine = (synthRoutine) jupiterVolume;
2969 
2970 	/* Arpeggio rate and clock source (latter not supported) */
2971 	dispatch[99].controller = BRISTOL_ARPEGGIATOR;
2972 	dispatch[99].operator = BRISTOL_ARPEG_RATE;
2973 	dispatch[99].routine = (synthRoutine) jupiterArpegRate;
2974 
2975 	/* Tuning and Tune */
2976 	dispatch[103].controller = 126;
2977 	dispatch[103].operator = 1;
2978 	dispatch[103].routine = (synthRoutine) jupiterGlobalTune;
2979 	dispatch[104].routine = (synthRoutine) jupiterTune;
2980 
2981 	dispatch[SEQ_MODE].routine = (synthRoutine) jupiterSeqMode;
2982 
2983 	/* 105 */
2984 	dispatch[PANEL_SELECT].routine = (synthRoutine) jupiterPanelSwitch;
2985 
2986 	/*
2987 	 * Memory management
2988 	 *
2989 	 * Two sets of locations - 8 bank and 8 memory, then a load and a save
2990 	 * button. Save will be doubleclick requirement. the selectors will be
2991 	 * radio buttons.
2992 	 * There are also issues with the dual layering that needs to be included.
2993 	 * This file was copied from the Juno, but the interface is more like the
2994 	 * prophet10 implementation so will have to borrow code from there.
2995 	 */
2996 	dispatch[MEM_MGT + 0].operator = 0;
2997 	dispatch[MEM_MGT + 1].operator = 1;
2998 	dispatch[MEM_MGT + 2].operator = 2;
2999 	dispatch[MEM_MGT + 3].operator = 3;
3000 	dispatch[MEM_MGT + 4].operator = 4;
3001 	dispatch[MEM_MGT + 5].operator = 5;
3002 	dispatch[MEM_MGT + 6].operator = 6;
3003 	dispatch[MEM_MGT + 7].operator = 7;
3004 	dispatch[MEM_MGT + 0].controller =
3005 		dispatch[MEM_MGT + 1].controller =
3006 		dispatch[MEM_MGT + 2].controller =
3007 		dispatch[MEM_MGT + 3].controller =
3008 		dispatch[MEM_MGT + 4].controller =
3009 		dispatch[MEM_MGT + 5].controller =
3010 		dispatch[MEM_MGT + 6].controller =
3011 		dispatch[MEM_MGT + 7].controller = 0;
3012 
3013 	/* Load button */
3014 	dispatch[MEM_MGT + 8].operator = 0;
3015 	dispatch[MEM_MGT + 8].controller = 2;
3016 	dispatch[MEM_MGT + 8].routine = (synthRoutine) jupiterMemory;
3017 
3018 	/* Bank selectors */
3019 	dispatch[MEM_MGT + 9].operator = 0;
3020 	dispatch[MEM_MGT + 10].operator = 1;
3021 	dispatch[MEM_MGT + 11].operator = 2;
3022 	dispatch[MEM_MGT + 12].operator = 3;
3023 	dispatch[MEM_MGT + 13].operator = 4;
3024 	dispatch[MEM_MGT + 14].operator = 5;
3025 	dispatch[MEM_MGT + 15].operator = 6;
3026 	dispatch[MEM_MGT + 16].operator = 7;
3027 	dispatch[MEM_MGT + 9].controller =
3028 		dispatch[MEM_MGT + 10].controller =
3029 		dispatch[MEM_MGT + 11].controller =
3030 		dispatch[MEM_MGT + 12].controller =
3031 		dispatch[MEM_MGT + 13].controller =
3032 		dispatch[MEM_MGT + 14].controller =
3033 		dispatch[MEM_MGT + 15].controller =
3034 		dispatch[MEM_MGT + 16].controller = 1;
3035 
3036 	/* Save button */
3037 	dispatch[MEM_MGT + 17].operator = 0;
3038 	dispatch[MEM_MGT + 17].controller = 3;
3039 	dispatch[MEM_MGT + 17].routine = (synthRoutine) jupiterMemory;
3040 
3041 	dispatch[MEM_MGT].routine = dispatch[MEM_MGT + 1].routine
3042 		= dispatch[MEM_MGT + 2].routine = dispatch[MEM_MGT + 3].routine
3043 		= dispatch[MEM_MGT + 4].routine = dispatch[MEM_MGT + 5].routine
3044 		= dispatch[MEM_MGT + 6].routine = dispatch[MEM_MGT + 7].routine
3045 		= dispatch[MEM_MGT + 9].routine = dispatch[MEM_MGT + 10].routine
3046 		= dispatch[MEM_MGT + 11].routine = dispatch[MEM_MGT + 12].routine
3047 		= dispatch[MEM_MGT + 13].routine = dispatch[MEM_MGT + 14].routine
3048 		= dispatch[MEM_MGT + 15].routine = dispatch[MEM_MGT + 16].routine
3049 			= (synthRoutine) jupiterButtonPanel;
3050 
3051 	/* Midi management */
3052 	dispatch[MIDI_MGT].controller = 1;
3053 	dispatch[MIDI_MGT + 1].controller = 2;
3054 	dispatch[MIDI_MGT].routine = dispatch[MIDI_MGT + 1].routine
3055 			= (synthRoutine) jupiterMidi;
3056 	dispatch[MIDI_MGT + 2].routine = (synthRoutine) midiRelease;
3057 
3058 	dispatch[MIDI_MGT + 3].controller = 2;
3059 	dispatch[MIDI_MGT + 3].routine = (synthRoutine) jupiterFunctionKey;
3060 
3061 	/* Noise gain */
3062 	jupiterDualSend(synth, synth->sid, 11, 0, 1024);
3063 	/* LFO-1 ADSR */
3064 	jupiterDualSend(synth, synth->sid, 2, 1, 12000);
3065 	jupiterDualSend(synth, synth->sid, 2, 2, 16000);
3066 	jupiterDualSend(synth, synth->sid, 2, 3, 1000);
3067 	jupiterDualSend(synth, synth->sid, 2, 4, 16000);
3068 	jupiterDualSend(synth, synth->sid, 2, 5, 0);
3069 	jupiterDualSend(synth, synth->sid, 2, 9, 0);
3070 	/* LFO-2 ADSR */
3071 	jupiterDualSend(synth, synth->sid, 3, 1, 12000);
3072 	jupiterDualSend(synth, synth->sid, 3, 2, 16000);
3073 	jupiterDualSend(synth, synth->sid, 3, 3, 1000);
3074 	jupiterDualSend(synth, synth->sid, 3, 4, 16000);
3075 	jupiterDualSend(synth, synth->sid, 3, 5, 0);
3076 	jupiterDualSend(synth, synth->sid, 3, 8, 0);
3077 	/* LFO PW */
3078 	jupiterDualSend(synth, synth->sid, 4, 7, 8192);
3079 	jupiterDualSend(synth, synth->sid, 5, 7, 8192);
3080 	/* ADSR gains */
3081 	jupiterDualSend(synth, synth->sid, 7, 4, 16383);
3082 	jupiterDualSend(synth, synth->sid, 9, 4, 16383);
3083 	/* Filter Mod */
3084 	jupiterDualSend(synth, synth->sid, 6, 2, 16383);
3085 	jupiterDualSend(synth, synth->sid, 6, 4, 4);
3086 
3087 	/* Fix some default pan and gain */
3088 	jupiterDualSend(synth, synth->sid, 126, 3, 16383);
3089 	jupiterDualSend(synth, synth->sid, 126, 4, 16383);
3090 	jupiterDualSend(synth, synth->sid, 126, 5, 16383);
3091 	jupiterDualSend(synth, synth->sid, 126, 6, 16383);
3092 	/* Configure pink noise filter level */
3093 	jupiterDualSend(synth, synth->sid, 10, 2, 4096);
3094 
3095 	/* Configure PWM for both DCO
3096 	jupiterDualSend(synth, synth->sid, 126, 33, 1);
3097 	jupiterDualSend(synth, synth->sid, 126, 34, 1);
3098 	*/
3099 
3100 	dispatch[ARPEG_RANGE].other1 = -1;
3101 	dispatch[POLY_MODE].other1 = -1;
3102 	dispatch[KEY_MODE].other1 = -1;
3103 
3104 	return(0);
3105 }
3106 
3107 /*
3108  * This will be called to make any routine specific parameters available.
3109  */
3110 static int
jupiterConfigure(brightonWindow * win)3111 jupiterConfigure(brightonWindow *win)
3112 {
3113 	guiSynth *synth = findSynth(global.synths, win);
3114 	brightonEvent event;
3115 	int offset;
3116 
3117 	if (synth == 0)
3118 	{
3119 		printf("problems going operational\n");
3120 		return(-1);
3121 	}
3122 
3123 	if (synth->flags & OPERATIONAL)
3124 		return(0);
3125 
3126 	printf("going operational\n");
3127 
3128 	if (synth->location == 0)
3129 	{
3130 		synth->bank = 10;
3131 		synth->location = 1;
3132 	} else {
3133 		if ((mw = synth->location / 10) == 0)
3134 			synth->bank = 10;
3135 		else {
3136 			synth->bank = mw % 10;
3137 			mw -= synth->bank;
3138 			mw *= 10;
3139 			synth->bank *= 10;
3140 		}
3141 		if ((synth->location = (synth->location % 10)) == 0)
3142 			synth->location = 1;
3143 	}
3144 
3145 	if (jupiterDebug(synth, 2))
3146 		printf("weight %i, bank %i, mem %i\n", mw, synth->bank,synth->location);
3147 
3148 	configureGlobals(synth);
3149 
3150 	synth->keypanel = KEY_PANEL;
3151 	synth->keypanel2 = -1;
3152 	synth->transpose = 12;
3153 
3154 	((guiSynth *) synth->second)->resources = synth->resources;
3155 	((guiSynth *) synth->second)->win = synth->win;
3156 	((guiSynth *) synth->second)->bank = 10;
3157 	((guiSynth *) synth->second)->location = 2;
3158 	((guiSynth *) synth->second)->panel = 0;
3159 	((guiSynth *) synth->second)->mem.active = ACTIVE_DEVS;
3160 	((guiSynth *) synth->second)->transpose = 12;
3161 
3162 	synth->flags |= OPERATIONAL;
3163 
3164 	event.type = BRIGHTON_FLOAT;
3165 	event.value = 1.0;
3166 
3167 	/* Push some radio buttons to set their starting point */
3168 	event.value = 1.0;
3169 	brightonParamChange(synth->win, 0, ARPEG_RANGE, &event);
3170 	brightonParamChange(synth->win, 0, ARPEG_MODE, &event);
3171 	brightonParamChange(synth->win, 0, POLY_MODE, &event);
3172 	brightonParamChange(synth->win, 0, KEY_MODE + 2, &event);
3173 
3174 	dc1 = brightonGetDCTimer(win->dcTimeout);
3175 
3176 	/* Set up the load buttons for an initial memory load */
3177 	if ((offset = synth->location - 1) > 7) offset = 0;
3178 	if (offset < 0) offset = 0;
3179 	brightonParamChange(synth->win, 0, PATCH_BUTTONS + offset, &event);
3180 	if ((offset = synth->bank - 1) > 7) offset = 0;
3181 	if (offset < 0) offset = 0;
3182 	brightonParamChange(synth->win, 0, BANK_BUTTONS + offset, &event);
3183 	/* And this will appear as a double click */
3184 	jupiterMemory(synth, global.controlfd, synth->sid, 2, 0, 1);
3185 	usleep(100000);
3186 	jupiterMemory(synth, global.controlfd, synth->sid, 2, 0, 1);
3187 
3188 	if (jupiterDebug(synth, 5)) {
3189 		int i;
3190 
3191 		for (i = 0; i < LAYER_DEVS; i+= 8)
3192 			printf("%f %f %f %f %f %f %f %f\n",
3193 				pcache[i], pcache[i + 1], pcache[i + 2], pcache[i + 3],
3194 				pcache[i + 4], pcache[i + 5], pcache[i + 6], pcache[i + 7]);
3195 		printf("\n");
3196 		for (i = 0; i < LAYER_DEVS; i+= 8)
3197 			printf("%f %f %f %f %f %f %f %f\n",
3198 				scache[i], scache[i + 1], scache[i + 2], scache[i + 3],
3199 				scache[i + 4], scache[i + 5], scache[i + 6], scache[i + 7]);
3200 	}
3201 
3202 	/*
3203 	 * Hm. This is a hack for a few bits of bad rendering of a keyboard. Only
3204 	 * occurs on first paint, so we suppress the first paint, and then request
3205 	 * an expose here.
3206 	 */
3207 	event.type = BRIGHTON_EXPOSE;
3208 	event.intvalue = 1;
3209 	brightonParamChange(synth->win, KEY_PANEL, -1, &event);
3210 
3211 	brightonPut(win,
3212 		"bitmaps/blueprints/jupitershade.xpm", 0, 0, win->width, win->height);
3213 	width = win->width;
3214 
3215 	/* Then set some defaults for volume, balance and tuning */
3216 	event.type = BRIGHTON_FLOAT;
3217 	event.value = 0.9;
3218 	brightonParamChange(synth->win, 0, 101, &event);
3219 	event.value = 0.5;
3220 	brightonParamChange(synth->win, 0, 102, &event);
3221 	brightonParamChange(synth->win, 0, 103, &event);
3222 
3223 	if (jupiterDebug(synth, 3))
3224 		printf("dct = %i\n", win->dcTimeout);
3225 
3226 	return(0);
3227 }
3228 
3229