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

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

Added include files for global functions and variables.

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