source: buchla-68k/ram/tundsp.c@ c65a0e2

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

Added RAM files.

  • Property mode set to 100644
File size: 14.0 KB
Line 
1/*
2 =============================================================================
3 tundsp.c -- MIDAS tuning table editor
4 Version 23 -- 1988-11-28 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "hwdefs.h"
9#include "biosdefs.h"
10#include "stddefs.h"
11#include "graphdef.h"
12#include "vsdd.h"
13#include "vsddsw.h"
14#include "vsddvars.h"
15#include "charset.h"
16#include "fields.h"
17
18#include "midas.h"
19#include "tundsp.h"
20
21#define TUN_VAL 100 /* default value for tunval in cents */
22
23extern short stcrow, stccol, cxval, cyval;
24
25extern short curtun; /* current tuning table */
26extern short submenu; /* submenu cursor switch */
27extern short tunmod; /* tuning table modified */
28extern short tunval; /* tuning table generator value */
29extern short ttcmdsv; /* tuning table editing state variable */
30extern short tdnamsw; /* tuning editor displaying typewriter */
31
32extern short oldtun[]; /* previous tuning table for undo */
33extern short tuntab[]; /* current tuning table */
34extern short tunlib[][128]; /* tuning table library */
35
36extern short panlkey[]; /* local key tunings */
37extern short lclkmap[]; /* local key to MIDI key map */
38
39extern char tuncurn[]; /* current tuning table name */
40extern char tunname[][32]; /* tuning table names */
41extern char sfdsp[];
42
43extern unsigned *obj0, *obj2;
44
45extern char bfs[];
46extern char *tdbxlb[];
47
48extern short tdbox[][8];
49
50extern unsigned *tunob;
51
52extern struct octent *tdoct;
53
54/*
55
56*/
57
58short tunpal[16][3] = { /* color palette */
59
60 {0, 0, 0}, /* 0 */
61 {3, 3, 3}, /* 1 */
62 {0, 0, 0}, /* 2 */
63 {3, 3, 3}, /* 3 */
64 {1, 1, 0}, /* 4 */
65 {1, 0, 1}, /* 5 */
66 {0, 1, 1}, /* 6 (was 0, 1, 0) */
67 {0, 1, 1}, /* 7 (was 0, 1, 0) */
68 {0, 0, 1}, /* 8 (was 0, 0, 2) */
69 {0, 2, 3}, /* 9 (was 0, 3, 0) */
70 {2, 2, 2}, /* 10 */
71 {2, 3, 3}, /* 11 */
72 {3, 3, 0}, /* 12 */
73 {3, 3, 0}, /* 13 */
74 {3, 0, 0}, /* 14 */
75 {0, 0, 3} /* 15 */
76};
77
78 /* 12345678901234567890123456789012 */
79static char dfltnam[] = "Local 3rds + MIDI 12 tone scale ";
80
81char *tdlabl[] = {
82
83 "C", "#", "D", "#", "E", "F", "#", "G",
84 "#", "A", "#", "B", "C", "#", "D", "#",
85 "E", "F", "#", "G", "#", "A", "#", "B"
86};
87
88/*
89
90*/
91
92/*
93 =============================================================================
94 gettun() -- retrieve a tuning table from the tuning table library
95 =============================================================================
96*/
97
98gettun(n)
99short n;
100{
101 memcpyw(tuntab, tunlib[n], 128);
102 memcpy(tuncurn, tunname[n], 32);
103 curtun = n;
104 tunmod = FALSE;
105}
106
107/*
108 =============================================================================
109 puttun() -- store a tuning table in the tuning table library
110 =============================================================================
111*/
112
113puttun(n)
114short n;
115{
116 memcpyw(tunlib[n], tuntab, 128);
117 memcpy(tunname[n], tuncurn, 32);
118 tunmod = FALSE;
119}
120
121/*
122
123*/
124
125/*
126 =============================================================================
127 inittt() -- initialize tuning table to equal tempered 12 tone scale
128 =============================================================================
129*/
130
131inittt(n)
132short n;
133{
134 register short i;
135
136 for (i = 0; i < 128; i++)
137 tunlib[n][i] = ((i < 21) ? 160 : (i > 108) ? 10960 :
138 (160 + ((i - 12) * 100))) << 1;
139
140 for (i = 0; i < 24; i++)
141 tunlib[n][lclkmap[i]] = panlkey[i] << 1;
142
143 strcpy(tunname[n], dfltnam);
144}
145
146
147/*
148 =============================================================================
149 inittl() -- initialize tuning table library
150 =============================================================================
151*/
152
153inittl()
154{
155 register short i;
156
157 for (i = 0; i < NTUNS; i++)
158 inittt(i);
159
160 tunval = TUN_VAL << 1;
161 gettun(0);
162 memcpyw(oldtun, tuntab, 128);
163}
164
165/*
166
167*/
168
169/*
170 =============================================================================
171 tt_trcp() -- transpose and copy tuning table values
172 =============================================================================
173*/
174
175tt_trcp(start, finish, dest)
176short start, finish, dest;
177{
178 register short i;
179 register long v;
180
181 memcpyw(oldtun, tuntab, 128); /* preserve old table for undo */
182
183 if (start > finish) {
184
185 for (i = finish; ((i LE start) AND (dest < 128)); i++) {
186
187 /* reverse copy */
188
189 v = oldtun[i] + (long)tunval; /* transpose */
190
191 if (v GT (long)PITCHMAX) /* limit */
192 v = (long)PITCHMAX;
193 else if (v LT (long)PITCHMIN)
194 v = (long)PITCHMIN;
195
196 tuntab[dest++] = (short)v; /* store the value */
197 }
198
199 } else {
200
201 for (i = start; ((i LE finish) AND (dest < 128)); i++) {
202
203 /* forward copy */
204
205 v = oldtun[i] + (long)tunval; /* transpose */
206
207 if (v GT (long)PITCHMAX) /* limit */
208 v = (long)PITCHMAX;
209 else if (v LT (long)PITCHMIN)
210 v = (long)PITCHMIN;
211
212 tuntab[dest++] = (short)v; /* store the value */
213 }
214 }
215
216 tunmod = TRUE;
217}
218
219/*
220
221*/
222
223/*
224 =============================================================================
225 tt_intp() -- interpolate tuning table values
226 =============================================================================
227*/
228
229short
230tt_intp(from, to)
231short from, to;
232{
233 register short i, j, k, n;
234 register long t;
235
236 memcpyw(oldtun, tuntab, 128); /* preserve old table for undo */
237
238 if (from > to) { /* adjust to and from for forward scan */
239
240 i = from;
241 from = to;
242 to = i;
243 }
244
245 n = to - from; /* get interval size */
246
247 if (n < 2)
248 return(FAILURE);
249
250 k = tuntab[from];
251 t = (((long)tuntab[to] - (long)k) << 16) / n;
252 j = 1 + from;
253 n--;
254
255 for (i = 0; i < n ; i++)
256 tuntab[j++] = (short)((t * (1 + i)) >> 16) + k;
257
258 tunmod = TRUE;
259 return(SUCCESS);
260}
261/*
262
263*/
264
265/*
266 =============================================================================
267 tt_incr() -- increment tuning table values
268 =============================================================================
269*/
270
271short
272tt_incr(from, to)
273short from, to;
274{
275 register short i;
276 register long v;
277
278 memcpyw(oldtun, tuntab, 128); /* preserve old table for undo */
279
280 if (from > to) { /* adjust to and from for forward scan */
281
282 i = from;
283 from = to;
284 to = i;
285
286 }
287
288 v = (long)oldtun[from]; /* initial value */
289
290 if (from++ EQ to) /* interval has to be at least 1 */
291 return(FAILURE);
292
293 for (i = from; i LE to; i++) {
294
295 v += (long)tunval; /* increment */
296
297 if (v GT (long)PITCHMAX) /* limit */
298 v = (long)PITCHMAX;
299 else if (v LT (long)PITCHMIN)
300 v = (long)PITCHMIN;
301
302 tuntab[i] = (short)v; /* store the value */
303 }
304
305 tunmod = TRUE;
306 return(SUCCESS);
307}
308
309/*
310
311*/
312
313/*
314 =============================================================================
315 td_trcp() -- display transpose select label
316 =============================================================================
317*/
318
319td_trcp(mode)
320short mode;
321{
322 register unsigned cx;
323
324 cx = exp_c(mode ? TDSELD : tdbox[6][4]);
325 vbank(0);
326 vcputsv(tunob, 64, cx, tdbox[6][5], 9, 54, "Transpose", 14);
327 vcputsv(tunob, 64, cx, tdbox[6][5], 10, 54, "and Copy", 14);
328}
329
330/*
331 =============================================================================
332 td_incr() -- display increment select label
333 =============================================================================
334*/
335
336td_incr(mode)
337short mode;
338{
339 register unsigned cx;
340
341 cx = exp_c(mode ? TDSELD : tdbox[6][4]);
342 vbank(0);
343 vcputsv(tunob, 64, cx, tdbox[6][5], 12, 54, "Increment", 14);
344}
345
346/*
347 =============================================================================
348 td_intp() -- display interpolate select label
349 =============================================================================
350*/
351
352td_intp(mode)
353short mode;
354{
355 register unsigned cx;
356
357 cx = exp_c(mode ? TDSELD : tdbox[6][4]);
358 vbank(0);
359 vcputsv(tunob, 64, cx, tdbox[6][5], 14, 54, "Intrpolat", 14);
360}
361
362/*
363
364*/
365
366/*
367 =============================================================================
368 advtcur() -- advance the tuning display text cursor
369 =============================================================================
370*/
371
372advtcur()
373{
374 register short newcol;
375
376 if (infield(stcrow, stccol, curfet))
377 cfetp = infetp;
378 else
379 return;
380
381 newcol = stccol + 1;
382
383 if (newcol LE cfetp->frcol)
384 itcpos(stcrow, newcol);
385
386 cxval = stccol * 8;
387 cyval = stcrow * 14;
388}
389
390/*
391 =============================================================================
392 bsptcur() -- backspace the tuning display text cursor
393 =============================================================================
394*/
395
396bsptcur()
397{
398 register short newcol;
399
400 if (infield(stcrow, stccol, curfet))
401 cfetp = infetp;
402 else
403 return;
404
405 newcol = stccol - 1;
406
407 if (newcol GE cfetp->flcol)
408 itcpos(stcrow, newcol);
409
410 cxval = stccol * 8;
411 cyval = stcrow * 14;
412}
413
414/*
415
416*/
417
418/*
419 =============================================================================
420 dsttval() -- display a tuning table value
421 =============================================================================
422*/
423
424dsttval(row, col, val, fg, bg)
425short row, col, val;
426unsigned fg, bg;
427{
428 register unsigned cfg, cbg;
429
430 cfg = exp_c(fg);
431 cbg = exp_c(bg);
432
433 cnvc2p(bfs, (val >> 1));
434
435 bfs[0] += '0';
436 bfs[1] += 'A';
437 bfs[2] = sfdsp[bfs[2] - 7];
438 bfs[3] += '0';
439 bfs[4] += '0';
440 bfs[5] = '\0';
441
442 vbank(0);
443 vcputsv(tunob, 64, cfg, cbg, row, col, bfs, 14);
444}
445
446/*
447
448*/
449
450/*
451 =============================================================================
452 tdswin() -- display a window
453 =============================================================================
454*/
455
456tdswin(n)
457register short n;
458{
459 register short cx, i, tv;
460 char ts;
461
462 cx = exp_c(tdbox[n][5]);
463
464 /* first, fill the box with the background color */
465
466 vbank(0);
467 vbfill4(tunob, 128, tdbox[n][0], tdbox[n][1], tdbox[n][2],
468 tdbox[n][3], cx);
469
470 /* put in the box label */
471
472 tsplot4(tunob, 64, tdbox[n][4], tdbox[n][6], tdbox[n][7],
473 tdbxlb[n], 14);
474
475/*
476
477*/
478 switch (n) { /* final text - overlays above stuff */
479
480 case 0: /* keys 0..23 */
481
482 for (i = 0; i < 24; i++) {
483
484 tsplot4(tunob, 64, TDLABEL, i, 1, tdlabl[i], 14);
485 sprintf(bfs, "%2d", 1 + i);
486 tsplot4(tunob, 64, TDMKEYC, i, 3, bfs, 14);
487 dsttval(i, 6, tuntab[i],
488 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
489 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
490 }
491
492 return;
493
494 case 1: /* keys 24..47 */
495
496 for (i = 24; i < 48; i++) {
497
498 sprintf(bfs, "%2d", 1 + i);
499 tsplot4(tunob, 64, TDMKEYC, i - 24, 13, bfs, 14);
500 dsttval(i - 24, 16, tuntab[i],
501 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
502 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
503 }
504
505 return;
506
507 case 2: /* keys 48..71 */
508
509 for (i = 48; i < 72; i++) {
510
511 sprintf(bfs, "%2d", 1 + i);
512 tsplot4(tunob, 64, TDMKEYC, i - 48, 23, bfs, 14);
513 dsttval(i - 48, 26, tuntab[i],
514 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
515 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
516 }
517
518 return;
519/*
520
521*/
522 case 3: /* keys 72..95 */
523
524 for (i = 72; i < 96; i++) {
525
526 sprintf(bfs, "%2d", 1 + i);
527 tsplot4(tunob, 64, TDMKEYC, i - 72, 33, bfs, 14);
528 dsttval(i - 72, 36, tuntab[i],
529 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
530 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
531 }
532
533 return;
534
535 case 4: /* keys 96..119 */
536
537 for (i = 96; i < 120; i++) {
538
539 sprintf(bfs, "%3d", 1 + i);
540 tsplot4(tunob, 64, TDMKEYC, i - 96, 43, bfs, 14);
541 dsttval(i - 96, 47, tuntab[i],
542 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
543 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
544 }
545
546 return;
547
548 case 5: /* keys 120..127 */
549
550 for (i = 120; i < 128; i++) {
551
552 sprintf(bfs, "%3d", 1 + i);
553 tsplot4(tunob, 64, TDMKEYC, i - 120, 54, bfs, 14);
554 dsttval(i - 120, 58, tuntab[i],
555 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
556 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
557 }
558
559 return;
560/*
561
562*/
563 case 6:
564
565 td_trcp(0);
566 td_incr(0);
567 td_intp(0);
568 tsplot4(tunob, 64, tdbox[n][4], 16, 54, "Undo", 14);
569
570 tv = (tunval GE 0 ? tunval : -tunval) >> 1;
571 ts = tunval GE 0 ? '+' : '-';
572 sprintf(bfs, "Val %c%04d", ts, tv);
573 tsplot4(tunob, 64, tdbox[n][4], 18, 54, bfs, 14);
574
575 tsplot4(tunob, 64, tdbox[n][4], 20, 54, "Store", 14);
576 tsplot4(tunob, 64, tdbox[n][4], 22, 54, "Retrieve", 14);
577
578 tsplot4(tunob, 64, tdbox[n][4], 24, 54, "Table #", 14);
579 bfs[0] = curtun + '0';
580 bfs[1] = '\0';
581 tsplot4(tunob, 64, tunmod ? TDCHGD : tdbox[n][4],
582 24, 61, bfs, 14);
583
584 return;
585
586 case 7: /* tuning table name */
587
588 tsplot4(tunob, 64, tdbox[n][4], 24, 7, tuncurn, 14);
589 return;
590 }
591}
592
593/*
594
595*/
596
597/*
598 =============================================================================
599 twins() -- display all tuning editor windows
600 =============================================================================
601*/
602
603twins()
604{
605 register short i;
606
607 for (i = 0; i < 8; i++)
608 tdswin(i);
609}
610
611/*
612
613*/
614
615/*
616 =============================================================================
617 tundsp() -- put up the tuning display
618 =============================================================================
619*/
620
621tundsp()
622{
623 tunob = &v_score[0]; /* setup object pointer */
624 obj0 = &v_curs0[0]; /* setup cursor object pointer */
625 obj2 = &v_tcur[0]; /* setup typewriter object pointer */
626 tdoct = &v_obtab[TUNOBJ]; /* setup object control table pointer */
627
628 ttcmdsv = 0; /* nothing selected */
629 tdnamsw = FALSE;
630 submenu = FALSE;
631
632 dswap(); /* initialize display */
633
634 if (v_regs[5] & 0x0180)
635 vbank(0);
636
637 memsetw(tunob, 0, 32767); /* clear the display */
638 memsetw(tunob+32767L, 0, 12033);
639
640 SetObj(TUNOBJ, 0, 0, tunob, 512, 350, 0, 0, TUNFL, -1);
641 SetObj( 0, 0, 1, obj0, 16, 16, TDCURX, TDCURY, OBFL_00, -1);
642 SetObj(TTCURS, 0, 1, obj2, 16, 16, 0, 0, TTCCFL, -1);
643
644 arcurs(TDCURSR); /* setup arrow cursor object */
645 itcini(TDCURSR); /* setup text cursor object */
646 ttcini(TDTCURC); /* setup typewriter cursor object */
647
648 twins();
649
650 SetPri(TUNOBJ, TUNPRI);
651
652 settc(YTOR(TDCURY), XTOC(TDCURX)); /* display the text cursor */
653
654 vsndpal(tunpal);
655}
Note: See TracBrowser for help on using the repository browser.