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

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

Fix conversion warnings.

  • 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 int16_t cx;
245
246 cx = 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 int16_t cx;
261
262 cx = 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 int16_t cx;
276
277 cx = 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, int16_t fg, int16_t bg)
337{
338 cnvc2p(bfs, (val >> 1));
339
340 bfs[0] = (int8_t)(bfs[0] + '0');
341 bfs[1] = (int8_t)(bfs[1] + 'A');
342 bfs[2] = (int8_t)(bfs[2] + sfdsp[bfs[2] - 7]);
343 bfs[3] = (int8_t)(bfs[3] + '0');
344 bfs[4] = (int8_t)(bfs[4] + '0');
345 bfs[5] = '\0';
346
347 vbank(0);
348 vcputsv(tunob, 64, fg, bg, row, col, bfs, 14);
349}
350
351/*
352 =============================================================================
353 tdswin() -- display a window
354 =============================================================================
355*/
356
357void tdswin(int16_t n)
358{
359 uint16_t cx;
360 int16_t i, tv;
361 int8_t ts;
362
363 cx = exp_c(tdbox[n][5]);
364
365 /* first, fill the box with the background color */
366
367 vbank(0);
368 vbfill4(tunob, 128, tdbox[n][0], tdbox[n][1], tdbox[n][2],
369 tdbox[n][3], cx);
370
371 /* put in the box label */
372
373 tsplot4(tunob, 64, tdbox[n][4], tdbox[n][6], tdbox[n][7],
374 tdbxlb[n], 14);
375
376
377 switch (n) { /* final text - overlays above stuff */
378
379 case 0: /* keys 0..23 */
380
381 for (i = 0; i < 24; i++) {
382
383 tsplot4(tunob, 64, TDLABEL, i, 1, tdlabl[i], 14);
384 sprintf(bfs, "%2d", 1 + i);
385 tsplot4(tunob, 64, TDMKEYC, i, 3, bfs, 14);
386 dsttval(i, 6, tuntab[i],
387 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
388 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
389 }
390
391 return;
392
393 case 1: /* keys 24..47 */
394
395 for (i = 24; i < 48; i++) {
396
397 sprintf(bfs, "%2d", 1 + i);
398 tsplot4(tunob, 64, TDMKEYC, i - 24, 13, bfs, 14);
399 dsttval(i - 24, 16, tuntab[i],
400 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
401 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
402 }
403
404 return;
405
406 case 2: /* keys 48..71 */
407
408 for (i = 48; i < 72; i++) {
409
410 sprintf(bfs, "%2d", 1 + i);
411 tsplot4(tunob, 64, TDMKEYC, i - 48, 23, bfs, 14);
412 dsttval(i - 48, 26, tuntab[i],
413 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
414 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
415 }
416
417 return;
418
419 case 3: /* keys 72..95 */
420
421 for (i = 72; i < 96; i++) {
422
423 sprintf(bfs, "%2d", 1 + i);
424 tsplot4(tunob, 64, TDMKEYC, i - 72, 33, bfs, 14);
425 dsttval(i - 72, 36, tuntab[i],
426 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
427 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
428 }
429
430 return;
431
432 case 4: /* keys 96..119 */
433
434 for (i = 96; i < 120; i++) {
435
436 sprintf(bfs, "%3d", 1 + i);
437 tsplot4(tunob, 64, TDMKEYC, i - 96, 43, bfs, 14);
438 dsttval(i - 96, 47, tuntab[i],
439 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
440 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
441 }
442
443 return;
444
445 case 5: /* keys 120..127 */
446
447 for (i = 120; i < 128; i++) {
448
449 sprintf(bfs, "%3d", 1 + i);
450 tsplot4(tunob, 64, TDMKEYC, i - 120, 54, bfs, 14);
451 dsttval(i - 120, 58, tuntab[i],
452 ((tuntab[i] EQ 320) OR (tuntab[i] EQ 21920))
453 ? TDMKEYC : tdbox[n][4], tdbox[n][5]);
454 }
455
456 return;
457
458 case 6:
459
460 td_trcp(0);
461 td_incr(0);
462 td_intp(0);
463 tsplot4(tunob, 64, tdbox[n][4], 16, 54, "Undo", 14);
464
465 tv = (tunval GE 0 ? tunval : -tunval) >> 1;
466 ts = tunval GE 0 ? '+' : '-';
467 sprintf(bfs, "Val %c%04d", ts, tv);
468 tsplot4(tunob, 64, tdbox[n][4], 18, 54, bfs, 14);
469
470 tsplot4(tunob, 64, tdbox[n][4], 20, 54, "Store", 14);
471 tsplot4(tunob, 64, tdbox[n][4], 22, 54, "Retrieve", 14);
472
473 tsplot4(tunob, 64, tdbox[n][4], 24, 54, "Table #", 14);
474 bfs[0] = (int8_t)(curtun + '0');
475 bfs[1] = '\0';
476 tsplot4(tunob, 64, tunmod ? TDCHGD : tdbox[n][4],
477 24, 61, bfs, 14);
478
479 return;
480
481 case 7: /* tuning table name */
482
483 tsplot4(tunob, 64, tdbox[n][4], 24, 7, tuncurn, 14);
484 return;
485 }
486}
487
488/*
489 =============================================================================
490 twins() -- display all tuning editor windows
491 =============================================================================
492*/
493
494void twins(void)
495{
496 register int16_t i;
497
498 for (i = 0; i < 8; i++)
499 tdswin(i);
500}
501
502/*
503 =============================================================================
504 tundsp() -- put up the tuning display
505 =============================================================================
506*/
507
508void tundsp(void)
509{
510 tunob = &v_score[0]; /* setup object pointer */
511 obj0 = &v_curs0[0]; /* setup cursor object pointer */
512 obj2 = &v_tcur[0]; /* setup typewriter object pointer */
513 tdoct = &v_obtab[TUNOBJ]; /* setup object control table pointer */
514
515 ttcmdsv = 0; /* nothing selected */
516 tdnamsw = FALSE;
517 submenu = FALSE;
518
519 dswap(); /* initialize display */
520
521 if (v_regs[5] & 0x0180)
522 vbank(0);
523
524 memsetw(tunob, 0, 32767); /* clear the display */
525 memsetw(tunob+32767L, 0, 12033);
526
527 SetObj(TUNOBJ, 0, 0, tunob, 512, 350, 0, 0, TUNFL, -1);
528 SetObj( 0, 0, 1, obj0, 16, 16, TDCURX, TDCURY, OBFL_00, -1);
529 SetObj(TTCURS, 0, 1, obj2, 16, 16, 0, 0, TTCCFL, -1);
530
531 arcurs(TDCURSR); /* setup arrow cursor object */
532 itcini(TDCURSR); /* setup text cursor object */
533 ttcini(TDTCURC); /* setup typewriter cursor object */
534
535 twins();
536
537 SetPri(TUNOBJ, TUNPRI);
538
539 settc(YTOR(TDCURY), XTOC(TDCURX)); /* display the text cursor */
540
541 vsndpal(tunpal);
542}
543
Note: See TracBrowser for help on using the repository browser.