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

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

Added missing includes and declarations.

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