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

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

Zero redundant declarations.

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