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

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

Added missing includes and declarations.

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