Marks can now be rewritten.
[ahxm.git] / compiler.y
blob26b0aacfc75a2173dac851e20f082e769363bd80
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 int seek_mark(char * name)
344 /* seeks a mark by name; returns its offset or -1 */
346 int n;
348 for(n = 0;n < n_marks;n++)
349 if(strcmp(marks[n].name, name) == 0)
350 return(n);
352 return(-1);
356 static void add_mark(char * name)
357 /* creates a new mark */
359 int n;
361 if((n = seek_mark(name)) == -1)
363 n = n_marks++;
364 GROW(marks, n, struct mark);
365 marks[n].name = strdup(name);
368 marks[n].time = cur_time;
372 static void find_mark(char * name, int set)
373 /* finds a mark by name, optionally moving time cursor there */
375 int n;
377 if((n = seek_mark(name)) != -1)
379 if(set)
381 if(cur_time > marks[n].time)
382 c_err("mark-overpassed", name, NULL);
383 else
384 cur_time = marks[n].time;
386 else
387 if(cur_time != marks[n].time)
388 c_err("mark-mismatch", name, NULL);
390 return;
393 c_err("mark-not-found", name, NULL);
397 /* arpeggiator */
399 static void arp_default(void)
400 /* resets arpeggiator values to the default ones */
402 arp_delay = 0.0;
403 arp_transpose = 0;
404 arp_volume = 1.0;
405 arp_track_off = 0;
409 static void add_arp(void)
410 /* adds an arpeggiator note */
412 struct arp * a;
414 /* if the note is exactly the same, do nothing */
415 if(arp_delay == 0.0 && arp_transpose == 0 &&
416 arp_volume == 1.0 && arp_track_off == 0)
417 return;
419 if(n_arps == arps_size)
421 GROW(arps, arps_size, struct arp);
422 arps_size ++;
425 a = &arps[n_arps];
427 a->delay = arp_delay;
428 a->transpose = arp_transpose;
429 a->volume = arp_volume;
430 a->track_off = arp_track_off;
432 n_arps++;
433 arp_default();
437 static void set_alteration(char * altstr)
438 /* sets the alterations from altstr */
440 int n, steps[] = { 2, 0, 2, 0, 1, 2, 0, 2, 0, 2, 0, 1 };
442 /* reset alterations */
443 for(n = 0;n < 12;n++) alterations[n] = 0;
445 /* changed according the altstr spec */
446 for(n = 0;*altstr != '\0' && n < 12;altstr++)
448 switch(*altstr)
450 case '&': alterations[n] = -1; break;
451 case '#': alterations[n] = 1; break;
454 /* move to next natural note */
455 n += steps[n];
460 /* song events */
462 static void add_note_event(int note)
463 /* adds a note event */
465 int n;
466 int np;
467 union song_ev e;
469 /* sum the alteration */
470 if((n = note % 12) < 0) n += 12;
471 note += alterations[n];
473 /* calculate the note */
474 np = note + transpose + (octave * 12);
476 /* is note out of range? */
477 if(np < 0 || np > 127)
479 c_err("note-out-of-range", NULL, NULL);
480 return;
483 e.note.trk_id = track;
484 e.note.note = np;
485 e.note.len = length * staccato;
486 e.note.vol = volume;
488 add_song_ev(SONG_EV_NOTE, cur_time, &e);
490 /* add arpeggiator repetitions */
491 for(n = 0;n < n_arps;n++)
493 e.note.trk_id = track + arps[n].track_off;
494 e.note.note = np + arps[n].transpose;
495 e.note.vol = volume * arps[n].volume;
497 add_song_ev(SONG_EV_NOTE, cur_time + arps[n].delay, &e);
502 static void add_back_event(void)
504 union song_ev e;
506 e.back.trk_id = track;
507 e.back.len = length;
508 add_song_ev(SONG_EV_BACK, cur_time, &e);
512 static void add_tempo_event(int trk_id, double tempo)
514 union song_ev e;
516 e.tempo.trk_id = trk_id;
517 e.tempo.tempo = tempo;
518 add_song_ev(SONG_EV_TEMPO, cur_time, &e);
522 static void add_meter_event(int trk_id, int num, int den)
524 union song_ev e;
526 e.meter.trk_id = trk_id;
527 e.meter.num = num;
528 e.meter.den = den;
529 add_song_ev(SONG_EV_METER, cur_time, &e);
532 static void add_measure_event(void)
534 union song_ev e;
536 e.measure.trk_id = -1;
537 e.measure.line = yyline;
539 add_song_ev(SONG_EV_MEASURE, cur_time, &e);
543 static void add_ss_sustain_event(double sustain)
545 union song_ev e;
547 e.ss_sustain.trk_id = track;
548 e.ss_sustain.sustain = sustain;
550 add_song_ev(SONG_EV_SS_SUSTAIN, cur_time, &e);
554 static void add_ss_vibrato_event(double depth, double freq)
556 union song_ev e;
558 e.ss_vibrato.trk_id = track;
559 e.ss_vibrato.vib_depth = depth;
560 e.ss_vibrato.vib_freq = freq;
562 add_song_ev(SONG_EV_SS_VIBRATO, cur_time, &e);
566 static void add_ss_portamento_event(double portamento)
568 union song_ev e;
570 e.ss_portamento.trk_id = track;
571 e.ss_portamento.portamento = portamento;
573 add_song_ev(SONG_EV_SS_PORTAMENTO, cur_time, &e);
577 static void add_ss_channel_event(int channel, float vol)
579 union song_ev e;
581 e.ss_channel.trk_id = track;
582 e.ss_channel.channel = channel;
583 e.ss_channel.vol = vol;
585 add_song_ev(SONG_EV_SS_CHANNEL, cur_time, &e);
589 static void add_ss_wav_event(char * wav_file, int base, int min, int max,
590 double loop_start, double loop_end, int first_channel, int skip_channels)
592 union song_ev e;
594 e.ss_wav.trk_id = track;
595 e.ss_wav.file = wav_file;
596 e.ss_wav.base = base;
597 e.ss_wav.min = min;
598 e.ss_wav.max = max;
599 e.ss_wav.loop_start = loop_start;
600 e.ss_wav.loop_end = loop_end;
601 e.ss_wav.first_channel = first_channel;
602 e.ss_wav.skip_channels = skip_channels;
604 add_song_ev(SONG_EV_SS_WAV, cur_time, &e);
608 static void add_ss_pat_event(char * pat_file)
610 union song_ev e;
612 e.ss_pat.trk_id = track;
613 e.ss_pat.file = pat_file;
615 add_song_ev(SONG_EV_SS_PAT, cur_time, &e);
619 static void add_ss_eff_event(int type, int channel, double size, float gain,
620 double depth, double freq, double phase, float initial, float final)
622 union song_ev e;
624 e.ss_eff.trk_id = track;
625 e.ss_eff.channel = channel;
626 e.ss_eff.size = size;
627 e.ss_eff.gain = gain;
628 e.ss_eff.depth = depth;
629 e.ss_eff.freq = freq;
630 e.ss_eff.phase = phase;
631 e.ss_eff.initial = initial;
632 e.ss_eff.final = final;
634 add_song_ev(type, cur_time, &e);
638 static void add_ss_pitch_stretch(int note, double len, float vol)
640 union song_ev e;
642 e.ss_pitch_stretch.trk_id = track;
643 e.ss_pitch_stretch.note = note;
644 e.ss_pitch_stretch.len = len;
645 e.ss_pitch_stretch.vol = vol;
647 add_song_ev(SONG_EV_SS_PITCH_STRETCH, cur_time, &e);
651 static void add_ss_print_wave_tempo(int note, double len)
653 union song_ev e;
655 e.ss_print_wave_tempo.trk_id = track;
656 e.ss_print_wave_tempo.note = note;
657 e.ss_print_wave_tempo.len = len;
659 add_song_ev(SONG_EV_SS_PRINT_WAVE_TEMPO, cur_time, &e);
663 static void add_midi_channel_event(int channel)
665 union song_ev e;
667 e.midi_channel.trk_id = track;
668 e.midi_channel.channel = channel - 1;
670 add_song_ev(SONG_EV_MIDI_CHANNEL, cur_time, &e);
674 static void add_midi_program_event(int program)
676 union song_ev e;
678 e.midi_program.trk_id = track;
679 e.midi_program.program = program;
681 add_song_ev(SONG_EV_MIDI_PROGRAM, cur_time, &e);
685 static void add_song_info_event(char * author, char * name)
687 union song_ev e;
689 e.song_info.trk_id = track;
690 e.song_info.author = author;
691 e.song_info.name = name;
693 add_song_ev(SONG_EV_SONG_INFO, cur_time, &e);
697 static void init_track(void)
698 /* sets the default values for a new track */
700 int n;
702 cur_time = 0.0;
703 length = 0.0;
704 transpose = 0;
705 staccato = 0.8;
706 volume = 0.75;
707 octave = 5;
708 gliss = 0;
710 /* groups should not cross track boundaries */
711 n_groups = 0;
713 /* reset arpeggiator */
714 n_arps = 0;
715 arp_default();
717 /* reset alterations */
718 for(n = 0;n < 12;n++)
719 alterations[n] = 0;
725 %union {
726 int i;
727 double d;
728 char * p;
731 %token <i> P_INTEGER S_INTEGER
732 %token <d> P_REAL S_REAL
733 %token <i> NOTE_P NOTE_T3 NOTE_T5
734 %token <p> NEW_MARK GOTO_MARK ASSERT_MARK
736 %token <p> BLOCK BLK_ASSIGN BLK_INSERT FILE_INSERT
738 %token <p> ALTSTR
740 %token <p> XC_STR
741 %token <i> XC_ABSNOTE
742 %token <d> XC_MSECS
744 %token SS_SEP SS_WAV SS_LOOP_WAV SS_PAT
745 %token SS_SUSTAIN SS_VIBRATO SS_PORTAMENTO SS_CHANNEL SS_VOL
747 %token SS_EFF_DELAY SS_EFF_ECHO SS_EFF_COMB SS_EFF_ALLPASS SS_EFF_FLANGER
748 %token SS_EFF_WOBBLE SS_EFF_SQWOBBLE SS_EFF_HFWOBBLE
749 %token SS_EFF_FADER SS_EFF_REVERB SS_EFF_FOLDBACK SS_EFF_OFF
751 %token SS_PITCH_STRETCH SS_TIME_STRETCH SS_PRINT_WAVE_TEMPO
753 %token SONG_INFO
755 %token MIDI_CHANNEL MIDI_PROGRAM MIDI_GENERIC
757 %type <i> integer note note_pitch rest back
758 %type <d> real p_number number note_length
760 %type <d> arp_list arp_note
761 %type <i> xc_absnote
765 script:
766 script stmt { ; }
767 | /* NULL */
770 stmt:
771 note {
772 /* note event */
773 add_note_event($1);
774 forward(length);
776 | rest {
777 /* rest */
778 forward(length);
780 | back {
781 /* back */
782 add_back_event();
784 | 'z' note_length {
785 /* zero note */
786 length = $2;
788 | 'o' P_INTEGER {
789 /* absolute octave */
790 octave = $2;
792 | 'o' S_INTEGER {
793 /* relative octave */
794 octave += $2;
796 | 'v' P_INTEGER {
797 /* absolute volume */
798 volume = (float)$2;
800 | 'v' P_REAL {
801 /* absolute volume */
802 volume = (float)$2;
804 | 'v' S_REAL {
805 /* relative volume */
806 volume += (float)$2;
808 | 't' integer {
809 /* transpose */
810 transpose = $2;
812 | 's' p_number {
813 /* staccato */
814 staccato = $2;
817 | '<' {
818 /* start of group */
819 push_group();
821 | ';' {
822 /* group delimiter */
823 next_group_part();
825 | '>' {
826 /* end of group */
827 pop_group();
829 | 'l' note_length {
830 /* glissando */
831 gliss = $2;
834 | '|' {
835 /* measure mark event */
836 add_measure_event();
839 | NEW_MARK {
840 /* add new mark */
841 add_mark($1);
843 | GOTO_MARK {
844 /* go to mark */
845 find_mark($1, 1);
847 | ASSERT_MARK {
848 /* assert mark */
849 find_mark($1, 0);
852 | '\\' {
853 /* new track */
855 track++;
856 init_track();
858 | 'T' p_number {
859 /* tempo setting */
860 add_tempo_event(-1, $2);
862 | 'M' P_INTEGER '/' P_INTEGER {
863 /* meter (time signature) setting */
864 add_meter_event(-1, $2, $4);
866 | ALTSTR {
867 /* alteration string */
868 set_alteration($1);
871 | BLOCK '*' P_INTEGER {
872 /* repeat block */
873 int n;
875 /* store the block as <TMP> */
876 set_block("<TMP>", $1);
878 for(n = 0;n < $3;n++)
879 insert_block("<TMP>");
881 | BLOCK BLK_ASSIGN {
882 /* assign block */
883 set_block($2, $1);
885 | BLK_INSERT {
886 /* insert block */
887 insert_block($1);
889 | FILE_INSERT {
890 /* insert file */
891 insert_file($1);
894 | arp { ; }
896 | xc_cmd { ; }
900 integer:
901 P_INTEGER { $$ = $1; }
902 | S_INTEGER { $$ = $1; }
905 real:
906 P_REAL { $$ = $1; }
907 | S_REAL { $$ = $1; }
910 p_number:
911 P_INTEGER { $$ = (double) $1; }
912 | P_REAL { $$ = $1; }
915 number:
916 integer { $$ = (double) $1; }
917 | real { $$ = $1; }
920 note:
921 note_pitch { $$ = $1; }
922 | note note_length { $$ = $1; length=$2; }
923 | note '~' number { $$ = $1; DEBUGF("imm volume: %lf\n", $3); }
926 note_pitch:
927 NOTE_P { $$ = $1; }
928 | note_pitch '&' { $$ = $1 - 1; }
929 | note_pitch '#' { $$ = $1 + 1; }
930 | note_pitch '\'' { $$ = $1 + 12; }
931 | note_pitch ',' { $$ = $1 - 12; }
934 note_length:
935 P_INTEGER { $$ = 1 / (double) $1; }
936 | note_length NOTE_T3 { $$ = $1 * 2.0 / 3.0; }
937 | note_length NOTE_T5 { $$ = $1 * 4.0 / 5.0; }
938 | note_length '*' p_number { $$ = $1 * $3; }
939 | note_length '.' { $$ = $1 * 1.5; }
942 rest:
943 'r' { ; }
944 | rest note_length {
945 /* rest with length */
946 length = $2;
950 back:
951 'k' { ; }
952 | back note_length {
953 /* back with length */
954 length = $2;
958 arp:
959 'x' {
960 /* empty arpeggiator */
961 n_arps = 0;
962 arp_default();
964 | 'x' arp_list { ; }
967 arp_list:
968 arp_note {
969 /* first arpeggiator note */
970 n_arps = 0;
971 add_arp();
973 | arp_list ',' arp_note {
974 /* rest of arpeggiator notes */
975 add_arp();
979 arp_note:
980 note_length {
981 /* arpeggiator delay */
982 arp_delay = $1;
984 | arp_note '~' number {
985 /* arpeggiator volume */
986 arp_volume = (float)$3;
988 | arp_note S_INTEGER {
989 /* arpeggiator transpose */
990 arp_transpose = $2;
992 | arp_note '/' P_INTEGER {
993 /* arpeggiator track offset */
994 arp_track_off = $3;
996 | arp_note NOTE_T3 {
997 /* HACK: /3 */
998 arp_track_off = 3;
1000 | arp_note NOTE_T5 {
1001 /* HACK: /5 */
1002 arp_track_off = 5;
1006 xc_absnote:
1007 P_INTEGER { $$ = $1; }
1008 | XC_ABSNOTE { $$ = $1; }
1011 xc_cmd:
1012 SS_WAV XC_STR xc_absnote {
1013 /* load .wav file with just one note */
1014 add_ss_wav_event($2, $3, $3, $3, -1.0, -1.0, 0, 0);
1016 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote {
1017 /* load .wav file */
1018 add_ss_wav_event($2, $3, $4, $5, -1.0, -1.0, 0, 0);
1020 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number {
1021 /* load .wav file, with loop boundaries */
1022 add_ss_wav_event($2, $3, $4, $5, $6, $7, 0, 0);
1024 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number number number {
1025 /* load .wav file, with loop boundaries,
1026 first channel and skip channels */
1027 add_ss_wav_event($2, $3, $4, $5, $6, $7, $8, $9);
1029 | SS_PAT XC_STR {
1030 /* load .pat file */
1031 add_ss_pat_event($2);
1033 | SS_SUSTAIN XC_MSECS {
1034 /* sets sustain */
1035 add_ss_sustain_event($2);
1037 | SS_VIBRATO XC_MSECS number {
1038 /* sets vibrato */
1039 add_ss_vibrato_event($2, $3);
1041 | SS_PORTAMENTO number {
1042 /* sets portamento */
1043 add_ss_portamento_event($2);
1045 | SS_CHANNEL integer number {
1046 /* sets volume for a channel */
1047 add_ss_channel_event($2, $3);
1049 | SS_VOL number number {
1050 /* set vol for 2 channels */
1051 add_ss_channel_event(0, $2);
1052 add_ss_channel_event(1, $3);
1054 | SS_VOL number number number {
1055 /* set vol for 3 channels */
1056 add_ss_channel_event(0, $2);
1057 add_ss_channel_event(1, $3);
1058 add_ss_channel_event(2, $4);
1060 | SS_VOL number number number number {
1061 /* set vol for 4 channels */
1062 add_ss_channel_event(0, $2);
1063 add_ss_channel_event(1, $3);
1064 add_ss_channel_event(2, $4);
1065 add_ss_channel_event(3, $5);
1067 | SS_VOL number number number number number number {
1068 /* set vol for 6 channels */
1069 add_ss_channel_event(0, $2);
1070 add_ss_channel_event(1, $3);
1071 add_ss_channel_event(2, $4);
1072 add_ss_channel_event(3, $5);
1073 add_ss_channel_event(4, $6);
1074 add_ss_channel_event(5, $7);
1076 | SS_EFF_DELAY integer XC_MSECS {
1077 /* delay effect */
1078 add_ss_eff_event(SONG_EV_SS_EFF_DELAY,
1079 $2, $3, 0, 0, 0, 0, 0, 0);
1082 | SS_EFF_ECHO integer XC_MSECS number {
1083 /* echo effect */
1084 add_ss_eff_event(SONG_EV_SS_EFF_ECHO,
1085 $2, $3, $4, 0, 0, 0, 0, 0);
1088 | SS_EFF_COMB integer XC_MSECS number {
1089 /* comb effect */
1090 add_ss_eff_event(SONG_EV_SS_EFF_COMB,
1091 $2, $3, $4, 0, 0, 0, 0, 0);
1094 | SS_EFF_ALLPASS integer XC_MSECS number {
1095 /* allpass effect */
1096 add_ss_eff_event(SONG_EV_SS_EFF_ALLPASS,
1097 $2, $3, $4, 0, 0, 0, 0, 0);
1100 | SS_EFF_FLANGER integer XC_MSECS number XC_MSECS number number {
1101 /* flanger effect */
1102 add_ss_eff_event(SONG_EV_SS_EFF_FLANGER,
1103 $2, $3, $4, $5, $6, $7, 0, 0);
1106 | SS_EFF_WOBBLE integer number number {
1107 /* wobble effect */
1108 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1109 $2, 0, 0.8, 0, $3, $4, 0, 0);
1112 | SS_EFF_WOBBLE integer number number number {
1113 /* wobble effect, with gain */
1114 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1115 $2, 0, $5, 0, $3, $4, 0, 0);
1118 | SS_EFF_SQWOBBLE integer number number {
1119 /* square wobble effect */
1120 add_ss_eff_event(SONG_EV_SS_EFF_SQWOBBLE,
1121 $2, 0, 0, 0, $3, $4, 0, 0);
1124 | SS_EFF_HFWOBBLE integer number number {
1125 /* half wobble effect */
1126 add_ss_eff_event(SONG_EV_SS_EFF_HFWOBBLE,
1127 $2, 0, 0, 0, $3, $4, 0, 0);
1130 | SS_EFF_FADER integer XC_MSECS number number {
1131 /* fader effect */
1132 add_ss_eff_event(SONG_EV_SS_EFF_FADER,
1133 $2, $3, 0, 0, 0, 0, $4, $5);
1136 | SS_EFF_REVERB integer {
1137 /* reverb effect */
1138 add_ss_eff_event(SONG_EV_SS_EFF_REVERB,
1139 $2, 0, 0, 0, 0, 0, 0, 0);
1142 | SS_EFF_FOLDBACK integer number {
1143 /* foldback distortion effect */
1144 add_ss_eff_event(SONG_EV_SS_EFF_FOLDBACK,
1145 $2, 0, $3, 0, 0, 0, 0, 0);
1147 | SS_EFF_OFF integer {
1148 /* off effect */
1149 add_ss_eff_event(SONG_EV_SS_EFF_OFF,
1150 $2, 0, 0, 0, 0, 0, 0, 0);
1153 | SS_PITCH_STRETCH xc_absnote number number {
1154 /* pitch stretch note */
1155 add_ss_pitch_stretch($2, $3, $4);
1157 forward($3);
1160 | SS_PRINT_WAVE_TEMPO xc_absnote number {
1161 /* print tempo from wave */
1162 add_ss_print_wave_tempo($2, $3);
1165 | SONG_INFO XC_STR XC_STR {
1166 /* add song info */
1167 add_song_info_event($2, $3);
1170 | MIDI_CHANNEL integer {
1171 /* midi channel */
1172 add_midi_channel_event($2);
1175 | MIDI_PROGRAM integer {
1176 /* midi program */
1177 add_midi_program_event($2);
1183 void yyerror(char * s)
1185 c_err(s, NULL, NULL);
1189 #define set_block_d(n,b) set_block(n,strdup(b))
1191 static void compile_startup(void)
1193 track = 0;
1194 yyline = 1;
1195 compiler_error = 0;
1197 /* default settings */
1198 add_tempo_event(-2, 120.0);
1199 add_meter_event(-2, 4, 4);
1200 init_track();
1202 /* standard tonalities */
1203 set_block_d("CM", "A"); set_block_d("Am", "$CM");
1204 set_block_d("C#M", "A#######"); set_block_d("A#m", "$C#M");
1205 set_block_d("DM", "A#--#---"); set_block_d("Bm", "$DM");
1206 set_block_d("E&M", "A--&--&&"); set_block_d("Cm", "$E&M");
1207 set_block_d("EM", "A##-##--"); set_block_d("C#m", "$EM");
1208 set_block_d("FM", "A------&"); set_block_d("Dm", "$FM");
1209 set_block_d("F#M", "A######-"); set_block_d("D#m", "$F#M");
1210 set_block_d("GM", "A---#---"); set_block_d("Em", "$GM");
1211 set_block_d("A&M", "A-&&--&&"); set_block_d("Fm", "$A&M");
1212 set_block_d("AM", "A#--##--"); set_block_d("F#m", "$AM");
1213 set_block_d("B&M", "A--&---&"); set_block_d("Gm", "$B&M");
1214 set_block_d("BM", "A##-###-"); set_block_d("G#m", "$BM");
1218 static int do_parse(void)
1220 int r = yyparse();
1222 return(r + compiler_error);
1226 int compile_ahs_string(char * code)
1228 compile_startup();
1230 push_code(strdup(code));
1232 return(do_parse());
1236 int compile_ahs(char * file)
1238 compile_startup();
1240 if(insert_file(file))
1241 return(1);
1243 return(do_parse());