source: buchla-68k/orig/RAM/SCWRITE.C@ 5f1d169

Last change on this file since 5f1d169 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

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