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

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

Added missing includes and declarations.

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