Updated TODO.
[ahxm.git] / compiler.y
blob8aa7e98c9336c7528b51a1cd3b56a169b15807dd
1 %{
2 /*
4 Ann Hell Ex Machina - Music Software
5 Copyright (C) 2003/2006 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 "ahxm.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);
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(verbose >= 2)printf
65 /* blocks */
67 struct block
69 char * name;
70 int n_sblocks;
71 char ** sblocks;
74 static struct block * blocks = NULL;
75 static int n_blocks = 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;
93 double time;
96 static struct mark * marks = NULL;
97 static int n_marks = 0;
99 /* arpeggiator */
100 struct arp
102 double delay;
103 int transpose;
104 float volume;
105 int track_off;
108 static struct arp * arps = NULL;
109 static int n_arps = 0;
110 static int arps_size = 0;
112 static double arp_delay;
113 static int arp_transpose;
114 static float arp_volume;
115 static int arp_track_off;
117 int compiler_error = 0;
119 extern int yyline;
121 /* alterations for each note */
122 int alterations[12];
124 /* random seeds */
125 unsigned long block_seed = 0;
127 /*******************
128 Code
129 ********************/
131 unsigned long ah_rnd(unsigned long * seed)
132 /* special randomizer */
134 *seed = (*seed * 58321) + 11113;
136 return(*seed >> 16);
140 void c_err(char * e1, char * e2, char * e3)
141 /* reports an error from the compiler */
143 printf("ahxm:");
144 if(e1 != NULL) printf(" %s", e1);
145 if(e2 != NULL) printf(" %s", e2);
146 if(e3 != NULL) printf(" %s", e3);
147 printf(" in line %d\n", yyline);
149 compiler_error++;
153 static void forward(double step)
154 /* moves forward current time */
156 /* add step */
157 cur_time += step;
159 /* quantizations could be done here */
163 /* blocks */
165 static int find_block(char * name)
166 /* finds a block */
168 int n;
170 for(n = 0;n < n_blocks;n++)
172 if(strcmp(name, blocks[n].name) == 0)
173 return(n);
176 return(-1);
180 static int set_block(char * name, char * block)
181 /* defines a block */
183 int n;
184 struct block * b;
185 char * start;
186 char * stop;
188 /* if block already exists, free it */
189 if((n = find_block(name)) >= 0)
191 b = &blocks[n];
193 /* free all subblocks */
194 for(n = 0;n < b->n_sblocks;n++)
195 free(b->sblocks[n]);
197 /* free the subblock array */
198 free(b->sblocks);
200 else
202 GROW(blocks, n_blocks, struct block);
203 b = &blocks[n_blocks++];
205 b->name = strdup(name);
208 /* reset */
209 b->n_sblocks = 0;
210 b->sblocks = NULL;
212 /* now split in subblocks (delimited by : ) */
213 start = block;
215 while((stop = strchr(start, ':')) != NULL)
217 /* break there */
218 *stop = '\0';
220 /* add the subblock */
221 GROW(b->sblocks, b->n_sblocks, char *);
222 b->sblocks[b->n_sblocks++] = strdup(start);
224 start = stop + 1;
227 /* no more separators? store the rest */
228 GROW(b->sblocks, b->n_sblocks, char *);
229 b->sblocks[b->n_sblocks++] = strdup(start);
231 /* the original block is no longer needed */
232 free(block);
234 return(1);
238 static void insert_block(char * name)
239 /* inserts a block */
241 int n;
243 if((n = find_block(name)) >= 0)
245 struct block * b;
247 b = &blocks[n];
249 /* get one of them, randomly */
250 n = ah_rnd(&block_seed) % b->n_sblocks;
252 push_code(strdup(b->sblocks[n]));
254 else
255 c_err("block-not-found", name, NULL);
259 static int insert_file(char * filename)
261 if(!push_code_from_file(filename))
263 c_err("script-not-found", filename, NULL);
264 return(1);
267 return(0);
271 /* groups */
273 static int push_group(void)
274 /* starts a new group of notes */
276 struct group * g;
278 if(n_groups == groups_size)
280 GROW(groups, groups_size, struct group);
281 groups_size ++;
284 g = &groups[n_groups++];
286 g->start = cur_time;
287 g->gliss = 0.0;
288 g->max = 0.0;
290 return(1);
294 static int next_group_part(void)
295 /* part delimiter */
297 struct group * g;
299 if(n_groups == 0)
301 c_err("missing-start-of-group", NULL, NULL);
302 return(0);
305 g = &groups[n_groups - 1];
307 /* store maximum frame */
308 if(g->max < cur_time)
309 g->max = cur_time;
311 /* add glissando delay */
312 g->gliss += gliss;
314 /* rewind */
315 cur_time = g->start + g->gliss;
317 return(1);
321 static int pop_group(void)
322 /* finishes a group, moving the frame to the end of the longer part */
324 if(n_groups == 0)
326 c_err("missing-start-of-group", NULL, NULL);
327 return(0);
330 n_groups--;
332 /* if other parts of group were longer than the last one,
333 move pointer there */
334 if(groups[n_groups].max > cur_time)
335 cur_time = groups[n_groups].max;
337 return(1);
341 /* marks */
343 static void add_mark(char * name)
344 /* creates a new mark */
346 GROW(marks, n_marks, struct mark);
348 marks[n_marks].name = strdup(name);
349 marks[n_marks].time = cur_time;
351 n_marks++;
355 static void find_mark(char * name, int set)
356 /* finds a mark by name, optionally moving time cursor there */
358 int n;
360 for(n = 0;n < n_marks;n++)
362 if(strcmp(marks[n].name, name) == 0)
364 if(set)
366 if(cur_time > marks[n].time)
367 c_err("mark-overpassed", name, NULL);
368 else
369 cur_time = marks[n].time;
371 else
372 if(cur_time != marks[n].time)
373 c_err("mark-mismatch", name, NULL);
375 return;
379 c_err("mark-not-found", name, NULL);
383 /* arpeggiator */
385 static void arp_default(void)
386 /* resets arpeggiator values to the default ones */
388 arp_delay = 0.0;
389 arp_transpose = 0;
390 arp_volume = 1.0;
391 arp_track_off = 0;
395 static void add_arp(void)
396 /* adds an arpeggiator note */
398 struct arp * a;
400 /* if the note is exactly the same, do nothing */
401 if(arp_delay == 0.0 && arp_transpose == 0 &&
402 arp_volume == 1.0 && arp_track_off == 0)
403 return;
405 if(n_arps == arps_size)
407 GROW(arps, arps_size, struct arp);
408 arps_size ++;
411 a = &arps[n_arps];
413 a->delay = arp_delay;
414 a->transpose = arp_transpose;
415 a->volume = arp_volume;
416 a->track_off = arp_track_off;
418 n_arps++;
419 arp_default();
423 static void set_alteration(char * altstr)
424 /* sets the alterations from altstr */
426 int n, steps[] = { 2, 0, 2, 0, 1, 2, 0, 2, 0, 2, 0, 1 };
428 /* reset alterations */
429 for(n = 0;n < 12;n++) alterations[n] = 0;
431 /* changed according the altstr spec */
432 for(n = 0;*altstr != '\0' && n < 12;altstr++)
434 switch(*altstr)
436 case '&': alterations[n] = -1; break;
437 case '#': alterations[n] = 1; break;
440 /* move to next natural note */
441 n += steps[n];
446 /* song events */
448 static void add_note_event(int note)
449 /* adds a note event */
451 int n;
452 int np;
453 union song_ev e;
455 /* sum the tonality alteration */
456 /* note += tonalities[tonality][((unsigned) note) % 12];*/
458 /* sum the alteration */
459 note += alterations[((unsigned) note) % 12];
461 /* calculate the note */
462 np = note + transpose + (octave * 12);
464 /* is note out of range? */
465 if(np < 0 || np > 127)
467 c_err("note-out-of-range", NULL, NULL);
468 return;
471 e.note.trk_id = track;
472 e.note.note = np;
473 e.note.len = length * staccato;
474 e.note.vol = volume;
476 add_song_ev(SONG_EV_NOTE, cur_time, &e);
478 /* add arpeggiator repetitions */
479 for(n = 0;n < n_arps;n++)
481 e.note.trk_id = track + arps[n].track_off;
482 e.note.note = np + arps[n].transpose;
483 e.note.vol = volume * arps[n].volume;
485 add_song_ev(SONG_EV_NOTE, cur_time + arps[n].delay, &e);
490 static void add_back_event(void)
492 union song_ev e;
494 e.back.trk_id = track;
495 e.back.len = length;
496 add_song_ev(SONG_EV_BACK, cur_time, &e);
500 static void add_tempo_event(int trk_id, double tempo)
502 union song_ev e;
504 e.tempo.trk_id = trk_id;
505 e.tempo.tempo = tempo;
506 add_song_ev(SONG_EV_TEMPO, cur_time, &e);
510 static void add_meter_event(int trk_id, int num, int den)
512 union song_ev e;
514 e.meter.trk_id = trk_id;
515 e.meter.num = num;
516 e.meter.den = den;
517 add_song_ev(SONG_EV_METER, cur_time, &e);
520 static void add_measure_event(void)
522 union song_ev e;
524 e.measure.trk_id = -1;
525 e.measure.line = yyline;
527 add_song_ev(SONG_EV_MEASURE, cur_time, &e);
531 static void add_ss_sustain_event(double sustain)
533 union song_ev e;
535 e.ss_sustain.trk_id = track;
536 e.ss_sustain.sustain = sustain;
538 add_song_ev(SONG_EV_SS_SUSTAIN, cur_time, &e);
542 static void add_ss_vibrato_event(double depth, double freq)
544 union song_ev e;
546 e.ss_vibrato.trk_id = track;
547 e.ss_vibrato.vib_depth = depth;
548 e.ss_vibrato.vib_freq = freq;
550 add_song_ev(SONG_EV_SS_VIBRATO, cur_time, &e);
554 static void add_ss_portamento_event(double portamento)
556 union song_ev e;
558 e.ss_portamento.trk_id = track;
559 e.ss_portamento.portamento = portamento;
561 add_song_ev(SONG_EV_SS_PORTAMENTO, cur_time, &e);
565 static void add_ss_channel_event(int channel, float vol)
567 union song_ev e;
569 e.ss_channel.trk_id = track;
570 e.ss_channel.channel = channel;
571 e.ss_channel.vol = vol;
573 add_song_ev(SONG_EV_SS_CHANNEL, cur_time, &e);
577 static void add_ss_wav_event(char * wav_file, int base, int min, int max,
578 double loop_start, double loop_end, int first_channel, int skip_channels)
580 union song_ev e;
582 e.ss_wav.trk_id = track;
583 e.ss_wav.file = wav_file;
584 e.ss_wav.base = base;
585 e.ss_wav.min = min;
586 e.ss_wav.max = max;
587 e.ss_wav.loop_start = loop_start;
588 e.ss_wav.loop_end = loop_end;
589 e.ss_wav.first_channel = first_channel;
590 e.ss_wav.skip_channels = skip_channels;
592 add_song_ev(SONG_EV_SS_WAV, cur_time, &e);
596 static void add_ss_pat_event(char * pat_file)
598 union song_ev e;
600 e.ss_pat.trk_id = track;
601 e.ss_pat.file = pat_file;
603 add_song_ev(SONG_EV_SS_PAT, cur_time, &e);
607 static void add_ss_eff_event(int type, int channel, double size, float gain,
608 double depth, double freq, double phase, float initial, float final)
610 union song_ev e;
612 e.ss_eff.trk_id = track;
613 e.ss_eff.channel = channel;
614 e.ss_eff.size = size;
615 e.ss_eff.gain = gain;
616 e.ss_eff.depth = depth;
617 e.ss_eff.freq = freq;
618 e.ss_eff.phase = phase;
619 e.ss_eff.initial = initial;
620 e.ss_eff.final = final;
622 add_song_ev(type, cur_time, &e);
626 static void add_ss_pitch_stretch(int note, double len, float vol)
628 union song_ev e;
630 e.ss_pitch_stretch.trk_id = track;
631 e.ss_pitch_stretch.note = note;
632 e.ss_pitch_stretch.len = len;
633 e.ss_pitch_stretch.vol = vol;
635 add_song_ev(SONG_EV_SS_PITCH_STRETCH, cur_time, &e);
639 static void add_ss_print_wave_tempo(int note, double len)
641 union song_ev e;
643 e.ss_print_wave_tempo.trk_id = track;
644 e.ss_print_wave_tempo.note = note;
645 e.ss_print_wave_tempo.len = len;
647 add_song_ev(SONG_EV_SS_PRINT_WAVE_TEMPO, cur_time, &e);
651 static void add_midi_channel_event(int channel)
653 union song_ev e;
655 e.midi_channel.trk_id = track;
656 e.midi_channel.channel = channel - 1;
658 add_song_ev(SONG_EV_MIDI_CHANNEL, cur_time, &e);
662 static void add_midi_program_event(int program)
664 union song_ev e;
666 e.midi_program.trk_id = track;
667 e.midi_program.program = program;
669 add_song_ev(SONG_EV_MIDI_PROGRAM, cur_time, &e);
673 static void add_song_info_event(char * author, char * name)
675 union song_ev e;
677 e.song_info.trk_id = track;
678 e.song_info.author = author;
679 e.song_info.name = name;
681 add_song_ev(SONG_EV_SONG_INFO, cur_time, &e);
685 static void init_track(void)
686 /* sets the default values for a new track */
688 int n;
690 cur_time = 0.0;
691 length = 0.0;
692 transpose = 0;
693 staccato = 0.8;
694 volume = 0.75;
695 octave = 5;
696 gliss = 0;
698 /* groups should not cross track boundaries */
699 n_groups = 0;
701 /* reset arpeggiator */
702 n_arps = 0;
703 arp_default();
705 /* reset alterations */
706 for(n = 0;n < 12;n++)
707 alterations[n] = 0;
713 %union {
714 int i;
715 double d;
716 char * p;
719 %token <i> P_INTEGER S_INTEGER
720 %token <d> P_REAL S_REAL
721 %token <i> NOTE_P NOTE_T3 NOTE_T5
722 %token <p> NEW_MARK GOTO_MARK ASSERT_MARK
724 %token <p> BLOCK BLK_ASSIGN BLK_INSERT FILE_INSERT
726 %token <p> ALTSTR
728 %token <p> XC_STR
729 %token <i> XC_ABSNOTE
730 %token <d> XC_MSECS
732 %token SS_SEP SS_WAV SS_LOOP_WAV SS_PAT
733 %token SS_SUSTAIN SS_VIBRATO SS_PORTAMENTO SS_CHANNEL SS_VOL
735 %token SS_EFF_DELAY SS_EFF_ECHO SS_EFF_COMB SS_EFF_ALLPASS SS_EFF_FLANGER
736 %token SS_EFF_WOBBLE SS_EFF_SQWOBBLE SS_EFF_HFWOBBLE
737 %token SS_EFF_FADER SS_EFF_REVERB SS_EFF_FOLDBACK SS_EFF_OFF
739 %token SS_PITCH_STRETCH SS_TIME_STRETCH SS_PRINT_WAVE_TEMPO
741 %token SONG_INFO
743 %token MIDI_CHANNEL MIDI_PROGRAM MIDI_GENERIC
745 %type <i> integer note note_pitch rest back
746 %type <d> real p_number number note_length
748 %type <d> arp_list arp_note
749 %type <i> xc_absnote
753 script:
754 script stmt { ; }
755 | /* NULL */
758 stmt:
759 note {
760 /* note event */
761 add_note_event($1);
762 forward(length);
764 | rest {
765 /* rest */
766 forward(length);
768 | back {
769 /* back */
770 add_back_event();
772 | 'z' note_length {
773 /* zero note */
774 length = $2;
776 | 'o' P_INTEGER {
777 /* absolute octave */
778 octave = $2;
780 | 'o' S_INTEGER {
781 /* relative octave */
782 octave += $2;
784 | 'v' P_INTEGER {
785 /* absolute volume */
786 volume = (float)$2;
788 | 'v' P_REAL {
789 /* absolute volume */
790 volume = (float)$2;
792 | 'v' S_REAL {
793 /* relative volume */
794 volume += (float)$2;
796 | 't' integer {
797 /* transpose */
798 transpose = $2;
800 | 's' p_number {
801 /* staccato */
802 staccato = $2;
805 | '<' {
806 /* start of group */
807 push_group();
809 | ';' {
810 /* group delimiter */
811 next_group_part();
813 | '>' {
814 /* end of group */
815 pop_group();
817 | 'l' note_length {
818 /* glissando */
819 gliss = $2;
822 | '|' {
823 /* measure mark event */
824 add_measure_event();
827 | NEW_MARK {
828 /* add new mark */
829 add_mark($1);
831 | GOTO_MARK {
832 /* go to mark */
833 find_mark($1, 1);
835 | ASSERT_MARK {
836 /* assert mark */
837 find_mark($1, 0);
840 | '\\' {
841 /* new track */
843 track++;
844 init_track();
846 | 'T' p_number {
847 /* tempo setting */
848 add_tempo_event(-1, $2);
850 | 'M' P_INTEGER '/' P_INTEGER {
851 /* meter (time signature) setting */
852 add_meter_event(-1, $2, $4);
854 | ALTSTR {
855 /* alteration string */
856 set_alteration($1);
859 | BLOCK '*' P_INTEGER {
860 /* repeat block */
861 int n;
863 /* store the block as <TMP> */
864 set_block("<TMP>", $1);
866 for(n = 0;n < $3;n++)
867 insert_block("<TMP>");
869 | BLOCK BLK_ASSIGN {
870 /* assign block */
871 set_block($2, $1);
873 | BLK_INSERT {
874 /* insert block */
875 insert_block($1);
877 | FILE_INSERT {
878 /* insert file */
879 insert_file($1);
882 | arp { ; }
884 | xc_cmd { ; }
888 integer:
889 P_INTEGER { $$ = $1; }
890 | S_INTEGER { $$ = $1; }
893 real:
894 P_REAL { $$ = $1; }
895 | S_REAL { $$ = $1; }
898 p_number:
899 P_INTEGER { $$ = (double) $1; }
900 | P_REAL { $$ = $1; }
903 number:
904 integer { $$ = (double) $1; }
905 | real { $$ = $1; }
908 note:
909 note_pitch { $$ = $1; }
910 | note note_length { $$ = $1; length=$2; }
911 | note '~' number { $$ = $1; DEBUGF("imm volume: %lf\n", $3); }
914 note_pitch:
915 NOTE_P { $$ = $1; }
916 | note_pitch '&' { $$ = $1 - 1; }
917 | note_pitch '#' { $$ = $1 + 1; }
918 | note_pitch '\'' { $$ = $1 + 12; }
919 | note_pitch ',' { $$ = $1 - 12; }
922 note_length:
923 P_INTEGER { $$ = 1 / (double) $1; }
924 | note_length NOTE_T3 { $$ = $1 * 2.0 / 3.0; }
925 | note_length NOTE_T5 { $$ = $1 * 4.0 / 5.0; }
926 | note_length '*' p_number { $$ = $1 * $3; }
927 | note_length '.' { $$ = $1 * 1.5; }
930 rest:
931 'r' { ; }
932 | rest note_length {
933 /* rest with length */
934 length = $2;
938 back:
939 'k' { ; }
940 | back note_length {
941 /* back with length */
942 length = $2;
946 arp:
947 'x' {
948 /* empty arpeggiator */
949 n_arps = 0;
950 arp_default();
952 | 'x' arp_list { ; }
955 arp_list:
956 arp_note {
957 /* first arpeggiator note */
958 n_arps = 0;
959 add_arp();
961 | arp_list ',' arp_note {
962 /* rest of arpeggiator notes */
963 add_arp();
967 arp_note:
968 note_length {
969 /* arpeggiator delay */
970 arp_delay = $1;
972 | arp_note '~' number {
973 /* arpeggiator volume */
974 arp_volume = (float)$3;
976 | arp_note S_INTEGER {
977 /* arpeggiator transpose */
978 arp_transpose = $2;
980 | arp_note '/' P_INTEGER {
981 /* arpeggiator track offset */
982 arp_track_off = $3;
984 | arp_note NOTE_T3 {
985 /* HACK: /3 */
986 arp_track_off = 3;
988 | arp_note NOTE_T5 {
989 /* HACK: /5 */
990 arp_track_off = 5;
994 xc_absnote:
995 P_INTEGER { $$ = $1; }
996 | XC_ABSNOTE { $$ = $1; }
999 xc_cmd:
1000 SS_WAV XC_STR xc_absnote {
1001 /* load .wav file with just one note */
1002 add_ss_wav_event($2, $3, $3, $3, -1.0, -1.0, 0, 0);
1004 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote {
1005 /* load .wav file */
1006 add_ss_wav_event($2, $3, $4, $5, -1.0, -1.0, 0, 0);
1008 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number {
1009 /* load .wav file, with loop boundaries */
1010 add_ss_wav_event($2, $3, $4, $5, $6, $7, 0, 0);
1012 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number number number {
1013 /* load .wav file, with loop boundaries,
1014 first channel and skip channels */
1015 add_ss_wav_event($2, $3, $4, $5, $6, $7, $8, $9);
1017 | SS_PAT XC_STR {
1018 /* load .pat file */
1019 add_ss_pat_event($2);
1021 | SS_SUSTAIN XC_MSECS {
1022 /* sets sustain */
1023 add_ss_sustain_event($2);
1025 | SS_VIBRATO XC_MSECS number {
1026 /* sets vibrato */
1027 add_ss_vibrato_event($2, $3);
1029 | SS_PORTAMENTO number {
1030 /* sets portamento */
1031 add_ss_portamento_event($2);
1033 | SS_CHANNEL integer number {
1034 /* sets volume for a channel */
1035 add_ss_channel_event($2, $3);
1037 | SS_VOL number number {
1038 /* set vol for 2 channels */
1039 add_ss_channel_event(0, $2);
1040 add_ss_channel_event(1, $3);
1042 | SS_VOL number number number {
1043 /* set vol for 3 channels */
1044 add_ss_channel_event(0, $2);
1045 add_ss_channel_event(1, $3);
1046 add_ss_channel_event(2, $4);
1048 | SS_VOL number number number number {
1049 /* set vol for 4 channels */
1050 add_ss_channel_event(0, $2);
1051 add_ss_channel_event(1, $3);
1052 add_ss_channel_event(2, $4);
1053 add_ss_channel_event(3, $5);
1055 | SS_VOL number number number number number number {
1056 /* set vol for 6 channels */
1057 add_ss_channel_event(0, $2);
1058 add_ss_channel_event(1, $3);
1059 add_ss_channel_event(2, $4);
1060 add_ss_channel_event(3, $5);
1061 add_ss_channel_event(4, $6);
1062 add_ss_channel_event(5, $7);
1064 | SS_EFF_DELAY integer XC_MSECS {
1065 /* delay effect */
1066 add_ss_eff_event(SONG_EV_SS_EFF_DELAY,
1067 $2, $3, 0, 0, 0, 0, 0, 0);
1070 | SS_EFF_ECHO integer XC_MSECS number {
1071 /* echo effect */
1072 add_ss_eff_event(SONG_EV_SS_EFF_ECHO,
1073 $2, $3, $4, 0, 0, 0, 0, 0);
1076 | SS_EFF_COMB integer XC_MSECS number {
1077 /* comb effect */
1078 add_ss_eff_event(SONG_EV_SS_EFF_COMB,
1079 $2, $3, $4, 0, 0, 0, 0, 0);
1082 | SS_EFF_ALLPASS integer XC_MSECS number {
1083 /* allpass effect */
1084 add_ss_eff_event(SONG_EV_SS_EFF_ALLPASS,
1085 $2, $3, $4, 0, 0, 0, 0, 0);
1088 | SS_EFF_FLANGER integer XC_MSECS number XC_MSECS number number {
1089 /* flanger effect */
1090 add_ss_eff_event(SONG_EV_SS_EFF_FLANGER,
1091 $2, $3, $4, $5, $6, $7, 0, 0);
1094 | SS_EFF_WOBBLE integer number number {
1095 /* wobble effect */
1096 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1097 $2, 0, 0, 0, $3, $4, 0, 0);
1100 | SS_EFF_SQWOBBLE integer number number {
1101 /* square wobble effect */
1102 add_ss_eff_event(SONG_EV_SS_EFF_SQWOBBLE,
1103 $2, 0, 0, 0, $3, $4, 0, 0);
1106 | SS_EFF_HFWOBBLE integer number number {
1107 /* half wobble effect */
1108 add_ss_eff_event(SONG_EV_SS_EFF_HFWOBBLE,
1109 $2, 0, 0, 0, $3, $4, 0, 0);
1112 | SS_EFF_FADER integer XC_MSECS number number {
1113 /* fader effect */
1114 add_ss_eff_event(SONG_EV_SS_EFF_FADER,
1115 $2, $3, 0, 0, 0, 0, $4, $5);
1118 | SS_EFF_REVERB integer {
1119 /* reverb effect */
1120 add_ss_eff_event(SONG_EV_SS_EFF_REVERB,
1121 $2, 0, 0, 0, 0, 0, 0, 0);
1124 | SS_EFF_FOLDBACK integer number {
1125 /* foldback distortion effect */
1126 add_ss_eff_event(SONG_EV_SS_EFF_FOLDBACK,
1127 $2, 0, $3, 0, 0, 0, 0, 0);
1129 | SS_EFF_OFF integer {
1130 /* off effect */
1131 add_ss_eff_event(SONG_EV_SS_EFF_OFF,
1132 $2, 0, 0, 0, 0, 0, 0, 0);
1135 | SS_PITCH_STRETCH xc_absnote number number {
1136 /* pitch stretch note */
1137 add_ss_pitch_stretch($2, $3, $4);
1139 forward($3);
1142 | SS_PRINT_WAVE_TEMPO xc_absnote number {
1143 /* print tempo from wave */
1144 add_ss_print_wave_tempo($2, $3);
1147 | SONG_INFO XC_STR XC_STR {
1148 /* add song info */
1149 add_song_info_event($2, $3);
1152 | MIDI_CHANNEL integer {
1153 /* midi channel */
1154 add_midi_channel_event($2);
1157 | MIDI_PROGRAM integer {
1158 /* midi program */
1159 add_midi_program_event($2);
1165 void yyerror(char * s)
1167 c_err(s, NULL, NULL);
1171 #define set_block_d(n,b) set_block(n,strdup(b))
1173 static void compile_startup(void)
1175 track = 0;
1176 yyline = 1;
1177 compiler_error = 0;
1179 /* default settings */
1180 add_tempo_event(-2, 120.0);
1181 add_meter_event(-2, 4, 4);
1182 init_track();
1184 /* standard tonalities */
1185 set_block_d("CM", "A"); set_block_d("Am", "$CM");
1186 set_block_d("C#M", "A#######"); set_block_d("A#m", "$C#M");
1187 set_block_d("DM", "A#--#---"); set_block_d("Bm", "$DM");
1188 set_block_d("E&M", "A--&--&&"); set_block_d("Cm", "$E&M");
1189 set_block_d("EM", "A##-##--"); set_block_d("C#m", "$EM");
1190 set_block_d("FM", "A------&"); set_block_d("Dm", "$FM");
1191 set_block_d("F#M", "A######-"); set_block_d("D#m", "$F#M");
1192 set_block_d("GM", "A---#---"); set_block_d("Em", "$GM");
1193 set_block_d("A&M", "A-&&--&&"); set_block_d("Fm", "$A&M");
1194 set_block_d("AM", "A#--##--"); set_block_d("F#m", "$AM");
1195 set_block_d("B&M", "A--&---&"); set_block_d("Gm", "$B&M");
1196 set_block_d("BM", "A##-###-"); set_block_d("G#m", "$BM");
1200 int compile_ahs_string(char * code)
1202 compile_startup();
1204 push_code(strdup(code));
1206 return(yyparse() + compiler_error);
1210 int compile_ahs(char * file)
1212 compile_startup();
1214 if(insert_file(file))
1215 return(1);
1217 return(yyparse() + compiler_error);