source: buchla-68k/orig/RAM/ETIOSC.C@ 0acb7d0

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

Imported original source code.

  • Property mode set to 100755
File size: 14.5 KB
Line 
1/*
2 =============================================================================
3 etiosc.c -- MIDAS instrument editor -- oscillator field handlers
4 Version 31 -- 1988-10-27 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "stddefs.h"
9#include "fields.h"
10#include "hwdefs.h"
11#include "vsdd.h"
12#include "vsddsw.h"
13#include "graphdef.h"
14#include "charset.h"
15
16#include "midas.h"
17#include "instdsp.h"
18
19/* functions defined elsewhere */
20
21extern int advicur(), dosync();
22
23extern char *strcpy();
24
25/* variables defined elsewhere */
26
27extern short stcrow, stccol, curvce;
28
29extern short idbox[][8];
30
31extern unsigned *instob;
32
33extern char dspbuf[];
34
35extern struct instdef vbufs[];
36
37extern short cents, bform;
38
39/*
40
41*/
42
43/* initialized variables */
44
45/* C C# D D# E F F# G G# A A# B */
46short notes[] = {2, 2, 3, 3, 4, 5, 5, 6, 6, 0, 0, 1};
47
48/* A B C D E F G */
49short pitches[] = { 900, 1100, 0, 200, 400, 500, 700};
50
51#include "ratio.h" /* short ratio[]; */
52
53/* C C# D D# E F F# G G# A A# B */
54short sharps[] = {7, 9, 7, 9, 7, 7, 9, 7, 9, 7, 9, 7};
55
56short shrpflt[] = { 0, -100, 100};
57
58char sfdsp[] = {' ', D_FLAT, D_SHARP};
59
60static char intstr[] = "+0000";
61static char ratstr[] = "1/1";
62static char frqstr[] = "00.0";
63static char pchstr[] = "0C 00";
64
65short ndvals[10] = {0, 0, 1200, 1902, 2400, 2786, 3102, 3369, 3600, 3804};
66
67
68/*
69
70*/
71
72/*
73 =============================================================================
74 int2rat() -- convert interval to ratio
75 =============================================================================
76*/
77
78int2rat(rat)
79short rat;
80{
81 register short den, inum, num;
82
83 ebuf[0] = '1';
84 ebuf[1] = '/';
85 ebuf[2] = '1';
86 ebuf[3] = '\0';
87
88 for (num = 1; num < 10; num++) {
89
90 inum = 10 * num;
91
92 for (den = 1; den < 10; den++) {
93
94 if (rat EQ ratio[inum + den]) {
95
96 ebuf[0] = num + '0';
97 ebuf[2] = den + '0';
98 return;
99 }
100 }
101 }
102}
103
104/*
105
106*/
107
108/*
109 =============================================================================
110 cnvc2p() -- convert cents to pitch
111 =============================================================================
112*/
113
114cnvc2p(buf, cv)
115char *buf;
116short cv;
117{
118 short rem, tmp;
119
120 cv -= 160;
121 buf[0] = cv / 1200;
122 rem = cv - (buf[0] * 1200);
123 tmp = rem / 100;
124 rem -= (tmp * 100);
125 buf[1] = notes[tmp];
126 buf[2] = sharps[tmp];
127 buf[3] = rem / 10;
128 buf[4] = rem - (buf[3] * 10);
129}
130
131/*
132
133*/
134
135/*
136 =============================================================================
137 cnvp2c() -- convert pitch to cents
138
139 input in edit buffer:
140
141 ebuf[0] = octave 0..9
142 ebuf[1] = note A..G (0..6)
143 ebuf[2] = type natural, flat, sharp (7..9)
144 ebuf[3] = ms byte of offset 0..9
145 ebuf[4] = ls byte of offset 0..9
146
147 output in cents
148 =============================================================================
149*/
150
151short
152cnvp2c()
153{
154 if (ebuf[0] EQ 9) /* high limit is C9 00 */
155 if (ebuf[1] GT 2)
156 return(FAILURE);
157 else if (ebuf[1] EQ 2)
158 if (ebuf[2] NE 7)
159 return(FAILURE);
160 else if (ebuf[3] OR ebuf[4])
161 return(FAILURE);
162
163 cents = (ebuf[0] * 1200) + pitches[ebuf[1]] + shrpflt[ebuf[2] - 7]
164 + (ebuf[3] * 10) + ebuf[4] + 160;
165
166 return(SUCCESS);
167}
168
169/*
170
171*/
172
173/*
174 =============================================================================
175 et_iosc() -- load the edit buffer
176 =============================================================================
177*/
178
179short
180et_iosc(nn)
181short nn;
182{
183 register struct instdef *ip;
184 register short val, ctl, fh, fl, v;
185
186 v = (nn >> 8) & 0x03;
187 ip = &vbufs[curvce];
188
189 switch (v) {
190
191 case 0:
192
193 val = ip->idhos1v;
194 ctl = ip->idhos1c;
195 break;
196
197 case 1:
198
199 val = ip->idhos2v;
200 ctl = ip->idhos2c;
201 break;
202
203 case 2:
204
205 val = ip->idhos3v;
206 ctl = ip->idhos3c;
207 break;
208
209 case 3:
210
211 val = ip->idhos4v;
212 ctl = ip->idhos4c;
213 break;
214 }
215/*
216
217*/
218 bform = ctl & OC_MOD;
219
220 switch (bform) {
221
222 case OC_INT: /* interval */
223
224 sprintf(ebuf, "%04d%c", ((val < 0 ? -val : val) >> 1),
225 (val < 0 ? '-' : '+'));
226
227 ebflag = TRUE;
228 return(SUCCESS);
229
230 case OC_RAT: /* ratio */
231
232 int2rat(val >> 1);
233 ebflag = TRUE;
234 return(SUCCESS);
235
236 case OC_FRQ: /* frequency */
237
238 fh = (val >> 1) / 10;
239 fl = (val >> 1) - (fh * 10);
240
241 sprintf(ebuf, "%02d.%d", fh, fl);
242 ebflag = TRUE;
243 return(SUCCESS);
244
245 case OC_PCH:
246
247 cnvc2p(ebuf, (val >> 1));
248 ebflag = TRUE;
249 return(SUCCESS);
250 }
251}
252
253/*
254
255*/
256
257/*
258 =============================================================================
259 setoval() -- set oscillator mode and pitch/ratio variables
260 =============================================================================
261*/
262
263setoval(ip, v, val)
264register struct instdef *ip;
265register short v, val;
266{
267 switch (v) {
268
269 case 0:
270
271 ip->idhos1v = val << 1;
272 ip->idhos1c = (ip->idhos1c & ~OC_MOD) | bform;
273 break;
274
275 case 1:
276
277 ip->idhos2v = val << 1;
278 ip->idhos2c = (ip->idhos2c & ~OC_MOD) | bform;
279 break;
280
281 case 2:
282
283 ip->idhos3v = val << 1;
284 ip->idhos3c = (ip->idhos3c & ~OC_MOD) | bform;
285 break;
286
287 case 3:
288
289 ip->idhos4v = val << 1;
290 ip->idhos4c = (ip->idhos4c & ~OC_MOD) | bform;
291 break;
292 }
293
294 ip->idhfnc[v].idftmd = (ip->idhfnc[v].idftmd & ~I_NRATIO)
295 | ((bform & 2) ? I_NRATIO : 0);
296}
297
298/*
299
300*/
301
302/*
303 =============================================================================
304 ef_iosc() -- unload (parse) edit buffer
305 =============================================================================
306*/
307
308short
309ef_iosc(nn)
310short nn;
311{
312 register struct instdef *ip;
313 register short v, i, tmp;
314
315 v = (nn >> 8) & 3;
316 ip = &vbufs[curvce];
317 ebflag = FALSE;
318
319 switch (bform) {
320
321 case OC_INT: /* interval */
322
323 tmp = 0;
324
325 for (i = 0; i < 4; i++)
326 tmp = (tmp * 10) + (ebuf[i] - '0');
327
328 if (ebuf[4] EQ '-')
329 tmp = -tmp;
330
331 setoval(ip, v, tmp);
332 modinst();
333 return(SUCCESS);
334
335 case OC_RAT: /* ratio */
336
337 tmp = ndvals[ebuf[0] - '0'] - ndvals[ebuf[2] - '0'];
338
339 setoval(ip, v, tmp);
340 modinst();
341 return(SUCCESS);
342/*
343
344*/
345 case OC_FRQ: /* frequency */
346
347 tmp = 0;
348
349 for (i = 0; i < 2; i++)
350 tmp = (tmp * 10) + ebuf[i] - '0';
351
352 tmp = (tmp * 10) + ebuf[3] - '0';
353
354 if (tmp GT 159)
355 return(FAILURE);
356
357 setoval(ip, v, tmp);
358 modinst();
359 return(SUCCESS);
360
361 case OC_PCH: /* pitch */
362
363 if (cnvp2c() EQ FAILURE)
364 return(FAILURE);
365
366 setoval(ip, v, cents);
367 modinst();
368 return(SUCCESS);
369 }
370}
371
372/*
373
374*/
375
376/*
377 =============================================================================
378 rd_iosc() -- (re)display the field
379 =============================================================================
380*/
381
382short
383rd_iosc(nn)
384short nn;
385{
386 register struct instdef *ip;
387 register short val, ctl, fh, fl, v;
388 short n;
389 char ocs;
390
391 v = (nn >> 8) & 0x03;
392 n = nn & 0xFF;
393 ip = &vbufs[curvce];
394
395 switch (v) {
396
397 case 0:
398
399 val = ip->idhos1v;
400 ctl = ip->idhos1c;
401 break;
402
403 case 1:
404
405 val = ip->idhos2v;
406 ctl = ip->idhos2c;
407 break;
408
409 case 2:
410
411 val = ip->idhos3v;
412 ctl = ip->idhos3c;
413 break;
414
415 case 3:
416
417 val = ip->idhos4v;
418 ctl = ip->idhos4c;
419 break;
420 }
421/*
422
423*/
424 bform = ctl & OC_MOD;
425 ocs = ((v EQ 3) ? ' ' : (ctl & OC_SYN ? 'S' : 's'));
426
427 switch (bform) {
428
429 case OC_INT: /* interval */
430
431 sprintf(dspbuf, "Int %c%04d %c",
432 (val < 0 ? '-' : '+'),
433 ((val < 0 ? -val : val) >> 1),
434 ocs);
435 break;
436
437 case OC_RAT: /* ratio */
438
439 int2rat(val >> 1);
440 sprintf(dspbuf, "Rat %c/%c %c", ebuf[0], ebuf[2], ocs);
441 break;
442
443 case OC_FRQ: /* frequency */
444
445 fh = (val >> 1) / 10;
446 fl = (val >> 1) - (fh * 10);
447
448 sprintf(dspbuf, "Frq %02d.%d %c", fh, fl, ocs);
449 break;
450
451 case OC_PCH:
452
453 strcpy(dspbuf, "Pch ");
454 cnvc2p(&dspbuf[4], (val >> 1));
455 dspbuf[4] += '0';
456 dspbuf[5] += 'A';
457 dspbuf[6] = sfdsp[dspbuf[6] - 7];
458 dspbuf[7] += '0';
459 dspbuf[8] += '0';
460 dspbuf[9] = ' ';
461 dspbuf[10] = ocs;
462 dspbuf[11] = '\0';
463 break;
464 }
465
466 if (v_regs[5] & 0x0180)
467 vbank(0);
468
469 vcputsv(instob, 64, idbox[n][4], idbox[n][5], 18 + v , 36, dspbuf, 14);
470
471 return(SUCCESS);
472}
473
474/*
475
476*/
477
478/*
479 =============================================================================
480 setoscb() -- change oscillator data entry buffer format
481 =============================================================================
482*/
483
484setoscb(n, v)
485short n, v;
486{
487 register struct instdef *ip;
488 register short bfm, ctl, val;
489 register char ocs;
490
491 ip = &vbufs[curvce];
492
493 switch (v) {
494
495 case 0:
496
497 ctl = ip->idhos1c;
498 val = ip->idhos1v;
499 break;
500
501 case 1:
502
503 ctl = ip->idhos2c;
504 val = ip->idhos2v;
505 break;
506
507 case 2:
508
509 ctl = ip->idhos3c;
510 val = ip->idhos3v;
511 break;
512
513 case 3:
514
515 ctl = ip->idhos4c;
516 val = ip->idhos4v;
517 break;
518 }
519
520 ocs = ((v EQ 3) ? ' ' : (ctl & OC_SYN ? 'S' : 's'));
521
522 bfm = ctl & OC_MOD;
523/*
524
525*/
526 switch (bform) {
527
528 case OC_INT: /* interval */
529
530 if ((bfm EQ OC_RAT) OR (bfm EQ OC_INT)) {
531
532 sprintf(ebuf, "%04d%c", ((val < 0 ? -val : val) >> 1),
533 (val < 0 ? '-' : '+'));
534
535 sprintf(dspbuf, "Int %c%04d %c",
536 (val < 0 ? '-' : '+'),
537 ((val < 0 ? -val : val) >> 1),
538 ocs);
539
540 } else {
541
542 strcpy(ebuf, "0000+");
543 sprintf(dspbuf, "Int %s %c", intstr, ocs);
544 }
545
546 break;
547
548 case OC_RAT: /* ratio */
549
550 if (bfm EQ OC_RAT) {
551
552 int2rat(val >> 1);
553
554 sprintf(dspbuf, "Rat %c/%c %c",
555 ebuf[0], ebuf[2], ocs);
556
557 } else {
558
559 strcpy(ebuf, ratstr);
560 sprintf(dspbuf, "Rat %s %c", ratstr, ocs);
561 }
562
563 break;
564/*
565
566*/
567 case OC_FRQ: /* frequency */
568
569 strcpy(ebuf, frqstr);
570 sprintf(dspbuf, "Frq %s %c", frqstr, ocs);
571 break;
572
573 case OC_PCH: /* pitch */
574
575 ebuf[0] = 0; /* 0 */
576 ebuf[1] = 2; /* C */
577 ebuf[2] = 7; /* */
578 ebuf[3] = 0; /* 0 */
579 ebuf[4] = 0; /* 0 */
580
581 sprintf(dspbuf, "Pch %s %c", pchstr, ocs);
582 break;
583 }
584
585 ebflag = TRUE;
586
587 if (v_regs[5] & 0x0180)
588 vbank(0);
589
590 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
591 stcrow, 36, dspbuf, 14);
592}
593
594/*
595
596*/
597
598/*
599 =============================================================================
600 setosyn() -- set oscillator sync mode
601 =============================================================================
602*/
603
604setosyn(n, v, t)
605short n, v, t;
606{
607 register struct instdef *ip;
608 register char *sc;
609
610 ip = &vbufs[curvce];
611
612 if (stcrow EQ 21)
613 return;
614
615 sc = t ? "S" : "s";
616
617 switch (v) {
618
619 case 0:
620
621 ip->idhos1c = (ip->idhos1c & ~OC_SYN) | (t ? OC_SYN : 0);
622 break;
623
624 case 1:
625
626 ip->idhos2c = (ip->idhos2c & ~OC_SYN) | (t ? OC_SYN : 0);
627 break;
628
629 case 2:
630
631 ip->idhos3c = (ip->idhos3c & ~OC_SYN) | (t ? OC_SYN : 0);
632 break;
633
634 case 3:
635
636 return;
637 }
638
639 dosync(curvce);
640
641 if (v_regs[5] & 0x0180)
642 vbank(0);
643
644 vcputsv(instob, 64, idbox[n][4], idbox[n][5], stcrow, stccol, sc, 14);
645 modinst();
646}
647
648/*
649
650*/
651
652/*
653 =============================================================================
654 nd_iosc() -- handle new data entry
655 =============================================================================
656*/
657
658short
659nd_iosc(nn, k)
660short nn, k;
661{
662 register short v, n;
663
664 n = nn & 0xFF;
665 v = (nn >> 8) & 3;
666
667 if (stccol LT 39) { /* mode */
668
669 if (k EQ 8) { /* - */
670
671 if (--bform LT 0)
672 bform = 3;
673
674 setoscb(n, v);
675 return(SUCCESS);
676
677 } else if (k EQ 9) { /* + */
678
679 if (++bform GT 3)
680 bform = 0;
681
682 setoscb(n, v);
683 return(SUCCESS);
684
685 } else
686 return(FAILURE);
687/*
688
689*/
690 } else if (stccol EQ 46) { /* sync */
691
692 if (stcrow EQ 21)
693 return(FAILURE);
694
695 if (k EQ 8) { /* - */
696
697 setosyn(n, v, 0); /* off */
698 return(SUCCESS);
699
700 } else if (k EQ 9) { /* + */
701
702 setosyn(n, v, 1); /* on */
703 return(SUCCESS);
704
705 } else
706 return(FAILURE);
707
708/*
709
710*/
711 } else if ((stccol GE 40) AND (stccol LE 44)) { /* value */
712
713 switch (bform) {
714
715 case OC_INT: /* interval */
716
717 if (stccol EQ 40) { /* sign */
718
719 if (k EQ 8) { /* - */
720
721 k = '-';
722 ebuf[4] = '-';
723
724 } else if (k EQ 9) { /* + */
725
726 k = '+';
727 ebuf[4] = '+';
728
729 } else
730 return(FAILURE);
731
732 } else {
733
734 ebuf[stccol - 41] = k + '0';
735 }
736
737 dspbuf[0] = (k > 9) ? k : (k + '0');
738 dspbuf[1] = '\0';
739
740 if (v_regs[5] & 0x0180)
741 vbank(0);
742
743 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
744 stcrow, stccol, dspbuf, 14);
745
746 if (stccol EQ 44)
747 return(SUCCESS);
748
749 advicur();
750 return(SUCCESS);
751/*
752
753*/
754 case OC_RAT: /* ratio */
755
756 if (stccol EQ 40) {
757
758 if (k) {
759
760 ebuf[0] = dspbuf[0] = k + '0';
761 dspbuf[1] = '\0';
762
763 if (v_regs[5] & 0x0180)
764 vbank(0);
765
766 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
767 stcrow, stccol, dspbuf, 14);
768
769 advicur();
770 advicur();
771
772 return(SUCCESS);
773
774 } else
775 return(FAILURE);
776
777 } else if (stccol EQ 42) {
778
779 if (k) {
780
781 ebuf[2] = dspbuf[0] = k + '0';
782 dspbuf[1] = '\0';
783
784 if (v_regs[5] & 0x0180)
785 vbank(0);
786
787 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
788 stcrow, stccol, dspbuf, 14);
789
790 return(SUCCESS);
791
792 } else
793 return(FAILURE);
794 } else {
795
796 return(FAILURE);
797 }
798/*
799
800*/
801 case OC_FRQ: /* frequency */
802
803 if (stccol EQ 42)
804 return(FAILURE);
805
806 ebuf[stccol - 40] = k + '0';
807 dspbuf[0] = k + '0';
808 dspbuf[1] = '\0';
809
810 if (v_regs[5] & 0x0180)
811 vbank(0);
812
813 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
814 stcrow, stccol, dspbuf, 14);
815
816 if (stccol EQ 44)
817 return(SUCCESS);
818
819 advicur();
820
821 if (stccol EQ 42)
822 advicur();
823
824 return(SUCCESS);
825/*
826
827*/
828 case OC_PCH: /* pitch */
829
830 switch (stccol) {
831
832 case 40:
833
834 ebuf[0] = k;
835 dspbuf[0] = k + '0';
836 break;
837
838 case 41:
839
840 if (k GT 6)
841 return(FAILURE);
842
843 ebuf[1] = k;
844 dspbuf[0] = k + 'A';
845 break;
846
847 case 42:
848
849 if (k EQ 7) { /* blank */
850
851 ebuf[2] = k;
852 dspbuf[0] = sfdsp[0];
853 break;
854
855 } else if (k EQ 8) { /* flat */
856
857 ebuf[2] = k;
858 dspbuf[0] = sfdsp[1];
859 break;
860
861 } else if (k EQ 9) { /* sharp */
862
863 ebuf[2] = k;
864 dspbuf[0] = sfdsp[2];
865 break;
866
867 } else
868 return(FAILURE);
869 case 43:
870 case 44:
871
872 ebuf[stccol - 40] = k;
873 dspbuf[0] = k + '0';
874 break;
875 }
876/*
877
878*/
879
880 dspbuf[1] = '\0';
881
882 if (v_regs[5] & 0x0180)
883 vbank(0);
884
885 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
886 stcrow, stccol, dspbuf, 14);
887
888 if (stccol EQ 44)
889 return(SUCCESS);
890
891 advicur();
892 return(SUCCESS);
893 }
894
895 } else {
896
897 return(FAILURE);
898 }
899}
Note: See TracBrowser for help on using the repository browser.