source: buchla-68k/ram/ptfield.c@ 3fcb810

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

Removed form-feed comments.

  • Property mode set to 100644
File size: 14.8 KB
Line 
1/*
2 =============================================================================
3 ptfield.c -- MIDAS-VII patch display field functions
4 Version 35 -- 1989-11-16 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGXP 0
9
10#define USEVECTR 0 /* to force vector cursor control */
11
12#include "ram.h"
13
14#if DEBUGXP
15short debugxp = 1;
16#endif
17
18#if USEVECTR
19short usevect = TRUE;
20#endif
21
22int8_t *trdata[] = { "Trans", "Stop ", "Start" };
23int8_t *ssdata[] = { "Stop ", "Start" };
24
25int8_t *stdata[] = { "Srce" , "Mult", "Time", "Valu", "Func" };
26
27int8_t *smdata[] = {
28
29 " ", /* SM_NONE 0 No source - always 0 */
30 "Randm", /* SM_RAND 1 Random source */
31 "GPC/V", /* SM_CTL1 2 Control Voltage 1 / MIDI GPC 1 */
32 "??3??", /* ------- 3 -unused- */
33 "??4??", /* ------- 4 -unused- */
34 "Pitch", /* SM_PTCH 5 Key Pitch */
35 "KeyPr", /* SM_KPRS 6 Key Pressure */
36 "KeyVL", /* SM_KVEL 7 Key Velocity */
37 "Pedal", /* SM_PED1 8 Pedal 1 */
38 "??9??", /* ------- 9 -unused- */
39 "Freq ", /* SM_FREQ 10 Key Frequency */
40 "PchWh", /* SM_HTPW 11 Tablet X / MIDI Pitch Wheel */
41 "ModWh", /* SM_VTMW 12 Tablet Y / MIDI Mod Wheel */
42 "Breth", /* SM_LPBR 13 LongPot / MIDI Breath Controller */
43};
44
45struct curpak pt_flds = {
46
47 stdctp5, /* curtype */
48 nokey, /* premove */
49 aftercm, /* pstmove */
50 cxkstd, /* cx_key */
51 cykstd, /* cy_key */
52 smxupd, /* cx_upd */
53 smyupd, /* cy_upd */
54 stopcm, /* xy_up */
55 nokey, /* xy_dn */
56 ptxkey, /* x_key */
57 ptekey, /* e_key */
58 ptmkey, /* m_key */
59 ptdkey, /* d_key */
60 nonf, /* not_fld */
61 (struct fet *)NULL, /* curfet */
62 ptboxes, /* csbp */
63 crate1, /* cratex */
64 crate1, /* cratey */
65 CT_SMTH, /* cmtype */
66 CTOX(2), /* cxval */
67 RTOY(DATAROW) /* cyval */
68};
69
70/*
71 =============================================================================
72 ptmkey() -- M key processing for the patch display
73 =============================================================================
74*/
75
76void ptmkey(void)
77{
78 register int16_t nc;
79
80 if (astat) {
81
82 if (stccol EQ 48) {
83
84 if (ss_sqsw EQ 0) {
85
86 (*xy_dn)(); /* handle KEY_DOWN functions */
87
88 (*premove)(); /* handle PRE-MOVE functions */
89
90 nc = (*curtype)(); /* get new CURSOR TYPE wanted */
91
92 cvtime = syrate;
93 ncvwait = curhold;
94
95 ss_ptsw = -1;
96 cmtype = nc;
97 cvwait = 1;
98 }
99
100 } else
101 stdmkey();
102
103 } else {
104
105 if (stccol EQ 48) {
106
107 ss_ptsw = 0;
108 cvwait = 1;
109 ncvwait = cvtime;
110 cmfirst = TRUE;
111
112 if (ss_sqsw EQ 0)
113 (*xy_up)();
114
115 (*pstmove)(); /* handle POST-MOVE functions */
116
117 } else
118 stdmkey();
119 }
120}
121
122/*
123 =============================================================================
124 ptekey() -- E key processing for the patch display
125 =============================================================================
126*/
127
128void ptekey(void)
129{
130 register int16_t nc;
131
132 if (astat) {
133
134 if (stccol EQ 48) {
135
136 if (ss_sqsw EQ 0) {
137
138 (*xy_dn)(); /* handle KEY_DOWN functions */
139
140 (*premove)(); /* handle PRE-MOVE functions */
141
142 nc = (*curtype)(); /* get new CURSOR TYPE wanted */
143
144 cvtime = syrate;
145 ncvwait = curhold;
146
147 ss_ptsw = 1;
148 cmtype = nc;
149 cvwait = 1;
150 }
151
152 } else
153 select();
154
155 } else {
156
157 if (stccol EQ 48) {
158
159 ss_ptsw = 0;
160 cvwait = 1;
161 ncvwait = cvtime;
162 cmfirst = TRUE;
163
164 if (ss_sqsw EQ 0)
165 (*xy_up)();
166
167 (*pstmove)(); /* handle POST-MOVE functions */
168
169 } else
170 select();
171 }
172}
173
174/*
175 =============================================================================
176 ptxkey() -- X key processing for the patch display
177 =============================================================================
178*/
179
180void ptxkey(void)
181{
182 register int16_t i, cp, pp, sp, stm;
183
184 if (NOT astat) /* only on key closures ... */
185 return;
186
187 if (inrange(stccol, 2, 13)) { /* definer -- clear definer */
188
189 if (ptecpos AND NOT ptbflag) { /* refresh data entry stuff */
190
191 memcpyw(&ptebuf.defnum, &patches[ptecpos].defnum, 6);
192 pteset = TRUE;
193 pte2buf();
194 }
195
196 ptedef = NULL_DEF;
197 ptedfok = TRUE;
198
199 memset(&ptdebuf[2], ' ', 12);
200
201 for (i = 0; i < 48; i++)
202 if (ptdebuf[i] EQ '\0')
203 ptdebuf[i] = ' ';
204
205 ptdebuf[0] = '\260';
206 ptdebuf[48] = '\0';
207
208 UpdVid(7, 0, ptdebuf, PTEATR);
209 movectc(stcrow, stccol);
210
211
212 } else if (inrange(stccol, 15, 26)) { /* stimulus -- clear stimulus */
213
214 if (ptecpos AND NOT ptbflag) { /* refresh data entry stuff */
215
216 memcpyw(&ptebuf.defnum, &patches[ptecpos].defnum, 6);
217 pteset = TRUE;
218 pte2buf();
219 }
220
221 ptestm = NULL_DEF;
222 ptestok = FALSE;
223
224 memset(&ptdebuf[15], ' ', 12);
225
226 for (i = 0; i < 48; i++)
227 if (ptdebuf[i] EQ '\0')
228 ptdebuf[i] = ' ';
229
230 ptdebuf[0] = '\260';
231 ptdebuf[48] = '\0';
232
233 UpdVid(7, 0, ptdebuf, PTEATR);
234 movectc(stcrow, stccol);
235
236 } else if (inrange(stccol, 28, 40)) { /* destination -- clear line */
237
238 voidpb(); /* void the patch buffer */
239
240 ptdebuf[0] = '\260';
241 ptdebuf[48] = '\0';
242
243 UpdVid(7, 0, ptdebuf, PTEATR);
244 movectc(stcrow, stccol);
245
246 } else if (inrange(stccol, 42, 46)) { /* datum -- delete the patch */
247
248 if (ptecpos) {
249
250 cp = ptecpos; /* setup indices */
251 pp = patches[cp].prevstm;
252 sp = patches[cp].nextstm;
253
254 stm = patches[cp].stmnum; /* get stimulus used */
255#if DEBUGXP
256 if (debugsw AND debugxp)
257 printf("ptxkey(): DELETING PATCH pp = %d cp = %d sp = %d\n",
258 pp, cp, sp);
259#endif
260
261 if (pp) /* adjust predecessor */
262 patches[pp].nextstm = sp;
263 else /* adjust stmptr */
264 stmptr[TRG_MASK & stm] = sp;
265
266 if (sp) /* adjust successor */
267 patches[sp].prevstm = pp;
268
269 if (sp = findnxt(cp)) /* adjust ptecpos */
270 ptecpos = sp;
271 else if (pp = findprv(cp))
272 ptecpos = pp;
273 else
274 ptecpos = 0;
275
276 pt_del(cp); /* delete the patch entry */
277
278 for (i = 0; i < NDEFSTMS; ++i) { /* adjust defptr list */
279
280 if (cp = defptr[i]) { /* in use ? */
281
282 pp = 0; /* initial predecessor */
283
284 while (cp) { /* check the chain */
285
286 sp = defents[cp].nextdef; /* successor */
287
288 if (defents[cp].stm EQ stm) {
289
290#if DEBUGXP
291 if (debugsw AND debugxp) {
292
293 printf("ptxkey(): DELETING DEF trg=$%04.4X stm=$%04.4X\n",
294 i, stm);
295
296 printf("ptxkey(): DELETING DEF pp=%d cp=%d sp=%d\n",
297 pp, cp, sp);
298 }
299#endif
300
301 if (pp) /* adjust predecessor */
302 defents[pp].nextdef = sp;
303 else /* adjust defptr */
304 defptr[i] = sp;
305
306 dt_del(cp); /* delete def entry */
307
308 } else {
309
310 pp = cp; /* update predecessor index */
311 }
312
313 cp = sp; /* next defent */
314 }
315 }
316 }
317
318 dptw(); /* update the display */
319 }
320 }
321}
322
323/*
324 =============================================================================
325 dspdfst() -- convert a patch DEF or STM value for display
326 =============================================================================
327*/
328
329void dspdfst(int8_t *buf, uint16_t val)
330{
331 register uint16_t chan, port, stim;
332
333 if (val EQ NULL_DEF) { /* handle possible blank definer */
334
335 strcpy(buf, " ");
336 return;
337 }
338
339 port = (val >> 11) & 0x0003;
340 chan = (val >> 7) & 0x000F;
341 stim = val & 0x007F;
342
343 switch (port) { /* use port to decode possible types */
344
345 case 0: /* MIDI-1 - Keys */
346 case 1: /* MIDI-2 - Keys */
347
348 sprintf(buf, "%s %03u %u %02u",
349 (val & 0x8000) ? "Rel" : "Key",
350 1 + stim, 1 + port, 1 + chan);
351
352 break;
353
354 case 2: /* Local Keys */
355
356 switch (chan) { /* use channel to further decode */
357
358 case 0: /* Keys - Local Keyboard */
359
360 sprintf(buf, "%s %03u L ",
361 (val & 0x8000) ? "Rel" : "Key",
362 1 + stim);
363
364 break;
365
366 case 2: /* Triggers */
367
368 sprintf(buf, "Trig %02u ", 1 + stim);
369 break;
370
371 case 3: /* Pulses */
372
373 sprintf(buf, "Pulse %u ", 1 + stim);
374 break;
375
376 default: /* spurious type -- shouldn't happen */
377
378 sprintf(buf, "%s?? %03u L %02u",
379 (val & 0x8000) ? "r" : "c",
380 1 + stim, 1 + chan);
381 break;
382
383 }
384
385 break;
386
387 default: /* spurious port -- should never happen */
388
389 sprintf(buf, "??? %03u %u %02u", 1 + stim, 1 + port, 1 + chan);
390 break;
391 }
392}
393
394/*
395 =============================================================================
396 dfpdat() -- convert FPU datum for display
397 =============================================================================
398*/
399
400int8_t *dfpdat(struct patch *pp)
401{
402 static int8_t buf[32];
403 uint16_t sgn, vp1, vp2;
404 int16_t val;
405
406 val = pp->padat2;
407
408 switch (pp->padat1) {
409
410 case PSA_SRC: /* source */
411
412 strcpy(buf, smdata[val]);
413 break;
414
415 case PSA_MLT: /* multiplier */
416
417 fr2dec(val, ebuf);
418
419 buf[0] = ebuf[3];
420 buf[1] = ebuf[0];
421 buf[2] = '.';
422 buf[3] = ebuf[1];
423 buf[4] = ebuf[2];
424 buf[5] = '\0';
425 break;
426
427 case PSA_VAL: /* value */
428
429 val >>= 5;
430
431 if (val < 0) {
432
433 val = -val;
434 sgn = '-';
435
436 } else {
437
438 sgn = '+';
439 }
440
441 vp1 = val / 100;
442 vp2 = val - (vp1 * 100);
443
444 if (vp1 > 9) {
445
446 vp1 = 0;
447
448 if (sgn EQ '+')
449 sgn = '\240';
450 else
451 sgn = '\241';
452 }
453
454 sprintf(buf, "%c%u.%02u", sgn, vp1, vp2);
455 break;
456
457 case PSA_TIM: /* time */
458
459 vp1 = fromfpu(val);
460
461 sprintf(buf, "%5u", vp1);
462 break;
463
464 case PSA_FNC: /* function / control */
465
466 if ((PE_SPEC & pp->paspec) EQ PA_AUX)
467 sprintf(buf, "%s", (val & 0x0001) ? "On " : "Off ");
468 else
469 sprintf(buf, "%s", (val & 0x0001) ? "Start" : "Stop ");
470
471 break;
472
473 default:
474
475 sprintf(buf, "$%04.4X", val);
476 break;
477 }
478
479 return(buf);
480}
481
482/*
483 =============================================================================
484 pafpu1() -- convert patch for display -- aaaaa ssss tn ddddd
485
486 Level, Filtr, Fil Q, Loctn, Dynmc
487 =============================================================================
488*/
489
490void pafpu1(int8_t *bf, int8_t *ad, uint16_t gt, uint16_t gn, struct patch *pp)
491{
492 sprintf(bf, "%s %s %c%c %s", ad, stdata[pp->padat1], gt, gn, dfpdat(pp));
493}
494
495/*
496 =============================================================================
497 pafpu2() -- convert patch for display -- aaa n ssss tn ddddd
498
499 Index, Freq
500 =============================================================================
501*/
502
503void pafpu2(int8_t *bf, int8_t *ad, uint16_t os, uint16_t gt, uint16_t gn, struct patch *pp)
504{
505 sprintf(bf, "%s %d %s %c%c %s", ad, os, stdata[pp->padat1], gt, gn, dfpdat(pp));
506}
507
508/*
509 =============================================================================
510 pafpu3() -- convert patch for display -- aaaaa ssss ddddd
511
512 Aux, Rate, Inten, Depth, Vlt
513 =============================================================================
514*/
515
516void pafpu3(int8_t *bf, int8_t *ad, struct patch *pp)
517{
518 sprintf(bf, "%s %s %s", ad, stdata[pp->padat1], dfpdat(pp));
519}
520
521/*
522 =============================================================================
523 dspdest() -- convert patch destination and datum for display
524 =============================================================================
525*/
526
527void dspdest(int8_t *buf, struct patch *pp)
528{
529 uint16_t chan, osc, port, stim, vg, vgt, vgn, vp1, vp2, sgn;
530 int16_t val;
531 int8_t buf2[16], *rtype;
532
533 port = (pp->pasuba >> 11) & 0x0003; /* for trg types */
534 chan = (pp->pasuba >> 7) & 0x000F;
535 stim = pp->pasuba & 0x007F;
536
537 vg = (pp->pasuba >> 8) & 0x00FF; /* for vg types */
538 osc = (pp->pasuba & 0x00FF) + 1;
539
540 if (vg > 11) {
541
542 vgt = 'G';
543 vgn = vg - 11;
544
545 } else {
546
547 vgt = 'V';
548 vgn = vg + 1;
549 }
550
551 vgn = vgn + ((vgn > 9) ? '\242' : '0');
552
553
554 switch (PE_SPEC & pp->paspec) {
555
556 case PA_KEY: /* key action */
557
558 sprintf(buf, "K %03u %u %02u %s",
559 1 + stim, 1 + port, 1 + chan,
560 trdata[pp->padat2 & 0x0003]);
561
562 break;
563
564 case PA_TRG:
565
566 sprintf(buf, "Trigger %02u %s",
567 1 + stim,
568 ssdata[pp->padat2 & 0x0001]);
569
570 break;
571
572 case PA_PLS:
573
574 sprintf(buf, "Pulse %u %s",
575 1 + stim,
576 trdata[pp->padat2 & 0x0003]);
577
578 break;
579
580 case PA_LED:
581
582 if (pp->pasuba & 0x0001) {
583
584 sprintf(buf, "LED %c %c%c%c%c",
585 'A' + pp->pasuba,
586 '0' + ((pp->padat1 >> 14) & 0x0003),
587 '0' + ((pp->padat1 >> 12) & 0x0003),
588 '0' + ((pp->padat1 >> 10) & 0x0003),
589 '0' + ((pp->padat1 >> 8) & 0x0003));
590
591 } else {
592
593 sprintf(buf, "LED %c %c%c%c",
594 'A' + pp->pasuba,
595 '0' + ((pp->padat1 >> 14) & 0x0003),
596 '0' + ((pp->padat1 >> 12) & 0x0003),
597 '0' + ((pp->padat1 >> 10) & 0x0003));
598 }
599
600 break;
601
602 case PA_SLIN:
603
604 sprintf(buf, "Seq %02u Lin %03u",
605 1 + pp->pasuba,
606 pp->padat1);
607
608 break;
609
610 case PA_SCTL:
611
612 sprintf(buf, "Seq %02u Ctl %s",
613 1 + pp->pasuba,
614 ssdata[pp->padat2 & 0x0001]);
615
616 break;
617
618 case PA_TUNE:
619
620 sprintf(buf, "Tune Table %u",
621 pp->padat1);
622
623 break;
624
625 case PA_RSET:
626
627 rtype = "Set";
628 goto doregs;
629
630 case PA_RADD:
631
632 rtype = "Add";
633
634doregs:
635
636 if (pp->padat1 & 0x0001) {
637
638 sprintf(buf, "Reg %02u %s R%02u",
639 1 + pp->pasuba, rtype,
640 1 + pp->padat2);
641
642 } else {
643
644 if ((val = pp->padat2) < 0) {
645
646 sgn = '-';
647 val = - val;
648
649 } else {
650
651 sgn = '+';
652 }
653
654 sprintf(buf, "Reg %02u %s %c%02u",
655 1 + pp->pasuba, rtype,
656 sgn, val);
657 }
658
659 break;
660
661 case PA_INST:
662
663 sprintf(buf, "Instrument %c%c %02u",
664 vgt, vgn, pp->padat1);
665
666 break;
667
668 case PA_OSC:
669
670 val = pp->padat2 >> 1;
671
672 switch (pp->padat1) {
673
674 case PSO_INT: /* interval */
675
676 if (val < 0) {
677
678 sgn = '-';
679 val = -val;
680
681 } else {
682
683 sgn = '+';
684 }
685
686 sprintf(buf, "Osc %u Int %c%c %c%04u",
687 osc, vgt, vgn, sgn, val);
688
689 break;
690
691 case PSO_RAT: /* ratio */
692
693 int2rat(val);
694
695 sprintf(buf, "Osc %u Rat %c%c %s",
696 osc, vgt, vgn, ebuf);
697
698 break;
699
700 case PSO_FRQ: /* frequency */
701
702 vp1 = val / 10;
703 vp2 = val - (vp1 * 10);
704
705 sprintf(buf, "Osc %u Frq %c%c %02u.%u",
706 osc, vgt, vgn, vp1, vp2);
707
708 break;
709
710 case PSO_PCH: /* pitch */
711
712 cnvc2p(ebuf, val);
713
714 sprintf(buf, "Osc %u Pch %c%c %s",
715 osc, vgt, vgn, ebuf);
716
717 break;
718
719 default:
720
721 break;
722 }
723
724 break;
725
726 case PA_WAVA:
727
728 sgn = 'A';
729 goto dowaves;
730
731 case PA_WAVB:
732
733 sgn = 'B';
734
735dowaves:
736
737 sprintf(buf, "Waveshape%c %c%c %02u",
738 sgn, vgt, vgn, pp->padat1);
739
740 break;
741
742 case PA_CNFG:
743
744 sprintf(buf, "Configure %c%c %02u",
745 vgt, vgn, pp->padat1);
746
747 break;
748
749 case PA_LEVL:
750
751 pafpu1(buf, "Level", vgt, vgn, pp);
752 break;
753
754 case PA_INDX:
755
756 pafpu2(buf, "Ind", osc, vgt, vgn, pp);
757 break;
758
759 case PA_FREQ:
760
761 pafpu2(buf, "Frq", osc, vgt, vgn, pp);
762 break;
763
764 case PA_FILT:
765
766 pafpu1(buf, "Filtr", vgt, vgn, pp);
767 break;
768
769 case PA_FILQ:
770
771 pafpu1(buf, "Fil Q", vgt, vgn, pp);
772 break;
773
774 case PA_LOCN:
775
776 pafpu1(buf, "Loctn", vgt, vgn, pp);
777 break;
778
779 case PA_DYNM:
780
781 pafpu1(buf, "Dynmc", vgt, vgn, pp);
782 break;
783
784 case PA_AUX:
785
786 pafpu3(buf, "Aux ", pp);
787 break;
788
789 case PA_RATE:
790
791 pafpu3(buf, "Rate ", pp);
792 break;
793
794 case PA_INTN:
795
796 pafpu3(buf, "Inten", pp);
797 break;
798
799 case PA_DPTH:
800
801 pafpu3(buf, "Depth", pp);
802 break;
803
804 case PA_VOUT:
805
806 sprintf(buf2, "Vlt %u", pp->pasuba);
807 pafpu3(buf, buf2, pp);
808 break;
809
810 default:
811
812 break;
813 }
814}
815
816/*
817 =============================================================================
818 ptfield() -- setup field routines for the patch editor
819 =============================================================================
820*/
821
822void ptfield(void)
823{
824 curset(&pt_flds);
825
826#if USEVECTR
827 if (usevect) {
828
829 cx_key = cxkstd;
830 cy_key = cykstd;
831 }
832#endif
833
834}
835
Note: See TracBrowser for help on using the repository browser.