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

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

Removed form-feed comments.

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