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

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

Zero redundant declarations.

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