source: buchla-68k/ram/scread.c@ 861ab45

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

Removed form-feed comments.

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