source: buchla-68k/ram/sqscan.c

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

Fixed buffer overrun.

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