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