source: buchla-68k/ram/scread.c@ 0c834c5

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

Prototypes for global function pointers. Consistent global types.

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