source: buchla-68k/ram/scwrite.c@ 7c0efb6

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

Removed form-feed comments.

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