1 | /*
|
---|
2 | =============================================================================
|
---|
3 | scwrite.c -- librarian - write score functions
|
---|
4 | Version 14 -- 1988-06-22 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define DEBUGIT 0
|
---|
9 |
|
---|
10 | #include "stddefs.h"
|
---|
11 | #include "stdio.h"
|
---|
12 | #include "hwdefs.h"
|
---|
13 | #include "graphdef.h"
|
---|
14 | #include "vsdd.h"
|
---|
15 | #include "score.h"
|
---|
16 | #include "scfns.h"
|
---|
17 |
|
---|
18 | #include "midas.h"
|
---|
19 | #include "libdsp.h"
|
---|
20 |
|
---|
21 | #if DEBUGIT
|
---|
22 | extern short debugsw;
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | extern long chksum(char *area, long len);
|
---|
26 |
|
---|
27 | extern long schksum; /* score checksum */
|
---|
28 | extern long snbreq; /* number of disk bytes required */
|
---|
29 | extern long snlreq; /* number of score bytes required */
|
---|
30 | extern long sntbreq; /* total number of disk bytes required */
|
---|
31 | extern long sntlreq; /* total number of score bytes required */
|
---|
32 |
|
---|
33 | extern long nlpersc[N_SCORES]; /* number of longs per score */
|
---|
34 | extern long scsums[N_SCORES]; /* score checksums */
|
---|
35 |
|
---|
36 | extern struct s_time stimes[N_SCORES][N_SECTS]; /* section times */
|
---|
37 |
|
---|
38 | /* |
---|
39 |
|
---|
40 | */
|
---|
41 |
|
---|
42 | long m1con = -1L; /* null score constant */
|
---|
43 |
|
---|
44 | short scsizes[N_ETYPES][2] = { /* score event sizes (in bytes) */
|
---|
45 |
|
---|
46 | /* [0] = score, [1] = disk */
|
---|
47 |
|
---|
48 | {20, 0}, /* 0 - EV_NULL */
|
---|
49 | {20, 6}, /* 1 - EV_SCORE */
|
---|
50 | {24, 6}, /* 2 - EV_SBGN */
|
---|
51 | {24, 6}, /* 3 - EV_SEND */
|
---|
52 | {24, 7}, /* 4 - EV_INST */
|
---|
53 | {20, 9}, /* 5 - EV_NBEG */
|
---|
54 | {20, 9}, /* 6 - EV_NEND */
|
---|
55 | {20, 5}, /* 7 - EV_STOP */
|
---|
56 | {20, 7}, /* 8 - EV_INTP */
|
---|
57 | {24, 6}, /* 9 - EV_TMPO */
|
---|
58 | {24, 6}, /* 10 - EV_TUNE */
|
---|
59 | {24, 7}, /* 11 - EV_GRP */
|
---|
60 | {24, 7}, /* 12 - EV_LOCN */
|
---|
61 | {24, 7}, /* 13 - EV_DYN */
|
---|
62 | {24, 8}, /* 14 - EV_ANVL */
|
---|
63 | {24, 7}, /* 15 - EV_ANRS */
|
---|
64 | {24, 6}, /* 16 - EV_ASGN */
|
---|
65 | {32, 8}, /* 17 - EV_TRNS */
|
---|
66 | {20, 6}, /* 18 - EV_REPT */
|
---|
67 | {20, 6}, /* 19 - EV_PNCH */
|
---|
68 | {20, 7}, /* 20 - EV_PRES */
|
---|
69 | {20, 6}, /* 21 - EV_FINI */
|
---|
70 | {20, 7}, /* 22 - EV_CPRS */
|
---|
71 | {20, 5}, /* 23 - EV_BAR */
|
---|
72 | {20, 5} /* 24 - EV_NEXT */
|
---|
73 | };
|
---|
74 |
|
---|
75 | /* |
---|
76 |
|
---|
77 | */
|
---|
78 |
|
---|
79 | /*
|
---|
80 | =============================================================================
|
---|
81 | scsize() -- return number of bytes needed for a score
|
---|
82 | =============================================================================
|
---|
83 | */
|
---|
84 |
|
---|
85 | long scsize(short sn)
|
---|
86 | {
|
---|
87 | register long nb, nl, sc;
|
---|
88 | register struct s_entry *ep;
|
---|
89 | register short go;
|
---|
90 |
|
---|
91 | snbreq = nb = 0L; /* number of disk bytes required */
|
---|
92 | snlreq = nl = 0L; /* number of score bytes required */
|
---|
93 | schksum = sc = 0L; /* score checksum */
|
---|
94 |
|
---|
95 | ep = scores[sn]; /* pointer to score begin */
|
---|
96 |
|
---|
97 | if (E_NULL EQ ep) { /* empty scores don't take any space */
|
---|
98 |
|
---|
99 | #if DEBUGIT
|
---|
100 | if (debugsw)
|
---|
101 | printf("scsize(%d): empty score\n", sn);
|
---|
102 | #endif
|
---|
103 | return(0L);
|
---|
104 | }
|
---|
105 |
|
---|
106 | go = TRUE;
|
---|
107 |
|
---|
108 | /* |
---|
109 |
|
---|
110 | */
|
---|
111 | do {
|
---|
112 | ep->e_type &= 0x7F; /* clear new-data flag */
|
---|
113 |
|
---|
114 | nl += scsizes[ep->e_type][0];
|
---|
115 | nb += scsizes[ep->e_type][1];
|
---|
116 |
|
---|
117 | switch (ep->e_type) {
|
---|
118 |
|
---|
119 | case EV_BAR: /* bar marker */
|
---|
120 | case EV_STOP: /* stop */
|
---|
121 | case EV_NEXT: /* next */
|
---|
122 |
|
---|
123 | sc += ep->e_type + ep->e_time;
|
---|
124 | break;
|
---|
125 |
|
---|
126 | case EV_SCORE: /* score begin */
|
---|
127 | case EV_SBGN: /* section begin */
|
---|
128 | case EV_SEND: /* section end */
|
---|
129 | case EV_TMPO: /* tempo */
|
---|
130 | case EV_TUNE: /* tuning */
|
---|
131 | case EV_ASGN: /* I/O assign */
|
---|
132 | case EV_REPT: /* repeat */
|
---|
133 | case EV_PNCH: /* punch in/out */
|
---|
134 |
|
---|
135 | sc += ep->e_type + ep->e_time + ep->e_data1;
|
---|
136 | break;
|
---|
137 |
|
---|
138 | case EV_NBEG: /* note begin */
|
---|
139 | case EV_NEND: /* note end */
|
---|
140 |
|
---|
141 | sc += ep->e_type + ep->e_time + ep->e_data1
|
---|
142 | + ep->e_data2 + ((struct n_entry *)ep)->e_vel;
|
---|
143 |
|
---|
144 | break;
|
---|
145 | /* |
---|
146 |
|
---|
147 | */
|
---|
148 | case EV_INST: /* instrument change */
|
---|
149 | case EV_INTP: /* interpolate */
|
---|
150 | case EV_GRP: /* group status */
|
---|
151 | case EV_LOCN: /* location */
|
---|
152 | case EV_DYN: /* dynamics */
|
---|
153 | case EV_PRES: /* polyphonic pressure */
|
---|
154 | case EV_CPRS: /* channel pressure */
|
---|
155 | case EV_ANRS: /* analog resolution */
|
---|
156 |
|
---|
157 | sc += ep->e_type + ep->e_time + ep->e_data1
|
---|
158 | + ep->e_data2;
|
---|
159 |
|
---|
160 | break;
|
---|
161 |
|
---|
162 | case EV_TRNS: /* transposition */
|
---|
163 |
|
---|
164 | sc += ep->e_type + ep->e_time + ep->e_data1
|
---|
165 | + (short)ep->e_lft;
|
---|
166 |
|
---|
167 | break;
|
---|
168 |
|
---|
169 | case EV_ANVL: /* analog value */
|
---|
170 |
|
---|
171 | sc += ep->e_type + ep->e_time + ep->e_data1
|
---|
172 | + (short)(0x0000FFFFL & ((long)ep->e_dn >> 16));
|
---|
173 |
|
---|
174 | break;
|
---|
175 |
|
---|
176 | case EV_FINI: /* score end */
|
---|
177 |
|
---|
178 | sc += ep->e_type + ep->e_time + ep->e_data1;
|
---|
179 | go = FALSE;
|
---|
180 | break;
|
---|
181 | }
|
---|
182 |
|
---|
183 | ep = ep->e_fwd;
|
---|
184 |
|
---|
185 | } while (go);
|
---|
186 |
|
---|
187 | schksum = sc;
|
---|
188 | snbreq = nb;
|
---|
189 | snlreq = (nl + 3L) >> 2;
|
---|
190 |
|
---|
191 | #if DEBUGIT
|
---|
192 | if (debugsw)
|
---|
193 | printf("scsize(%d): %ld bytes, checksum = %ld\n", nb, schksum);
|
---|
194 | #endif
|
---|
195 |
|
---|
196 | return(nb);
|
---|
197 | }
|
---|
198 |
|
---|
199 | /* |
---|
200 |
|
---|
201 | */
|
---|
202 |
|
---|
203 | /*
|
---|
204 | =============================================================================
|
---|
205 | scsizer() -- return number of bytes necessary for storing active scores
|
---|
206 | =============================================================================
|
---|
207 | */
|
---|
208 |
|
---|
209 | long scsizer(void)
|
---|
210 | {
|
---|
211 | register short i;
|
---|
212 | register long nb;
|
---|
213 |
|
---|
214 | sntlreq = 0L;
|
---|
215 | nb = 0L;
|
---|
216 |
|
---|
217 | for (i = 0; i < N_SCORES; i++) {
|
---|
218 |
|
---|
219 | nlpersc[i] = 0L;
|
---|
220 | scsums[i] = 0L;
|
---|
221 |
|
---|
222 | nb += 4L; /* overhead for number of longs or -1L marker */
|
---|
223 |
|
---|
224 | if (scores[i] NE E_NULL) {
|
---|
225 |
|
---|
226 | /* add storage length of events + name + times */
|
---|
227 |
|
---|
228 | nb += scsize(i) + 16L
|
---|
229 | + (long)(N_SECTS * sizeof (struct s_time));
|
---|
230 |
|
---|
231 | nlpersc[i] = snlreq; /* update size table */
|
---|
232 | scsums[i] = schksum; /* update checksum table */
|
---|
233 | sntlreq += snlreq; /* update total longs count */
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | nb += 4L; /* overhead for total longs count */
|
---|
238 |
|
---|
239 | #if DEBUGIT
|
---|
240 | if (debugsw)
|
---|
241 | printf("scsizer(): %ld bytes required\n", nb);
|
---|
242 | #endif
|
---|
243 |
|
---|
244 | sntbreq = nb;
|
---|
245 |
|
---|
246 | return(nb);
|
---|
247 | }
|
---|
248 |
|
---|
249 | /* |
---|
250 |
|
---|
251 | */
|
---|
252 |
|
---|
253 | /*
|
---|
254 | =============================================================================
|
---|
255 | scwrite() -- store a score
|
---|
256 | =============================================================================
|
---|
257 | */
|
---|
258 |
|
---|
259 | short scwrite(short sn, FILE *fp)
|
---|
260 | {
|
---|
261 | register struct s_entry *ep;
|
---|
262 | register short go;
|
---|
263 | char scid[48];
|
---|
264 |
|
---|
265 | ep = scores[sn]; /* pointer to score begin */
|
---|
266 |
|
---|
267 | #if DEBUGIT
|
---|
268 | if (debugsw)
|
---|
269 | printf("scwrite(%d, $%08lX): ep = $%08lX\n", sn, fp, ep);
|
---|
270 | #endif
|
---|
271 |
|
---|
272 | if (E_NULL EQ ep) { /* empty scores only get a flag */
|
---|
273 |
|
---|
274 | sprintf(scid, "score %d was empty", sn + 1);
|
---|
275 |
|
---|
276 | ldwmsg((char *)0L, scid, (char *)0L, LCFBX10, LCBBX10);
|
---|
277 |
|
---|
278 | if (wr_ec(fp, &m1con, 4L))
|
---|
279 | return(FAILURE);
|
---|
280 | else
|
---|
281 | return(SUCCESS);
|
---|
282 | }
|
---|
283 |
|
---|
284 | sprintf(scid, " writing score %d", sn + 1);
|
---|
285 |
|
---|
286 | ldwmsg("Busy -- Please stand by", (char *)0L, scid,
|
---|
287 | LCFBX10, LCBBX10);
|
---|
288 |
|
---|
289 | if (wr_ec(fp, &nlpersc[sn], 4L)) /* number of longs required */
|
---|
290 | return(FAILURE);
|
---|
291 |
|
---|
292 | if (wr_ec(fp, &scname[sn], 16L)) /* score name */
|
---|
293 | return(FAILURE);
|
---|
294 |
|
---|
295 | if (wr_ec(fp, &stimes[sn], (long)(N_SECTS * 12))) /* section times */
|
---|
296 | return(FAILURE);
|
---|
297 |
|
---|
298 | go = TRUE;
|
---|
299 |
|
---|
300 | do {
|
---|
301 |
|
---|
302 | switch (ep->e_type) {
|
---|
303 |
|
---|
304 | case EV_BAR: /* bar marker */
|
---|
305 | case EV_STOP: /* stop */
|
---|
306 | case EV_NEXT: /* next */
|
---|
307 |
|
---|
308 | if (wr_ec(fp, &ep->e_type, 1L))
|
---|
309 | return(FAILURE);
|
---|
310 |
|
---|
311 | if (wr_ec(fp, &ep->e_time, 4L))
|
---|
312 | return(FAILURE);
|
---|
313 |
|
---|
314 | break;
|
---|
315 |
|
---|
316 | case EV_SCORE: /* score begin */
|
---|
317 | case EV_SBGN: /* section begin */
|
---|
318 | case EV_SEND: /* section end */
|
---|
319 | case EV_TMPO: /* tempo */
|
---|
320 | case EV_TUNE: /* tuning */
|
---|
321 | case EV_ASGN: /* I/O assign */
|
---|
322 | case EV_REPT: /* repeat */
|
---|
323 | case EV_PNCH: /* punch in/out */
|
---|
324 |
|
---|
325 | if (wr_ec(fp, &ep->e_type, 1L))
|
---|
326 | return(FAILURE);
|
---|
327 |
|
---|
328 | if (wr_ec(fp, &ep->e_time, 4L))
|
---|
329 | return(FAILURE);
|
---|
330 |
|
---|
331 | if (wr_ec(fp, &ep->e_data1, 1L))
|
---|
332 | return(FAILURE);
|
---|
333 |
|
---|
334 | break;
|
---|
335 | /* |
---|
336 |
|
---|
337 | */
|
---|
338 | case EV_INST: /* instrument change */
|
---|
339 | case EV_INTP: /* interpolate */
|
---|
340 | case EV_GRP: /* group status */
|
---|
341 | case EV_LOCN: /* location */
|
---|
342 | case EV_DYN: /* dynamics */
|
---|
343 | case EV_PRES: /* polyphonic pressure */
|
---|
344 | case EV_CPRS: /* channel pressure */
|
---|
345 | case EV_ANRS: /* analog resolution */
|
---|
346 |
|
---|
347 | if (wr_ec(fp, &ep->e_type, 1L))
|
---|
348 | return(FAILURE);
|
---|
349 |
|
---|
350 | if (wr_ec(fp, &ep->e_time, 4L))
|
---|
351 | return(FAILURE);
|
---|
352 |
|
---|
353 | if (wr_ec(fp, &ep->e_data1, 1L))
|
---|
354 | return(FAILURE);
|
---|
355 |
|
---|
356 | if (wr_ec(fp, &ep->e_data2, 1L))
|
---|
357 | return(FAILURE);
|
---|
358 |
|
---|
359 | break;
|
---|
360 | /* |
---|
361 |
|
---|
362 | */
|
---|
363 | case EV_NBEG: /* note begin */
|
---|
364 | case EV_NEND: /* note end */
|
---|
365 |
|
---|
366 | if (wr_ec(fp, &ep->e_type, 1L))
|
---|
367 | return(FAILURE);
|
---|
368 |
|
---|
369 | if (wr_ec(fp, &ep->e_time, 4L))
|
---|
370 | return(FAILURE);
|
---|
371 |
|
---|
372 | if (wr_ec(fp, &ep->e_data1, 1L))
|
---|
373 | return(FAILURE);
|
---|
374 |
|
---|
375 | if (wr_ec(fp, &ep->e_data2, 1L))
|
---|
376 | return(FAILURE);
|
---|
377 |
|
---|
378 | if (wr_ec(fp, &(((struct n_entry *)ep)->e_vel), 2L))
|
---|
379 | return(FAILURE);
|
---|
380 |
|
---|
381 | break;
|
---|
382 |
|
---|
383 | case EV_TRNS: /* transposition */
|
---|
384 |
|
---|
385 | if (wr_ec(fp, &ep->e_type, 1L))
|
---|
386 | return(FAILURE);
|
---|
387 |
|
---|
388 | if (wr_ec(fp, &ep->e_time, 4L))
|
---|
389 | return(FAILURE);
|
---|
390 |
|
---|
391 | if (wr_ec(fp, &ep->e_data1, 1L))
|
---|
392 | return(FAILURE);
|
---|
393 |
|
---|
394 | if (wr_ec(fp, &ep->e_lft, 2L))
|
---|
395 | return(FAILURE);
|
---|
396 |
|
---|
397 | break;
|
---|
398 | /* |
---|
399 |
|
---|
400 | */
|
---|
401 | case EV_ANVL: /* analog value */
|
---|
402 |
|
---|
403 | if (wr_ec(fp, &ep->e_type, 1L))
|
---|
404 | return(FAILURE);
|
---|
405 |
|
---|
406 | if (wr_ec(fp, &ep->e_time, 4L))
|
---|
407 | return(FAILURE);
|
---|
408 |
|
---|
409 | if (wr_ec(fp, &ep->e_data1, 1L))
|
---|
410 | return(FAILURE);
|
---|
411 |
|
---|
412 | if (wr_ec(fp, &ep->e_dn, 2L))
|
---|
413 | return(FAILURE);
|
---|
414 |
|
---|
415 | break;
|
---|
416 |
|
---|
417 | case EV_FINI: /* score end */
|
---|
418 |
|
---|
419 | if (wr_ec(fp, &ep->e_type, 1L))
|
---|
420 | return(FAILURE);
|
---|
421 |
|
---|
422 | if (wr_ec(fp, &ep->e_time, 4L))
|
---|
423 | return(FALSE);
|
---|
424 |
|
---|
425 | if (wr_ec(fp, &ep->e_data1, 1L))
|
---|
426 | return(FAILURE);
|
---|
427 |
|
---|
428 | go = FALSE;
|
---|
429 |
|
---|
430 | #if DEBUGIT
|
---|
431 | if (debugsw)
|
---|
432 | printf("scwrite(): EV_FINI\n");
|
---|
433 | #endif
|
---|
434 | break;
|
---|
435 |
|
---|
436 | }
|
---|
437 |
|
---|
438 | ep = ep->e_fwd;
|
---|
439 |
|
---|
440 | } while (go);
|
---|
441 |
|
---|
442 | #if DEBUGIT
|
---|
443 | if (debugsw)
|
---|
444 | printf("scwrite(): SUCCESS\n");
|
---|
445 | #endif
|
---|
446 |
|
---|
447 | return(SUCCESS);
|
---|
448 | }
|
---|