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

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

Point of no return.

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