1 | /*
|
---|
2 | =============================================================================
|
---|
3 | scread.c -- librarian - read score functions
|
---|
4 | Version 15 -- 1988-08-02 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "graphdef.h"
|
---|
9 | #include "stddefs.h"
|
---|
10 | #include "stdio.h"
|
---|
11 | #include "score.h"
|
---|
12 | #include "scfns.h"
|
---|
13 | #include "vsdd.h"
|
---|
14 |
|
---|
15 | #include "midas.h"
|
---|
16 | #include "libdsp.h"
|
---|
17 |
|
---|
18 | extern int16_t scskip(FILE *fp, int16_t ns);
|
---|
19 |
|
---|
20 | extern int16_t rd_ec(FILE *fp, int8_t *to, int32_t len);
|
---|
21 | extern int16_t skp_ec(FILE *fp, int32_t len);
|
---|
22 | extern void clrlsel(void);
|
---|
23 | extern void ldermsg(int8_t *p1, int8_t *p2, int8_t *p3, uint16_t p4, uint16_t p5);
|
---|
24 | extern void ldwmsg(int8_t *line1, int8_t *line2, int8_t *line3, uint16_t fgcolor, uint16_t bgcolor);
|
---|
25 | extern void skperr(int16_t sn);
|
---|
26 |
|
---|
27 | extern int32_t schksum; /* score checksum */
|
---|
28 |
|
---|
29 | extern int16_t errno; /* system error number */
|
---|
30 | extern int16_t lderrsw; /* librarian error message switch */
|
---|
31 | extern int16_t lrasw; /* "Content" switch */
|
---|
32 |
|
---|
33 | extern int16_t ldmap[]; /* librarian gather-read map */
|
---|
34 |
|
---|
35 | extern struct s_entry *libsp; /* librarian score insert pointer */
|
---|
36 |
|
---|
37 | extern struct s_time stimes[N_SCORES][N_SECTS];
|
---|
38 |
|
---|
39 | /* |
---|
40 |
|
---|
41 | */
|
---|
42 |
|
---|
43 | /*
|
---|
44 | =============================================================================
|
---|
45 | scioerr() -- clear a partially built score after an I/O error
|
---|
46 | =============================================================================
|
---|
47 | */
|
---|
48 |
|
---|
49 | void scioerr(int16_t sn, struct s_entry *ep)
|
---|
50 | {
|
---|
51 | int8_t scid[40];
|
---|
52 | int8_t erms[40];
|
---|
53 |
|
---|
54 | if (E_NULL NE ep)
|
---|
55 | e_del(ep);
|
---|
56 |
|
---|
57 | sc_clr(sn);
|
---|
58 | clrlsel();
|
---|
59 |
|
---|
60 | sprintf(scid, " score %d", sn + 1);
|
---|
61 | sprintf(erms, " errno = %d", errno);
|
---|
62 |
|
---|
63 | ldermsg("Couldn't read", scid, erms,
|
---|
64 | LD_EMCF, LD_EMCB);
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*
|
---|
68 | =============================================================================
|
---|
69 | noevent() -- clear a partially built score after running out of space
|
---|
70 | =============================================================================
|
---|
71 | */
|
---|
72 |
|
---|
73 | void noevent(int16_t sn)
|
---|
74 | {
|
---|
75 | int8_t scid[24];
|
---|
76 |
|
---|
77 | sc_clr(sn);
|
---|
78 | clrlsel();
|
---|
79 |
|
---|
80 | sprintf(scid, " score %d", sn + 1);
|
---|
81 |
|
---|
82 | ldermsg("Couldn't read", scid, " Ran out of space",
|
---|
83 | LD_EMCF, LD_EMCB);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /* |
---|
87 |
|
---|
88 | */
|
---|
89 |
|
---|
90 | /*
|
---|
91 | =============================================================================
|
---|
92 | scread() -- read a score
|
---|
93 | =============================================================================
|
---|
94 | */
|
---|
95 |
|
---|
96 | int16_t scread(int16_t ns, FILE *fp)
|
---|
97 | {
|
---|
98 | register struct s_entry *ep;
|
---|
99 | register int16_t ehdr, go, sn;
|
---|
100 | int32_t nbr, nev;
|
---|
101 | int8_t etype;
|
---|
102 | int8_t scid[40];
|
---|
103 | int8_t erms[40];
|
---|
104 |
|
---|
105 | sn = ldmap[ns]; /* map the score */
|
---|
106 |
|
---|
107 | if (-1 EQ sn) { /* skip score if map = -1 */
|
---|
108 |
|
---|
109 | if (rd_ec(fp, &nbr, 4L)) { /* get length */
|
---|
110 |
|
---|
111 | skperr(ns);
|
---|
112 | return(FAILURE);
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (nbr EQ -1L) /* done if it's null */
|
---|
116 | return(SUCCESS);
|
---|
117 |
|
---|
118 | if (skp_ec(fp, 16L)) { /* skip the score name */
|
---|
119 |
|
---|
120 | skperr(ns);
|
---|
121 | return(FAILURE);
|
---|
122 | }
|
---|
123 |
|
---|
124 | return(scskip(fp, ns)); /* skip the rest of it */
|
---|
125 | }
|
---|
126 |
|
---|
127 | /* |
---|
128 |
|
---|
129 | */
|
---|
130 | go = TRUE;
|
---|
131 |
|
---|
132 | sprintf(scid, " Reading score %2d", ns + 1);
|
---|
133 | sprintf(erms, " as score %2d", sn + 1);
|
---|
134 |
|
---|
135 | ldwmsg(" Busy -- please stand by", scid, erms,
|
---|
136 | LCFBX10, LCBBX10);
|
---|
137 |
|
---|
138 | if (rd_ec(fp, &nbr, 4L)) { /* get number of longs required */
|
---|
139 |
|
---|
140 | scioerr(sn, 0L);
|
---|
141 | return(FAILURE);
|
---|
142 | }
|
---|
143 |
|
---|
144 | if (nbr EQ -1L) { /* see if it's a null score marker */
|
---|
145 |
|
---|
146 | return(SUCCESS);
|
---|
147 | }
|
---|
148 |
|
---|
149 | if (lrasw) /* clear target if in append mode */
|
---|
150 | sc_clr(sn);
|
---|
151 |
|
---|
152 | if (nbr > (nev = evleft())) { /* see if we have enough space */
|
---|
153 |
|
---|
154 | sprintf(scid, " score %d - no space", sn + 1);
|
---|
155 | sprintf(erms, " Need %ld, Have %ld", nbr, nev);
|
---|
156 |
|
---|
157 | ldermsg("Couldn't read", scid, erms,
|
---|
158 | LD_EMCF, LD_EMCB);
|
---|
159 |
|
---|
160 | return(FAILURE);
|
---|
161 | }
|
---|
162 |
|
---|
163 | if (rd_ec(fp, &scname[sn], 16L)) { /* score name */
|
---|
164 |
|
---|
165 | scioerr(sn, 0L);
|
---|
166 | return(FAILURE);
|
---|
167 | }
|
---|
168 |
|
---|
169 | if (rd_ec(fp, &stimes[sn], (int32_t)(N_SECTS * 12))) { /* section times */
|
---|
170 |
|
---|
171 | scioerr(sn, 0L);
|
---|
172 | return(FAILURE);
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (rd_ec(fp, &etype, 1L)) { /* read score header event */
|
---|
176 |
|
---|
177 | scioerr(sn, 0L);
|
---|
178 | return(FAILURE);
|
---|
179 | }
|
---|
180 |
|
---|
181 | if (etype NE EV_SCORE) { /* complain if it's not a score event */
|
---|
182 |
|
---|
183 | sprintf(scid, " score %d", sn + 1);
|
---|
184 |
|
---|
185 | ldermsg("Bad score --", " 1st event is wrong",
|
---|
186 | scid, LD_EMCF, LD_EMCB);
|
---|
187 |
|
---|
188 | return(FAILURE);
|
---|
189 | }
|
---|
190 |
|
---|
191 | if (E_NULL EQ (ep = e_alc(E_SIZE1))) { /* allocate header space */
|
---|
192 |
|
---|
193 | noevent(sn);
|
---|
194 | return(FAILURE);
|
---|
195 | }
|
---|
196 |
|
---|
197 | libsp = ep;
|
---|
198 | scores[sn] = ep;
|
---|
199 |
|
---|
200 | ep->e_type = EV_SCORE;
|
---|
201 |
|
---|
202 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
203 |
|
---|
204 | scioerr(sn, ep);
|
---|
205 | return(FAILURE);
|
---|
206 | }
|
---|
207 |
|
---|
208 | ep->e_fwd = ep;
|
---|
209 | ep->e_bak = ep;
|
---|
210 | /* |
---|
211 |
|
---|
212 | */
|
---|
213 | do {
|
---|
214 |
|
---|
215 | if (rd_ec(fp, &etype, 1L)) { /* get event type */
|
---|
216 |
|
---|
217 | scioerr(sn, 0L);
|
---|
218 | return(FAILURE);
|
---|
219 | }
|
---|
220 |
|
---|
221 | switch (etype) { /* process event entry */
|
---|
222 |
|
---|
223 | case EV_BAR: /* bar marker */
|
---|
224 | case EV_STOP: /* stop */
|
---|
225 | case EV_NEXT: /* next */
|
---|
226 |
|
---|
227 | if (E_NULL EQ (ep = e_alc(E_SIZE1))) {
|
---|
228 |
|
---|
229 | noevent(sn);
|
---|
230 | return(FAILURE);
|
---|
231 | }
|
---|
232 |
|
---|
233 | ep->e_type = etype;
|
---|
234 |
|
---|
235 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
236 |
|
---|
237 | scioerr(sn, ep);
|
---|
238 | return(FAILURE);
|
---|
239 | }
|
---|
240 |
|
---|
241 | libsp = e_ins(ep, libsp);
|
---|
242 | break;
|
---|
243 | /* |
---|
244 |
|
---|
245 | */
|
---|
246 | case EV_SBGN: /* section begin */
|
---|
247 |
|
---|
248 | ehdr = EH_SBGN;
|
---|
249 | goto doit1;
|
---|
250 |
|
---|
251 | case EV_SEND: /* section end */
|
---|
252 |
|
---|
253 | ehdr = EH_SEND;
|
---|
254 | goto doit1;
|
---|
255 |
|
---|
256 | case EV_TMPO: /* tempo */
|
---|
257 |
|
---|
258 | ehdr = EH_TMPO;
|
---|
259 | goto doit1;
|
---|
260 |
|
---|
261 | case EV_TUNE: /* tuning */
|
---|
262 |
|
---|
263 | ehdr = EH_TUNE;
|
---|
264 | goto doit1;
|
---|
265 |
|
---|
266 | case EV_ASGN: /* I/O assign */
|
---|
267 |
|
---|
268 | ehdr = EH_ASGN;
|
---|
269 | /* |
---|
270 |
|
---|
271 | */
|
---|
272 | doit1:
|
---|
273 |
|
---|
274 | if (E_NULL EQ (ep = e_alc(E_SIZE2))) {
|
---|
275 |
|
---|
276 | noevent(sn);
|
---|
277 | return(FAILURE);
|
---|
278 | }
|
---|
279 |
|
---|
280 | ep->e_type = etype;
|
---|
281 |
|
---|
282 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
283 |
|
---|
284 | scioerr(sn, ep);
|
---|
285 | return(FAILURE);
|
---|
286 | }
|
---|
287 |
|
---|
288 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
289 |
|
---|
290 | scioerr(sn, ep);
|
---|
291 | return(FAILURE);
|
---|
292 | }
|
---|
293 |
|
---|
294 | libsp = e_ins(ep, libsp);
|
---|
295 | eh_ins(ep, ehdr);
|
---|
296 |
|
---|
297 | if (etype EQ EV_SBGN)
|
---|
298 | seclist[sn][ep->e_data1] = ep;
|
---|
299 |
|
---|
300 | break;
|
---|
301 | /* |
---|
302 |
|
---|
303 | */
|
---|
304 | case EV_SCORE: /* score begin */
|
---|
305 | case EV_REPT: /* repeat */
|
---|
306 | case EV_PNCH: /* punch in/out */
|
---|
307 |
|
---|
308 | if (E_NULL EQ (ep = e_alc(E_SIZE1))) {
|
---|
309 |
|
---|
310 | noevent(sn);
|
---|
311 | return(FAILURE);
|
---|
312 | }
|
---|
313 |
|
---|
314 | ep->e_type = etype;
|
---|
315 |
|
---|
316 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
317 |
|
---|
318 | scioerr(sn, ep);
|
---|
319 | return(FAILURE);
|
---|
320 | }
|
---|
321 |
|
---|
322 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
323 |
|
---|
324 | scioerr(sn, ep);
|
---|
325 | return(FAILURE);
|
---|
326 | }
|
---|
327 |
|
---|
328 | libsp = e_ins(ep, libsp);
|
---|
329 | break;
|
---|
330 | /* |
---|
331 |
|
---|
332 | */
|
---|
333 | case EV_NBEG: /* note begin */
|
---|
334 | case EV_NEND: /* note end */
|
---|
335 |
|
---|
336 | if (E_NULL EQ (ep = e_alc(E_SIZE1))) {
|
---|
337 |
|
---|
338 | noevent(sn);
|
---|
339 | return(FAILURE);
|
---|
340 | }
|
---|
341 |
|
---|
342 | ep->e_type = etype;
|
---|
343 |
|
---|
344 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
345 |
|
---|
346 | scioerr(sn, ep);
|
---|
347 | return(FAILURE);
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
351 |
|
---|
352 | scioerr(sn, ep);
|
---|
353 | return(FAILURE);
|
---|
354 | }
|
---|
355 |
|
---|
356 | if (rd_ec(fp, &ep->e_data2, 1L)) {
|
---|
357 |
|
---|
358 | scioerr(sn, ep);
|
---|
359 | return(FAILURE);
|
---|
360 | }
|
---|
361 |
|
---|
362 | if (rd_ec(fp, &ep->e_dn, 2L)) {
|
---|
363 |
|
---|
364 | scioerr(sn, ep);
|
---|
365 | return(FAILURE);
|
---|
366 | }
|
---|
367 |
|
---|
368 | libsp = e_ins(ep, libsp);
|
---|
369 | break;
|
---|
370 | /* |
---|
371 |
|
---|
372 | */
|
---|
373 | case EV_PRES: /* polyphonic pressure */
|
---|
374 |
|
---|
375 | if (E_NULL EQ (ep = e_alc(E_SIZE1))) {
|
---|
376 |
|
---|
377 | noevent(sn);
|
---|
378 | return(FAILURE);
|
---|
379 | }
|
---|
380 |
|
---|
381 | ep->e_type = etype;
|
---|
382 |
|
---|
383 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
384 |
|
---|
385 | scioerr(sn, ep);
|
---|
386 | return(FAILURE);
|
---|
387 | }
|
---|
388 |
|
---|
389 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
390 |
|
---|
391 | scioerr(sn, ep);
|
---|
392 | return(FAILURE);
|
---|
393 | }
|
---|
394 |
|
---|
395 | if (rd_ec(fp, &ep->e_data2, 1L)) {
|
---|
396 |
|
---|
397 | scioerr(sn, ep);
|
---|
398 | return(FAILURE);
|
---|
399 | }
|
---|
400 |
|
---|
401 | libsp = e_ins(ep, libsp);
|
---|
402 | break;
|
---|
403 | /* |
---|
404 |
|
---|
405 | */
|
---|
406 | case EV_CPRS: /* channel pressure */
|
---|
407 |
|
---|
408 | if (E_NULL EQ (ep = e_alc(E_SIZE1))) {
|
---|
409 |
|
---|
410 | noevent(sn);
|
---|
411 | return(FAILURE);
|
---|
412 | }
|
---|
413 |
|
---|
414 | ep->e_type = etype;
|
---|
415 |
|
---|
416 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
417 |
|
---|
418 | scioerr(sn, ep);
|
---|
419 | return(FAILURE);
|
---|
420 | }
|
---|
421 |
|
---|
422 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
423 |
|
---|
424 | scioerr(sn, ep);
|
---|
425 | return(FAILURE);
|
---|
426 | }
|
---|
427 |
|
---|
428 | if (rd_ec(fp, &ep->e_data2, 1L)) {
|
---|
429 |
|
---|
430 | scioerr(sn, ep);
|
---|
431 | return(FAILURE);
|
---|
432 | }
|
---|
433 |
|
---|
434 | libsp = e_ins(ep, libsp);
|
---|
435 | break;
|
---|
436 |
|
---|
437 | /* |
---|
438 |
|
---|
439 | */
|
---|
440 | case EV_INST: /* instrument change */
|
---|
441 |
|
---|
442 | ehdr = EH_INST;
|
---|
443 | goto doit2;
|
---|
444 |
|
---|
445 | case EV_INTP: /* interpolate */
|
---|
446 |
|
---|
447 | ehdr = EH_INTP;
|
---|
448 | goto doit2;
|
---|
449 |
|
---|
450 | case EV_GRP: /* group status */
|
---|
451 |
|
---|
452 | ehdr = EH_GRP;
|
---|
453 | goto doit2;
|
---|
454 |
|
---|
455 | case EV_LOCN: /* location */
|
---|
456 |
|
---|
457 | ehdr = EH_LOCN;
|
---|
458 | goto doit2;
|
---|
459 |
|
---|
460 | case EV_DYN: /* dynamics */
|
---|
461 |
|
---|
462 | ehdr = EH_DYN;
|
---|
463 | goto doit2;
|
---|
464 |
|
---|
465 | case EV_ANRS: /* analog resolution */
|
---|
466 |
|
---|
467 | ehdr = EH_ANRS;
|
---|
468 | /* |
---|
469 |
|
---|
470 | */
|
---|
471 | doit2:
|
---|
472 |
|
---|
473 | if (E_NULL EQ (ep = e_alc(E_SIZE2))) {
|
---|
474 |
|
---|
475 | noevent(sn);
|
---|
476 | return(FAILURE);
|
---|
477 | }
|
---|
478 |
|
---|
479 | ep->e_type = etype;
|
---|
480 |
|
---|
481 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
482 |
|
---|
483 | scioerr(sn, ep);
|
---|
484 | return(FAILURE);
|
---|
485 | }
|
---|
486 |
|
---|
487 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
488 |
|
---|
489 | scioerr(sn, ep);
|
---|
490 | return(FAILURE);
|
---|
491 | }
|
---|
492 |
|
---|
493 | if (rd_ec(fp, &ep->e_data2, 1L)) {
|
---|
494 |
|
---|
495 | scioerr(sn, ep);
|
---|
496 | return(FAILURE);
|
---|
497 | }
|
---|
498 |
|
---|
499 | libsp = e_ins(ep, libsp);
|
---|
500 | eh_ins(ep, ehdr);
|
---|
501 | break;
|
---|
502 | /* |
---|
503 |
|
---|
504 | */
|
---|
505 | case EV_TRNS: /* transposition */
|
---|
506 |
|
---|
507 | if (E_NULL EQ (ep = e_alc(E_SIZE3))) {
|
---|
508 |
|
---|
509 | noevent(sn);
|
---|
510 | return(FAILURE);
|
---|
511 | }
|
---|
512 |
|
---|
513 | ep->e_type = etype;
|
---|
514 |
|
---|
515 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
516 |
|
---|
517 | scioerr(sn, ep);
|
---|
518 | return(FAILURE);
|
---|
519 | }
|
---|
520 |
|
---|
521 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
522 |
|
---|
523 | scioerr(sn, ep);
|
---|
524 | return(FAILURE);
|
---|
525 | }
|
---|
526 |
|
---|
527 | if (rd_ec(fp, &ep->e_lft, 2L)) {
|
---|
528 |
|
---|
529 | scioerr(sn, ep);
|
---|
530 | return(FAILURE);
|
---|
531 | }
|
---|
532 |
|
---|
533 | libsp = e_ins(ep, libsp);
|
---|
534 | eh_ins(ep, EH_INTP);
|
---|
535 | break;
|
---|
536 | /* |
---|
537 |
|
---|
538 | */
|
---|
539 | case EV_ANVL: /* analog value */
|
---|
540 |
|
---|
541 | if (E_NULL EQ (ep = e_alc(E_SIZE2))) {
|
---|
542 |
|
---|
543 | noevent(sn);
|
---|
544 | return(FAILURE);
|
---|
545 | }
|
---|
546 |
|
---|
547 | ep->e_type = etype;
|
---|
548 |
|
---|
549 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
550 |
|
---|
551 | scioerr(sn, ep);
|
---|
552 | return(FAILURE);
|
---|
553 | }
|
---|
554 |
|
---|
555 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
556 |
|
---|
557 | scioerr(sn, ep);
|
---|
558 | return(FAILURE);
|
---|
559 | }
|
---|
560 |
|
---|
561 | ep->e_dn = 0L;
|
---|
562 |
|
---|
563 | if (rd_ec(fp, &ep->e_dn, 2L)) {
|
---|
564 |
|
---|
565 | scioerr(sn, ep);
|
---|
566 | return(FAILURE);
|
---|
567 | }
|
---|
568 |
|
---|
569 | libsp = e_ins(ep, libsp);
|
---|
570 | break;
|
---|
571 | /* |
---|
572 |
|
---|
573 | */
|
---|
574 | case EV_FINI: /* score end */
|
---|
575 |
|
---|
576 | if (E_NULL EQ (ep = e_alc(E_SIZE1))) {
|
---|
577 |
|
---|
578 | noevent(sn);
|
---|
579 | return(FAILURE);
|
---|
580 | }
|
---|
581 |
|
---|
582 | ep->e_type = etype;
|
---|
583 |
|
---|
584 | if (rd_ec(fp, &ep->e_time, 4L)) {
|
---|
585 |
|
---|
586 | scioerr(sn, ep);
|
---|
587 | return(FAILURE);
|
---|
588 | }
|
---|
589 |
|
---|
590 | if (rd_ec(fp, &ep->e_data1, 1L)) {
|
---|
591 |
|
---|
592 | scioerr(sn, ep);
|
---|
593 | return(FAILURE);
|
---|
594 | }
|
---|
595 |
|
---|
596 | libsp = e_ins(ep, libsp);
|
---|
597 | go = FALSE;
|
---|
598 | }
|
---|
599 |
|
---|
600 | } while (go);
|
---|
601 |
|
---|
602 | return(SUCCESS);
|
---|
603 | }
|
---|