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

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

Removed form-feed comments.

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