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