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

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

Prototypes for global function pointers. Consistent global types.

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