source: buchla-68k/orig/RAM/CHKSEC.C@ 4f508e6

Last change on this file since 4f508e6 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
RevLine 
[3ae31e9]1/*
2 =============================================================================
3 chksec.c -- section operation support functions
4 Version 18 -- 1988-07-16 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#undef DEBUGGER /* define to enable debug trace */
9
10#include "stddefs.h"
11#include "debug.h"
12#include "score.h"
13#include "scfns.h"
14#include "secops.h"
15#include "secdefs.h"
16
17extern short ancmsw;
18extern short grptran;
19
20extern short grpmode[];
21extern short grpstat[];
22extern short grptmap[];
23
24extern short varmode[][16];
25
26short cmslens[N_ETYPES] = { /* score event sizes for copy / merge */
27
28 0, /* 0 - EV_NULL not copied or merged */
29 0, /* 1 - EV_SCORE not copied or merged */
30 0, /* 2 - EV_SBGN not copied or merged */
31 0, /* 3 - EV_SEND not copied or merged */
32 6, /* 4 - EV_INST */
33 5, /* 5 - EV_NBEG */
34 5, /* 6 - EV_NEND */
35 5, /* 7 - EV_STOP */
36 5, /* 8 - EV_INTP */
37 6, /* 9 - EV_TMPO */
38 6, /* 10 - EV_TUNE */
39 6, /* 11 - EV_GRP */
40 6, /* 12 - EV_LOCN */
41 6, /* 13 - EV_DYN */
42 6, /* 14 - EV_ANVL */
43 6, /* 15 - EV_ANRS */
44 6, /* 16 - EV_ASGN */
45 6, /* 17 - EV_TRNS */
46 5, /* 18 - EV_REPT */
47 5, /* 19 - EV_PNCH */
48 5, /* 20 - EV_PRES */
49 0, /* 21 - EV_FINI not copied or merged */
50 5, /* 22 - EV_CPRS */
51 5, /* 23 - EV_BAR */
52 5 /* 24 - EV_NEXT */
53};
54
55/*
56
57*/
58
59char cmgtags[N_ETYPES] = { /* score event group sensitivity tags */
60
61 FALSE, /* 0 - EV_NULL not copied or merged */
62 FALSE, /* 1 - EV_SCORE not copied or merged */
63 FALSE, /* 2 - EV_SBGN not copied or merged */
64 FALSE, /* 3 - EV_SEND not copied or merged */
65 TRUE, /* 4 - EV_INST */
66 TRUE, /* 5 - EV_NBEG */
67 TRUE, /* 6 - EV_NEND */
68 FALSE, /* 7 - EV_STOP */
69 FALSE, /* 8 - EV_INTP */
70 FALSE, /* 9 - EV_TMPO */
71 FALSE, /* 10 - EV_TUNE */
72 TRUE, /* 11 - EV_GRP */
73 TRUE, /* 12 - EV_LOCN */
74 TRUE, /* 13 - EV_DYN */
75 TRUE, /* 14 - EV_ANVL */
76 TRUE, /* 15 - EV_ANRS */
77 FALSE, /* 16 - EV_ASGN */
78 TRUE, /* 17 - EV_TRNS */
79 FALSE, /* 18 - EV_REPT */
80 FALSE, /* 19 - EV_PNCH */
81 FALSE, /* 20 - EV_PRES */
82 FALSE, /* 21 - EV_FINI not copied or merged */
83 TRUE, /* 22 - EV_CPRS */
84 FALSE, /* 23 - EV_BAR */
85 FALSE /* 24 - EV_NEXT */
86};
87
88/*
89
90*/
91
92char cmgtype[N_ETYPES] = { /* score event group types for copy / merge */
93
94 0, /* 0 - EV_NULL not copied or merged */
95 0, /* 1 - EV_SCORE not copied or merged */
96 0, /* 2 - EV_SBGN not copied or merged */
97 0, /* 3 - EV_SEND not copied or merged */
98 0, /* 4 - EV_INST */
99 1, /* 5 - EV_NBEG */
100 1, /* 6 - EV_NEND */
101 0, /* 7 - EV_STOP */
102 0, /* 8 - EV_INTP */
103 0, /* 9 - EV_TMPO */
104 0, /* 10 - EV_TUNE */
105 0, /* 11 - EV_GRP */
106 0, /* 12 - EV_LOCN */
107 0, /* 13 - EV_DYN */
108 0, /* 14 - EV_ANVL */
109 0, /* 15 - EV_ANRS */
110 0, /* 16 - EV_ASGN */
111 0, /* 17 - EV_TRNS */
112 0, /* 18 - EV_REPT */
113 0, /* 19 - EV_PNCH */
114 0, /* 20 - EV_PRES */
115 0, /* 21 - EV_FINI not copied or merged */
116 1, /* 22 - EV_CPRS */
117 0, /* 23 - EV_BAR */
118 0 /* 24 - EV_NEXT */
119};
120
121/*
122
123*/
124
125short ehdlist[N_ETYPES] = { /* hplist update type table */
126
127 -1, /* 0 - EV_NULL */
128 -1, /* 1 - EV_SCORE */
129 EH_SBGN, /* 2 - EV_SBGN */
130 EH_SEND, /* 3 - EV_SEND */
131 EH_INST, /* 4 - EV_INST */
132 -1, /* 5 - EV_NBEG */
133 -1, /* 6 - EV_NEND */
134 -1, /* 7 - EV_STOP */
135 EH_INTP, /* 8 - EV_INTP */
136 EH_TMPO, /* 9 - EV_TMPO */
137 EH_TUNE, /* 10 - EV_TUNE */
138 EH_GRP, /* 11 - EV_GRP */
139 EH_LOCN, /* 12 - EV_LOCN */
140 EH_DYN, /* 13 - EV_DYN */
141 -1, /* 14 - EV_ANVL */
142 EH_ANRS, /* 15 - EV_ANRS */
143 EH_ASGN, /* 16 - EV_ASGN */
144 EH_TRNS, /* 17 - EV_TRNS */
145 -1, /* 18 - EV_REPT */
146 -1, /* 19 - EV_PNCH */
147 -1, /* 20 - EV_PRES */
148 -1, /* 21 - EV_FINI */
149 -1, /* 22 - EV_CPRS */
150 -1, /* 23 - EV_BAR */
151 -1 /* 24 - EV_NEXT */
152};
153
154/*
155
156*/
157
158/*
159 =============================================================================
160 oktocm() -- see if an event is OK to copy or merge
161
162 returns:
163
164 TRUE OK to copy or merge
165 FALSE don't copy or merge
166 =============================================================================
167*/
168
169short
170oktocm(ep)
171register struct s_entry *ep;
172{
173 register short et, grp, mode;
174
175 et = 0x007F & ep->e_type; /* get event type */
176
177 if (0 EQ cmslens[et]) /* is this type not copied ? */
178 return(FALSE); /* return FALSE if so */
179
180 if (NOT cmgtags[et]) /* is it group sensitive ? */
181 return(TRUE); /* return TRUE if not */
182
183 /* get group number */
184
185 grp = 0x000F & (cmgtype[et] ? ep->e_data2 : ep->e_data1);
186
187 if (NOT grpstat[grp]) /* group enabled ? */
188 return(FALSE); /* can't do it if not */
189
190 if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) /* analog */
191 mode = ancmsw ?
192 varmode[0x0007 & (ep->e_data1 >> 4)][grp] :
193 (grptmap[grp] EQ -1 ? 0 : 2);
194 else /* other */
195 mode = grptmap[grp] EQ -1 ? 0 : 2;
196
197 /* return TRUE if in record mode */
198
199 return((mode EQ 2) ? TRUE : FALSE);
200}
201
202/*
203
204*/
205
206/*
207 =============================================================================
208 oktode() -- see if an non-note event is OK to delete
209
210 returns:
211
212 TRUE OK to delete
213 FALSE don't delete
214 =============================================================================
215*/
216
217short
218oktode(ep)
219register struct s_entry *ep;
220{
221 register short et, grp, mode;
222
223 et = 0x007F & ep->e_type; /* get event type */
224
225 if ((et EQ EV_NBEG) OR (et EQ EV_NEND)) /* don't delete notes */
226 return(FALSE);
227
228 if (NOT cmgtags[et]) /* is event group sensitive ? */
229 return(TRUE); /* return TRUE if not */
230
231 /* get group number */
232
233 grp = 0x000F & (cmgtype[et] ? ep->e_data2 : ep->e_data1);
234
235 if (NOT grpstat[grp]) /* enabled ? */
236 return(FALSE); /* can't do it if not */
237
238 if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) /* analog */
239 mode = ancmsw ?
240 varmode[7 & (ep->e_data1 >> 4)][grp] : grpmode[grp];
241 else /* other */
242 mode = grpmode[grp];
243
244 /* return TRUE if in record mode */
245
246 return((mode EQ 2) ? TRUE : FALSE);
247}
248
249/*
250
251*/
252
253/*
254 =============================================================================
255 oktodg() -- see if a note event is OK to delete
256
257 returns:
258
259 TRUE OK to delete
260 FALSE don't delete
261 =============================================================================
262*/
263
264short
265oktodg(ep)
266register struct s_entry *ep;
267{
268 register short et, grp;
269
270 et = 0x007F & ep->e_type; /* get event type */
271
272 if ((et NE EV_NBEG) AND /* is it a note begin ... */
273 (et NE EV_NEND)) /* ... or a note end ? */
274 return(FALSE); /* return FALSE if not */
275
276 grp = ep->e_data2; /* get group number */
277
278 if ((grpmode[grp] EQ 2) AND /* is group in record mode ... */
279 grpstat[grp]) /* ... and enabled ? */
280 return(TRUE); /* return TRUE if so */
281 else
282 return(FALSE); /* return FALSE if not */
283}
284
285/*
286
287*/
288
289/*
290 =============================================================================
291 chksec() -- check for a valid section
292
293 returns:
294
295 0 section OK (both ends found in proper order)
296 1 can't find the begin event
297 2 can't find the end event
298 3 section end occurs before section begin
299 =============================================================================
300*/
301
302short
303chksec(ns)
304register short ns;
305{
306 register struct s_entry *ep;
307
308 DB_ENTR("chksec");
309
310 /* find section beginning in seclist */
311
312 if (E_NULL EQ (p_sbgn = seclist[curscor][ns])) {
313
314 secopok = FALSE;
315 p_send = E_NULL;
316 DB_EXIT("chksec - 1");
317 return(1);
318 }
319
320 t_sbgn = p_sbgn->e_time; /* save section start time */
321
322/*
323
324*/
325 /* find section end by scanning hplist */
326
327 ep = hplist[curscor][EH_SEND];
328
329 while (ep) {
330
331 if (((ep->e_type & 0x007F) EQ EV_SEND) AND
332 (ep->e_data1 EQ ns))
333 break;
334
335 ep = ep->e_up;
336 }
337
338 if (E_NULL EQ (p_send = ep)) { /* error if not found */
339
340 secopok = FALSE;
341 DB_EXIT("chksec - 2");
342 return(2);
343 }
344
345 /* get section end and check that it occurs after section begin */
346
347 if (t_sbgn GE (t_send = ep->e_time)) {
348
349 secopok = FALSE;
350 DB_EXIT("chksec - 3");
351 return(3);
352 }
353
354 t_sect = 1 + t_send - t_sbgn; /* calculate section time */
355
356 DB_EXIT("chksec - 0");
357 return(0);
358}
359
360/*
361
362*/
363
364/*
365 =============================================================================
366 sizesec() -- find the size of a section
367
368 returns: number of storage units required
369
370 Assumes that the section passed chksec() and that p_sbgn and p_send
371 are valid. Fails badly if not.
372 =============================================================================
373*/
374
375long
376sizesec()
377{
378 register long ec;
379 register short et;
380 register struct s_entry *sbp, *sep;
381
382 DB_ENTR("sizesec");
383
384 ec = 0L; /* start with zero length */
385 sbp = p_sbgn->e_fwd; /* point to first event to copy */
386 sep = p_send; /* point at section end */
387
388 while (sbp NE sep) { /* scan up to section end ... */
389
390 et = 0x007F & sbp->e_type; /* get event type */
391
392 if (oktocm(sbp)) /* if it's one we want ... */
393 ec += cmslens[et]; /* ... add its length */
394
395 sbp = sbp->e_fwd; /* point at next event */
396 }
397
398#ifdef DEBUGGER
399 if (ec)
400 DB_CMNT("sizesec - non-null copy");
401 else
402 DB_CMNT("sizesec - null copy");
403#endif
404
405 DB_EXIT("sizesec");
406 return(ec); /* return number of longs required */
407}
408
409/*
410
411*/
412
413/*
414 =============================================================================
415 edelta() -- adjust times in events above 'btime' by 'delta'
416
417 ep pointer to event to start adjusting at
418 btime base time
419 delta adjustment factor added to event times
420 =============================================================================
421*/
422
423edelta(ep, btime, delta)
424register struct s_entry *ep;
425register long btime, delta;
426{
427 DB_ENTR("edelta");
428
429 while ((ep->e_type & 0x007F) NE EV_FINI) { /* for each event */
430
431 if (ep->e_time > btime) /* in range ? */
432 ep->e_time += delta; /* add delta */
433
434 ep = ep->e_fwd; /* point at next event */
435 }
436
437 DB_EXIT("edelta");
438}
439
440/*
441
442*/
443
444/*
445 =============================================================================
446 madjsec() -- make a time-adjusted section copy
447
448 Returns a pointer to the copy, or E_NULL if copy is empty.
449
450 sbp section begin pointer to section to copy
451 btime base time of copy
452
453 Copy is bi-linked on e_fwd/e_bak, E_NULL terminated.
454
455 Assumes that the section is complete and well ordered, and that
456 we have enough free events to make the copy. Fails badly if not.
457 =============================================================================
458*/
459
460struct s_entry *
461madjsec(sbp, btime)
462register struct s_entry *sbp;
463register long btime;
464{
465 short ns, nv;
466 register short grp, es, et;
467 register struct s_entry *ep, *np;
468 struct s_entry *cp;
469 register long sat;
470
471 DB_ENTR("madjsec");
472
473 np = ep = cp = E_NULL; /* initialize np, ep and cp */
474 ns = sbp->e_data1; /* get section number */
475 sat = sbp->e_time - btime; /* get section adjust time */
476 sbp = sbp->e_fwd; /* advance to first event to copy */
477
478/*
479
480*/
481
482 /* copy up to section end */
483
484 while (TRUE) {
485
486 et = sbp->e_type & 0x007F; /* get event type */
487
488 /* we're done when we see the section end */
489
490 if ((EV_SEND EQ et) AND (sbp->e_data1 EQ ns))
491 break;
492
493 if (oktocm(sbp)) { /* if event is copyable */
494
495 es = sbp->e_size; /* get event size */
496 np = e_alc(es); /* allocate event */
497 memcpyw(np, sbp, es << 1); /* make copy */
498
499 if (cmgtags[et]) { /* group sensitive ? */
500
501 grp = 0x000F & (cmgtype[et] ?
502 np->e_data2 : np->e_data1);
503
504 if ((et EQ EV_NBEG) OR (et EQ EV_NEND)) {
505
506 /* regroup */
507
508 np->e_data2 = (np->e_data2 & 0x00F0) |
509 grptmap[grp];
510
511 /* transpose */
512
513 nv = np->e_data1 + grptran;
514
515 if (nv > 127)
516 nv = 127;
517 else if (nv < 0)
518 nv = 0;
519
520 np->e_data1 = nv;
521
522 } else if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) {
523
524 /* regroup */
525
526 np->e_data1 = (np->e_data1 & 0x000F) |
527 (grptmap[grp] << 4);
528
529 } else {
530
531 /* regroup */
532
533 if (cmgtype[et])
534 np->e_data2 = (np->e_data2 & 0x00F0) |
535 grptmap[grp];
536 else
537 np->e_data1 = (np->e_data1 & 0x00F0) |
538 grptmap[grp];
539 }
540 }
541
542/*
543
544*/
545 if (ep) { /* if copy started */
546
547 ep->e_fwd = np; /* link new event to copy */
548
549 } else { /* first event in chain */
550
551 DB_CMNT("madjsec - making copy");
552 cp = np; /* start the copy chain */
553 }
554
555 np->e_bak = ep; /* link new event to previous one */
556 np->e_fwd = E_NULL; /* terminate the copy chain */
557 np->e_time -= sat; /* adjust the copied event time */
558 ep = np; /* point ep at new event */
559 }
560
561 sbp = sbp->e_fwd; /* point at next event to copy */
562 }
563
564 p_cbgn = cp; /* save address of start of copy */
565 p_cend = np; /* save address of end of copy */
566
567 if (cp) {
568
569 DB_CMNT("madjsec - copy made");
570 t_cbgn = cp->e_time; /* save start time of copy */
571 t_cend = np->e_time; /* save end time of copy */
572 }
573
574 DB_EXIT("madjsec");
575 return(cp); /* return start address of copy */
576}
577
578/*
579
580*/
581
582/*
583 =============================================================================
584 ehfix() -- put event headers in a copied section into hplist
585
586 cbp pointer to first event in copy
587 cep pointer to last event in copy
588 =============================================================================
589*/
590
591ehfix(cbp, cep)
592register struct s_entry *cbp, *cep;
593{
594 register short et;
595
596 for (;;) { /* for each event from cbp to cep ... */
597
598 et = 0x007F & cbp->e_type; /* get event type */
599
600 /* does event belong in hplist ? */
601
602 if (-1 NE ehdlist[et])
603 eh_ins(cbp, ehdlist[et]); /* if so, update hplist */
604
605 if (cbp EQ cep) /* see if we're done */
606 return; /* return if so */
607
608 cbp = cbp->e_fwd; /* advance to the next event */
609 }
610}
Note: See TracBrowser for help on using the repository browser.