1
2 /*
3 * Diverse Bristol audio routines.
4 * Copyright (c) by Nick Copeland <nickycopeland@hotmail.com> 1996,2012
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22 /*
23 * Variables:
24 * Some LFO
25 * Some ADSR (7 stage?)
26 * Osc: F/V/S, G/V/S, D/V/S, Waveforms.
27 */
28
29
30 #include <fcntl.h>
31
32 #include "brighton.h"
33 #include "brightonMini.h"
34 #include "brightoninternals.h"
35
36 static int granularInit();
37 static int granularConfigure();
38 static int granularCallback(brightonWindow *, int, int, float);
39 static int midiCallback(brightonWindow *, int, int, float);
40
41 extern guimain global;
42 static int dc1, dc2;
43
44 #include "brightonKeys.h"
45
46 #define MOD_PANEL 0
47 #define KEY_PANEL 1
48 #define MEM_PANEL 2
49
50 #define MOD_COUNT 150
51 #define MEM_COUNT 21
52
53 #define MOD_START 0
54 #define MEM_START (MOD_COUNT - MEM_COUNT)
55
56 #define ACTIVE_DEVS (MOD_COUNT - MEM_COUNT)
57 #define DEVICE_COUNT MOD_COUNT
58
59 /*
60 * This structure is for device definition. The structure is defined in
61 * include/brighton.h, further definitions in brighton/brightonDevtable.h and
62 * include/brightoninternals.h
63 *
64 * typedef int (*brightonCallback)(int, float);
65 * typedef struct BrightonLocations {
66 * int device; 0=rotary, 1=scale, etc.
67 * float relx, rely; relative position with regards to 1000 by 1000 window
68 * float relw, relh; relative height.
69 * int from, to;
70 * brightonCallback callback; specific to this dev
71 * char *image; bitmap. If zero take a device default.
72 * int flags;
73 * } brightonLocations;
74 *
75 * This example is for a granularBristol type synth interface.
76 */
77
78 #define SBXS 15
79 #define SBYS 50
80 #define SBXD 15
81 #define SBYD 50
82
83 #define SELECTBUS(x, y) \
84 {"", 2, x + 0 * SBXD, y + 0 * SBYD, SBXS, SBYS, 0, 1.01, 0, \
85 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
86 {"", 2, x + 0 * SBXD, y + 1 * SBYD, SBXS, SBYS, 0, 4, 0, \
87 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
88 {"", 2, x + 0 * SBXD, y + 2 * SBYD, SBXS, SBYS, 0, 7, 0, \
89 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
90 {"", 2, x + 1 * SBXD, y + 0 * SBYD, SBXS, SBYS, 0, 2, 0, \
91 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
92 {"", 2, x + 1 * SBXD, y + 1 * SBYD, SBXS, SBYS, 0, 5, 0, \
93 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
94 {"", 2, x + 1 * SBXD, y + 2 * SBYD, SBXS, SBYS, 0, 8, 0, \
95 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
96 {"", 2, x + 2 * SBXD, y + 0 * SBYD, SBXS, SBYS, 0, 3, 0, \
97 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
98 {"", 2, x + 2 * SBXD, y + 1 * SBYD, SBXS, SBYS, 0, 6, 0, \
99 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
100 {"", 2, x + 2 * SBXD, y + 2 * SBYD, SBXS, SBYS, 0, 9, 0, \
101 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}
102
103 #define MRXS 15
104 #define MRYS 50
105 #define MRXD 15
106 #define MRYD 54
107
108 #define MODROUTING(x, y) \
109 {"", 2, x + 0 * MRXD, y + 0 * MRYD, MRXS, MRYS, 0, 1.01, 0, \
110 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
111 {"", 2, x + 0 * MRXD, y + 1 * MRYD, MRXS, MRYS, 0, 4, 0, \
112 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
113 {"", 2, x + 1 * MRXD, y + 0 * MRYD, MRXS, MRYS, 0, 7, 0, \
114 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
115 {"", 2, x + 1 * MRXD, y + 1 * MRYD, MRXS, MRYS, 0, 2, 0, \
116 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
117 {"", 2, x + 2 * MRXD, y + 0 * MRYD, MRXS, MRYS, 0, 5, 0, \
118 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
119 {"", 2, x + 2 * MRXD, y + 1 * MRYD, MRXS, MRYS, 0, 8, 0, \
120 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
121 {"", 2, x + 3 * MRXD, y + 0 * MRYD, MRXS, MRYS, 0, 3, 0, \
122 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
123 {"", 2, x + 3 * MRXD, y + 1 * MRYD, MRXS, MRYS, 0, 6, 0, \
124 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", 0}, \
125 {"", 2, 0 + 2 * MRXD, 0 + 2 * MRYD, MRXS, MRYS, 0, 9, 0, \
126 "bitmaps/buttons/pressoff.xpm", "bitmaps/buttons/presson.xpm", \
127 BRIGHTON_WITHDRAWN}
128
129 #define S1 200
130
131 #define D1 65
132
133 #define oW1 120
134 #define oL1 120
135
136 #define oC1 39
137
138 #define oC2 180
139 #define oC3 (oC2 + D1)
140 #define oC4 (oC3 + D1)
141 #define oC5 (oC4 + D1)
142 #define oC6 (oC5 + D1)
143 #define oC62 (oC6 + D1 - 5)
144
145 #define oC7 600
146 #define oC8 (oC7 + D1)
147 #define oC9 (oC8 + D1)
148 #define oC10 (oC9 + D1)
149
150 #define oC15 900
151 #define oC16 950
152
153 #define oR1 350
154 #define oR2 550
155 #define oR3 750
156
157 #define oR4 400
158 #define oR6 600
159
160 static brightonLocations options[MOD_COUNT] = {
161 /* Env ADSRG 0 */
162 {"", 0, oC2, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
163 {"", 0, oC3, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
164 {"", 0, oC4, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
165 {"", 0, oC5, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
166 {"", 0, oC6, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
167
168 /* Second env 5 */
169 {"", 0, oC2, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
170 {"", 0, oC3, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
171 {"", 0, oC4, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
172 {"", 0, oC5, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
173 {"", 0, oC6, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
174
175 /* Third Env 10 */
176 {"", 0, oC2, oR3, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
177 {"", 0, oC3, oR3, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
178 {"", 0, oC4, oR3, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
179 {"", 0, oC5, oR3, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
180 {"", 0, oC6, oR3, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
181
182 /* Osc Depth 15 */
183 {"", 0, oC7, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
184 {"", 0, oC8, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", BRIGHTON_NOTCH},
185 {"", 0, oC9, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
186 {"", 0, oC10, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
187 /* Osc Scatter */
188 {"", 0, oC7, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
189 {"", 0, oC8, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
190 {"", 0, oC9, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
191 {"", 0, oC10, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
192 /* Osc params, Fine tune, glide 23/24/25 */
193 {"", 0, oC7, oR3, oW1, oL1, 0, 9, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
194 {"", 0, oC8, oR3, oW1, oL1, 0, 8, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
195 {"", 0, oC9, oR3, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
196
197 MODROUTING(oC62, oR1 + 12), /* 26 - Env */
198 MODROUTING(oC62, oR2 + 12), /* 35 - Env */
199 MODROUTING(oC62, oR3 + 12), /* 44 - Env */
200 SELECTBUS(oC10 - 2, oR3), /* 53 */
201
202 /* LFO - 62 */
203 {"", 0, oC1, oR1, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
204 MODROUTING(85, oR1 + 12),
205 /* Noise 72 */
206 {"", 0, oC1, oR2, oW1, oL1, 0, 1, 0, "bitmaps/knobs/grotary.xpm", "bitmaps/knobs/alpharotary.xpm", 0},
207 MODROUTING(85, oR2 + 12),
208
209 /* Dummies for later implementation */
210 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
211 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
212 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
213 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
214 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
215 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
216 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
217 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
218 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
219 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
220 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
221 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
222 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
223 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
224 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
225 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
226 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
227 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
228 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
229 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
230 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
231 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
232 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
233 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
234 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
235 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
236 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
237 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
238 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
239 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
240 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
241 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
242 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
243 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
244 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
245 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
246 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
247 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
248 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
249 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
250 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
251 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
252 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
253 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
254 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
255 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
256 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
257 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
258 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
259 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
260 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
261 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
262 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
263 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
264 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
265 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
266 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
267 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
268 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
269 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
270 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
271 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
272 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
273 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
274 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
275 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
276 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
277 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
278 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
279 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
280 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
281 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
282 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
283 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
284 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
285 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
286 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
287 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
288 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
289 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
290 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
291 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
292 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
293 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
294 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
295 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
296 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
297 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
298 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
299 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
300 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
301 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
302 {"", 0, 0, 0, 25, 25, 0, 1, 0, "bitmaps/knobs/grotary.xpm",
303 "bitmaps/knobs/alpharotary.xpm", BRIGHTON_WITHDRAWN},
304
305 /* Memories */
306 SELECTBUS(900, oR1),
307 SELECTBUS(900, oR2),
308
309 /* Midi up/down, save */
310 {"", 2, 900, oR3, MRXS, MRYS, 0, 1, 0,
311 "bitmaps/buttons/pressoffg.xpm",
312 "bitmaps/buttons/pressong.xpm", BRIGHTON_CHECKBUTTON},
313 {"", 2, 900 + MRXD, oR3, MRXS, MRYS, 0, 1, 0,
314 "bitmaps/buttons/pressoffg.xpm",
315 "bitmaps/buttons/pressong.xpm", BRIGHTON_CHECKBUTTON},
316 {"", 2, 900 + 2 * MRXD, oR3, MRXS, MRYS, 0, 1, 0,
317 "bitmaps/buttons/pressoffo.xpm",
318 "bitmaps/buttons/pressono.xpm", BRIGHTON_CHECKBUTTON},
319 };
320
321 #define mR1 200
322 #define mR2 450
323 #define mR3 700
324
325 #define mC1 100
326 #define mC2 283
327 #define mC3 466
328 #define mC4 649
329 #define mC5 835
330
331 #define mC11 100
332 #define mC12 255
333 #define mC13 410
334 #define mC14 565
335 #define mC15 720
336 #define mC16 874
337
338 #define S3 100
339 #define S4 80
340 #define S5 120
341 #define S6 150
342
343 /*
344 * Should try and make this one as generic as possible, and try to use it as
345 * a general memory routine. has Midi u/d, mem u/d, load/save and a display.
346 */
347 static int
memCallback(brightonWindow * win,int panel,int index,float value)348 memCallback(brightonWindow* win, int panel, int index, float value)
349 {
350 guiSynth *synth = findSynth(global.synths, win);
351
352 if (synth->flags & SUPPRESS)
353 return(0);
354
355 /*
356 * The first ten buttons are exclusive highlighting, we use the first mem
357 * pointer to handle this.
358 */
359 if (synth->dispatch[MEM_START].other2)
360 {
361 synth->dispatch[MEM_START].other2 = 0;
362 return(0);
363 }
364 if (synth->dispatch[MEM_START + 1].other2)
365 {
366 synth->dispatch[MEM_START + 1].other2 = 0;
367 return(0);
368 }
369
370 printf("memCallback(%i, %i, %f) %i, %s\n", panel, index, value,
371 synth->mem.active, synth->resources->name);
372
373 if (index == (DEVICE_COUNT - 1))
374 {
375 if (brightonDoubleClick(dc1)) {
376 saveMemory(synth, "granular", 0, synth->bank * 10
377 + synth->location, 0);
378 }
379 return(0);
380 }
381
382 /* First bank selections */
383 if (index < (MEM_START + 9))
384 {
385 brightonEvent event;
386
387 event.command = BRIGHTON_PARAMCHANGE;
388 event.type = BRIGHTON_FLOAT;
389 event.value = 0;
390
391 /*
392 * This is a numeric. We need to force exclusion.
393 */
394 if (synth->dispatch[MEM_START].other1 != -1)
395 {
396 synth->dispatch[MEM_START].other2 = 1;
397
398 if (synth->dispatch[MEM_START].other1 != index)
399 event.value = 0;
400 else
401 event.value = 1;
402
403 brightonParamChange(synth->win, panel,
404 synth->dispatch[MEM_START].other1, &event);
405 }
406
407 synth->bank = index - MEM_START;
408
409 if (brightonDoubleClick(dc2)) {
410 printf("bank %i, mem %i\n", synth->bank, synth->location);
411 loadMemory(synth, "granular", 0, synth->bank * 10 + synth->location,
412 synth->mem.active, 0, BRISTOL_FORCE);
413 }
414
415 synth->dispatch[MEM_START].other1 = index;
416 } else if (index < (MEM_START + 18)) {
417 brightonEvent event;
418
419 event.command = BRIGHTON_PARAMCHANGE;
420 event.type = BRIGHTON_FLOAT;
421 event.value = 0;
422
423 /*
424 * This is a numeric. We need to force exclusion.
425 */
426 if (synth->dispatch[MEM_START + 1].other1 != -1)
427 {
428 synth->dispatch[MEM_START + 1].other2 = 1;
429
430 if (synth->dispatch[MEM_START + 1].other1 != index)
431 event.value = 0;
432 else
433 event.value = 1;
434
435 brightonParamChange(synth->win, panel,
436 synth->dispatch[MEM_START + 1].other1, &event);
437 }
438
439 synth->location = index - MEM_START - 9;
440
441 if (brightonDoubleClick(dc2)) {
442 printf("bank %i, mem %i\n", synth->bank, synth->location);
443 loadMemory(synth, "granular", 0, synth->bank * 10 + synth->location,
444 synth->mem.active, 0, BRISTOL_FORCE);
445 }
446
447 synth->dispatch[MEM_START + 1].other1 = index;
448 } else {
449 int newchan;
450
451 /*
452 * This is a control button.
453 */
454 switch(index) {
455 case MOD_COUNT - 3:
456 /*
457 * Midi Down
458 */
459 if ((newchan = synth->midichannel - 1) < 0)
460 {
461 synth->midichannel = 0;
462 return(0);
463 }
464
465 if (global.libtest)
466 {
467 printf("midi chan %i\n", newchan);
468 synth->midichannel = newchan;
469 return(0);
470 }
471
472 bristolMidiSendMsg(global.controlfd, synth->sid,
473 127, 0, BRISTOL_MIDICHANNEL|newchan);
474
475 synth->midichannel = newchan;
476 break;
477 case MOD_COUNT - 2:
478 /*
479 * Midi Up
480 */
481 if ((newchan = synth->midichannel + 1) > 15)
482 {
483 synth->midichannel = 15;
484 return(0);
485 }
486
487 if (global.libtest)
488 {
489 printf("midi chan %i\n", newchan);
490 synth->midichannel = newchan;
491 return(0);
492 }
493
494 bristolMidiSendMsg(global.controlfd, synth->sid,
495 127, 0, BRISTOL_MIDICHANNEL|newchan);
496
497 synth->midichannel = newchan;
498 break;
499 }
500 }
501
502 return(0);
503 }
504
505 /*
506 * This is a set of globals for the main window rendering. Again taken from
507 * include/brighton.h
508 */
509 brightonApp granularApp = {
510 "granular",
511 0, /* no blueprint on wood background. */
512 "bitmaps/textures/granular.xpm",
513 BRIGHTON_STRETCH,
514 granularInit,
515 granularConfigure, /* 3 callbacks */
516 midiCallback,
517 destroySynth,
518 {16, 0, 2, 2, 5, 520, 0, 0},
519 740, 400, 0, 0,
520 4, /* panel count */
521 {
522 {
523 "Mods",
524 0,
525 0, /* flags */
526 0,
527 0,
528 0,
529 granularCallback,
530 //30, 50, 940, 365,
531 5, 5, 990, 560,
532 MOD_COUNT,
533 options
534 },
535 {
536 "Keyboard",
537 0,
538 "bitmaps/newkeys/kbg.xpm", /* flags */
539 BRIGHTON_STRETCH,
540 0,
541 0,
542 keyCallback,
543 100, 710, 900, 250,
544 KEY_COUNT,
545 keysprofile
546 },
547 {
548 "Mods",
549 "bitmaps/blueprints/mods.xpm",
550 0, /* flags */
551 BRIGHTON_STRETCH,
552 0,
553 0,
554 modCallback,
555 0, 710, 100, 250,
556 2,
557 mods
558 },
559 }
560 };
561
562 static int
midiCallback(brightonWindow * win,int controller,int value,float n)563 midiCallback(brightonWindow *win, int controller, int value, float n)
564 {
565 guiSynth *synth = findSynth(global.synths, win);
566
567 printf("midi callback: %x, %i\n", controller, value);
568
569 switch(controller)
570 {
571 case MIDI_PROGRAM:
572 printf("midi program: %x, %i\n", controller, value);
573 synth->location = value;
574 loadMemory(synth, synth->resources->name, 0,
575 synth->bank + synth->location, synth->mem.active, 0, 0);
576 break;
577 case MIDI_BANK_SELECT:
578 printf("midi banksel: %x, %i\n", controller, value);
579 synth->bank = value;
580 break;
581 }
582 return(0);
583 }
584
585 static int
granularMods(guiSynth * synth,int fd,int chan,int c,int o,int v)586 granularMods(guiSynth *synth, int fd, int chan, int c, int o, int v)
587 {
588 unsigned int i, flags = 0;
589
590 for (i = 0; i < 9; i++)
591 {
592 if (synth->mem.param[o + i] != 0)
593 flags |= (0x01 << i);
594 }
595
596 if (c == 15)
597 bristolMidiSendMsg(fd, chan, 0, 10, flags);
598 else
599 bristolMidiSendMsg(fd, chan, 126, c, flags);
600
601 return(0);
602 }
603
604 /*
605 static int
606 granularOscWaveform(guiSynth *synth, int fd, int chan, int c, int o, int v)
607 {
608 brightonEvent event;
609
610 if (synth->dispatch[53].other2)
611 {
612 synth->dispatch[53].other2 = 0;
613 return(0);
614 }
615
616 if (synth->dispatch[53].other1 != -1)
617 {
618 event.command = BRIGHTON_PARAMCHANGE;
619 event.type = BRIGHTON_FLOAT;
620
621 synth->dispatch[53].other2 = o;
622
623 if (synth->dispatch[53].other1 != o)
624 event.value = 0;
625 else
626 event.value = 1;
627
628 brightonParamChange(synth->win, 0, synth->dispatch[53].other1, &event);
629 }
630
631 if (v != 0)
632 bristolMidiSendMsg(fd, chan, 0, 10, v - 1);
633
634 synth->dispatch[53].other1 = o;
635
636 return(0);
637 }
638 */
639
640 static int
granularMidiSendMsg(void * synth,int fd,int chan,int c,int o,int v)641 granularMidiSendMsg(void *synth, int fd, int chan, int c, int o, int v)
642 {
643 /* printf("%i, %i, %i\n", c, o, v); */
644 bristolMidiSendMsg(fd, chan, c, o, v);
645 return(0);
646 }
647
648 /*
649 * For the sake of ease of use, links have been placed here to be called
650 * by any of the devices created. They would be better in some other file,
651 * perhaps with this as a dispatch.
652 *
653 * Param refers to the device index in the locations table given below.
654 */
655 static int
granularCallback(brightonWindow * win,int panel,int index,float value)656 granularCallback(brightonWindow *win, int panel, int index, float value)
657 {
658 guiSynth *synth = findSynth(global.synths, win);
659 int sendvalue;
660
661 if (synth == 0)
662 return(0);
663
664 if ((index >= DEVICE_COUNT) || ((synth->flags & OPERATIONAL) == 0))
665 return(0);
666
667 if (granularApp.resources[panel].devlocn[index].to == 1)
668 sendvalue = value * C_RANGE_MIN_1;
669 else
670 sendvalue = value;
671
672 if (index >= MEM_START)
673 return(memCallback(win, panel, index, value));
674
675 synth->mem.param[index] = value;
676
677 if ((!global.libtest) || (index >= ACTIVE_DEVS))
678 synth->dispatch[index].routine(synth,
679 global.controlfd, synth->sid,
680 synth->dispatch[index].controller,
681 synth->dispatch[index].operator,
682 sendvalue);
683 #ifdef DEBUG
684 else
685 printf("dispatch[%p,%i](%i, %i, %i, %i, %i)\n", synth, index,
686 global.controlfd, synth->sid,
687 synth->dispatch[index].controller,
688 synth->dispatch[index].operator,
689 sendvalue);
690 #endif
691
692 return(0);
693 }
694
695 /*
696 * Any location initialisation required to run the callbacks. For bristol, this
697 * will connect to the engine, and give it some base parameters.
698 * May need to generate some application specific menus.
699 * Will also then make specific requests to some of the devices to alter their
700 * rendering.
701 */
702 static int
granularInit(brightonWindow * win)703 granularInit(brightonWindow* win)
704 {
705 guiSynth *synth = findSynth(global.synths, win);
706 dispatcher *dispatch;
707 int i;
708
709 if (synth == 0)
710 {
711 synth = findSynth(global.synths, 0);
712 if (synth == 0)
713 {
714 printf("cannot init\n");
715 return(0);
716 }
717 }
718
719 synth->win = win;
720
721 printf("Initialise the granular link to bristol: %p\n", synth->win);
722
723 synth->mem.param = (float *) brightonmalloc(DEVICE_COUNT * sizeof(float));
724 synth->mem.count = DEVICE_COUNT;
725 synth->mem.active = ACTIVE_DEVS;
726 synth->dispatch = (dispatcher *)
727 brightonmalloc(DEVICE_COUNT * sizeof(dispatcher));
728 dispatch = synth->dispatch;
729
730 /*
731 * We really want to have three connection mechanisms. These should be
732 * 1. Unix named sockets.
733 * 2. UDP sockets.
734 * 3. MIDI pipe.
735 */
736 if (!global.libtest)
737 if ((synth->sid = initConnection(&global, synth)) < 0)
738 return(-1);
739
740 for (i = 0; i < DEVICE_COUNT; i++)
741 {
742 synth->dispatch[i].controller = 88;
743 synth->dispatch[i].routine = granularMidiSendMsg;
744 }
745
746 synth->dispatch[MOD_START + 0].controller = 1; /* Env */
747 synth->dispatch[MOD_START + 0].operator = 0;
748 synth->dispatch[MOD_START + 1].controller = 1; /* Env */
749 synth->dispatch[MOD_START + 1].operator = 1;
750 synth->dispatch[MOD_START + 2].controller = 1; /* Env */
751 synth->dispatch[MOD_START + 2].operator = 2;
752 synth->dispatch[MOD_START + 3].controller = 1; /* Env */
753 synth->dispatch[MOD_START + 3].operator = 3;
754 synth->dispatch[MOD_START + 4].controller = 1; /* Env */
755 synth->dispatch[MOD_START + 4].operator = 4;
756
757 synth->dispatch[MOD_START + 5].controller = 2; /* Env2 */
758 synth->dispatch[MOD_START + 5].operator = 0;
759 synth->dispatch[MOD_START + 6].controller = 2; /* Env2 */
760 synth->dispatch[MOD_START + 6].operator = 1;
761 synth->dispatch[MOD_START + 7].controller = 2; /* Env2 */
762 synth->dispatch[MOD_START + 7].operator = 2;
763 synth->dispatch[MOD_START + 8].controller = 2; /* Env2 */
764 synth->dispatch[MOD_START + 8].operator = 3;
765 synth->dispatch[MOD_START + 9].controller = 2; /* Env2 */
766 synth->dispatch[MOD_START + 9].operator = 4;
767
768 synth->dispatch[MOD_START + 10].controller = 3; /* Env3 */
769 synth->dispatch[MOD_START + 10].operator = 0;
770 synth->dispatch[MOD_START + 11].controller = 3; /* Env3 */
771 synth->dispatch[MOD_START + 11].operator = 1;
772 synth->dispatch[MOD_START + 12].controller = 3; /* Env3 */
773 synth->dispatch[MOD_START + 12].operator = 2;
774 synth->dispatch[MOD_START + 13].controller = 3; /* Env3 */
775 synth->dispatch[MOD_START + 13].operator = 3;
776 synth->dispatch[MOD_START + 14].controller = 3; /* Env3 */
777 synth->dispatch[MOD_START + 14].operator = 4;
778
779 synth->dispatch[MOD_START + 15].controller = 0; /* Gain */
780 synth->dispatch[MOD_START + 15].operator = 0;
781 synth->dispatch[MOD_START + 16].controller = 0; /* Frequency */
782 synth->dispatch[MOD_START + 16].operator = 2;
783 synth->dispatch[MOD_START + 17].controller = 0; /* Delay */
784 synth->dispatch[MOD_START + 17].operator = 4;
785 synth->dispatch[MOD_START + 18].controller = 0; /* Duration */
786 synth->dispatch[MOD_START + 18].operator = 6;
787 synth->dispatch[MOD_START + 19].controller = 0; /* Gain Scatter */
788 synth->dispatch[MOD_START + 19].operator = 1;
789 synth->dispatch[MOD_START + 20].controller = 0; /* Frequency scatter */
790 synth->dispatch[MOD_START + 20].operator = 3;
791 synth->dispatch[MOD_START + 21].controller = 0; /* Delay scatter */
792 synth->dispatch[MOD_START + 21].operator = 5;
793 synth->dispatch[MOD_START + 22].controller = 0; /* Duration scatter */
794 synth->dispatch[MOD_START + 22].operator = 7;
795 /* Transpose and graincount */
796 synth->dispatch[MOD_START + 23].controller = 0; /* Osc */
797 synth->dispatch[MOD_START + 23].operator = 8;
798 synth->dispatch[MOD_START + 24].controller = 0; /* Osc */
799 synth->dispatch[MOD_START + 24].operator = 9;
800 /* Glide */
801 synth->dispatch[MOD_START + 25].controller = 126; /* Osc */
802 synth->dispatch[MOD_START + 25].operator = 0;
803
804 /* Env routing */
805 for (i = 0; i < 9; i++)
806 {
807 synth->dispatch[MOD_START + 26 + i].controller = 10; /* Mod */
808 synth->dispatch[MOD_START + 26 + i].operator = 26;
809 synth->dispatch[MOD_START + 26 + i].routine =
810 (synthRoutine) granularMods;
811 }
812 for (i = 0; i < 9; i++)
813 {
814 synth->dispatch[MOD_START + 35 + i].controller = 11; /* Mod */
815 synth->dispatch[MOD_START + 35 + i].operator = 35;
816 synth->dispatch[MOD_START + 35 + i].routine =
817 (synthRoutine) granularMods;
818 }
819 for (i = 0; i < 9; i++)
820 {
821 synth->dispatch[MOD_START + 44 + i].controller = 12; /* Mod */
822 synth->dispatch[MOD_START + 44 + i].operator = 44;
823 synth->dispatch[MOD_START + 44 + i].routine =
824 (synthRoutine) granularMods;
825 }
826
827 /* Waveform
828 synth->dispatch[MOD_START + 53].controller =
829 synth->dispatch[MOD_START + 54].controller =
830 synth->dispatch[MOD_START + 55].controller =
831 synth->dispatch[MOD_START + 56].controller =
832 synth->dispatch[MOD_START + 57].controller =
833 synth->dispatch[MOD_START + 58].controller =
834 synth->dispatch[MOD_START + 59].controller =
835 synth->dispatch[MOD_START + 60].controller =
836 synth->dispatch[MOD_START + 61].controller = 0;
837 synth->dispatch[MOD_START + 53].operator = 53;
838 synth->dispatch[MOD_START + 54].operator = 54;
839 synth->dispatch[MOD_START + 55].operator = 55;
840 synth->dispatch[MOD_START + 56].operator = 56;
841 synth->dispatch[MOD_START + 57].operator = 57;
842 synth->dispatch[MOD_START + 58].operator = 58;
843 synth->dispatch[MOD_START + 59].operator = 59;
844 synth->dispatch[MOD_START + 60].operator = 60;
845 synth->dispatch[MOD_START + 61].operator = 61;
846 synth->dispatch[MOD_START + 53].routine =
847 synth->dispatch[MOD_START + 54].routine =
848 synth->dispatch[MOD_START + 55].routine =
849 synth->dispatch[MOD_START + 56].routine =
850 synth->dispatch[MOD_START + 57].routine =
851 synth->dispatch[MOD_START + 58].routine =
852 synth->dispatch[MOD_START + 59].routine =
853 synth->dispatch[MOD_START + 60].routine =
854 synth->dispatch[MOD_START + 61].routine =
855 (synthRoutine) granularOscWaveform;
856 */
857 for (i = 0; i < 9; i++)
858 {
859 synth->dispatch[MOD_START + 53 + i].controller = 15; /* Mod */
860 synth->dispatch[MOD_START + 53 + i].operator = 53;
861 synth->dispatch[MOD_START + 53 + i].routine =
862 (synthRoutine) granularMods;
863 }
864
865
866 synth->dispatch[MOD_START + 62].controller = 4; /* LFO */
867 synth->dispatch[MOD_START + 62].operator = 0;
868 for (i = 0; i < 9; i++)
869 {
870 synth->dispatch[MOD_START + 63 + i].controller = 13; /* LFO */
871 synth->dispatch[MOD_START + 63 + i].operator = 63;
872 synth->dispatch[MOD_START + 63 + i].routine =
873 (synthRoutine) granularMods;
874 }
875
876 synth->dispatch[MOD_START + 72].controller = 5; /* Noise */
877 synth->dispatch[MOD_START + 72].operator = 0;
878 for (i = 0; i < 9; i++)
879 {
880 synth->dispatch[MOD_START + 73 + i].controller = 14; /* NOISE */
881 synth->dispatch[MOD_START + 73 + i].operator = 73;
882 synth->dispatch[MOD_START + 73 + i].routine =
883 (synthRoutine) granularMods;
884 }
885
886 /*
887 * These will be replaced by some opts controllers. We need to tie the
888 * envelope parameters for decay, sustain. We need to fix a few parameters
889 * of the oscillators too - transpose, tune and gain.
890 bristolMidiSendMsg(global.controlfd, synth->sid, 3, 1, 10);
891 bristolMidiSendMsg(global.controlfd, synth->sid, 3, 2, 16382);
892 */
893
894 /* Velocity tracking to zero on second envelope */
895 bristolMidiSendMsg(global.controlfd, synth->sid, 2, 5, 1);
896 /* Enable key tracking and multi LFO with sync to keyOn */
897 bristolMidiSendMsg(global.controlfd, synth->sid, 126, 3, 1);
898 bristolMidiSendMsg(global.controlfd, synth->sid, 126, 4, 1);
899 bristolMidiSendMsg(global.controlfd, synth->sid, 4, 1, 1);
900
901 return(0);
902 }
903
904 /*
905 * This will be called to make any routine specific parameters available.
906 */
907 static int
granularConfigure(brightonWindow * win)908 granularConfigure(brightonWindow *win)
909 {
910 guiSynth *synth = findSynth(global.synths, win);
911 brightonEvent event;
912
913 if (synth == 0)
914 {
915 printf("problems going operational\n");
916 return(-1);
917 }
918
919 if (synth->flags & OPERATIONAL)
920 return(0);
921
922 printf("going operational\n");
923
924 synth->flags |= OPERATIONAL;
925 synth->keypanel = KEY_PANEL;
926 synth->keypanel2 = -1;
927 synth->transpose = 36;
928 loadMemory(synth, "granular", 0, synth->location, synth->mem.active, 0, 0);
929
930 /*
931 * Hm. This is a hack for a few bits of bad rendering of a keyboard. Only
932 * occurs on first paint, so we suppress the first paint, and then request
933 * an expose here.
934 */
935 brightonPut(win,
936 "bitmaps/blueprints/granular.xpm", 0, 0, win->width, win->height);
937 event.type = BRIGHTON_EXPOSE;
938 event.intvalue = 1;
939 brightonParamChange(synth->win, KEY_PANEL, -1, &event);
940 configureGlobals(synth);
941
942 event.command = BRIGHTON_PARAMCHANGE;
943 event.type = BRIGHTON_FLOAT;
944 event.value = 1;
945 brightonParamChange(synth->win, 0, MEM_START, &event);
946 brightonParamChange(synth->win, 0, MEM_START + 9, &event);
947
948 dc1 = brightonGetDCTimer(win->dcTimeout);
949 dc2 = brightonGetDCTimer(win->dcTimeout);
950
951 return(0);
952 }
953
954