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