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

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

Added include files for global functions and variables.

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