source: buchla-68k/orig/RAM/INITI.C@ 0170798

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

Imported original source code.

  • Property mode set to 100755
File size: 13.7 KB
Line 
1/*
2 =============================================================================
3 initi.c -- MIDAS-VII - instrument editor support functions
4 Version 2 -- 1989-12-19 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGPS 0 /* define non-zero to debug pntsel() */
9
10#include "stddefs.h"
11#include "fpu.h"
12#include "hwdefs.h"
13#include "vsdd.h"
14#include "graphdef.h"
15
16#include "midas.h"
17#include "instdsp.h"
18
19extern int setipl();
20
21extern unsigned tofpu(), fromfpu();
22
23extern short s_inst[], vce2trg[], vce2grp[];
24
25extern short curfunc; /* current function number */
26extern short curinst; /* current instrument number */
27extern short curpnt; /* current point number (absolute) */
28extern short curvce; /* current voice number */
29extern short cxval; /* graphics cursor x value */
30extern short editsw; /* edit mode switch */
31extern short initcfg; /* initialization cfg value */
32extern short npts; /* number of points in function */
33extern short pecase; /* point edit case variable */
34extern short pntsv; /* point selection state variable */
35extern short subj; /* edited point number (relative) */
36extern short temax; /* time upper limit */
37extern short temin; /* time lower limit */
38
39extern char *funcndx[256][2]; /* function header pointers */
40
41extern short idbox[][8]; /* display box parameters */
42extern short instmod[12]; /* intrument data modified */
43
44extern short fnoff[]; /* instrument fn to FPU fn table */
45
46extern struct instpnt *pntptr; /* pointer to edited point */
47
48extern struct instdef idefs[NINST]; /* current instrument definitions */
49extern struct instdef vbufs[12]; /* voice instrument buffers */
50
51/*
52
53*/
54
55#include "dfltins.h" /* short dfltins[]; default instrument */
56#include "ptoftab.h" /* short ptoftab[]; pitch to frequency table */
57
58short finival[NFINST] = { /* initial function values */
59
60 FPUVAL(500), /* 0: Freq 1 */
61 FPUVAL(500), /* 1: Freq 2 */
62 FPUVAL(500), /* 2: Freq 3 */
63 FPUVAL(500), /* 3: Freq 4 */
64 FPUVAL(500), /* 4: Filter / Resonance */
65 FPUVAL(500), /* 5: Location */
66
67 FPUVAL(0), /* 6: Index 1 */
68 FPUVAL(0), /* 7: Index 2 */
69 FPUVAL(0), /* 8: Index 3 */
70 FPUVAL(0), /* 9: Index 4 */
71 FPUVAL(0), /* 10: Index 5 */
72 FPUVAL(0), /* 11: Index 6 */
73
74 FPUVAL(0) /* 12: Level */
75};
76
77short expbit[16] = { /* FPU time exponent bit expansion table */
78
79 0x0001, /* 0 */
80 0x0002, /* 1 */
81 0x0004, /* 2 */
82 0x0008, /* 3 */
83 0x0010, /* 4 */
84 0x0020, /* 5 */
85 0x0040, /* 6 */
86 0x0080, /* 7 */
87 0x0100, /* 8 */
88 0x0200, /* 9 */
89 0x0400, /* 10 */
90 0x0800, /* 11 */
91 0x1000, /* 12 */
92 0x2000, /* 13 */
93 0x4000, /* 14 */
94 0x8000 /* 15 */
95};
96
97/*
98
99*/
100
101/*
102 =============================================================================
103 segtime() -- determine time to a point using a new segment time
104 =============================================================================
105*/
106
107short
108segtime(pn, ptime)
109short pn;
110unsigned ptime;
111{
112 register struct instpnt *pp;
113 register short i;
114 register unsigned tacc;
115
116 pp = &vbufs[curvce].idhpnt[vbufs[curvce].idhfnc[curfunc].idfpt1];
117 tacc = 0;
118
119 for (i = 0; i < pn; i++)
120 tacc += fromfpu(pp++->iptim);
121
122 tacc += fromfpu(ptime);
123
124 return(tacc);
125}
126
127/*
128 =============================================================================
129 setseg() -- set the time to a segment
130 =============================================================================
131*/
132
133setseg(pn, ptime)
134short pn;
135unsigned ptime;
136{
137 register short i;
138 register unsigned tacc;
139 register struct instpnt *pp;
140
141 pp = &vbufs[curvce].idhpnt[vbufs[curvce].idhfnc[curfunc].idfpt1];
142 tacc = 0;
143
144 for (i = 0; i < pn; i++)
145 tacc += fromfpu(pp++->iptim);
146
147 pp->iptim = tofpu(ptime - tacc);
148}
149
150/*
151
152*/
153
154/*
155 =============================================================================
156 timeto() -- find the time at a point in a function
157 =============================================================================
158*/
159
160short
161timeto(fn, pj)
162short fn, pj;
163{
164 register struct instdef *ip;
165 register struct instpnt *pt;
166 register short tf, pm, pn;
167
168 ip = &vbufs[curvce];
169 pn = ip->idhfnc[fn].idfpt1;
170 pt = &ip->idhpnt[pn];
171 pm = pn + pj;
172 tf = 0;
173
174 while (pn LE pm) {
175
176 tf += fromfpu(pt->iptim);
177 ++pt;
178 ++pn;
179 }
180
181 return(tf);
182}
183
184/*
185
186*/
187
188/*
189 =============================================================================
190 pntsel() -- setup editing limits for subj in the current function
191 =============================================================================
192*/
193
194pntsel()
195{
196 register struct idfnhdr *fp;
197
198 fp = &vbufs[curvce].idhfnc[curfunc];
199
200 curpnt = fp->idfpt1 + subj;
201 pntptr = &vbufs[curvce].idhpnt[curpnt];
202
203 npts = fp->idfpif;
204
205 if (npts EQ 1) { /* detemine editing case */
206
207 pecase = 0; /* single point */
208 temin = 1;
209 temax = 32767;
210
211 } else if (subj EQ (npts - 1)) {
212
213 pecase = 1; /* last point */
214 temin = timeto(curfunc, subj - 1);
215 temax = 32767;
216
217 } else {
218
219 pecase = 2; /* interior point */
220 temin = timeto(curfunc, subj - 1);
221 temax = timeto(curfunc, subj + 1);
222 }
223
224#if DEBUGPS
225 printf("pntsel(): curpnt=%d, subj=%d, fp=0x%08lx, pntptr=0x%08lx\r\n",
226 curpnt, subj, fp, pntptr);
227 printf("pntsel(): npts=%d, pecase=%d, temin=%d, temax=%d\r\n",
228 npts, pecase, temin, temax);
229#endif
230}
231
232/*
233
234*/
235
236/*
237 =============================================================================
238 vtoy() -- convert a value to a y coordinate for display
239 =============================================================================
240*/
241
242short
243vtoy(val, window)
244short val, window;
245{
246 register short yval;
247
248 if (val GT 1000)
249 val = 1000;
250
251 yval = 56 + (((1000 - val) * 14) / 100);
252
253 if (window < 12)
254 return((short)(idbox[window][1] + (((yval - 56) * 100L) / 540L)));
255 else
256 return(yval);
257}
258
259/*
260
261*/
262
263/*
264 =============================================================================
265 ttox() -- convert a time to an x coordinate for display
266 =============================================================================
267*/
268
269short
270ttox(time, window)
271unsigned time;
272short window;
273{
274 register short xval;
275
276 if (time < 128) /* 0..127 */
277 xval = 8 + (short)(((time * 1000L) / 2309L));
278 else if (time < 256) /* 128..255 */
279 xval = 64 + (short)((((time - 128) * 1000L) / 2309L));
280 else if (time < 512) /* 256..511 */
281 xval = 120 + (short)((((time - 256) * 1000L) / 4636L));
282 else if (time < 1024) /* 512..1023 */
283 xval = 176 + (short)((((time - 512) * 1000L) / 9290L));
284 else if (time < 2048) /* 1024..2047 */
285 xval = 232 + (short)((((time - 1024) * 1000L) / 18600L));
286 else if (time < 4096) /* 2048..4095 */
287 xval = 288 + (short)((((time - 2048) * 1000L) / 37218L));
288 else if (time < 8192) /* 4096..8191 */
289 xval = 344 + (short)((((time - 4096) * 1000L)/ 74454L));
290 else if (time < 16384) /* 8192..16383 */
291 xval = 400 + (short)((((time - 8192) * 1000L) / 148927L));
292 else if (time < (unsigned)32768) /* 16384..32767 */
293 xval = 456 + (short)((((time - 16384) * 1000L) / 309113L));
294 else
295 xval = 509;
296
297 if (xval > 509)
298 xval = 509;
299
300 if (window < 12)
301 return((short)(idbox[window][0] + (((xval - 8) * 100L) / 599L)));
302 else
303 return(xval);
304}
305
306/*
307
308*/
309
310/*
311 =============================================================================
312 selpnt() -- select a point for editing
313 =============================================================================
314*/
315
316short
317selpnt()
318{
319 register struct idfnhdr *fp;
320
321 register short i, xv, np;
322
323 short lo_x, lo_x_pt, hi_x, hi_x_pt;
324
325 fp = &vbufs[curvce].idhfnc[curfunc];
326 np = fp->idfpif;
327 lo_x_pt = 0;
328 lo_x = ttox(timeto(curfunc, lo_x_pt), 12);
329 hi_x_pt = np - 1;
330 hi_x = ttox(timeto(curfunc, hi_x_pt), 12);
331
332 for (i = 0; i < np; i++) {
333
334 xv = ttox(timeto(curfunc, i), 12);
335
336 if (xv LE cxval) /* largest x LE cxval */
337 if (xv GE lo_x) {
338
339 lo_x = xv;
340 lo_x_pt = i;
341 }
342
343 if (xv GE cxval) /* smallest x GE cxval*/
344 if (xv LT hi_x) {
345
346 hi_x = xv;
347 hi_x_pt = i;
348 }
349 }
350
351 if (lo_x EQ hi_x)
352 return(lo_x_pt);
353
354 if ((cxval - lo_x) LT (hi_x - cxval))
355 return(lo_x_pt);
356 else
357 return(hi_x_pt);
358}
359
360/*
361
362*/
363
364/*
365 =============================================================================
366 setinst() -- setup for editing a new instrument
367 =============================================================================
368*/
369
370setinst()
371{
372 register struct instdef *ip;
373 register struct idfnhdr *fp;
374
375 curfunc = 12; /* current function = 12 = level */
376 subj = 0; /* current edited point = 0 (first point) */
377 pntsv = 0; /* point selection state = unselected */
378 pecase = 0; /* point selection case = 0 (first point) */
379
380 ip = &vbufs[curvce]; /* instrument definition pointer */
381 fp = &ip->idhfnc[curfunc]; /* function pointer */
382
383 curpnt = subj + fp->idfpt1; /* current point in function */
384 pntptr = &ip->idhpnt[curpnt]; /* current point pointer */
385
386 newws(); /* setup waveshape variables */
387}
388
389/*
390
391*/
392
393/*
394 =============================================================================
395 newinst() -- select a new instrument
396 =============================================================================
397*/
398
399newinst(inst)
400short inst;
401{
402 curinst = inst;
403 s_inst[curvce] = inst;
404 setinst();
405}
406
407/*
408 =============================================================================
409 newvce() -- select a new voice
410 =============================================================================
411*/
412
413newvce(voice)
414short voice;
415{
416 curvce = voice;
417 curinst = s_inst[curvce];
418 setinst();
419}
420
421/*
422
423*/
424
425/*
426 =============================================================================
427 setivce() -- set instrument definition for a voice
428 =============================================================================
429*/
430
431setivce(voice)
432short voice;
433{
434 register short i, j, k, oldi;
435 register struct instdef *ip;
436
437 ip = &vbufs[voice];
438
439 oldi = setipl(FPU_DI); /* disable FPU interrupts */
440
441/* +++++++++++++++++++++++ FPU interrupts disabled ++++++++++++++++++++++++++ */
442
443 for (j = 0; j < NFINST; j++) { /* set funcndx[] entries */
444
445 k = (voice << 4) + fnoff[j];
446 funcndx[k][0] = &ip->idhfnc[j];
447 funcndx[k][1] = ip->idhpnt;
448 }
449
450 /* set waveshapes */
451
452 memcpyw((io_fpu + FPU_OWST + (voice << 9) + 0x0100 + 1),
453 ip->idhwvaf, NUMWPNT);
454
455 memcpyw((io_fpu + FPU_OWST + (voice << 9) + 1),
456 ip->idhwvbf, NUMWPNT);
457
458 setipl(oldi); /* restore interrupts */
459
460/* ++++++++++++++++++++++++++ Interrupts restored +++++++++++++++++++++++++++ */
461
462 instmod[voice] = FALSE; /* instrument matches library */
463}
464
465/*
466
467*/
468
469/*
470 =============================================================================
471 modinst() -- handle instrument modifications
472 =============================================================================
473*/
474
475modinst()
476{
477 short f, i, grp, oldi;
478
479 if (NOT instmod[curvce]) {
480
481 instmod[curvce] = TRUE;
482 dswin(19);
483 }
484
485 if (NOT editsw) {
486
487 if ((grp = vce2grp[curvce]) > 0) {
488
489 oldi = setipl(FPU_DI); /* +++++ disable FPU interrupts */
490
491 for (i = 0; i < 12; i++) {
492
493 if (vce2grp[i] EQ grp) {
494
495 memcpyw(&vbufs[i], &vbufs[curvce],
496 sizeof (struct instdef) / 2);
497
498 for (f = 0; f < 12; f++)
499 vbufs[i].idhfnc[f].idftmd
500 &= ~I_ACTIVE;
501
502 s_inst[i] = curinst;
503 clrvce(i);
504 setivce(i);
505 dosync(i);
506 execkey(0, 0, i, 1);
507 vce2trg[i] = -1;
508 }
509 }
510
511 setipl(oldi); /* +++++ enable FPU interrupts */
512 }
513 }
514}
515
516/*
517
518*/
519
520/*
521 =============================================================================
522 initi() -- initialize an instrument definition
523 =============================================================================
524*/
525
526initi(ip)
527register struct instdef *ip;
528{
529 register short i, mintfpu, rb;
530
531 memsetw(ip, 0, sizeof (struct instdef) / 2);
532
533 memcpy(ip->idhname, " ", MAXIDLN+1);
534 memcpy(ip->idhcom1, " ", MAXIDLN+1);
535 memcpy(ip->idhcom2, " ", MAXIDLN+1);
536 memcpy(ip->idhcom3, " ", MAXIDLN+1);
537
538 ip->idhplft = NIPNTS - NFINST;
539 ip->idhcfg = (initcfg >> 8) & 0x00FF;
540 mintfpu = tofpu(1);
541
542 for (i = 0; i < NFINST; i++) { /* for each function ... */
543
544 /* initialize the function header */
545
546 rb = ((i < 4) AND (i NE 0)) ? 0 : I_NRATIO;
547 ip->idhfnc[i].idfpif = 1;
548 ip->idhfnc[i].idfpt1 = i;
549 ip->idhfnc[i].idftmd = (I_TM_KEY | 0x0010) | rb;
550
551 /* initialize the first point in the function */
552
553 ip->idhpnt[i].iptim = mintfpu;
554 ip->idhpnt[i].ipval = finival[i];
555 }
556
557 for (i = 0; i < NUMWPNT; i++) {
558
559 ip->idhwvaf[i] = (ip->idhwvao[i] = 0x8000 ^ ((i + 1) << 8));
560 ip->idhwvbf[i] = (ip->idhwvbo[i] = 0x8000 ^ ((i + 1) << 8));
561 }
562}
563
564/*
565
566*/
567
568/*
569 =============================================================================
570 initil() -- initialize instrument library
571 =============================================================================
572*/
573
574initil()
575{
576 register short i;
577
578 setipl(FPU_DI); /* disable FPU interrupts */
579
580/* +++++++++++++++++++++++ FPU interrupts disabled ++++++++++++++++++++++++++ */
581
582 fpuclr(); /* clear the FPU */
583
584 memcpyw(&idefs[0], dfltins, sizeof (struct instdef) / 2);
585
586 for (i = 1; i < NINST; i++) /* initialize each instrument */
587 initi(&idefs[i]);
588
589 memset(funcndx, 0, sizeof funcndx);
590
591 for (i = 0; i < 12; i++) { /* initialize voices */
592
593 memcpyw(&vbufs[i], &idefs[0], sizeof (struct instdef) / 2);
594 setivce(i);
595 }
596
597 setipl(FPU_EI); /* enable FPU interrupts */
598
599/* ++++++++++++++++++++++++++ Interrupts enabled ++++++++++++++++++++++++++++ */
600
601 newvce(0); /* setup editing for instrument 0, voice 0 */
602 newinst(0);
603}
604
Note: See TracBrowser for help on using the repository browser.