source: buchla-68k/ram/scread.c@ 2340de6

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

Zero redundant declarations.

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