source: buchla-68k/ram/chksec.c@ 6262b5c

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

Added include files for global functions and variables.

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