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

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

Zero redundant declarations.

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