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

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

Fixed parentheses and braces.

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