source: buchla-68k/orig/RAM/SCREAD.C@ 4f508e6

Last change on this file since 4f508e6 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

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