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

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

Fix conversion warnings.

  • Property mode set to 100644
File size: 12.3 KB
RevLine 
[f40a309]1/*
2 =============================================================================
3 tundsp.c -- MIDAS tuning table editor
4 Version 23 -- 1988-11-28 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
[b28a12e]8#include "ram.h"
[e225e77]9
[f40a309]10#define TUN_VAL 100 /* default value for tunval in cents */
11
[7258c6a]12int16_t tunpal[16][3] = { /* color palette */
[f40a309]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 */
[7258c6a]33static int8_t dfltnam[] = "Local 3rds + MIDI 12 tone scale ";
[f40a309]34
[7258c6a]35int8_t *tdlabl[] = {
[f40a309]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
[7258c6a]48void gettun(int16_t n)
[f40a309]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
[7258c6a]62void puttun(int16_t n)
[f40a309]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
[7258c6a]75void inittt(int16_t n)
[f40a309]76{
[7258c6a]77 register int16_t i;
[f40a309]78
79 for (i = 0; i < 128; i++)
[9519422]80 tunlib[n][i] = ((i < 21) ? 160 : (i > 108) ? 10960 :
[f40a309]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
[0580615]96void inittl(void)
[f40a309]97{
[7258c6a]98 register int16_t i;
[f40a309]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
[7258c6a]114void tt_trcp(int16_t start, int16_t finish, int16_t dest)
[f40a309]115{
[7258c6a]116 register int16_t i;
117 register int32_t v;
[f40a309]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
[7258c6a]127 v = oldtun[i] + (int32_t)tunval; /* transpose */
[f40a309]128
[7258c6a]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;
[f40a309]133
[7258c6a]134 tuntab[dest++] = (int16_t)v; /* store the value */
[f40a309]135 }
136
137 } else {
138
139 for (i = start; ((i LE finish) AND (dest < 128)); i++) {
140
141 /* forward copy */
142
[7258c6a]143 v = oldtun[i] + (int32_t)tunval; /* transpose */
[f40a309]144
[7258c6a]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;
[f40a309]149
[7258c6a]150 tuntab[dest++] = (int16_t)v; /* store the value */
[f40a309]151 }
152 }
153
154 tunmod = TRUE;
155}
156
157/*
158 =============================================================================
159 tt_intp() -- interpolate tuning table values
160 =============================================================================
161*/
162
[7258c6a]163int16_t tt_intp(int16_t from, int16_t to)
[f40a309]164{
[7258c6a]165 register int16_t i, j, k, n;
166 register int32_t t;
[f40a309]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];
[7258c6a]183 t = (((int32_t)tuntab[to] - (int32_t)k) << 16) / n;
[f40a309]184 j = 1 + from;
185 n--;
186
187 for (i = 0; i < n ; i++)
[7258c6a]188 tuntab[j++] = (int16_t)((t * (1 + i)) >> 16) + k;
[f40a309]189
190 tunmod = TRUE;
191 return(SUCCESS);
192}
193
194/*
195 =============================================================================
196 tt_incr() -- increment tuning table values
197 =============================================================================
198*/
199
[7258c6a]200int16_t tt_incr(int16_t from, int16_t to)
[f40a309]201{
[7258c6a]202 register int16_t i;
203 register int32_t v;
[f40a309]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
[7258c6a]215 v = (int32_t)oldtun[from]; /* initial value */
[f40a309]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
[7258c6a]222 v += (int32_t)tunval; /* increment */
[f40a309]223
[7258c6a]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;
[f40a309]228
[7258c6a]229 tuntab[i] = (int16_t)v; /* store the value */
[f40a309]230 }
231
232 tunmod = TRUE;
233 return(SUCCESS);
234}
235
236/*
237 =============================================================================
238 td_trcp() -- display transpose select label
239 =============================================================================
240*/
241
[7258c6a]242void td_trcp(int16_t mode)
[f40a309]243{
[432327d]244 register int16_t cx;
[f40a309]245
[432327d]246 cx = mode ? TDSELD : tdbox[6][4];
[f40a309]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
[7258c6a]258void td_incr(int16_t mode)
[f40a309]259{
[432327d]260 register int16_t cx;
[f40a309]261
[432327d]262 cx = mode ? TDSELD : tdbox[6][4];
[f40a309]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
[7258c6a]273void td_intp(int16_t mode)
[f40a309]274{
[432327d]275 register int16_t cx;
[f40a309]276
[432327d]277 cx = mode ? TDSELD : tdbox[6][4];
[f40a309]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
[0580615]288void advtcur(void)
[f40a309]289{
[7258c6a]290 register int16_t newcol;
[f40a309]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
[0580615]312void bsptcur(void)
[f40a309]313{
[7258c6a]314 register int16_t newcol;
[f40a309]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
[432327d]336void dsttval(int16_t row, int16_t col, int16_t val, int16_t fg, int16_t bg)
[f40a309]337{
338 cnvc2p(bfs, (val >> 1));
339
[432327d]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');
[f40a309]345 bfs[5] = '\0';
346
347 vbank(0);
[432327d]348 vcputsv(tunob, 64, fg, bg, row, col, bfs, 14);
[f40a309]349}
350
351/*
352 =============================================================================
353 tdswin() -- display a window
354 =============================================================================
355*/
356
[7258c6a]357void tdswin(int16_t n)
[f40a309]358{
[432327d]359 uint16_t cx;
360 int16_t i, tv;
[7258c6a]361 int8_t ts;
[f40a309]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
[fa38804]376
[f40a309]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;
[fa38804]418
[f40a309]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;
[fa38804]457
[f40a309]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);
[432327d]474 bfs[0] = (int8_t)(curtun + '0');
[f40a309]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
[0580615]494void twins(void)
[f40a309]495{
[7258c6a]496 register int16_t i;
[f40a309]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
[0580615]508void tundsp(void)
[f40a309]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}
[6262b5c]543
Note: See TracBrowser for help on using the repository browser.