source: buchla-68k/ram/localkb.c@ a4bd34f

Last change on this file since a4bd34f was a4bd34f, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Fixed localkb.c.

  • Property mode set to 100644
File size: 9.7 KB
Line 
1/*
2 =============================================================================
3 localkb.c -- local keyboard processing
4 Version 39 -- 1988-11-28 -- D.N. Lynx Crowe
5
6 List with the pr -e4 option to expand tabs to 4 spaces instead of 8.
7 =============================================================================
8*/
9
10#include "ram.h"
11
12#define LCL_PRT 3 /* 1-origin local keyboard port number */
13
14int16_t lclkmap[24] = { /* local key to MIDI key number map table */
15
16 0, 1, 2, 3, 4, 5, 6, /* 1..7 */
17 7, 8, 9, 10, 11, 12, 13, /* 8..14 */
18 114, 115, 116, 117, 118, 119, 120, /* 15..21 */
19 121, 122, 123 /* 22..24 */
20};
21
22int16_t panlkey[24] = { /* default tunings, in cents, for local keys */
23
24 560, 960, 1360, 1760, 2160, 2560, 2960, 3360,
25 3760, 4160, 4560, 4960, 5360, 5760, 6160, 6560, 6960,
26 7360, 7760, 8160, 8560, 8960, 9360, 9760
27};
28
29int16_t stepfrm[4][17] = { /* step mode frame counts */
30
31 /* 1 1 1 1 1 1 */
32 /* -- -- -- - - - */
33 /* 64 32 16 8 4 2 1 */
34
35 { 3, 4, 10, 22, 46, 94, 190, /* legato - normal */
36 7, 16, 34, 70, 142, 286, /* legato - dotted */
37 3, 6, 14, 30}, /* legato - triplets */
38
39 { 2, 4, 8, 16, 32, 64, 128, /* normal - normal */
40 6, 12, 24, 48, 96, 192, /* normal - dotted */
41 3, 5, 10, 20}, /* normal - triplets */
42
43 { 2, 3, 4, 6, 10, 16, 24, /* stacato - normal */
44 4, 5, 8, 12, 20, 30, /* stacato - dotted */
45 3, 4, 5, 8}, /* stacato - triplets */
46
47 { 3, 6, 12, 24, 48, 96, 192, /* interval - normal */
48 9, 18, 36, 72, 144, 288, /* interval - dotted */
49 4, 8, 16, 32} /* interval - triplets */
50};
51
52/*
53 =============================================================================
54 setleds() -- set LEDs according to pkctrl, etc.
55 =============================================================================
56*/
57
58void setleds(void)
59{
60 int16_t i;
61
62 for (i = 0; i < 24; i++) /* turn off all LEDs */
63 io_leds = (uint8_t)(0x0080 | i);
64
65 switch (pkctrl) {
66
67 default:
68 case PK_PFRM: /* performance */
69 case PK_INST: /* instrument */
70 case PK_LOAD: /* load */
71
72 return;
73
74 case PK_NOTE: /* note entry */
75
76 if (stepenb)
77 io_leds = 0x01;
78
79 io_leds = (uint8_t)(6 - stepwgt);
80 io_leds = (uint8_t)(7 + stepint);
81 return;
82
83 case PK_ASGN: /* assignment table */
84
85 if (curasg EQ 0)
86 return;
87
88 io_leds = (uint8_t)((curasg - 1) % 20); /* indicate current assignment */
89 return;
90
91 case PK_GOTO: /* go to */
92
93 if (gomode EQ GO_SECT) { /* indicate active sections */
94
95 for (i = 0; i < 20; i++)
96 if (E_NULL NE seclist[curscor][i])
97 io_leds = (uint8_t)i;
98
99 } else { /* indicate active scores */
100
101 for (i = 0; i < 20; i++)
102 if (E_NULL NE scores[i])
103 io_leds = (uint8_t)i;
104 }
105
106 return;
107
108 case PK_LIBR:
109
110 for (i = 0; i < 20; i++)
111 if (E_NULL NE scores[i])
112 io_leds = (uint8_t)i;
113
114 return;
115 }
116}
117
118/*
119 =============================================================================
120 localkb() -- local keyboard processing
121 =============================================================================
122*/
123
124void localkb(int16_t sig)
125{
126 register int16_t i, trg, lclkey, key, vel;
127 register struct s_entry *ep;
128 int16_t val, disptag;
129
130 key = sig - 1;
131
132 switch (pkctrl) {
133
134 case PK_PFRM: /* performance */
135
136 lclkey = lclkmap[key];
137 trg = ((LCL_PRT - 1) << 11) + lclkey;
138
139 if (astat) { /* key down */
140
141 prstab[trg] = SM_SCALE(aval);
142
143 if (keystat[key] EQ 0) { /* initial key closure */
144
145 trgtab[trg] |= M_KSTATE;
146 veltab[trg] = vel = SM_SCALE(64);
147 keystat[key] = 1;
148
149 stmproc((uint16_t)trg); /* process as a patch stimulus */
150
151 if (editsw) { /* edit mode */
152
153 execkey(trg, tuntab[lclkey], curvce, 0);
154
155 } else { /* normal mode */
156
157 for (i = 0; i < 12; i++)
158 if ((grp2prt[i][0] EQ LCL_PRT) AND
159 (grp2prt[i][1] EQ 1)) {
160
161 asgvce(i, LCL_PRT - 1, 0, lclkey, vel);
162 ne_bgn(i, lclkey, vel);
163 }
164 }
165
166 } else { /* pressure change */
167
168 val = SM_SCALE(aval);
169
170 for (i = 0; i < 12; i++) {
171
172 if ((grp2prt[i][0] EQ LCL_PRT) AND
173 (grp2prt[i][1] EQ 1)) {
174
175 if (newsv(i, SM_KPRS, val)) {
176
177 if (recsw AND grpstat[i] AND
178 (2 EQ (ancmsw ? varmode[5][i] : grpmode[i]))) {
179
180 if (E_NULL NE (ep = e_alc(E_SIZE2))) {
181
182 ep->e_time = t_cur;
183 ep->e_type = EV_ANVL;
184 ep->e_data1 = (int8_t)(0x0050 | i);
185 ep->e_dn = (struct s_entry *)((int32_t)val << 16);
186 p_cur = e_ins(ep, ep_adj(p_cur, 0, t_cur))->e_fwd;
187 ctrsw = TRUE;
188 se_disp(ep, D_FWD, gdstbc, 1);
189 ctrsw = FALSE;
190 }
191
192 } else if ((angroup - 1) EQ i) {
193
194 dsanval(5);
195 }
196 }
197 }
198 }
199 }
200
201 } else { /* key release */
202
203 keystat[key] = 0;
204 trgtab[trg] &= ~M_KSTATE;
205 prstab[trg] = 0;
206
207 if (NOT trgtab[trg]) {
208
209 for (i = 0; i < 12; i++) {
210
211 if (vce2trg[i] EQ trg) {
212
213 vce2trg[i] = -1;
214 procpfl(trg);
215 }
216
217 if ((grp2prt[i][0] EQ LCL_PRT) AND
218 (grp2prt[i][1] EQ 1))
219 ne_end(trg, i);
220 }
221
222 /* process as a patch stimulus */
223 stmproc(0x8000 | (uint16_t)trg);
224 }
225 }
226
227 return;
228
229
230 case PK_NOTE: /* note entry - interval and weight selection */
231
232 if (astat) { /* key down */
233
234 if (keystat[key] EQ 0) { /* closure */
235
236 keystat[key] = 1;
237
238 if (key EQ 0) { /* delete last entry */
239
240 disptag = FALSE;
241
242 while (lstendc-- > 0) { /* note ends */
243
244 ep = lstends[lstendc];
245 lstends[lstendc] = (struct n_entry *)NULL;
246
247 if ((struct n_entry *)NULL EQ ep)
248 continue;
249
250 if (ep EQ p_bak)
251 p_bak = p_bak->e_bak;
252
253 if (ep EQ p_ctr)
254 p_ctr = p_ctr->e_bak;
255
256 if (ep EQ p_cur)
257 p_cur = p_cur->e_bak;
258
259 if (ep EQ p_fwd)
260 p_fwd = p_fwd->e_bak;
261
262 e_del(e_rmv(ep));
263 disptag = TRUE;
264 }
265
266 lstendc = 0;
267
268 while (lstbgnc-- > 0) { /* note begins */
269
270 ep = lstbgns[lstbgnc];
271 lstbgns[lstbgnc] = (struct n_entry *)NULL;
272
273 if ((struct n_entry *)NULL EQ ep)
274 continue;
275
276 if (ep EQ p_bak)
277 p_bak = p_bak->e_bak;
278
279 if (ep EQ p_ctr)
280 p_ctr = p_ctr->e_bak;
281
282 if (ep EQ p_cur)
283 p_cur = p_cur->e_bak;
284
285 if (ep EQ p_fwd)
286 p_fwd = p_fwd->e_bak;
287
288 e_del(e_rmv(ep));
289 disptag = TRUE;
290 }
291
292 lstbgnc = 0;
293 lstflag = FALSE;
294
295 if (disptag) {
296
297 if ((fc_val - stepfrm[3][stepint]) GE 0L)
298 fc_val -= stepfrm[3][stepint];
299
300 sc_refr(fc_val);
301 }
302
303 } else if (key EQ 1) { /* enable step */
304
305 stepenb = NOT stepenb;
306 setleds();
307
308
309 } else if (key EQ 2) { /* insert bar */
310
311 if (recsw) {
312
313 if (E_NULL NE (ep = e_alc(E_SIZE1))) {
314
315 ep->e_type = EV_BAR;
316 ep->e_time = t_cur;
317 p_cur = e_ins(ep, ep_adj(p_cur, 1, t_cur)->e_bak)->e_fwd;
318 sc_refr(fc_val);
319 }
320 }
321
322 } else if (key EQ 3) { /* insert a rest */
323
324 if ((fc_val + stepfrm[3][stepint]) < 0x00FFFFFEL)
325 fc_val += stepfrm[3][stepint];
326
327 } else if ((key GE 4) AND (key LE 6)) {
328
329 stepwgt = 6 - key; /* select weight */
330 setleds();
331
332 } else if ((key GE 7) AND (key LE 23)) {
333
334 stepint = key - 7; /* select interval */
335 setleds();
336 }
337 }
338
339 } else { /* key up */
340
341 keystat[key] = 0;
342 }
343
344 return;
345
346 case PK_INST: /* instrument selection */
347
348 if (astat) {
349
350 if (keystat[key] EQ 0) {
351
352 keystat[key] = 1;
353
354 if (key GE 20)
355 return;
356
357 if (ismode EQ IS_LORC)
358 selins(key + 1);
359 else
360 selins(key + 21);
361 }
362
363 } else {
364
365 keystat[key] = 0;
366 }
367
368 return;
369
370 case PK_ASGN: /* assignment table selection */
371
372 if (astat) {
373
374 if (keystat[key] EQ 0) {
375
376 keystat[key] = 1;
377
378 if ((asmode EQ 5) AND (key GE 19))
379 return;
380 else if (key GE 20)
381 return;
382
383 selasg(key + 1 + ((asmode - 1) * 20));
384 }
385
386 } else {
387
388 keystat[key] = 0;
389 }
390
391 return;
392
393 case PK_GOTO: /* go to */
394
395 if (astat) {
396
397 if (keystat[key] EQ 0) {
398
399 keystat[key] = 1;
400
401 if (key GE 20) /* limit key range */
402 return;
403
404 if (gomode EQ GO_SECT) { /* section */
405
406 if (E_NULL NE (ep = seclist[curscor][key])) {
407
408 if (insmode) {
409
410 icancel();
411 dsimode();
412 }
413
414 sc_goto(fc_val = ep->e_time);
415 pkctrl = oldpk;
416 gomode = GO_NULL;
417 GLCcurs(G_ON);
418 GLCtext(0, 31, "Go To");
419 point = GLCplot;
420 lseg(GOTO_XL, GOTO_Y, GOTO_XR, GOTO_Y, 0);
421 GLCcurs(G_OFF);
422 setleds();
423 return;
424 }
425
426 } else { /* score */
427
428 if (E_NULL NE scores[key]) {
429
430 if (insmode) {
431
432 icancel();
433 dsimode();
434 }
435
436 selscor(key);
437 pkctrl = oldpk;
438 gomode = GO_NULL;
439 GLCcurs(G_ON);
440 GLCtext(0, 31, "Go To");
441 point = GLCplot;
442 lseg(GOTO_XL, GOTO_Y, GOTO_XR, GOTO_Y, 0);
443 GLCcurs(G_OFF);
444 setleds();
445 return;
446 }
447 }
448 }
449
450 } else {
451
452 keystat[key] = 0;
453 }
454
455 return;
456
457 case PK_LIBR:
458
459 if (astat) {
460
461 if (keystat[key] EQ 0) {
462
463 keystat[key] = 1;
464
465 if ((-1 NE lksel) AND (key < 20)) {
466
467 ldpass = 2;
468
469 for (i = 0; i < N_SCORES; i++)
470 if (ldmap[i] EQ key) {
471
472 ldmap[i] = -1;
473 dpy_scr(ldbox[1][4], i);
474 }
475
476 ldmap[lksel] = key;
477 dpy_scr(ldbox[1][4], lksel);
478 lksel = -1;
479 }
480 }
481
482 } else {
483
484 keystat[key] = 0;
485 }
486
487 return;
488
489 case PK_NGRP:
490
491 if (astat) {
492
493 if (keystat[key] EQ 0) {
494
495 keystat[key] = 1;
496
497 if ((-1 NE gtmsel) AND (key < 12)) {
498
499 for (i = 0; i < 12; i++)
500 if (grptmap[i] EQ key) {
501
502 grptmap[i] = -1;
503 dsgtme(i);
504 }
505
506 grptmap[gtmsel] = key;
507 dsgtmn(gtmsel, FALSE);
508 dsgtme(gtmsel);
509 gtmsel = -1;
510 }
511 }
512
513 } else {
514
515 keystat[key] = 0;
516 }
517
518 return;
519
520 case PK_LOAD:
521
522 if (astat)
523 keystat[key] = 1;
524 else
525 keystat[key] = 0;
526
527 return;
528 }
529}
530
Note: See TracBrowser for help on using the repository browser.