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

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

Removed form-feed comments.

  • Property mode set to 100644
File size: 9.6 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 register int16_t i;
61
62 for (i = 0; i < 24; i++) /* turn off all LEDs */
63 io_leds = 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 = 6 - stepwgt;
80 io_leds = 7 + stepint;
81 return;
82
83 case PK_ASGN: /* assignment table */
84
85 if (curasg EQ 0)
86 return;
87
88 io_leds = (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 = 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 = 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 = 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(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 = 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 stmproc(0x8000 | trg); /* process as a patch stimulus */
223 }
224 }
225
226 return;
227
228
229 case PK_NOTE: /* note entry - interval and weight selection */
230
231 if (astat) { /* key down */
232
233 if (keystat[key] EQ 0) { /* closure */
234
235 keystat[key] = 1;
236
237 if (key EQ 0) { /* delete last entry */
238
239 disptag = FALSE;
240
241 while (lstendc-- > 0) { /* note ends */
242
243 ep = lstends[lstendc];
244 lstends[lstendc] = (struct n_entry *)NULL;
245
246 if ((struct n_entry *)NULL EQ ep)
247 continue;
248
249 if (ep EQ p_bak)
250 p_bak = p_bak->e_bak;
251
252 if (ep EQ p_ctr)
253 p_ctr = p_ctr->e_bak;
254
255 if (ep EQ p_cur)
256 p_cur = p_cur->e_bak;
257
258 if (ep EQ p_fwd)
259 p_fwd = p_fwd->e_bak;
260
261 e_del(e_rmv(ep));
262 disptag = TRUE;
263 }
264
265 lstendc = 0;
266
267 while (lstbgnc-- > 0) { /* note begins */
268
269 ep = lstbgns[lstbgnc];
270 lstbgns[lstbgnc] = (struct n_entry *)NULL;
271
272 if ((struct n_entry *)NULL EQ ep)
273 continue;
274
275 if (ep EQ p_bak)
276 p_bak = p_bak->e_bak;
277
278 if (ep EQ p_ctr)
279 p_ctr = p_ctr->e_bak;
280
281 if (ep EQ p_cur)
282 p_cur = p_cur->e_bak;
283
284 if (ep EQ p_fwd)
285 p_fwd = p_fwd->e_bak;
286
287 e_del(e_rmv(ep));
288 disptag = TRUE;
289 }
290
291 lstbgnc = 0;
292 lstflag = FALSE;
293
294 if (disptag) {
295
296 if ((fc_val - stepfrm[3][stepint]) GE 0L)
297 fc_val -= stepfrm[3][stepint];
298
299 sc_refr(fc_val);
300 }
301
302 } else if (key EQ 1) { /* enable step */
303
304 stepenb = NOT stepenb;
305 setleds();
306
307
308 } else if (key EQ 2) { /* insert bar */
309
310 if (recsw) {
311
312 if (E_NULL NE (ep = e_alc(E_SIZE1))) {
313
314 ep->e_type = EV_BAR;
315 ep->e_time = t_cur;
316 p_cur = e_ins(ep, ep_adj(p_cur, 1, t_cur)->e_bak)->e_fwd;
317 sc_refr(fc_val);
318 }
319 }
320
321 } else if (key EQ 3) { /* insert a rest */
322
323 if ((fc_val + stepfrm[3][stepint]) < 0x00FFFFFEL)
324 fc_val += stepfrm[3][stepint];
325
326 } else if ((key GE 4) AND (key LE 6)) {
327
328 stepwgt = 6 - key; /* select weight */
329 setleds();
330
331 } else if ((key GE 7) AND (key LE 23)) {
332
333 stepint = key - 7; /* select interval */
334 setleds();
335 }
336 }
337
338 } else { /* key up */
339
340 keystat[key] = 0;
341 }
342
343 return;
344
345 case PK_INST: /* instrument selection */
346
347 if (astat) {
348
349 if (keystat[key] EQ 0) {
350
351 keystat[key] = 1;
352
353 if (key GE 20)
354 return;
355
356 if (ismode EQ IS_LORC)
357 selins(key + 1);
358 else
359 selins(key + 21);
360 }
361
362 } else {
363
364 keystat[key] = 0;
365 }
366
367 return;
368
369 case PK_ASGN: /* assignment table selection */
370
371 if (astat) {
372
373 if (keystat[key] EQ 0) {
374
375 keystat[key] = 1;
376
377 if ((asmode EQ 5) AND (key GE 19))
378 return;
379 else if (key GE 20)
380 return;
381
382 selasg(key + 1 + ((asmode - 1) * 20));
383 }
384
385 } else {
386
387 keystat[key] = 0;
388 }
389
390 return;
391
392 case PK_GOTO: /* go to */
393
394 if (astat) {
395
396 if (keystat[key] EQ 0) {
397
398 keystat[key] = 1;
399
400 if (key GE 20) /* limit key range */
401 return;
402
403 if (gomode EQ GO_SECT) { /* section */
404
405 if (E_NULL NE (ep = seclist[curscor][key])) {
406
407 if (insmode) {
408
409 icancel();
410 dsimode();
411 }
412
413 sc_goto(fc_val = ep->e_time);
414 pkctrl = oldpk;
415 gomode = GO_NULL;
416 GLCcurs(G_ON);
417 GLCtext(0, 31, "Go To");
418 point = GLCplot;
419 lseg(GOTO_XL, GOTO_Y, GOTO_XR, GOTO_Y, 0);
420 GLCcurs(G_OFF);
421 setleds();
422 return;
423 }
424
425 } else { /* score */
426
427 if (E_NULL NE scores[key]) {
428
429 if (insmode) {
430
431 icancel();
432 dsimode();
433 }
434
435 selscor(key);
436 pkctrl = oldpk;
437 gomode = GO_NULL;
438 GLCcurs(G_ON);
439 GLCtext(0, 31, "Go To");
440 point = GLCplot;
441 lseg(GOTO_XL, GOTO_Y, GOTO_XR, GOTO_Y, 0);
442 GLCcurs(G_OFF);
443 setleds();
444 return;
445 }
446 }
447 }
448
449 } else {
450
451 keystat[key] = 0;
452 }
453
454 return;
455
456 case PK_LIBR:
457
458 if (astat) {
459
460 if (keystat[key] EQ 0) {
461
462 keystat[key] = 1;
463
464 if ((-1 NE lksel) AND (key < 20)) {
465
466 ldpass = 2;
467
468 for (i = 0; i < N_SCORES; i++)
469 if (ldmap[i] EQ key) {
470
471 ldmap[i] = -1;
472 dpy_scr(ldbox[1][4], i);
473 }
474
475 ldmap[lksel] = key;
476 dpy_scr(ldbox[1][4], lksel);
477 lksel = -1;
478 }
479 }
480
481 } else {
482
483 keystat[key] = 0;
484 }
485
486 return;
487
488 case PK_NGRP:
489
490 if (astat) {
491
492 if (keystat[key] EQ 0) {
493
494 keystat[key] = 1;
495
496 if ((-1 NE gtmsel) AND (key < 12)) {
497
498 for (i = 0; i < 12; i++)
499 if (grptmap[i] EQ key) {
500
501 grptmap[i] = -1;
502 dsgtme(i);
503 }
504
505 grptmap[gtmsel] = key;
506 dsgtmn(gtmsel, FALSE);
507 dsgtme(gtmsel);
508 gtmsel = -1;
509 }
510 }
511
512 } else {
513
514 keystat[key] = 0;
515 }
516
517 return;
518
519 case PK_LOAD:
520
521 if (astat)
522 keystat[key] = 1;
523 else
524 keystat[key] = 0;
525
526 return;
527 }
528}
529
Note: See TracBrowser for help on using the repository browser.