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

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

Missing return values. Missing int declarations.

  • Property mode set to 100644
File size: 13.8 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 return(FAILURE);
248}
249
250/*
251
252*/
253
254/*
255 =============================================================================
256 setoval() -- set oscillator mode and pitch/ratio variables
257 =============================================================================
258*/
259
260void setoval(struct instdef *ip, short v, short val)
261{
262 switch (v) {
263
264 case 0:
265
266 ip->idhos1v = val << 1;
267 ip->idhos1c = (ip->idhos1c & ~OC_MOD) | bform;
268 break;
269
270 case 1:
271
272 ip->idhos2v = val << 1;
273 ip->idhos2c = (ip->idhos2c & ~OC_MOD) | bform;
274 break;
275
276 case 2:
277
278 ip->idhos3v = val << 1;
279 ip->idhos3c = (ip->idhos3c & ~OC_MOD) | bform;
280 break;
281
282 case 3:
283
284 ip->idhos4v = val << 1;
285 ip->idhos4c = (ip->idhos4c & ~OC_MOD) | bform;
286 break;
287 }
288
289 ip->idhfnc[v].idftmd = (ip->idhfnc[v].idftmd & ~I_NRATIO)
290 | ((bform & 2) ? I_NRATIO : 0);
291}
292
293/*
294
295*/
296
297/*
298 =============================================================================
299 ef_iosc() -- unload (parse) edit buffer
300 =============================================================================
301*/
302
303short ef_iosc(short nn)
304{
305 register struct instdef *ip;
306 register short v, i, tmp;
307
308 v = (nn >> 8) & 3;
309 ip = &vbufs[curvce];
310 ebflag = FALSE;
311
312 switch (bform) {
313
314 case OC_INT: /* interval */
315
316 tmp = 0;
317
318 for (i = 0; i < 4; i++)
319 tmp = (tmp * 10) + (ebuf[i] - '0');
320
321 if (ebuf[4] EQ '-')
322 tmp = -tmp;
323
324 setoval(ip, v, tmp);
325 modinst();
326 return(SUCCESS);
327
328 case OC_RAT: /* ratio */
329
330 tmp = ndvals[ebuf[0] - '0'] - ndvals[ebuf[2] - '0'];
331
332 setoval(ip, v, tmp);
333 modinst();
334 return(SUCCESS);
335/*
336
337*/
338 case OC_FRQ: /* frequency */
339
340 tmp = 0;
341
342 for (i = 0; i < 2; i++)
343 tmp = (tmp * 10) + ebuf[i] - '0';
344
345 tmp = (tmp * 10) + ebuf[3] - '0';
346
347 if (tmp GT 159)
348 return(FAILURE);
349
350 setoval(ip, v, tmp);
351 modinst();
352 return(SUCCESS);
353
354 case OC_PCH: /* pitch */
355
356 if (cnvp2c() EQ FAILURE)
357 return(FAILURE);
358
359 setoval(ip, v, cents);
360 modinst();
361 return(SUCCESS);
362 }
363
364 return(FAILURE);
365}
366
367/*
368
369*/
370
371/*
372 =============================================================================
373 rd_iosc() -- (re)display the field
374 =============================================================================
375*/
376
377short rd_iosc(short nn)
378{
379 register struct instdef *ip;
380 register short val, ctl, fh, fl, v;
381 short n;
382 char ocs;
383
384 v = (nn >> 8) & 0x03;
385 n = nn & 0xFF;
386 ip = &vbufs[curvce];
387
388 switch (v) {
389
390 case 0:
391
392 val = ip->idhos1v;
393 ctl = ip->idhos1c;
394 break;
395
396 case 1:
397
398 val = ip->idhos2v;
399 ctl = ip->idhos2c;
400 break;
401
402 case 2:
403
404 val = ip->idhos3v;
405 ctl = ip->idhos3c;
406 break;
407
408 case 3:
409
410 val = ip->idhos4v;
411 ctl = ip->idhos4c;
412 break;
413 }
414/*
415
416*/
417 bform = ctl & OC_MOD;
418 ocs = ((v EQ 3) ? ' ' : (ctl & OC_SYN ? 'S' : 's'));
419
420 switch (bform) {
421
422 case OC_INT: /* interval */
423
424 sprintf(dspbuf, "Int %c%04d %c",
425 (val < 0 ? '-' : '+'),
426 ((val < 0 ? -val : val) >> 1),
427 ocs);
428 break;
429
430 case OC_RAT: /* ratio */
431
432 int2rat(val >> 1);
433 sprintf(dspbuf, "Rat %c/%c %c", ebuf[0], ebuf[2], ocs);
434 break;
435
436 case OC_FRQ: /* frequency */
437
438 fh = (val >> 1) / 10;
439 fl = (val >> 1) - (fh * 10);
440
441 sprintf(dspbuf, "Frq %02d.%d %c", fh, fl, ocs);
442 break;
443
444 case OC_PCH:
445
446 strcpy(dspbuf, "Pch ");
447 cnvc2p(&dspbuf[4], (val >> 1));
448 dspbuf[4] += '0';
449 dspbuf[5] += 'A';
450 dspbuf[6] = sfdsp[dspbuf[6] - 7];
451 dspbuf[7] += '0';
452 dspbuf[8] += '0';
453 dspbuf[9] = ' ';
454 dspbuf[10] = ocs;
455 dspbuf[11] = '\0';
456 break;
457 }
458
459 if (v_regs[5] & 0x0180)
460 vbank(0);
461
462 vcputsv(instob, 64, idbox[n][4], idbox[n][5], 18 + v , 36, dspbuf, 14);
463
464 return(SUCCESS);
465}
466
467/*
468
469*/
470
471/*
472 =============================================================================
473 setoscb() -- change oscillator data entry buffer format
474 =============================================================================
475*/
476
477void setoscb(short n, short v)
478{
479 register struct instdef *ip;
480 register short bfm, ctl, val;
481 register char ocs;
482
483 ip = &vbufs[curvce];
484
485 switch (v) {
486
487 case 0:
488
489 ctl = ip->idhos1c;
490 val = ip->idhos1v;
491 break;
492
493 case 1:
494
495 ctl = ip->idhos2c;
496 val = ip->idhos2v;
497 break;
498
499 case 2:
500
501 ctl = ip->idhos3c;
502 val = ip->idhos3v;
503 break;
504
505 case 3:
506
507 ctl = ip->idhos4c;
508 val = ip->idhos4v;
509 break;
510 }
511
512 ocs = ((v EQ 3) ? ' ' : (ctl & OC_SYN ? 'S' : 's'));
513
514 bfm = ctl & OC_MOD;
515/*
516
517*/
518 switch (bform) {
519
520 case OC_INT: /* interval */
521
522 if ((bfm EQ OC_RAT) OR (bfm EQ OC_INT)) {
523
524 sprintf(ebuf, "%04d%c", ((val < 0 ? -val : val) >> 1),
525 (val < 0 ? '-' : '+'));
526
527 sprintf(dspbuf, "Int %c%04d %c",
528 (val < 0 ? '-' : '+'),
529 ((val < 0 ? -val : val) >> 1),
530 ocs);
531
532 } else {
533
534 strcpy(ebuf, "0000+");
535 sprintf(dspbuf, "Int %s %c", intstr, ocs);
536 }
537
538 break;
539
540 case OC_RAT: /* ratio */
541
542 if (bfm EQ OC_RAT) {
543
544 int2rat(val >> 1);
545
546 sprintf(dspbuf, "Rat %c/%c %c",
547 ebuf[0], ebuf[2], ocs);
548
549 } else {
550
551 strcpy(ebuf, ratstr);
552 sprintf(dspbuf, "Rat %s %c", ratstr, ocs);
553 }
554
555 break;
556/*
557
558*/
559 case OC_FRQ: /* frequency */
560
561 strcpy(ebuf, frqstr);
562 sprintf(dspbuf, "Frq %s %c", frqstr, ocs);
563 break;
564
565 case OC_PCH: /* pitch */
566
567 ebuf[0] = 0; /* 0 */
568 ebuf[1] = 2; /* C */
569 ebuf[2] = 7; /* */
570 ebuf[3] = 0; /* 0 */
571 ebuf[4] = 0; /* 0 */
572
573 sprintf(dspbuf, "Pch %s %c", pchstr, ocs);
574 break;
575 }
576
577 ebflag = TRUE;
578
579 if (v_regs[5] & 0x0180)
580 vbank(0);
581
582 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
583 stcrow, 36, dspbuf, 14);
584}
585
586/*
587
588*/
589
590/*
591 =============================================================================
592 setosyn() -- set oscillator sync mode
593 =============================================================================
594*/
595
596void setosyn(short n, short v, short t)
597{
598 register struct instdef *ip;
599 register char *sc;
600
601 ip = &vbufs[curvce];
602
603 if (stcrow EQ 21)
604 return;
605
606 sc = t ? "S" : "s";
607
608 switch (v) {
609
610 case 0:
611
612 ip->idhos1c = (ip->idhos1c & ~OC_SYN) | (t ? OC_SYN : 0);
613 break;
614
615 case 1:
616
617 ip->idhos2c = (ip->idhos2c & ~OC_SYN) | (t ? OC_SYN : 0);
618 break;
619
620 case 2:
621
622 ip->idhos3c = (ip->idhos3c & ~OC_SYN) | (t ? OC_SYN : 0);
623 break;
624
625 case 3:
626
627 return;
628 }
629
630 dosync(curvce);
631
632 if (v_regs[5] & 0x0180)
633 vbank(0);
634
635 vcputsv(instob, 64, idbox[n][4], idbox[n][5], stcrow, stccol, sc, 14);
636 modinst();
637}
638
639/*
640
641*/
642
643/*
644 =============================================================================
645 nd_iosc() -- handle new data entry
646 =============================================================================
647*/
648
649short nd_iosc(short nn, short k)
650{
651 register short v, n;
652
653 n = nn & 0xFF;
654 v = (nn >> 8) & 3;
655
656 if (stccol LT 39) { /* mode */
657
658 if (k EQ 8) { /* - */
659
660 if (--bform LT 0)
661 bform = 3;
662
663 setoscb(n, v);
664 return(SUCCESS);
665
666 } else if (k EQ 9) { /* + */
667
668 if (++bform GT 3)
669 bform = 0;
670
671 setoscb(n, v);
672 return(SUCCESS);
673
674 } else
675 return(FAILURE);
676/*
677
678*/
679 } else if (stccol EQ 46) { /* sync */
680
681 if (stcrow EQ 21)
682 return(FAILURE);
683
684 if (k EQ 8) { /* - */
685
686 setosyn(n, v, 0); /* off */
687 return(SUCCESS);
688
689 } else if (k EQ 9) { /* + */
690
691 setosyn(n, v, 1); /* on */
692 return(SUCCESS);
693
694 } else
695 return(FAILURE);
696
697/*
698
699*/
700 } else if ((stccol GE 40) AND (stccol LE 44)) { /* value */
701
702 switch (bform) {
703
704 case OC_INT: /* interval */
705
706 if (stccol EQ 40) { /* sign */
707
708 if (k EQ 8) { /* - */
709
710 k = '-';
711 ebuf[4] = '-';
712
713 } else if (k EQ 9) { /* + */
714
715 k = '+';
716 ebuf[4] = '+';
717
718 } else
719 return(FAILURE);
720
721 } else {
722
723 ebuf[stccol - 41] = k + '0';
724 }
725
726 dspbuf[0] = (k > 9) ? k : (k + '0');
727 dspbuf[1] = '\0';
728
729 if (v_regs[5] & 0x0180)
730 vbank(0);
731
732 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
733 stcrow, stccol, dspbuf, 14);
734
735 if (stccol EQ 44)
736 return(SUCCESS);
737
738 advicur();
739 return(SUCCESS);
740/*
741
742*/
743 case OC_RAT: /* ratio */
744
745 if (stccol EQ 40) {
746
747 if (k) {
748
749 ebuf[0] = dspbuf[0] = k + '0';
750 dspbuf[1] = '\0';
751
752 if (v_regs[5] & 0x0180)
753 vbank(0);
754
755 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
756 stcrow, stccol, dspbuf, 14);
757
758 advicur();
759 advicur();
760
761 return(SUCCESS);
762
763 } else
764 return(FAILURE);
765
766 } else if (stccol EQ 42) {
767
768 if (k) {
769
770 ebuf[2] = dspbuf[0] = k + '0';
771 dspbuf[1] = '\0';
772
773 if (v_regs[5] & 0x0180)
774 vbank(0);
775
776 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
777 stcrow, stccol, dspbuf, 14);
778
779 return(SUCCESS);
780
781 } else
782 return(FAILURE);
783 } else {
784
785 return(FAILURE);
786 }
787/*
788
789*/
790 case OC_FRQ: /* frequency */
791
792 if (stccol EQ 42)
793 return(FAILURE);
794
795 ebuf[stccol - 40] = k + '0';
796 dspbuf[0] = k + '0';
797 dspbuf[1] = '\0';
798
799 if (v_regs[5] & 0x0180)
800 vbank(0);
801
802 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
803 stcrow, stccol, dspbuf, 14);
804
805 if (stccol EQ 44)
806 return(SUCCESS);
807
808 advicur();
809
810 if (stccol EQ 42)
811 advicur();
812
813 return(SUCCESS);
814/*
815
816*/
817 case OC_PCH: /* pitch */
818
819 switch (stccol) {
820
821 case 40:
822
823 ebuf[0] = k;
824 dspbuf[0] = k + '0';
825 break;
826
827 case 41:
828
829 if (k GT 6)
830 return(FAILURE);
831
832 ebuf[1] = k;
833 dspbuf[0] = k + 'A';
834 break;
835
836 case 42:
837
838 if (k EQ 7) { /* blank */
839
840 ebuf[2] = k;
841 dspbuf[0] = sfdsp[0];
842 break;
843
844 } else if (k EQ 8) { /* flat */
845
846 ebuf[2] = k;
847 dspbuf[0] = sfdsp[1];
848 break;
849
850 } else if (k EQ 9) { /* sharp */
851
852 ebuf[2] = k;
853 dspbuf[0] = sfdsp[2];
854 break;
855
856 } else
857 return(FAILURE);
858 case 43:
859 case 44:
860
861 ebuf[stccol - 40] = k;
862 dspbuf[0] = k + '0';
863 break;
864 }
865/*
866
867*/
868
869 dspbuf[1] = '\0';
870
871 if (v_regs[5] & 0x0180)
872 vbank(0);
873
874 vcputsv(instob, 64, ID_ENTRY, idbox[n][5],
875 stcrow, stccol, dspbuf, 14);
876
877 if (stccol EQ 44)
878 return(SUCCESS);
879
880 advicur();
881 return(SUCCESS);
882 }
883
884 return(FAILURE);
885
886 } else {
887
888 return(FAILURE);
889 }
890}
Note: See TracBrowser for help on using the repository browser.