1 | /*
|
---|
2 | =============================================================================
|
---|
3 | sqscan.c -- scan a string and turn it into score events
|
---|
4 | Version 24 -- 1988-06-20 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #define CHEKSTOP 1 /* non-zero to trap to ROMP on error */
|
---|
9 |
|
---|
10 | #include "ram.h"
|
---|
11 |
|
---|
12 | #if CHEKSTOP
|
---|
13 | int16_t chkstop = TRUE;
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | int8_t *nlist[] = { "a", "b", "c", "d", "e", "f", "g", NULL };
|
---|
17 |
|
---|
18 | int16_t notetab[] = { 0, 2, 3, 5, 7, 8, 10 };
|
---|
19 | int16_t octab[] = { 21, 33, 45, 57, 69, 81, 93, 105 };
|
---|
20 |
|
---|
21 | /*
|
---|
22 | =============================================================================
|
---|
23 | nospace(et) -- print error message for no space condition
|
---|
24 | =============================================================================
|
---|
25 | */
|
---|
26 |
|
---|
27 | void nospace(int8_t *et)
|
---|
28 | {
|
---|
29 |
|
---|
30 | #if CHEKSTOP
|
---|
31 | if (chkstop) {
|
---|
32 |
|
---|
33 | printf("\n** sqscan: ERROR - no space for %s **\n\n", et);
|
---|
34 | xtrap15(); /* ERROR: trap to ROMP */
|
---|
35 |
|
---|
36 | SEsnap();
|
---|
37 | waitcr();
|
---|
38 | }
|
---|
39 | #endif
|
---|
40 | }
|
---|
41 |
|
---|
42 | /*
|
---|
43 | =============================================================================
|
---|
44 | Pcheck(ptr, msg) -- check 'ptr' for validity -- output msg if bad.
|
---|
45 | A pointer is invalid if it points outside the score or is null.
|
---|
46 | Returns SUCCESS for a good pointer, FAILURE for a bad one.
|
---|
47 | =============================================================================
|
---|
48 | */
|
---|
49 |
|
---|
50 | int16_t Pcheck(struct s_entry *ptr, int8_t *msg)
|
---|
51 | {
|
---|
52 | register struct s_entry *cval;
|
---|
53 |
|
---|
54 | if (ptr EQ E_NULL) {
|
---|
55 |
|
---|
56 | printf("** Pcheck($%08.8lx): ZERO - %s **\n", ptr, msg);
|
---|
57 |
|
---|
58 | #if CHEKSTOP
|
---|
59 | if (chkstop)
|
---|
60 | xtrap15(); /* ERROR: trap to ROMP */
|
---|
61 | #endif
|
---|
62 | return(FAILURE);
|
---|
63 | }
|
---|
64 |
|
---|
65 | cval = spool;
|
---|
66 |
|
---|
67 | if (ptr LT cval) {
|
---|
68 |
|
---|
69 | printf("** Pcheck($%08.8lx): LOW - %s **\n", ptr, msg);
|
---|
70 | #if CHEKSTOP
|
---|
71 | if (chkstop)
|
---|
72 | xtrap15(); /* ERROR: trap to ROMP */
|
---|
73 | #endif
|
---|
74 | return(FAILURE);
|
---|
75 | }
|
---|
76 |
|
---|
77 | cval = &spool[(int32_t)MAX_SE-1];
|
---|
78 |
|
---|
79 | if (ptr GT cval) {
|
---|
80 |
|
---|
81 | printf("** Pcheck($%08.8lx): HIGH - %s **\n", ptr, msg);
|
---|
82 | #if CHEKSTOP
|
---|
83 | if (chkstop)
|
---|
84 | xtrap15(); /* ERROR: trap to ROMP */
|
---|
85 | #endif
|
---|
86 | return(FAILURE);
|
---|
87 | }
|
---|
88 |
|
---|
89 | return(SUCCESS);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /*
|
---|
93 | =============================================================================
|
---|
94 | insnevt() -- insert a note event at t_cur/p_cur
|
---|
95 | =============================================================================
|
---|
96 | */
|
---|
97 |
|
---|
98 | struct n_entry *insnevt(struct n_entry *nsp, int16_t nt, int16_t grp, int16_t note, int16_t vel)
|
---|
99 | {
|
---|
100 | nsp->e_time = t_cur;
|
---|
101 | nsp->e_type = (int8_t)nt;
|
---|
102 | nsp->e_note = (int8_t)note;
|
---|
103 | nsp->e_group = (int8_t)grp;
|
---|
104 | nsp->e_vel = vel;
|
---|
105 |
|
---|
106 | return(e_ins((struct s_entry *)nsp, ep_adj(p_cur, 0, t_cur))->e_fwd);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*
|
---|
110 | =============================================================================
|
---|
111 | Qevent() -- 'event' syntax equation
|
---|
112 | =============================================================================
|
---|
113 | */
|
---|
114 |
|
---|
115 | int16_t Qevent(void)
|
---|
116 | {
|
---|
117 | register int16_t aux1, aux2, aux3, aux4;
|
---|
118 | register int8_t *chptr;
|
---|
119 | register struct s_entry *tsp1, *tsp2;
|
---|
120 | struct s_entry *tsp3;
|
---|
121 |
|
---|
122 | if (!CM_CHR('!')) /* all commands start with ! */
|
---|
123 | CM_NOGO;
|
---|
124 |
|
---|
125 | if (CM_USTR("group")) { /* !group = n */
|
---|
126 |
|
---|
127 | if (!CM_CHR('='))
|
---|
128 | CM_NOGO;
|
---|
129 |
|
---|
130 | if (!CM_NUM)
|
---|
131 | CM_NOGO;
|
---|
132 |
|
---|
133 | curgrp = (int16_t)QQnum;
|
---|
134 |
|
---|
135 | if (verbose)
|
---|
136 | printf("<Current group = %d>\n", curgrp);
|
---|
137 |
|
---|
138 | CM_OK;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | if (CM_USTR("status")) { /* !status = {on|off} */
|
---|
143 |
|
---|
144 | if (!CM_CHR('='))
|
---|
145 | CM_NOGO;
|
---|
146 |
|
---|
147 | if (CM_USTR("on")) {
|
---|
148 |
|
---|
149 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
150 |
|
---|
151 | nospace("!status=on");
|
---|
152 | CM_NOGO;
|
---|
153 | }
|
---|
154 |
|
---|
155 | tsp1->e_time = t_cur;
|
---|
156 | tsp1->e_type = EV_GRP;
|
---|
157 | tsp1->e_data1 = (int8_t)curgrp;
|
---|
158 | tsp1->e_data2 = GS_ENBL;
|
---|
159 |
|
---|
160 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
161 | eh_ins(tsp1, EH_GRP);
|
---|
162 |
|
---|
163 | if (verbose)
|
---|
164 | printf("%8ld: Group %d enabled\n",
|
---|
165 | t_cur, curgrp);
|
---|
166 | CM_OK;
|
---|
167 |
|
---|
168 | } else if (CM_USTR("off")) {
|
---|
169 |
|
---|
170 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
171 |
|
---|
172 | nospace("!status=off");
|
---|
173 | CM_NOGO;
|
---|
174 | }
|
---|
175 |
|
---|
176 | tsp1->e_time = t_cur;
|
---|
177 | tsp1->e_type = EV_GRP;
|
---|
178 | tsp1->e_data1 = (int8_t)curgrp;
|
---|
179 | tsp1->e_data2 = GS_DSBL;
|
---|
180 |
|
---|
181 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
182 | eh_ins(tsp1, EH_GRP);
|
---|
183 |
|
---|
184 | if (verbose)
|
---|
185 | printf("%8ld: Group %d disabled\n",
|
---|
186 | t_cur, curgrp);
|
---|
187 | CM_OK;
|
---|
188 |
|
---|
189 | } else
|
---|
190 | CM_NOGO;
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | if (CM_USTR("tempo")) { /* !tempo = n */
|
---|
195 |
|
---|
196 | if (!CM_CHR('='))
|
---|
197 | CM_NOGO;
|
---|
198 |
|
---|
199 | if (!CM_NUM)
|
---|
200 | CM_NOGO;
|
---|
201 |
|
---|
202 | aux1 = (int16_t)QQnum;
|
---|
203 |
|
---|
204 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
205 |
|
---|
206 | nospace("!tempo");
|
---|
207 | CM_NOGO;
|
---|
208 | }
|
---|
209 |
|
---|
210 | tsp1->e_time = t_cur;
|
---|
211 | tsp1->e_type = EV_TMPO;
|
---|
212 | tsp1->e_data1 = (int8_t)aux1;
|
---|
213 |
|
---|
214 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
215 | eh_ins(tsp1, EH_TMPO);
|
---|
216 |
|
---|
217 | if (verbose)
|
---|
218 | printf("%8ld: Tempo = %d\n", t_cur, aux1);
|
---|
219 | CM_OK;
|
---|
220 | }
|
---|
221 |
|
---|
222 | if (CM_USTR("inst")) { /* !inst = n */
|
---|
223 |
|
---|
224 | if (!CM_CHR('='))
|
---|
225 | CM_NOGO;
|
---|
226 |
|
---|
227 | if (!CM_NUM)
|
---|
228 | CM_NOGO;
|
---|
229 |
|
---|
230 | aux1 = (int16_t)QQnum;
|
---|
231 |
|
---|
232 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
233 |
|
---|
234 | nospace("!inst");
|
---|
235 | CM_NOGO;
|
---|
236 | }
|
---|
237 |
|
---|
238 | tsp1->e_time = t_cur;
|
---|
239 | tsp1->e_type = EV_INST;
|
---|
240 | tsp1->e_data1 = (int8_t)curgrp;
|
---|
241 | tsp1->e_data2 = (int8_t)aux1;
|
---|
242 |
|
---|
243 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
244 | eh_ins(tsp1, EH_INST);
|
---|
245 |
|
---|
246 | if (verbose)
|
---|
247 | printf("%8ld: group %d set to inst %d\n",
|
---|
248 | t_cur, curgrp, aux1);
|
---|
249 | CM_OK;
|
---|
250 | }
|
---|
251 |
|
---|
252 | if (CM_USTR("tuning")) { /* !tuning = n */
|
---|
253 |
|
---|
254 | if (!CM_CHR('='))
|
---|
255 | CM_NOGO;
|
---|
256 |
|
---|
257 | if (!CM_NUM)
|
---|
258 | CM_NOGO;
|
---|
259 |
|
---|
260 | aux1 = (int16_t)QQnum;
|
---|
261 |
|
---|
262 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
263 |
|
---|
264 | nospace("!tuning");
|
---|
265 | CM_NOGO;
|
---|
266 | }
|
---|
267 |
|
---|
268 | tsp1->e_time = t_cur;
|
---|
269 | tsp1->e_type = EV_TUNE;
|
---|
270 | tsp1->e_data1 = (int8_t)aux1;
|
---|
271 |
|
---|
272 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
273 | eh_ins(tsp1, EH_TUNE);
|
---|
274 |
|
---|
275 | if (verbose)
|
---|
276 | printf("%8ld: Tuning %d selected\n", t_cur, aux1);
|
---|
277 | CM_OK;
|
---|
278 | }
|
---|
279 |
|
---|
280 | if (CM_USTR("trans")) { /* !trans = {+|-} n */
|
---|
281 |
|
---|
282 | if (!CM_CHR('='))
|
---|
283 | CM_NOGO;
|
---|
284 |
|
---|
285 | if (CM_CHR('+')) {
|
---|
286 |
|
---|
287 | } else if (CM_CHR('-')) {
|
---|
288 |
|
---|
289 | } else
|
---|
290 | CM_NOGO;
|
---|
291 |
|
---|
292 | if (!CM_NUM)
|
---|
293 | CM_NOGO;
|
---|
294 |
|
---|
295 | aux1 = (int16_t)QQnum;
|
---|
296 |
|
---|
297 | if (QQchr EQ '-')
|
---|
298 | aux1 = -aux1;
|
---|
299 |
|
---|
300 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
301 |
|
---|
302 | nospace("!trans");
|
---|
303 | CM_NOGO;
|
---|
304 | }
|
---|
305 |
|
---|
306 | tsp1->e_time = t_cur;
|
---|
307 | tsp1->e_type = EV_TRNS;
|
---|
308 | tsp1->e_data1 = (int8_t)curgrp;
|
---|
309 | tsp1->e_lft = (struct s_entry *)aux1;
|
---|
310 |
|
---|
311 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
312 | eh_ins(tsp1, EH_TRNS);
|
---|
313 |
|
---|
314 | if (verbose)
|
---|
315 | printf("%8ld: Transposition set to %d\n",
|
---|
316 | t_cur, aux1);
|
---|
317 | CM_OK;
|
---|
318 | }
|
---|
319 |
|
---|
320 | if (CM_USTR("dyn")) { /* !dyn = n */
|
---|
321 |
|
---|
322 | if (!CM_CHR('='))
|
---|
323 | CM_NOGO;
|
---|
324 |
|
---|
325 | if (!CM_NUM)
|
---|
326 | CM_NOGO;
|
---|
327 |
|
---|
328 | aux1 = (int16_t)QQnum;
|
---|
329 |
|
---|
330 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
331 |
|
---|
332 | nospace("!dyn");
|
---|
333 | CM_NOGO;
|
---|
334 | }
|
---|
335 |
|
---|
336 | tsp1->e_time = t_cur;
|
---|
337 | tsp1->e_type = EV_DYN;
|
---|
338 | tsp1->e_data1 = (int8_t)curgrp;
|
---|
339 | tsp1->e_data2 = (int8_t)aux1;
|
---|
340 |
|
---|
341 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
342 | eh_ins(tsp1, EH_DYN);
|
---|
343 |
|
---|
344 | if (verbose)
|
---|
345 | printf("%8ld: Dynamics set to %d\n", t_cur, aux1);
|
---|
346 | CM_OK;
|
---|
347 | }
|
---|
348 |
|
---|
349 | if (CM_USTR("loc")) { /* !loc = n */
|
---|
350 |
|
---|
351 | if (!CM_CHR('='))
|
---|
352 | CM_NOGO;
|
---|
353 |
|
---|
354 | if (!CM_NUM)
|
---|
355 | CM_NOGO;
|
---|
356 |
|
---|
357 | aux1 = (int16_t)QQnum;
|
---|
358 |
|
---|
359 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE2))) {
|
---|
360 |
|
---|
361 | nospace("!loc");
|
---|
362 | CM_NOGO;
|
---|
363 | }
|
---|
364 |
|
---|
365 | tsp1->e_time = t_cur;
|
---|
366 | tsp1->e_type = EV_LOCN;
|
---|
367 | tsp1->e_data1 = (int8_t)curgrp;
|
---|
368 | tsp1->e_data2 = (int8_t)aux1;
|
---|
369 |
|
---|
370 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
371 | eh_ins(tsp1, EH_LOCN);
|
---|
372 |
|
---|
373 | if (verbose)
|
---|
374 | printf("%8ld: Location set to %d\n", t_cur, aux1);
|
---|
375 | CM_OK;
|
---|
376 | }
|
---|
377 |
|
---|
378 | if (CM_USTR("goto")) { /* !goto n @ n */
|
---|
379 |
|
---|
380 | if (!CM_NUM)
|
---|
381 | CM_NOGO;
|
---|
382 |
|
---|
383 | curtime = QQnum * 48;
|
---|
384 |
|
---|
385 | if (!CM_CHR('@'))
|
---|
386 | CM_NOGO;
|
---|
387 |
|
---|
388 | if (!CM_NUM)
|
---|
389 | CM_NOGO;
|
---|
390 |
|
---|
391 | sc_goto(curtime += QQnum);
|
---|
392 |
|
---|
393 | if (verbose)
|
---|
394 | printf("\n<Score time set to %ld>\n", t_cur);
|
---|
395 |
|
---|
396 | CM_OK;
|
---|
397 | }
|
---|
398 |
|
---|
399 | if (CM_USTR("pos")) { /* !pos = n @ n */
|
---|
400 |
|
---|
401 | if (!CM_CHR('='))
|
---|
402 | CM_NOGO;
|
---|
403 |
|
---|
404 | if (!CM_NUM)
|
---|
405 | CM_NOGO;
|
---|
406 |
|
---|
407 | curtime = QQnum * 48;
|
---|
408 |
|
---|
409 | if (!CM_CHR('@'))
|
---|
410 | CM_NOGO;
|
---|
411 |
|
---|
412 | if (!CM_NUM)
|
---|
413 | CM_NOGO;
|
---|
414 |
|
---|
415 | t_cur = (curtime += QQnum);
|
---|
416 | p_cur = frfind(t_cur, 0);
|
---|
417 |
|
---|
418 | if (verbose)
|
---|
419 | printf("\n<Score time set to %ld>\n", t_cur);
|
---|
420 |
|
---|
421 | CM_OK;
|
---|
422 | }
|
---|
423 |
|
---|
424 | if (CM_USTR("beat")) { /* !beat = n */
|
---|
425 |
|
---|
426 | if (!CM_CHR('='))
|
---|
427 | CM_NOGO;
|
---|
428 |
|
---|
429 | if (!CM_NUM)
|
---|
430 | CM_NOGO;
|
---|
431 |
|
---|
432 | t_cur = QQnum * 48;
|
---|
433 | p_cur = frfind(t_cur, 0);
|
---|
434 |
|
---|
435 | if (verbose)
|
---|
436 | printf("\n<Score time set to %ld>\n", t_cur);
|
---|
437 |
|
---|
438 | CM_OK;
|
---|
439 | }
|
---|
440 |
|
---|
441 | if (CM_USTR("frame")) { /* !frame = n */
|
---|
442 |
|
---|
443 | if (!CM_CHR('='))
|
---|
444 | CM_NOGO;
|
---|
445 |
|
---|
446 | if (!CM_NUM)
|
---|
447 | CM_NOGO;
|
---|
448 |
|
---|
449 | t_cur = QQnum;
|
---|
450 | p_cur = frfind(t_cur, 0);
|
---|
451 |
|
---|
452 | if (verbose)
|
---|
453 | printf("\n<Score time set to %ld>\n", t_cur);
|
---|
454 |
|
---|
455 | CM_OK;
|
---|
456 | }
|
---|
457 |
|
---|
458 | if (CM_USTR("score")) { /* !score = n */
|
---|
459 |
|
---|
460 | if (!CM_CHR('='))
|
---|
461 | CM_NOGO;
|
---|
462 |
|
---|
463 | if (!CM_NUM)
|
---|
464 | CM_NOGO;
|
---|
465 |
|
---|
466 | if (QQnum > 127)
|
---|
467 | CM_NOGO;
|
---|
468 |
|
---|
469 | thescore = (int16_t)QQnum;
|
---|
470 |
|
---|
471 | selscor(thescore);
|
---|
472 |
|
---|
473 | if (verbose)
|
---|
474 | printf("\n<Score %d selected>\n", thescore);
|
---|
475 | CM_OK;
|
---|
476 | }
|
---|
477 |
|
---|
478 | if (CM_USTR("weight")) { /* !weight = n */
|
---|
479 |
|
---|
480 | if (!CM_CHR('='))
|
---|
481 | CM_NOGO;
|
---|
482 |
|
---|
483 | if (!CM_NUM)
|
---|
484 | CM_NOGO;
|
---|
485 |
|
---|
486 | if (QQnum > 100L)
|
---|
487 | CM_NOGO;
|
---|
488 |
|
---|
489 | noteper = QQnum;
|
---|
490 |
|
---|
491 | if (verbose)
|
---|
492 | printf("<Note weight = %ld percent>\n", noteper);
|
---|
493 |
|
---|
494 | CM_OK;
|
---|
495 | }
|
---|
496 |
|
---|
497 | if (CM_USTR("snap")) { /* !snap */
|
---|
498 |
|
---|
499 | SEsnap();
|
---|
500 | CM_OK;
|
---|
501 | }
|
---|
502 |
|
---|
503 | if (CM_USTR("wait")) { /* !wait */
|
---|
504 |
|
---|
505 | waitcr();
|
---|
506 | CM_OK;
|
---|
507 | }
|
---|
508 |
|
---|
509 | if (CM_USTR("stop")) { /* !stop */
|
---|
510 |
|
---|
511 | if (E_NULL EQ (tsp1 = e_alc(E_SIZE1))) {
|
---|
512 |
|
---|
513 | nospace("!stop");
|
---|
514 | CM_NOGO;
|
---|
515 | }
|
---|
516 |
|
---|
517 | tsp1->e_time = t_cur;
|
---|
518 | tsp1->e_type = EV_STOP;
|
---|
519 |
|
---|
520 | p_cur = e_ins(tsp1, ep_adj(p_cur, 0, t_cur))->e_fwd;
|
---|
521 |
|
---|
522 | if (verbose)
|
---|
523 | printf("%8ld: Stop entered\n", t_cur);
|
---|
524 | CM_OK;
|
---|
525 | }
|
---|
526 |
|
---|
527 | if (CM_USTR("clear")) { /* !clear {n | * | $} */
|
---|
528 |
|
---|
529 | if (CM_NUM) {
|
---|
530 |
|
---|
531 | aux1 = (int16_t)QQnum;
|
---|
532 | sc_clr(aux1);
|
---|
533 |
|
---|
534 | if (verbose)
|
---|
535 | printf("\n<Score %d cleared>\n", aux1);
|
---|
536 |
|
---|
537 | CM_OK;
|
---|
538 | }
|
---|
539 |
|
---|
540 | if (CM_CHR('*')) {
|
---|
541 |
|
---|
542 | scinit();
|
---|
543 |
|
---|
544 | if (verbose)
|
---|
545 | printf("\n<All scores cleared>\n");
|
---|
546 |
|
---|
547 | CM_OK;
|
---|
548 | }
|
---|
549 |
|
---|
550 | if (CM_CHR('$')) {
|
---|
551 |
|
---|
552 | sc_clr(curscor);
|
---|
553 |
|
---|
554 | if (verbose)
|
---|
555 | printf("\n<Current score (%d) cleared>\n", curscor);
|
---|
556 |
|
---|
557 | CM_OK;
|
---|
558 | }
|
---|
559 |
|
---|
560 | CM_NOGO;
|
---|
561 | }
|
---|
562 |
|
---|
563 | if (CM_USTR("show")) { /* !show {active | names | sections} */
|
---|
564 |
|
---|
565 | if (CM_USTR("active")) {
|
---|
566 |
|
---|
567 | printf("<Active scores:\n");
|
---|
568 | aux1 = aux2 = 0;
|
---|
569 |
|
---|
570 | for (aux3 = 0; aux3 < 4; aux3++) {
|
---|
571 |
|
---|
572 | printf("<");
|
---|
573 |
|
---|
574 | for (aux4 = 0; aux4 < 16; aux4++) {
|
---|
575 |
|
---|
576 | if (scores[aux1]) {
|
---|
577 |
|
---|
578 | printf("%3d ", aux1);
|
---|
579 | ++aux2;
|
---|
580 |
|
---|
581 | } else {
|
---|
582 |
|
---|
583 | printf("... ");
|
---|
584 | }
|
---|
585 |
|
---|
586 | ++aux1;
|
---|
587 | }
|
---|
588 |
|
---|
589 | printf(">\n");
|
---|
590 | }
|
---|
591 |
|
---|
592 | printf("<%d active scores, score %d is current>\n\n",
|
---|
593 | aux2, curscor);
|
---|
594 | CM_OK;
|
---|
595 | }
|
---|
596 |
|
---|
597 | if (CM_USTR("names")) {
|
---|
598 |
|
---|
599 | printf("<Active score names:>\n");
|
---|
600 | aux2 = 0;
|
---|
601 |
|
---|
602 | for (aux1 = 0; aux1 < 128; aux1++) {
|
---|
603 |
|
---|
604 | if (scores[aux1] NE E_NULL) {
|
---|
605 |
|
---|
606 | printf("<%3d: ", aux1);
|
---|
607 | chptr = scname[aux1];
|
---|
608 | printf("[$%08.8lx, $%08.8lx] ",
|
---|
609 | scores[aux1], chptr);
|
---|
610 |
|
---|
611 | for (aux3 = 0; aux3 < 16; aux3++)
|
---|
612 | printf("%c", (*chptr++ & 0xFF));
|
---|
613 |
|
---|
614 | printf(">\n");
|
---|
615 | ++aux2;
|
---|
616 | }
|
---|
617 | }
|
---|
618 |
|
---|
619 | printf("<%d active scores, %d is current>\n\n",
|
---|
620 | aux2, curscor);
|
---|
621 |
|
---|
622 | CM_OK;
|
---|
623 | }
|
---|
624 |
|
---|
625 | if (CM_USTR("sections")) {
|
---|
626 |
|
---|
627 | printf("<Active sections:>\n");
|
---|
628 | aux1 = aux2 = 0;
|
---|
629 |
|
---|
630 | for (aux3 = 0; aux3 < 5; aux3++) {
|
---|
631 |
|
---|
632 | printf("<");
|
---|
633 |
|
---|
634 | for (aux4 = 0; aux4 < 10; aux4++) {
|
---|
635 |
|
---|
636 | if (seclist[curscor][aux1]) {
|
---|
637 |
|
---|
638 | printf("%3d ", aux1);
|
---|
639 | ++aux2;
|
---|
640 |
|
---|
641 | } else {
|
---|
642 |
|
---|
643 | printf("... ");
|
---|
644 | }
|
---|
645 |
|
---|
646 | ++aux1;
|
---|
647 | }
|
---|
648 |
|
---|
649 | printf(">\n");
|
---|
650 | }
|
---|
651 |
|
---|
652 | printf("<%d active sections, %d is current>\n\n",
|
---|
653 | aux2, cursect);
|
---|
654 | CM_OK;
|
---|
655 | }
|
---|
656 |
|
---|
657 | CM_NOGO;
|
---|
658 | }
|
---|
659 |
|
---|
660 | if (CM_USTR("find")) { /* !find {l | r} n */
|
---|
661 |
|
---|
662 | if (CM_UCHR('l'))
|
---|
663 | aux1 = 1;
|
---|
664 | else if (CM_UCHR('r'))
|
---|
665 | aux1 = 0;
|
---|
666 | else
|
---|
667 | CM_NOGO;
|
---|
668 |
|
---|
669 | if (!CM_NUM)
|
---|
670 | CM_NOGO;
|
---|
671 |
|
---|
672 | tsp1 = frfind(QQnum, aux1);
|
---|
673 |
|
---|
674 | if (tsp1 NE E_NULL) {
|
---|
675 |
|
---|
676 | if (verbose)
|
---|
677 | printf("\n<FIND: Found %ld at $%08.8lx>\n\n",
|
---|
678 | QQnum, tsp1);
|
---|
679 |
|
---|
680 | p_cur = tsp1;
|
---|
681 | t_cur = QQnum;
|
---|
682 |
|
---|
683 | } else {
|
---|
684 |
|
---|
685 | if (verbose)
|
---|
686 | printf("<FIND: Found the current score empty>\n\n");
|
---|
687 |
|
---|
688 | CM_NOGO;
|
---|
689 | }
|
---|
690 |
|
---|
691 | CM_OK;
|
---|
692 | }
|
---|
693 |
|
---|
694 | if (CM_USTR("chase")) { /* !chase */
|
---|
695 |
|
---|
696 | if (E_NULL EQ (tsp1 = p_cur)) {
|
---|
697 |
|
---|
698 | printf("<CHASE: Current score not active>\n\n");
|
---|
699 | CM_NOGO;
|
---|
700 | }
|
---|
701 |
|
---|
702 | tsp2 = tsp1;
|
---|
703 |
|
---|
704 | while (tsp2) {
|
---|
705 |
|
---|
706 | tsp3 = &spool[0];
|
---|
707 |
|
---|
708 | if (tsp2 LT tsp3) {
|
---|
709 |
|
---|
710 | printf("\nCHASE: Error\n");
|
---|
711 | printf("** Bad pointer: $%08.8lx\n", tsp2);
|
---|
712 | printf("** spool: $%08.8lx, pspool: $%08.8lx\n",
|
---|
713 | &spool[0], pspool);
|
---|
714 | CM_NOGO;
|
---|
715 | }
|
---|
716 |
|
---|
717 | tsp3 = &spool[MAX_SE-1];
|
---|
718 |
|
---|
719 | if (tsp2 GT tsp3) {
|
---|
720 |
|
---|
721 | printf("\nCHASE: Error\n");
|
---|
722 | printf("** Bad pointer: $%08.8lx\n", tsp2);
|
---|
723 | printf("** spool: $%08.8lx, pspool: $%08.8lx\n",
|
---|
724 | &spool[0], pspool);
|
---|
725 | CM_NOGO;
|
---|
726 | }
|
---|
727 |
|
---|
728 | SEdump(tsp2);
|
---|
729 | tsp2 = tsp2->e_fwd;
|
---|
730 |
|
---|
731 | if ((tsp1 EQ tsp2) OR
|
---|
732 | (tsp2->e_type EQ EV_SCORE)) {
|
---|
733 |
|
---|
734 | printf("-- End of chain --\n\n");
|
---|
735 | break;
|
---|
736 | }
|
---|
737 | }
|
---|
738 |
|
---|
739 | CM_OK;
|
---|
740 | }
|
---|
741 |
|
---|
742 | if (CM_USTR("verbose")) { /* !verbose */
|
---|
743 |
|
---|
744 | verbose = TRUE;
|
---|
745 | CM_OK;
|
---|
746 | }
|
---|
747 |
|
---|
748 | if (CM_USTR("quiet")) { /* !quiet */
|
---|
749 |
|
---|
750 | verbose = FALSE;
|
---|
751 | CM_OK;
|
---|
752 | }
|
---|
753 |
|
---|
754 | if (CM_USTR("test")) { /* !test */
|
---|
755 |
|
---|
756 | testing = TRUE;
|
---|
757 | CM_OK;
|
---|
758 | }
|
---|
759 |
|
---|
760 | if (CM_USTR("normal")) { /* !normal */
|
---|
761 |
|
---|
762 | testing = FALSE;
|
---|
763 | CM_OK;
|
---|
764 | }
|
---|
765 |
|
---|
766 | if (CM_USTR("end")) { /* !end */
|
---|
767 |
|
---|
768 | if (verbose)
|
---|
769 | printf("\n<End command encountered>\n");
|
---|
770 |
|
---|
771 | endflg = TRUE;
|
---|
772 | CM_OK;
|
---|
773 | }
|
---|
774 |
|
---|
775 | CM_NOGO;
|
---|
776 | }
|
---|
777 |
|
---|
778 | /*
|
---|
779 | =============================================================================
|
---|
780 | Qnote() -- 'note' and rest syntax equation
|
---|
781 |
|
---|
782 | "val [#] oct [+|-|/n]" | "r n / m"
|
---|
783 | e.g.: a#0+ .. a#0- .. c3/4 , r2/1 d3 , e3
|
---|
784 | =============================================================================
|
---|
785 | */
|
---|
786 |
|
---|
787 | int16_t Qnote(void)
|
---|
788 | {
|
---|
789 | struct n_entry *nsp1;
|
---|
790 |
|
---|
791 | if (CM_UCHR('r')) { /* try for a rest */
|
---|
792 |
|
---|
793 | if (!CM_NUM)
|
---|
794 | CM_NOGO;
|
---|
795 |
|
---|
796 | nrest = QQnum;
|
---|
797 |
|
---|
798 | if (!CM_CHR('/'))
|
---|
799 | CM_NOGO;
|
---|
800 |
|
---|
801 | if (!CM_NUM)
|
---|
802 | CM_NOGO;
|
---|
803 |
|
---|
804 | dvwork = 192L;
|
---|
805 | noteval = dvwork / QQnum;
|
---|
806 | t_cur += (noteval * nrest);
|
---|
807 | p_cur = ep_adj(p_cur, 0, t_cur);
|
---|
808 |
|
---|
809 | if (verbose)
|
---|
810 | printf("%8ld: <rest>\n", t_cur);
|
---|
811 |
|
---|
812 | CM_OK;
|
---|
813 | }
|
---|
814 |
|
---|
815 | if (!CM_ULIST(nlist)) /* try for a note */
|
---|
816 | CM_NOGO;
|
---|
817 |
|
---|
818 | notepit = QQlnum;
|
---|
819 |
|
---|
820 | if (CM_CHR('#'))
|
---|
821 | sharp = 1;
|
---|
822 | else
|
---|
823 | sharp = 0;
|
---|
824 |
|
---|
825 | if (!CM_DIG)
|
---|
826 | CM_NOGO;
|
---|
827 |
|
---|
828 | if (QQdig > '7')
|
---|
829 | CM_NOGO;
|
---|
830 |
|
---|
831 | notenum = octab[QQdig - '0'] + notetab[notepit] + sharp;
|
---|
832 |
|
---|
833 | if (CM_CHR('+')) { /* output note begin */
|
---|
834 |
|
---|
835 | if (E_NULL EQ (nsp1 = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
836 |
|
---|
837 | nospace("note event");
|
---|
838 | CM_NOGO;
|
---|
839 | }
|
---|
840 |
|
---|
841 | noteon = t_cur;
|
---|
842 | p_cur = insnevt(nsp1, EV_NBEG, curgrp, notenum, 64);
|
---|
843 |
|
---|
844 | if (verbose)
|
---|
845 | printf("%8ld: Note %3d ON\n", noteon, notenum);
|
---|
846 |
|
---|
847 | CM_OK;
|
---|
848 | }
|
---|
849 |
|
---|
850 | if (CM_CHR('-')) { /* output note end */
|
---|
851 |
|
---|
852 | if (E_NULL EQ (nsp1 = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
853 |
|
---|
854 | nospace("note event");
|
---|
855 | CM_NOGO;
|
---|
856 | }
|
---|
857 |
|
---|
858 | noteoff = t_cur;
|
---|
859 | p_cur = insnevt(nsp1, EV_NEND, curgrp, notenum, 64);
|
---|
860 |
|
---|
861 | if (verbose)
|
---|
862 | printf("%8ld: Note %3d OFF\n", noteoff, notenum);
|
---|
863 |
|
---|
864 | CM_OK;
|
---|
865 | }
|
---|
866 |
|
---|
867 | if (CM_CHR('/')) { /* output note begin and end, given value */
|
---|
868 |
|
---|
869 | if (!CM_NUM)
|
---|
870 | CM_NOGO;
|
---|
871 |
|
---|
872 | dvwork = 192L;
|
---|
873 | noteval = dvwork / QQnum;
|
---|
874 | noteon = t_cur;
|
---|
875 | dvwork = 100L;
|
---|
876 | noteoff = t_cur + ((noteper * noteval) / dvwork);
|
---|
877 |
|
---|
878 | if (E_NULL EQ (nsp1 = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
879 |
|
---|
880 | nospace("note event");
|
---|
881 | CM_NOGO;
|
---|
882 | }
|
---|
883 |
|
---|
884 | p_cur = insnevt(nsp1, EV_NBEG, curgrp, notenum, 64);
|
---|
885 |
|
---|
886 | if (E_NULL EQ (nsp1 = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
887 |
|
---|
888 | nospace("note event");
|
---|
889 | CM_NOGO;
|
---|
890 | }
|
---|
891 |
|
---|
892 | p_cur = ep_adj(p_cur, 0, (t_cur = noteoff));
|
---|
893 |
|
---|
894 | insnevt(nsp1, EV_NEND, curgrp, notenum, 64);
|
---|
895 |
|
---|
896 | p_cur = ep_adj(p_cur, 0, (t_cur = noteon));
|
---|
897 |
|
---|
898 | if (verbose)
|
---|
899 | printf("%8ld: Note %3d ON at %8ld, OFF at %8ld\n",
|
---|
900 | t_cur, notenum, noteon, noteoff);
|
---|
901 |
|
---|
902 | CM_OK;
|
---|
903 | }
|
---|
904 |
|
---|
905 | /* output note begin and end, use previous value */
|
---|
906 |
|
---|
907 | noteon = t_cur;
|
---|
908 | dvwork = 100L;
|
---|
909 | noteoff = t_cur + ((noteval * noteper) / dvwork);
|
---|
910 |
|
---|
911 | if (E_NULL EQ (nsp1 = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
912 |
|
---|
913 | nospace("note event");
|
---|
914 | CM_NOGO;
|
---|
915 | }
|
---|
916 |
|
---|
917 | p_cur = insnevt(nsp1, EV_NBEG, curgrp, notenum, 64);
|
---|
918 |
|
---|
919 | if (E_NULL EQ (nsp1 = (struct n_entry *)e_alc(E_SIZE1))) {
|
---|
920 |
|
---|
921 | nospace("note event");
|
---|
922 | CM_NOGO;
|
---|
923 | }
|
---|
924 |
|
---|
925 | p_cur = ep_adj(p_cur, 0, (t_cur = noteoff));
|
---|
926 |
|
---|
927 | insnevt(nsp1, EV_NEND, curgrp, notenum, 64);
|
---|
928 |
|
---|
929 | p_cur = ep_adj(p_cur, 0, (t_cur = noteon));
|
---|
930 |
|
---|
931 | if (verbose)
|
---|
932 | printf("%8ld: Note %3d ON at %8ld, OFF at %8ld\n",
|
---|
933 | t_cur, notenum, noteon, noteoff);
|
---|
934 | CM_OK;
|
---|
935 | }
|
---|
936 |
|
---|
937 | /*
|
---|
938 | =============================================================================
|
---|
939 | Qadv() -- 'adv' syntax equation
|
---|
940 | =============================================================================
|
---|
941 | */
|
---|
942 |
|
---|
943 | int16_t Qadv(void)
|
---|
944 | {
|
---|
945 | if (CM_CHR('.')) { /* advance by 1 frame */
|
---|
946 |
|
---|
947 | ++t_cur;
|
---|
948 | p_cur = ep_adj(p_cur, 0, t_cur);
|
---|
949 | CM_OK;
|
---|
950 | }
|
---|
951 |
|
---|
952 | if (CM_CHR(',')) { /* advance by current note value */
|
---|
953 |
|
---|
954 | t_cur += noteval;
|
---|
955 | p_cur = ep_adj(p_cur, 0, t_cur);
|
---|
956 | CM_OK;
|
---|
957 | }
|
---|
958 |
|
---|
959 | if (CM_CHR(';')) { /* avance to next beat */
|
---|
960 |
|
---|
961 | dvwork = 48L;
|
---|
962 | t_cur = ((t_cur / dvwork) + 1L) * 48L;
|
---|
963 | p_cur = ep_adj(p_cur, 0, t_cur);
|
---|
964 | CM_OK;
|
---|
965 | }
|
---|
966 |
|
---|
967 | if (CM_CHR(':')) { /* advance by one beat interval */
|
---|
968 |
|
---|
969 | t_cur += 48L;
|
---|
970 | p_cur = ep_adj(p_cur, 0, t_cur);
|
---|
971 | CM_OK;
|
---|
972 | }
|
---|
973 |
|
---|
974 | CM_NOGO;
|
---|
975 | }
|
---|
976 |
|
---|
977 | /*
|
---|
978 | =============================================================================
|
---|
979 | Qseq() -- 'seq' syntax equation
|
---|
980 | =============================================================================
|
---|
981 | */
|
---|
982 |
|
---|
983 | int16_t Qseq(void)
|
---|
984 | {
|
---|
985 | CM_DBLK;
|
---|
986 |
|
---|
987 | if (!*QQip)
|
---|
988 | CM_OK;
|
---|
989 |
|
---|
990 | if (Qnote() OR Qadv() OR (Qevent() AND !endflg)) {
|
---|
991 |
|
---|
992 | CM_DBLK;
|
---|
993 |
|
---|
994 | if (!*QQip)
|
---|
995 | return(QQsw);
|
---|
996 |
|
---|
997 | while (QQsw AND !endflg) {
|
---|
998 |
|
---|
999 | if (!Qadv())
|
---|
1000 | if (!Qnote())
|
---|
1001 | Qevent();
|
---|
1002 |
|
---|
1003 | CM_DBLK;
|
---|
1004 |
|
---|
1005 | if (!*QQip)
|
---|
1006 | return(QQsw);
|
---|
1007 | }
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | return(QQsw);
|
---|
1011 | }
|
---|
1012 |
|
---|
1013 | /*
|
---|
1014 | =============================================================================
|
---|
1015 | sqinit() -- setup score interpreter variables
|
---|
1016 | =============================================================================
|
---|
1017 | */
|
---|
1018 |
|
---|
1019 | void sqinit(void)
|
---|
1020 | {
|
---|
1021 | verbose = FALSE;
|
---|
1022 | testing = FALSE;
|
---|
1023 | endflg = FALSE;
|
---|
1024 |
|
---|
1025 | noteval = 48L; /* default value = 1/4 note (192/48) */
|
---|
1026 | noteper = 80L; /* default weight = 80 percent */
|
---|
1027 |
|
---|
1028 | curtime = t_cur = t_ctr = 0L;
|
---|
1029 | t_bak = t_cur - TO_BAK;
|
---|
1030 | t_fwd = t_cur + TO_FWD;
|
---|
1031 |
|
---|
1032 | p_bak = p_cur = p_ctr = p_fwd = E_NULL;
|
---|
1033 |
|
---|
1034 | curgrp = 0;
|
---|
1035 | thescore = 0;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | /*
|
---|
1039 | =============================================================================
|
---|
1040 | sqscan(ip) -- scans the string at 'ip' and converts the event
|
---|
1041 | descriptions therein to events in the current score. Returns
|
---|
1042 | the value of the parser switch.
|
---|
1043 | =============================================================================
|
---|
1044 | */
|
---|
1045 |
|
---|
1046 | int16_t sqscan(int8_t *ip)
|
---|
1047 | {
|
---|
1048 | endflg = FALSE;
|
---|
1049 | CMinit(ip);
|
---|
1050 |
|
---|
1051 | if (!Qseq())
|
---|
1052 | CMstat("Syntax error");
|
---|
1053 |
|
---|
1054 | return(QQsw);
|
---|
1055 | }
|
---|
1056 |
|
---|