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

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

Added missing includes and declarations.

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