source: buchla-68k/ram/etiosc.c@ 0580615

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

Point of no return.

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