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