EOTs are inserted in song_sort(), so they are really each track's last
[ahxm.git] / compiler.y
blob890c6f499da1e6c174402c3de2af07060f1d64e2
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 alteration */
456 if((n = note % 12) < 0) n += 12;
457 note += alterations[n];
459 /* calculate the note */
460 np = note + transpose + (octave * 12);
462 /* is note out of range? */
463 if(np < 0 || np > 127)
465 c_err("note-out-of-range", NULL, NULL);
466 return;
469 e.note.trk_id = track;
470 e.note.note = np;
471 e.note.len = length * staccato;
472 e.note.vol = volume;
474 add_song_ev(SONG_EV_NOTE, cur_time, &e);
476 /* add arpeggiator repetitions */
477 for(n = 0;n < n_arps;n++)
479 e.note.trk_id = track + arps[n].track_off;
480 e.note.note = np + arps[n].transpose;
481 e.note.vol = volume * arps[n].volume;
483 add_song_ev(SONG_EV_NOTE, cur_time + arps[n].delay, &e);
488 static void add_back_event(void)
490 union song_ev e;
492 e.back.trk_id = track;
493 e.back.len = length;
494 add_song_ev(SONG_EV_BACK, cur_time, &e);
498 static void add_tempo_event(int trk_id, double tempo)
500 union song_ev e;
502 e.tempo.trk_id = trk_id;
503 e.tempo.tempo = tempo;
504 add_song_ev(SONG_EV_TEMPO, cur_time, &e);
508 static void add_meter_event(int trk_id, int num, int den)
510 union song_ev e;
512 e.meter.trk_id = trk_id;
513 e.meter.num = num;
514 e.meter.den = den;
515 add_song_ev(SONG_EV_METER, cur_time, &e);
518 static void add_measure_event(void)
520 union song_ev e;
522 e.measure.trk_id = -1;
523 e.measure.line = yyline;
525 add_song_ev(SONG_EV_MEASURE, cur_time, &e);
529 static void add_ss_sustain_event(double sustain)
531 union song_ev e;
533 e.ss_sustain.trk_id = track;
534 e.ss_sustain.sustain = sustain;
536 add_song_ev(SONG_EV_SS_SUSTAIN, cur_time, &e);
540 static void add_ss_vibrato_event(double depth, double freq)
542 union song_ev e;
544 e.ss_vibrato.trk_id = track;
545 e.ss_vibrato.vib_depth = depth;
546 e.ss_vibrato.vib_freq = freq;
548 add_song_ev(SONG_EV_SS_VIBRATO, cur_time, &e);
552 static void add_ss_portamento_event(double portamento)
554 union song_ev e;
556 e.ss_portamento.trk_id = track;
557 e.ss_portamento.portamento = portamento;
559 add_song_ev(SONG_EV_SS_PORTAMENTO, cur_time, &e);
563 static void add_ss_channel_event(int channel, float vol)
565 union song_ev e;
567 e.ss_channel.trk_id = track;
568 e.ss_channel.channel = channel;
569 e.ss_channel.vol = vol;
571 add_song_ev(SONG_EV_SS_CHANNEL, cur_time, &e);
575 static void add_ss_wav_event(char * wav_file, int base, int min, int max,
576 double loop_start, double loop_end, int first_channel, int skip_channels)
578 union song_ev e;
580 e.ss_wav.trk_id = track;
581 e.ss_wav.file = wav_file;
582 e.ss_wav.base = base;
583 e.ss_wav.min = min;
584 e.ss_wav.max = max;
585 e.ss_wav.loop_start = loop_start;
586 e.ss_wav.loop_end = loop_end;
587 e.ss_wav.first_channel = first_channel;
588 e.ss_wav.skip_channels = skip_channels;
590 add_song_ev(SONG_EV_SS_WAV, cur_time, &e);
594 static void add_ss_pat_event(char * pat_file)
596 union song_ev e;
598 e.ss_pat.trk_id = track;
599 e.ss_pat.file = pat_file;
601 add_song_ev(SONG_EV_SS_PAT, cur_time, &e);
605 static void add_ss_eff_event(int type, int channel, double size, float gain,
606 double depth, double freq, double phase, float initial, float final)
608 union song_ev e;
610 e.ss_eff.trk_id = track;
611 e.ss_eff.channel = channel;
612 e.ss_eff.size = size;
613 e.ss_eff.gain = gain;
614 e.ss_eff.depth = depth;
615 e.ss_eff.freq = freq;
616 e.ss_eff.phase = phase;
617 e.ss_eff.initial = initial;
618 e.ss_eff.final = final;
620 add_song_ev(type, cur_time, &e);
624 static void add_ss_pitch_stretch(int note, double len, float vol)
626 union song_ev e;
628 e.ss_pitch_stretch.trk_id = track;
629 e.ss_pitch_stretch.note = note;
630 e.ss_pitch_stretch.len = len;
631 e.ss_pitch_stretch.vol = vol;
633 add_song_ev(SONG_EV_SS_PITCH_STRETCH, cur_time, &e);
637 static void add_ss_print_wave_tempo(int note, double len)
639 union song_ev e;
641 e.ss_print_wave_tempo.trk_id = track;
642 e.ss_print_wave_tempo.note = note;
643 e.ss_print_wave_tempo.len = len;
645 add_song_ev(SONG_EV_SS_PRINT_WAVE_TEMPO, cur_time, &e);
649 static void add_midi_channel_event(int channel)
651 union song_ev e;
653 e.midi_channel.trk_id = track;
654 e.midi_channel.channel = channel - 1;
656 add_song_ev(SONG_EV_MIDI_CHANNEL, cur_time, &e);
660 static void add_midi_program_event(int program)
662 union song_ev e;
664 e.midi_program.trk_id = track;
665 e.midi_program.program = program;
667 add_song_ev(SONG_EV_MIDI_PROGRAM, cur_time, &e);
671 static void add_song_info_event(char * author, char * name)
673 union song_ev e;
675 e.song_info.trk_id = track;
676 e.song_info.author = author;
677 e.song_info.name = name;
679 add_song_ev(SONG_EV_SONG_INFO, cur_time, &e);
683 static void init_track(void)
684 /* sets the default values for a new track */
686 int n;
688 cur_time = 0.0;
689 length = 0.0;
690 transpose = 0;
691 staccato = 0.8;
692 volume = 0.75;
693 octave = 5;
694 gliss = 0;
696 /* groups should not cross track boundaries */
697 n_groups = 0;
699 /* reset arpeggiator */
700 n_arps = 0;
701 arp_default();
703 /* reset alterations */
704 for(n = 0;n < 12;n++)
705 alterations[n] = 0;
711 %union {
712 int i;
713 double d;
714 char * p;
717 %token <i> P_INTEGER S_INTEGER
718 %token <d> P_REAL S_REAL
719 %token <i> NOTE_P NOTE_T3 NOTE_T5
720 %token <p> NEW_MARK GOTO_MARK ASSERT_MARK
722 %token <p> BLOCK BLK_ASSIGN BLK_INSERT FILE_INSERT
724 %token <p> ALTSTR
726 %token <p> XC_STR
727 %token <i> XC_ABSNOTE
728 %token <d> XC_MSECS
730 %token SS_SEP SS_WAV SS_LOOP_WAV SS_PAT
731 %token SS_SUSTAIN SS_VIBRATO SS_PORTAMENTO SS_CHANNEL SS_VOL
733 %token SS_EFF_DELAY SS_EFF_ECHO SS_EFF_COMB SS_EFF_ALLPASS SS_EFF_FLANGER
734 %token SS_EFF_WOBBLE SS_EFF_SQWOBBLE SS_EFF_HFWOBBLE
735 %token SS_EFF_FADER SS_EFF_REVERB SS_EFF_FOLDBACK SS_EFF_OFF
737 %token SS_PITCH_STRETCH SS_TIME_STRETCH SS_PRINT_WAVE_TEMPO
739 %token SONG_INFO
741 %token MIDI_CHANNEL MIDI_PROGRAM MIDI_GENERIC
743 %type <i> integer note note_pitch rest back
744 %type <d> real p_number number note_length
746 %type <d> arp_list arp_note
747 %type <i> xc_absnote
751 script:
752 script stmt { ; }
753 | /* NULL */
756 stmt:
757 note {
758 /* note event */
759 add_note_event($1);
760 forward(length);
762 | rest {
763 /* rest */
764 forward(length);
766 | back {
767 /* back */
768 add_back_event();
770 | 'z' note_length {
771 /* zero note */
772 length = $2;
774 | 'o' P_INTEGER {
775 /* absolute octave */
776 octave = $2;
778 | 'o' S_INTEGER {
779 /* relative octave */
780 octave += $2;
782 | 'v' P_INTEGER {
783 /* absolute volume */
784 volume = (float)$2;
786 | 'v' P_REAL {
787 /* absolute volume */
788 volume = (float)$2;
790 | 'v' S_REAL {
791 /* relative volume */
792 volume += (float)$2;
794 | 't' integer {
795 /* transpose */
796 transpose = $2;
798 | 's' p_number {
799 /* staccato */
800 staccato = $2;
803 | '<' {
804 /* start of group */
805 push_group();
807 | ';' {
808 /* group delimiter */
809 next_group_part();
811 | '>' {
812 /* end of group */
813 pop_group();
815 | 'l' note_length {
816 /* glissando */
817 gliss = $2;
820 | '|' {
821 /* measure mark event */
822 add_measure_event();
825 | NEW_MARK {
826 /* add new mark */
827 add_mark($1);
829 | GOTO_MARK {
830 /* go to mark */
831 find_mark($1, 1);
833 | ASSERT_MARK {
834 /* assert mark */
835 find_mark($1, 0);
838 | '\\' {
839 /* new track */
841 track++;
842 init_track();
844 | 'T' p_number {
845 /* tempo setting */
846 add_tempo_event(-1, $2);
848 | 'M' P_INTEGER '/' P_INTEGER {
849 /* meter (time signature) setting */
850 add_meter_event(-1, $2, $4);
852 | ALTSTR {
853 /* alteration string */
854 set_alteration($1);
857 | BLOCK '*' P_INTEGER {
858 /* repeat block */
859 int n;
861 /* store the block as <TMP> */
862 set_block("<TMP>", $1);
864 for(n = 0;n < $3;n++)
865 insert_block("<TMP>");
867 | BLOCK BLK_ASSIGN {
868 /* assign block */
869 set_block($2, $1);
871 | BLK_INSERT {
872 /* insert block */
873 insert_block($1);
875 | FILE_INSERT {
876 /* insert file */
877 insert_file($1);
880 | arp { ; }
882 | xc_cmd { ; }
886 integer:
887 P_INTEGER { $$ = $1; }
888 | S_INTEGER { $$ = $1; }
891 real:
892 P_REAL { $$ = $1; }
893 | S_REAL { $$ = $1; }
896 p_number:
897 P_INTEGER { $$ = (double) $1; }
898 | P_REAL { $$ = $1; }
901 number:
902 integer { $$ = (double) $1; }
903 | real { $$ = $1; }
906 note:
907 note_pitch { $$ = $1; }
908 | note note_length { $$ = $1; length=$2; }
909 | note '~' number { $$ = $1; DEBUGF("imm volume: %lf\n", $3); }
912 note_pitch:
913 NOTE_P { $$ = $1; }
914 | note_pitch '&' { $$ = $1 - 1; }
915 | note_pitch '#' { $$ = $1 + 1; }
916 | note_pitch '\'' { $$ = $1 + 12; }
917 | note_pitch ',' { $$ = $1 - 12; }
920 note_length:
921 P_INTEGER { $$ = 1 / (double) $1; }
922 | note_length NOTE_T3 { $$ = $1 * 2.0 / 3.0; }
923 | note_length NOTE_T5 { $$ = $1 * 4.0 / 5.0; }
924 | note_length '*' p_number { $$ = $1 * $3; }
925 | note_length '.' { $$ = $1 * 1.5; }
928 rest:
929 'r' { ; }
930 | rest note_length {
931 /* rest with length */
932 length = $2;
936 back:
937 'k' { ; }
938 | back note_length {
939 /* back with length */
940 length = $2;
944 arp:
945 'x' {
946 /* empty arpeggiator */
947 n_arps = 0;
948 arp_default();
950 | 'x' arp_list { ; }
953 arp_list:
954 arp_note {
955 /* first arpeggiator note */
956 n_arps = 0;
957 add_arp();
959 | arp_list ',' arp_note {
960 /* rest of arpeggiator notes */
961 add_arp();
965 arp_note:
966 note_length {
967 /* arpeggiator delay */
968 arp_delay = $1;
970 | arp_note '~' number {
971 /* arpeggiator volume */
972 arp_volume = (float)$3;
974 | arp_note S_INTEGER {
975 /* arpeggiator transpose */
976 arp_transpose = $2;
978 | arp_note '/' P_INTEGER {
979 /* arpeggiator track offset */
980 arp_track_off = $3;
982 | arp_note NOTE_T3 {
983 /* HACK: /3 */
984 arp_track_off = 3;
986 | arp_note NOTE_T5 {
987 /* HACK: /5 */
988 arp_track_off = 5;
992 xc_absnote:
993 P_INTEGER { $$ = $1; }
994 | XC_ABSNOTE { $$ = $1; }
997 xc_cmd:
998 SS_WAV XC_STR xc_absnote {
999 /* load .wav file with just one note */
1000 add_ss_wav_event($2, $3, $3, $3, -1.0, -1.0, 0, 0);
1002 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote {
1003 /* load .wav file */
1004 add_ss_wav_event($2, $3, $4, $5, -1.0, -1.0, 0, 0);
1006 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number {
1007 /* load .wav file, with loop boundaries */
1008 add_ss_wav_event($2, $3, $4, $5, $6, $7, 0, 0);
1010 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number number number {
1011 /* load .wav file, with loop boundaries,
1012 first channel and skip channels */
1013 add_ss_wav_event($2, $3, $4, $5, $6, $7, $8, $9);
1015 | SS_PAT XC_STR {
1016 /* load .pat file */
1017 add_ss_pat_event($2);
1019 | SS_SUSTAIN XC_MSECS {
1020 /* sets sustain */
1021 add_ss_sustain_event($2);
1023 | SS_VIBRATO XC_MSECS number {
1024 /* sets vibrato */
1025 add_ss_vibrato_event($2, $3);
1027 | SS_PORTAMENTO number {
1028 /* sets portamento */
1029 add_ss_portamento_event($2);
1031 | SS_CHANNEL integer number {
1032 /* sets volume for a channel */
1033 add_ss_channel_event($2, $3);
1035 | SS_VOL number number {
1036 /* set vol for 2 channels */
1037 add_ss_channel_event(0, $2);
1038 add_ss_channel_event(1, $3);
1040 | SS_VOL number number number {
1041 /* set vol for 3 channels */
1042 add_ss_channel_event(0, $2);
1043 add_ss_channel_event(1, $3);
1044 add_ss_channel_event(2, $4);
1046 | SS_VOL number number number number {
1047 /* set vol for 4 channels */
1048 add_ss_channel_event(0, $2);
1049 add_ss_channel_event(1, $3);
1050 add_ss_channel_event(2, $4);
1051 add_ss_channel_event(3, $5);
1053 | SS_VOL number number number number number number {
1054 /* set vol for 6 channels */
1055 add_ss_channel_event(0, $2);
1056 add_ss_channel_event(1, $3);
1057 add_ss_channel_event(2, $4);
1058 add_ss_channel_event(3, $5);
1059 add_ss_channel_event(4, $6);
1060 add_ss_channel_event(5, $7);
1062 | SS_EFF_DELAY integer XC_MSECS {
1063 /* delay effect */
1064 add_ss_eff_event(SONG_EV_SS_EFF_DELAY,
1065 $2, $3, 0, 0, 0, 0, 0, 0);
1068 | SS_EFF_ECHO integer XC_MSECS number {
1069 /* echo effect */
1070 add_ss_eff_event(SONG_EV_SS_EFF_ECHO,
1071 $2, $3, $4, 0, 0, 0, 0, 0);
1074 | SS_EFF_COMB integer XC_MSECS number {
1075 /* comb effect */
1076 add_ss_eff_event(SONG_EV_SS_EFF_COMB,
1077 $2, $3, $4, 0, 0, 0, 0, 0);
1080 | SS_EFF_ALLPASS integer XC_MSECS number {
1081 /* allpass effect */
1082 add_ss_eff_event(SONG_EV_SS_EFF_ALLPASS,
1083 $2, $3, $4, 0, 0, 0, 0, 0);
1086 | SS_EFF_FLANGER integer XC_MSECS number XC_MSECS number number {
1087 /* flanger effect */
1088 add_ss_eff_event(SONG_EV_SS_EFF_FLANGER,
1089 $2, $3, $4, $5, $6, $7, 0, 0);
1092 | SS_EFF_WOBBLE integer number number {
1093 /* wobble effect */
1094 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1095 $2, 0, 0.8, 0, $3, $4, 0, 0);
1098 | SS_EFF_WOBBLE integer number number number {
1099 /* wobble effect, with gain */
1100 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1101 $2, 0, $5, 0, $3, $4, 0, 0);
1104 | SS_EFF_SQWOBBLE integer number number {
1105 /* square wobble effect */
1106 add_ss_eff_event(SONG_EV_SS_EFF_SQWOBBLE,
1107 $2, 0, 0, 0, $3, $4, 0, 0);
1110 | SS_EFF_HFWOBBLE integer number number {
1111 /* half wobble effect */
1112 add_ss_eff_event(SONG_EV_SS_EFF_HFWOBBLE,
1113 $2, 0, 0, 0, $3, $4, 0, 0);
1116 | SS_EFF_FADER integer XC_MSECS number number {
1117 /* fader effect */
1118 add_ss_eff_event(SONG_EV_SS_EFF_FADER,
1119 $2, $3, 0, 0, 0, 0, $4, $5);
1122 | SS_EFF_REVERB integer {
1123 /* reverb effect */
1124 add_ss_eff_event(SONG_EV_SS_EFF_REVERB,
1125 $2, 0, 0, 0, 0, 0, 0, 0);
1128 | SS_EFF_FOLDBACK integer number {
1129 /* foldback distortion effect */
1130 add_ss_eff_event(SONG_EV_SS_EFF_FOLDBACK,
1131 $2, 0, $3, 0, 0, 0, 0, 0);
1133 | SS_EFF_OFF integer {
1134 /* off effect */
1135 add_ss_eff_event(SONG_EV_SS_EFF_OFF,
1136 $2, 0, 0, 0, 0, 0, 0, 0);
1139 | SS_PITCH_STRETCH xc_absnote number number {
1140 /* pitch stretch note */
1141 add_ss_pitch_stretch($2, $3, $4);
1143 forward($3);
1146 | SS_PRINT_WAVE_TEMPO xc_absnote number {
1147 /* print tempo from wave */
1148 add_ss_print_wave_tempo($2, $3);
1151 | SONG_INFO XC_STR XC_STR {
1152 /* add song info */
1153 add_song_info_event($2, $3);
1156 | MIDI_CHANNEL integer {
1157 /* midi channel */
1158 add_midi_channel_event($2);
1161 | MIDI_PROGRAM integer {
1162 /* midi program */
1163 add_midi_program_event($2);
1169 void yyerror(char * s)
1171 c_err(s, NULL, NULL);
1175 #define set_block_d(n,b) set_block(n,strdup(b))
1177 static void compile_startup(void)
1179 track = 0;
1180 yyline = 1;
1181 compiler_error = 0;
1183 /* default settings */
1184 add_tempo_event(-2, 120.0);
1185 add_meter_event(-2, 4, 4);
1186 init_track();
1188 /* standard tonalities */
1189 set_block_d("CM", "A"); set_block_d("Am", "$CM");
1190 set_block_d("C#M", "A#######"); set_block_d("A#m", "$C#M");
1191 set_block_d("DM", "A#--#---"); set_block_d("Bm", "$DM");
1192 set_block_d("E&M", "A--&--&&"); set_block_d("Cm", "$E&M");
1193 set_block_d("EM", "A##-##--"); set_block_d("C#m", "$EM");
1194 set_block_d("FM", "A------&"); set_block_d("Dm", "$FM");
1195 set_block_d("F#M", "A######-"); set_block_d("D#m", "$F#M");
1196 set_block_d("GM", "A---#---"); set_block_d("Em", "$GM");
1197 set_block_d("A&M", "A-&&--&&"); set_block_d("Fm", "$A&M");
1198 set_block_d("AM", "A#--##--"); set_block_d("F#m", "$AM");
1199 set_block_d("B&M", "A--&---&"); set_block_d("Gm", "$B&M");
1200 set_block_d("BM", "A##-###-"); set_block_d("G#m", "$BM");
1204 static int do_parse(void)
1206 int r = yyparse();
1208 return(r + compiler_error);
1212 int compile_ahs_string(char * code)
1214 compile_startup();
1216 push_code(strdup(code));
1218 return(do_parse());
1222 int compile_ahs(char * file)
1224 compile_startup();
1226 if(insert_file(file))
1227 return(1);
1229 return(do_parse());