source: buchla-68k/ram/chksec.c@ 0c834c5

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

Point of no return.

  • Property mode set to 100644
File size: 13.0 KB
Line 
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 oktocm(struct s_entry *ep)
170{
171 register short et, grp, mode;
172
173 et = 0x007F & ep->e_type; /* get event type */
174
175 if (0 EQ cmslens[et]) /* is this type not copied ? */
176 return(FALSE); /* return FALSE if so */
177
178 if (NOT cmgtags[et]) /* is it group sensitive ? */
179 return(TRUE); /* return TRUE if not */
180
181 /* get group number */
182
183 grp = 0x000F & (cmgtype[et] ? ep->e_data2 : ep->e_data1);
184
185 if (NOT grpstat[grp]) /* group enabled ? */
186 return(FALSE); /* can't do it if not */
187
188 if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) /* analog */
189 mode = ancmsw ?
190 varmode[0x0007 & (ep->e_data1 >> 4)][grp] :
191 (grptmap[grp] EQ -1 ? 0 : 2);
192 else /* other */
193 mode = grptmap[grp] EQ -1 ? 0 : 2;
194
195 /* return TRUE if in record mode */
196
197 return((mode EQ 2) ? TRUE : FALSE);
198}
199
200/*
201
202*/
203
204/*
205 =============================================================================
206 oktode() -- see if an non-note event is OK to delete
207
208 returns:
209
210 TRUE OK to delete
211 FALSE don't delete
212 =============================================================================
213*/
214
215short oktode(struct s_entry *ep)
216{
217 register short et, grp, mode;
218
219 et = 0x007F & ep->e_type; /* get event type */
220
221 if ((et EQ EV_NBEG) OR (et EQ EV_NEND)) /* don't delete notes */
222 return(FALSE);
223
224 if (NOT cmgtags[et]) /* is event group sensitive ? */
225 return(TRUE); /* return TRUE if not */
226
227 /* get group number */
228
229 grp = 0x000F & (cmgtype[et] ? ep->e_data2 : ep->e_data1);
230
231 if (NOT grpstat[grp]) /* enabled ? */
232 return(FALSE); /* can't do it if not */
233
234 if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) /* analog */
235 mode = ancmsw ?
236 varmode[7 & (ep->e_data1 >> 4)][grp] : grpmode[grp];
237 else /* other */
238 mode = grpmode[grp];
239
240 /* return TRUE if in record mode */
241
242 return((mode EQ 2) ? TRUE : FALSE);
243}
244
245/*
246
247*/
248
249/*
250 =============================================================================
251 oktodg() -- see if a note event is OK to delete
252
253 returns:
254
255 TRUE OK to delete
256 FALSE don't delete
257 =============================================================================
258*/
259
260short oktodg(struct s_entry *ep)
261{
262 register short et, grp;
263
264 et = 0x007F & ep->e_type; /* get event type */
265
266 if ((et NE EV_NBEG) AND /* is it a note begin ... */
267 (et NE EV_NEND)) /* ... or a note end ? */
268 return(FALSE); /* return FALSE if not */
269
270 grp = ep->e_data2; /* get group number */
271
272 if ((grpmode[grp] EQ 2) AND /* is group in record mode ... */
273 grpstat[grp]) /* ... and enabled ? */
274 return(TRUE); /* return TRUE if so */
275 else
276 return(FALSE); /* return FALSE if not */
277}
278
279/*
280
281*/
282
283/*
284 =============================================================================
285 chksec() -- check for a valid section
286
287 returns:
288
289 0 section OK (both ends found in proper order)
290 1 can't find the begin event
291 2 can't find the end event
292 3 section end occurs before section begin
293 =============================================================================
294*/
295
296short chksec(short ns)
297{
298 register struct s_entry *ep;
299
300 DB_ENTR("chksec");
301
302 /* find section beginning in seclist */
303
304 if (E_NULL EQ (p_sbgn = seclist[curscor][ns])) {
305
306 secopok = FALSE;
307 p_send = E_NULL;
308 DB_EXIT("chksec - 1");
309 return(1);
310 }
311
312 t_sbgn = p_sbgn->e_time; /* save section start time */
313
314/*
315
316*/
317 /* find section end by scanning hplist */
318
319 ep = hplist[curscor][EH_SEND];
320
321 while (ep) {
322
323 if (((ep->e_type & 0x007F) EQ EV_SEND) AND
324 (ep->e_data1 EQ ns))
325 break;
326
327 ep = ep->e_up;
328 }
329
330 if (E_NULL EQ (p_send = ep)) { /* error if not found */
331
332 secopok = FALSE;
333 DB_EXIT("chksec - 2");
334 return(2);
335 }
336
337 /* get section end and check that it occurs after section begin */
338
339 if (t_sbgn GE (t_send = ep->e_time)) {
340
341 secopok = FALSE;
342 DB_EXIT("chksec - 3");
343 return(3);
344 }
345
346 t_sect = 1 + t_send - t_sbgn; /* calculate section time */
347
348 DB_EXIT("chksec - 0");
349 return(0);
350}
351
352/*
353
354*/
355
356/*
357 =============================================================================
358 sizesec() -- find the size of a section
359
360 returns: number of storage units required
361
362 Assumes that the section passed chksec() and that p_sbgn and p_send
363 are valid. Fails badly if not.
364 =============================================================================
365*/
366
367long sizesec(void)
368{
369 register long ec;
370 register short et;
371 register struct s_entry *sbp, *sep;
372
373 DB_ENTR("sizesec");
374
375 ec = 0L; /* start with zero length */
376 sbp = p_sbgn->e_fwd; /* point to first event to copy */
377 sep = p_send; /* point at section end */
378
379 while (sbp NE sep) { /* scan up to section end ... */
380
381 et = 0x007F & sbp->e_type; /* get event type */
382
383 if (oktocm(sbp)) /* if it's one we want ... */
384 ec += cmslens[et]; /* ... add its length */
385
386 sbp = sbp->e_fwd; /* point at next event */
387 }
388
389#ifdef DEBUGGER
390 if (ec)
391 DB_CMNT("sizesec - non-null copy");
392 else
393 DB_CMNT("sizesec - null copy");
394#endif
395
396 DB_EXIT("sizesec");
397 return(ec); /* return number of longs required */
398}
399
400/*
401
402*/
403
404/*
405 =============================================================================
406 edelta() -- adjust times in events above 'btime' by 'delta'
407
408 ep pointer to event to start adjusting at
409 btime base time
410 delta adjustment factor added to event times
411 =============================================================================
412*/
413
414void edelta(struct s_entry *ep, long btime, long delta)
415{
416 DB_ENTR("edelta");
417
418 while ((ep->e_type & 0x007F) NE EV_FINI) { /* for each event */
419
420 if (ep->e_time > btime) /* in range ? */
421 ep->e_time += delta; /* add delta */
422
423 ep = ep->e_fwd; /* point at next event */
424 }
425
426 DB_EXIT("edelta");
427}
428
429/*
430
431*/
432
433/*
434 =============================================================================
435 madjsec() -- make a time-adjusted section copy
436
437 Returns a pointer to the copy, or E_NULL if copy is empty.
438
439 sbp section begin pointer to section to copy
440 btime base time of copy
441
442 Copy is bi-linked on e_fwd/e_bak, E_NULL terminated.
443
444 Assumes that the section is complete and well ordered, and that
445 we have enough free events to make the copy. Fails badly if not.
446 =============================================================================
447*/
448
449struct s_entry *madjsec(struct s_entry *sbp, long btime)
450{
451 short ns, nv;
452 register short grp, es, et;
453 register struct s_entry *ep, *np;
454 struct s_entry *cp;
455 register long sat;
456
457 DB_ENTR("madjsec");
458
459 np = ep = cp = E_NULL; /* initialize np, ep and cp */
460 ns = sbp->e_data1; /* get section number */
461 sat = sbp->e_time - btime; /* get section adjust time */
462 sbp = sbp->e_fwd; /* advance to first event to copy */
463
464/*
465
466*/
467
468 /* copy up to section end */
469
470 while (TRUE) {
471
472 et = sbp->e_type & 0x007F; /* get event type */
473
474 /* we're done when we see the section end */
475
476 if ((EV_SEND EQ et) AND (sbp->e_data1 EQ ns))
477 break;
478
479 if (oktocm(sbp)) { /* if event is copyable */
480
481 es = sbp->e_size; /* get event size */
482 np = e_alc(es); /* allocate event */
483 memcpyw(np, sbp, es << 1); /* make copy */
484
485 if (cmgtags[et]) { /* group sensitive ? */
486
487 grp = 0x000F & (cmgtype[et] ?
488 np->e_data2 : np->e_data1);
489
490 if ((et EQ EV_NBEG) OR (et EQ EV_NEND)) {
491
492 /* regroup */
493
494 np->e_data2 = (np->e_data2 & 0x00F0) |
495 grptmap[grp];
496
497 /* transpose */
498
499 nv = np->e_data1 + grptran;
500
501 if (nv > 127)
502 nv = 127;
503 else if (nv < 0)
504 nv = 0;
505
506 np->e_data1 = nv;
507
508 } else if ((et EQ EV_ANRS) OR (et EQ EV_ANVL)) {
509
510 /* regroup */
511
512 np->e_data1 = (np->e_data1 & 0x000F) |
513 (grptmap[grp] << 4);
514
515 } else {
516
517 /* regroup */
518
519 if (cmgtype[et])
520 np->e_data2 = (np->e_data2 & 0x00F0) |
521 grptmap[grp];
522 else
523 np->e_data1 = (np->e_data1 & 0x00F0) |
524 grptmap[grp];
525 }
526 }
527
528/*
529
530*/
531 if (ep) { /* if copy started */
532
533 ep->e_fwd = np; /* link new event to copy */
534
535 } else { /* first event in chain */
536
537 DB_CMNT("madjsec - making copy");
538 cp = np; /* start the copy chain */
539 }
540
541 np->e_bak = ep; /* link new event to previous one */
542 np->e_fwd = E_NULL; /* terminate the copy chain */
543 np->e_time -= sat; /* adjust the copied event time */
544 ep = np; /* point ep at new event */
545 }
546
547 sbp = sbp->e_fwd; /* point at next event to copy */
548 }
549
550 p_cbgn = cp; /* save address of start of copy */
551 p_cend = np; /* save address of end of copy */
552
553 if (cp) {
554
555 DB_CMNT("madjsec - copy made");
556 t_cbgn = cp->e_time; /* save start time of copy */
557 t_cend = np->e_time; /* save end time of copy */
558 }
559
560 DB_EXIT("madjsec");
561 return(cp); /* return start address of copy */
562}
563
564/*
565
566*/
567
568/*
569 =============================================================================
570 ehfix() -- put event headers in a copied section into hplist
571
572 cbp pointer to first event in copy
573 cep pointer to last event in copy
574 =============================================================================
575*/
576
577void ehfix(struct s_entry *cbp, struct s_entry *cep)
578{
579 register short et;
580
581 for (;;) { /* for each event from cbp to cep ... */
582
583 et = 0x007F & cbp->e_type; /* get event type */
584
585 /* does event belong in hplist ? */
586
587 if (-1 NE ehdlist[et])
588 eh_ins(cbp, ehdlist[et]); /* if so, update hplist */
589
590 if (cbp EQ cep) /* see if we're done */
591 return; /* return if so */
592
593 cbp = cbp->e_fwd; /* advance to the next event */
594 }
595}
Note: See TracBrowser for help on using the repository browser.