Updated TODO.
[ahxm.git] / compiler.y
blob73908acf377774c74a18214ecf0fe7060a1e949b
1 %{
2 /*
4 Ann Hell Ex Machina - Music Software
5 Copyright (C) 2003/2005 Angel Ortega <angel@triptico.com>
7 compiler.y - Scripting language YACC parser
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 http://www.triptico.com
27 #include "config.h"
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <math.h>
34 #include "annhell.h"
36 /*******************
37 Data
38 ********************/
40 int yylex(void);
41 void yyerror(char * s);
43 /* injecting code functions (defined in compiler.l) */
44 int push_code(char * code, int times, int dyn);
45 int push_code_from_file(char * file);
47 /* current track */
48 int track;
50 /* current time */
51 double cur_time;
53 /* note globals */
54 static double length;
55 static int octave;
56 static int transpose;
57 static double staccato;
58 static float volume;
59 static double gliss;
61 /* parser debugging */
63 #define DEBUGF if(ss_debug)printf
65 /* named blocks */
67 struct named_block
69 char name[64];
70 char * block;
73 static struct named_block * named_blocks=NULL;
74 static int n_named_blocks=0;
75 static int named_blocks_size=0;
77 /* group info */
78 struct group
80 double start;
81 double gliss;
82 double max;
85 static struct group * groups=NULL;
86 static int n_groups=0;
87 static int groups_size=0;
89 /* mark info */
90 struct mark
92 char name[64];
93 double time;
96 static struct mark * marks=NULL;
97 static int n_marks=0;
98 static int marks_size=0;
100 /* arpeggiator */
101 struct arp
103 double delay;
104 int transpose;
105 float volume;
106 int track;
109 static struct arp * arps=NULL;
110 static int n_arps=0;
111 static int arps_size=0;
113 static double arp_delay;
114 static int arp_transpose;
115 static float arp_volume;
116 static int arp_track;
118 int compiler_error=0;
120 extern int yyline;
122 /*******************
123 Code
124 ********************/
126 void c_err(char * e1, char * e2, char * e3)
127 /* reports an error from the compiler */
129 printf("ahxm:");
130 if(e1 != NULL) printf(" %s", e1);
131 if(e2 != NULL) printf(" %s", e2);
132 if(e3 != NULL) printf(" %s", e3);
133 printf(" in line %d\n", yyline);
135 compiler_error++;
139 static void forward(double step)
140 /* moves forward current time */
142 /* add step */
143 cur_time += step;
145 /* quantizations could be done here */
149 /* named blocks */
151 static int set_named_block(char * name, char * block)
152 /* sets a named block */
154 int n;
156 /* find first if block is previously defined */
157 for(n=0;n < n_named_blocks;n++)
159 if(strcmp(name, named_blocks[n].name) == 0)
161 free(named_blocks[n].block);
162 break;
166 if(n == n_named_blocks)
168 /* need to expand? */
169 if(n_named_blocks == named_blocks_size)
171 named_blocks_size += 4;
173 named_blocks=(struct named_block *)
174 realloc(named_blocks,
175 named_blocks_size *
176 sizeof(struct named_block));
179 n_named_blocks++;
182 strncpy(named_blocks[n].name, name, sizeof(named_blocks[n].name));
183 named_blocks[n].block=block;
185 return(1);
189 static void insert_named_block(char * name)
190 /* inserts a named block */
192 int n;
194 for(n=0;n < n_named_blocks;n++)
196 if(strcmp(name, named_blocks[n].name) == 0)
198 push_code(named_blocks[n].block, 1, 0);
199 return;
203 c_err("block-not-found", name, NULL);
207 static int insert_file(char * filename)
209 if(!push_code_from_file(filename))
211 c_err("script-not-found", filename, NULL);
212 return(1);
215 return(0);
219 /* groups */
221 static int push_group(void)
222 /* starts a new group of notes */
224 if(n_groups == groups_size)
226 groups_size += 4;
228 groups=(struct group *) realloc(groups,
229 groups_size * sizeof(struct group));
232 groups[n_groups].start=cur_time;
233 groups[n_groups].gliss=0.0;
234 groups[n_groups].max=0.0;
236 n_groups++;
238 return(1);
242 static int next_group_part(void)
243 /* part delimiter */
245 if(n_groups == 0)
247 c_err("missing-start-of-group", NULL, NULL);
248 return(0);
251 /* store maximum frame */
252 if(groups[n_groups - 1].max < cur_time)
253 groups[n_groups - 1].max=cur_time;
255 /* add glissando delay */
256 groups[n_groups - 1].gliss += gliss;
258 /* rewind */
259 cur_time=groups[n_groups - 1].start + groups[n_groups - 1].gliss;
261 return(1);
265 static int pop_group(void)
266 /* finishes a group, moving the frame to the end of the longer part */
268 if(n_groups == 0)
270 c_err("missing-start-of-group", NULL, NULL);
271 return(0);
274 n_groups--;
276 /* if other parts of group were longer than the last one,
277 move pointer there */
278 if(groups[n_groups].max > cur_time)
279 cur_time=groups[n_groups].max;
281 return(1);
285 /* marks */
287 static void add_mark(char * name)
288 /* creates a new mark */
290 if(n_marks == marks_size)
292 marks_size += 4;
294 marks=(struct mark *) realloc(marks,
295 marks_size * sizeof(struct mark));
298 strncpy(marks[n_marks].name, name, sizeof(marks[n_marks].name));
299 marks[n_marks].time=cur_time;
301 n_marks++;
305 static void find_mark(char * name, int set)
306 /* finds a mark by name, optionally moving time cursor there */
308 int n;
310 for(n=0;n < n_marks;n++)
312 if(strcmp(marks[n].name, name) == 0)
314 if(set)
316 if(cur_time > marks[n].time)
317 c_err("mark-overpassed", name, NULL);
318 else
319 cur_time=marks[n].time;
321 else
322 if(cur_time != marks[n].time)
323 c_err("mark-mismatch", name, NULL);
325 return;
329 c_err("mark-not-found", name, NULL);
333 /* arpeggiator */
335 static void arp_default(void)
336 /* resets arpeggiator values to the default ones */
338 arp_delay=0.0;
339 arp_transpose=0;
340 arp_volume=1.0;
341 arp_track=track;
345 static void add_arp(void)
346 /* adds an arpeggiator note */
348 /* if the note is exactly the same, do nothing */
349 if(arp_delay == 0.0 && arp_transpose == 0 &&
350 arp_volume == 1.0 && arp_track == track)
351 return;
353 if(n_arps == arps_size)
355 arps_size += 4;
357 arps=(struct arp *) realloc(arps,
358 arps_size * sizeof(struct arp));
361 arps[n_arps].delay=arp_delay;
362 arps[n_arps].transpose=arp_transpose;
363 arps[n_arps].volume=arp_volume;
364 arps[n_arps].track=arp_track;
366 n_arps++;
367 arp_default();
371 /* song events */
373 static void add_note_event(int note)
374 /* adds a note event */
376 int n;
377 int np;
378 union song_ev e;
380 /* calculate the note */
381 np=note + transpose + (octave * 12);
383 /* is note out of range? */
384 if(np < 0 || np > 127)
386 c_err("note-out-of-range", NULL, NULL);
387 return;
390 e.note.type=SONG_EV_NOTE;
391 e.note.time=cur_time;
392 e.note.trk_id=track;
393 e.note.note=np;
394 e.note.len=length * staccato;
395 e.note.vol=volume;
397 add_song_ev(&e);
399 /* add arpeggiator repetitions */
400 for(n=0;n < n_arps;n++)
402 e.note.time=cur_time + arps[n].delay;
403 e.note.trk_id=arps[n].track;
404 e.note.note=np + arps[n].transpose;
405 e.note.vol=volume * arps[n].volume;
407 add_song_ev(&e);
412 static void add_tempo_event(int trk_id, double tempo)
414 union song_ev e;
416 e.tempo.type=SONG_EV_TEMPO;
417 e.tempo.time=cur_time;
418 e.tempo.trk_id=trk_id;
419 e.tempo.tempo=tempo;
420 add_song_ev(&e);
424 static void add_meter_event(int trk_id, int num, int den)
426 union song_ev e;
428 e.meter.type=SONG_EV_METER;
429 e.meter.time=cur_time;
430 e.meter.trk_id=trk_id;
431 e.meter.num=num;
432 e.meter.den=den;
433 add_song_ev(&e);
436 static void add_measure_event(void)
438 union song_ev e;
440 e.measure.type=SONG_EV_MEASURE;
441 e.measure.time=cur_time;
442 e.measure.trk_id=-1;
443 e.measure.line=yyline;
445 add_song_ev(&e);
449 static void add_ss_sustain_event(double sustain)
451 union song_ev e;
453 e.ss_sustain.type=SONG_EV_SS_SUSTAIN;
454 e.ss_sustain.time=cur_time;
455 e.ss_sustain.trk_id=track;
456 e.ss_sustain.sustain=sustain;
458 add_song_ev(&e);
462 static void add_ss_vibrato_event(double depth, double freq)
464 union song_ev e;
466 e.ss_vibrato.type=SONG_EV_SS_VIBRATO;
467 e.ss_vibrato.time=cur_time;
468 e.ss_vibrato.trk_id=track;
469 e.ss_vibrato.vib_depth=depth;
470 e.ss_vibrato.vib_freq=freq;
472 add_song_ev(&e);
476 static void add_ss_channel_event(int channel, float vol)
478 union song_ev e;
480 e.ss_channel.type=SONG_EV_SS_CHANNEL;
481 e.ss_channel.time=cur_time;
482 e.ss_channel.trk_id=track;
483 e.ss_channel.channel=channel;
484 e.ss_channel.vol=vol;
486 add_song_ev(&e);
490 static void add_ss_wav_event(char * wav_file, int base, int min, int max,
491 double loop_start, double loop_end)
493 union song_ev e;
495 e.ss_wav.type=SONG_EV_SS_WAV;
496 e.ss_wav.time=cur_time;
497 e.ss_wav.trk_id=track;
498 e.ss_wav.file=wav_file;
499 e.ss_wav.base=base;
500 e.ss_wav.min=min;
501 e.ss_wav.max=max;
502 e.ss_wav.loop_start=loop_start;
503 e.ss_wav.loop_end=loop_end;
504 add_song_ev(&e);
508 static void add_ss_pat_event(char * pat_file)
510 union song_ev e;
512 e.ss_pat.type=SONG_EV_SS_PAT;
513 e.ss_pat.time=cur_time;
514 e.ss_pat.trk_id=track;
515 e.ss_pat.file=pat_file;
517 add_song_ev(&e);
521 static void add_ss_eff_event(int type, int channel, double size, float gain,
522 double depth, double freq, double phase, float initial, float final)
524 union song_ev e;
526 e.ss_eff.type=type;
527 e.ss_eff.time=cur_time;
528 e.ss_eff.trk_id=track;
529 e.ss_eff.channel=channel;
530 e.ss_eff.size=size;
531 e.ss_eff.gain=gain;
532 e.ss_eff.depth=depth;
533 e.ss_eff.freq=freq;
534 e.ss_eff.phase=phase;
535 e.ss_eff.initial=initial;
536 e.ss_eff.final=final;
538 add_song_ev(&e);
542 static void add_ss_pitch_stretch(int note, double len, float vol)
544 union song_ev e;
546 e.ss_pitch_stretch.type=SONG_EV_SS_PITCH_STRETCH;
547 e.ss_pitch_stretch.time=cur_time;
548 e.ss_pitch_stretch.trk_id=track;
549 e.ss_pitch_stretch.note=note;
550 e.ss_pitch_stretch.len=len;
551 e.ss_pitch_stretch.vol=vol;
553 add_song_ev(&e);
557 static void add_midi_channel_event(int channel)
559 union song_ev e;
561 /* 1st channel is 0 */
562 channel--;
564 e.midi_channel.type=SONG_EV_MIDI_CHANNEL;
565 e.midi_channel.time=cur_time;
566 e.midi_channel.trk_id=track;
567 e.midi_channel.channel=channel;
569 add_song_ev(&e);
573 static void add_midi_program_event(int program)
575 union song_ev e;
577 e.midi_program.type=SONG_EV_MIDI_PROGRAM;
578 e.midi_program.time=cur_time;
579 e.midi_program.trk_id=track;
580 e.midi_program.program=program;
582 add_song_ev(&e);
586 static void init_track(void)
587 /* sets the default values for a new track */
589 cur_time=0.0;
590 length=0.0;
591 transpose=0;
592 staccato=0.8;
593 volume=0.75;
594 octave=5;
595 gliss=0;
597 /* groups should not cross track boundaries */
598 n_groups=0;
600 /* reset arpeggiator */
601 n_arps=0;
602 arp_default();
608 %union {
609 int i;
610 double d;
611 char * p;
614 %token <i> P_INTEGER S_INTEGER
615 %token <d> P_REAL S_REAL
616 %token <i> NOTE_P NOTE_T3 NOTE_T5
617 %token <p> NEW_MARK GOTO_MARK ASSERT_MARK
619 %token <p> BLOCK BLK_ASSIGN BLK_INSERT FILE_INSERT
621 %token <p> XC_STR
622 %token <i> XC_ABSNOTE
623 %token <d> XC_MSECS
625 %token SS_SEP SS_WAV SS_LOOP_WAV SS_PAT SS_SUSTAIN SS_VIBRATO SS_CHANNEL SS_VOL
627 %token SS_EFF_DELAY SS_EFF_ECHO SS_EFF_COMB SS_EFF_ALLPASS SS_EFF_FLANGER
628 %token SS_EFF_WOBBLE SS_EFF_SQWOBBLE SS_EFF_FADER SS_EFF_REVERB SS_EFF_OFF
630 %token SS_PITCH_STRETCH SS_TIME_STRETCH
632 %token MIDI_CHANNEL MIDI_PROGRAM MIDI_GENERIC
634 %type <i> integer note note_pitch rest
635 %type <d> real p_number number note_length
637 %type <d> arp_list arp_note
638 %type <i> xc_absnote
642 script:
643 script stmt { ; }
644 | /* NULL */
647 stmt:
648 note {
649 /* note event */
650 add_note_event($1);
651 forward(length);
653 | rest {
654 /* rest */
655 forward(length);
657 | 'z' note_length {
658 /* zero note */
659 length=$2;
661 | 'o' P_INTEGER {
662 /* absolute octave */
663 octave=$2;
665 | 'o' S_INTEGER {
666 /* relative octave */
667 octave += $2;
669 | 'v' P_INTEGER {
670 /* absolute volume */
671 volume=(float)$2;
673 | 'v' P_REAL {
674 /* absolute volume */
675 volume=(float)$2;
677 | 'v' S_REAL {
678 /* relative volume */
679 volume += (float)$2;
681 | 't' integer {
682 /* transpose */
683 transpose=$2;
685 | 's' p_number {
686 /* staccato */
687 staccato=$2;
690 | '<' {
691 /* start of group */
692 push_group();
694 | ';' {
695 /* group delimiter */
696 next_group_part();
698 | '>' {
699 /* end of group */
700 pop_group();
702 | 'l' note_length {
703 /* glissando */
704 gliss=$2;
707 | '|' {
708 /* measure mark event */
709 add_measure_event();
712 | NEW_MARK {
713 /* add new mark */
714 add_mark($1);
716 | GOTO_MARK {
717 /* go to mark */
718 find_mark($1, 1);
720 | ASSERT_MARK {
721 /* assert mark */
722 find_mark($1, 0);
725 | '\\' {
726 /* new track */
728 track++;
729 init_track();
731 | 'T' p_number {
732 /* tempo setting */
733 add_tempo_event(-1, $2);
735 | 'M' P_INTEGER '/' P_INTEGER {
736 /* meter (time signature) setting */
737 add_meter_event(-1, $2, $4);
740 | BLOCK '*' P_INTEGER {
741 /* repeat block */
742 push_code($1, $3, 1);
744 | BLOCK BLK_ASSIGN {
745 /* assign block */
746 set_named_block($2, $1);
748 | BLK_INSERT {
749 /* insert named block */
750 insert_named_block($1);
752 | FILE_INSERT {
753 /* insert file */
754 insert_file($1);
757 | arp { ; }
759 | xc_cmd { ; }
763 integer:
764 P_INTEGER { $$ = $1; }
765 | S_INTEGER { $$ = $1; }
768 real:
769 P_REAL { $$ = $1; }
770 | S_REAL { $$ = $1; }
773 p_number:
774 P_INTEGER { $$ = (double) $1; }
775 | P_REAL { $$ = $1; }
778 number:
779 integer { $$ = (double) $1; }
780 | real { $$ = $1; }
783 note:
784 note_pitch { $$ = $1; }
785 | note note_length { $$ = $1; length=$2; }
786 | note '~' number { $$ = $1; DEBUGF("imm volume: %lf\n", $3); }
789 note_pitch:
790 NOTE_P { $$ = $1; }
791 | note_pitch '&' { $$ = $1 - 1; }
792 | note_pitch '#' { $$ = $1 + 1; }
793 | note_pitch '\'' { $$ = $1 + 12; }
794 | note_pitch ',' { $$ = $1 - 12; }
797 note_length:
798 P_INTEGER { $$ = 1 / (double) $1; }
799 | note_length NOTE_T3 { $$ = $1 * 2.0 / 3.0; }
800 | note_length NOTE_T5 { $$ = $1 * 4.0 / 5.0; }
801 | note_length '*' p_number { $$ = $1 * $3; }
802 | note_length '.' { $$ = $1 * 1.5; }
805 rest:
806 'r' { ; }
807 | rest note_length {
808 /* rest with length */
809 length=$2;
813 arp:
814 'x' {
815 /* empty arpeggiator */
816 n_arps=0;
817 arp_default();
819 | 'x' arp_list { ; }
822 arp_list:
823 arp_note {
824 /* first arpeggiator note */
825 n_arps=0;
826 add_arp();
828 | arp_list ',' arp_note {
829 /* rest of arpeggiator notes */
830 add_arp();
834 arp_note:
835 note_length {
836 /* arpeggiator delay */
837 arp_delay=$1;
839 | arp_note '~' number {
840 /* arpeggiator volume */
841 arp_volume=(float)$3;
843 | arp_note S_INTEGER {
844 /* arpeggiator transpose */
845 arp_transpose=$2;
847 | arp_note '@' P_INTEGER {
848 /* arpeggiator track */
849 arp_track=$3;
853 xc_absnote:
854 P_INTEGER { $$ = $1; }
855 | XC_ABSNOTE { $$ = $1; }
858 xc_cmd:
859 SS_WAV XC_STR xc_absnote {
860 /* load .wav file with just one note */
861 add_ss_wav_event($2, $3, $3, $3, -1.0, -1.0);
863 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote {
864 /* load .wav file */
865 add_ss_wav_event($2, $3, $4, $5, -1.0, -1.0);
867 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number {
868 /* load .wav file, with loop boundaries */
869 add_ss_wav_event($2, $3, $4, $5, $6, $7);
871 | SS_PAT XC_STR {
872 /* load .pat file */
873 add_ss_pat_event($2);
875 | SS_SUSTAIN XC_MSECS {
876 /* sets sustain */
877 add_ss_sustain_event($2);
879 | SS_VIBRATO XC_MSECS number {
880 /* sets vibrato */
881 add_ss_vibrato_event($2, $3);
883 | SS_CHANNEL integer number {
884 /* sets volume for a channel */
885 add_ss_channel_event($2, $3);
887 | SS_VOL number number {
888 /* set vol for 2 channels */
889 add_ss_channel_event(0, $2);
890 add_ss_channel_event(1, $3);
892 | SS_VOL number number number {
893 /* set vol for 3 channels */
894 add_ss_channel_event(0, $2);
895 add_ss_channel_event(1, $3);
896 add_ss_channel_event(2, $4);
898 | SS_VOL number number number number {
899 /* set vol for 4 channels */
900 add_ss_channel_event(0, $2);
901 add_ss_channel_event(1, $3);
902 add_ss_channel_event(2, $4);
903 add_ss_channel_event(3, $5);
905 | SS_VOL number number number number number number {
906 /* set vol for 6 channels */
907 add_ss_channel_event(0, $2);
908 add_ss_channel_event(1, $3);
909 add_ss_channel_event(2, $4);
910 add_ss_channel_event(3, $5);
911 add_ss_channel_event(4, $6);
912 add_ss_channel_event(5, $7);
914 | SS_EFF_DELAY integer XC_MSECS {
915 /* delay effect */
916 add_ss_eff_event(SONG_EV_SS_EFF_DELAY,
917 $2, $3, 0, 0, 0, 0, 0, 0);
920 | SS_EFF_ECHO integer XC_MSECS number {
921 /* echo effect */
922 add_ss_eff_event(SONG_EV_SS_EFF_ECHO,
923 $2, $3, $4, 0, 0, 0, 0, 0);
926 | SS_EFF_COMB integer XC_MSECS number {
927 /* comb effect */
928 add_ss_eff_event(SONG_EV_SS_EFF_COMB,
929 $2, $3, $4, 0, 0, 0, 0, 0);
932 | SS_EFF_ALLPASS integer XC_MSECS number {
933 /* allpass effect */
934 add_ss_eff_event(SONG_EV_SS_EFF_ALLPASS,
935 $2, $3, $4, 0, 0, 0, 0, 0);
938 | SS_EFF_FLANGER integer XC_MSECS number XC_MSECS number number {
939 /* flanger effect */
940 add_ss_eff_event(SONG_EV_SS_EFF_FLANGER,
941 $2, $3, $4, $5, $6, $7, 0, 0);
944 | SS_EFF_WOBBLE integer number number {
945 /* wobble effect */
946 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
947 $2, 0, 0, 0, $3, $4, 0, 0);
950 | SS_EFF_SQWOBBLE integer number number {
951 /* square wobble effect */
952 add_ss_eff_event(SONG_EV_SS_EFF_SQWOBBLE,
953 $2, 0, 0, 0, $3, $4, 0, 0);
956 | SS_EFF_FADER integer XC_MSECS number number {
957 /* fader effect */
958 add_ss_eff_event(SONG_EV_SS_EFF_FADER,
959 $2, $3, 0, 0, 0, 0, $4, $5);
962 | SS_EFF_REVERB integer {
963 /* reverb effect */
964 add_ss_eff_event(SONG_EV_SS_EFF_REVERB,
965 $2, 0, 0, 0, 0, 0, 0, 0);
968 | SS_EFF_OFF integer {
969 /* off effect */
970 add_ss_eff_event(SONG_EV_SS_EFF_OFF,
971 $2, 0, 0, 0, 0, 0, 0, 0);
974 | SS_PITCH_STRETCH xc_absnote number number {
975 /* pitch stretch note */
976 add_ss_pitch_stretch($2, $3, $4);
978 forward($3);
981 | MIDI_CHANNEL integer {
982 /* midi channel */
983 add_midi_channel_event($2);
986 | MIDI_PROGRAM integer {
987 /* midi program */
988 add_midi_program_event($2);
994 void yyerror(char * s)
996 c_err(s, NULL, NULL);
999 #ifdef QQ
1000 int main(void)
1002 init_track();
1004 push_code("!this-is-a-mark", 1, 0);
1005 push_code("< c1 ; e& ; g>", 1, 0);
1006 push_code("^this-is-a-mark", 1, 0);
1007 push_code("x4,2-1,2.+4", 1, 0);
1008 push_code("a b'' c,, ", 1, 0);
1009 push_code("v0.1 (d8 v+0.1)*10", 1, 0);
1010 push_code("t1 t-2 t+3", 1, 0);
1011 push_code("{ fader -1 100ms 0 1 } r r4. z2 `room_kit.ahs` o4 o+1 o-2 ", 1, 0);
1012 push_code("{ sustain 100ms }", 1, 0);
1013 push_code("T120.0 M4/4 z8 abcde T80 (edcba)=drum1 $drum1 $drum1 ((a&b)*3 (cd)*2)*10", 2, 0);
1015 yyparse();
1017 printf("Exiting main...\n");
1018 exit(0);
1020 #endif
1022 static void compile_startup(void)
1024 track=0;
1025 yyline=1;
1026 compiler_error=0;
1028 /* default settings */
1029 add_tempo_event(-2, 120.0);
1030 add_meter_event(-2, 4, 4);
1031 init_track();
1035 int compile(char * code)
1037 compile_startup();
1039 push_code(code, 1, 0);
1041 return(yyparse() + compiler_error);
1045 int compile_file(char * file)
1047 compile_startup();
1049 if(insert_file(file))
1050 return(1);
1052 return(yyparse() + compiler_error);