source: buchla-68k/ram/ptfield.c@ 081eee0

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

Fixed ptfield.c.

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