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

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

Added include files for global functions and variables.

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