Sustain volume delta in generators renamed from dvol to dsvol.
[ahxm.git] / compiler.y
blobe1f1ae4c8982c2a68c226cb9dae5ea815d812493
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 = 0.0;
53 /* end time (longest time seen) */
54 double end_time = 0.0;
56 /* note globals */
57 static double length;
58 static int octave;
59 static int transpose;
60 static double staccato;
61 static float volume;
62 static double gliss;
64 /* parser debugging */
66 #define DEBUGF if(verbose >= 2)printf
68 /* blocks */
70 struct block
72 char * name;
73 int n_sblocks;
74 char ** sblocks;
77 static struct block * blocks = NULL;
78 static int n_blocks = 0;
80 /* group info */
81 struct group
83 double start;
84 double gliss;
85 double max;
88 static struct group * groups = NULL;
89 static int n_groups = 0;
90 static int groups_size = 0;
92 /* mark info */
93 struct mark
95 char * name;
96 double time;
99 static struct mark * marks = NULL;
100 static int n_marks = 0;
102 /* arpeggiator */
103 struct arp
105 double delay;
106 int transpose;
107 float volume;
108 int track_off;
111 static struct arp * arps = NULL;
112 static int n_arps = 0;
113 static int arps_size = 0;
115 static double arp_delay;
116 static int arp_transpose;
117 static float arp_volume;
118 static int arp_track_off;
120 int compiler_error = 0;
122 extern int yyline;
124 /* alterations for each note */
125 int alterations[12];
127 /* random seeds */
128 unsigned long block_seed = 0;
130 /*******************
131 Code
132 ********************/
134 unsigned long ah_rnd(unsigned long * seed)
135 /* special randomizer */
137 *seed = (*seed * 58321) + 11113;
139 return(*seed >> 16);
143 void c_err(char * e1, char * e2, char * e3)
144 /* reports an error from the compiler */
146 printf("ahxm:");
147 if(e1 != NULL) printf(" %s", e1);
148 if(e2 != NULL) printf(" %s", e2);
149 if(e3 != NULL) printf(" %s", e3);
150 printf(" in line %d\n", yyline);
152 compiler_error++;
156 static void forward(double step)
157 /* moves forward current time */
159 /* add step */
160 cur_time += step;
162 /* quantizations could be done here */
166 /* blocks */
168 static int find_block(char * name)
169 /* finds a block */
171 int n;
173 for(n = 0;n < n_blocks;n++)
175 if(strcmp(name, blocks[n].name) == 0)
176 return(n);
179 return(-1);
183 static int set_block(char * name, char * block)
184 /* defines a block */
186 int n;
187 struct block * b;
188 char * start;
189 char * stop;
191 /* if block already exists, free it */
192 if((n = find_block(name)) >= 0)
194 b = &blocks[n];
196 /* free all subblocks */
197 for(n = 0;n < b->n_sblocks;n++)
198 free(b->sblocks[n]);
200 /* free the subblock array */
201 free(b->sblocks);
203 else
205 GROW(blocks, n_blocks, struct block);
206 b = &blocks[n_blocks++];
208 b->name = strdup(name);
211 /* reset */
212 b->n_sblocks = 0;
213 b->sblocks = NULL;
215 /* now split in subblocks (delimited by : ) */
216 start = block;
218 while((stop = strchr(start, ':')) != NULL)
220 /* break there */
221 *stop = '\0';
223 /* add the subblock */
224 GROW(b->sblocks, b->n_sblocks, char *);
225 b->sblocks[b->n_sblocks++] = strdup(start);
227 start = stop + 1;
230 /* no more separators? store the rest */
231 GROW(b->sblocks, b->n_sblocks, char *);
232 b->sblocks[b->n_sblocks++] = strdup(start);
234 /* the original block is no longer needed */
235 free(block);
237 return(1);
241 static void insert_block(char * name)
242 /* inserts a block */
244 int n;
246 if((n = find_block(name)) >= 0)
248 struct block * b;
250 b = &blocks[n];
252 /* get one of them, randomly */
253 n = ah_rnd(&block_seed) % b->n_sblocks;
255 push_code(strdup(b->sblocks[n]));
257 else
258 c_err("block-not-found", name, NULL);
262 static int insert_file(char * filename)
264 if(!push_code_from_file(filename))
266 c_err("script-not-found", filename, NULL);
267 return(1);
270 return(0);
274 /* groups */
276 static int push_group(void)
277 /* starts a new group of notes */
279 struct group * g;
281 if(n_groups == groups_size)
283 GROW(groups, groups_size, struct group);
284 groups_size ++;
287 g = &groups[n_groups++];
289 g->start = cur_time;
290 g->gliss = 0.0;
291 g->max = 0.0;
293 return(1);
297 static int next_group_part(void)
298 /* part delimiter */
300 struct group * g;
302 if(n_groups == 0)
304 c_err("missing-start-of-group", NULL, NULL);
305 return(0);
308 g = &groups[n_groups - 1];
310 /* store maximum frame */
311 if(g->max < cur_time)
312 g->max = cur_time;
314 /* add glissando delay */
315 g->gliss += gliss;
317 /* rewind */
318 cur_time = g->start + g->gliss;
320 return(1);
324 static int pop_group(void)
325 /* finishes a group, moving the frame to the end of the longer part */
327 if(n_groups == 0)
329 c_err("missing-start-of-group", NULL, NULL);
330 return(0);
333 n_groups--;
335 /* if other parts of group were longer than the last one,
336 move pointer there */
337 if(groups[n_groups].max > cur_time)
338 cur_time = groups[n_groups].max;
340 return(1);
344 /* marks */
346 static int seek_mark(char * name)
347 /* seeks a mark by name; returns its offset or -1 */
349 int n;
351 for(n = 0;n < n_marks;n++)
352 if(strcmp(marks[n].name, name) == 0)
353 return(n);
355 return(-1);
359 static void add_mark(char * name)
360 /* creates a new mark */
362 int n;
364 if((n = seek_mark(name)) == -1)
366 n = n_marks++;
367 GROW(marks, n, struct mark);
368 marks[n].name = strdup(name);
371 marks[n].time = cur_time;
375 static void find_mark(char * name, int set)
376 /* finds a mark by name, optionally moving time cursor there */
378 int n;
380 if((n = seek_mark(name)) != -1)
382 if(set)
384 if(cur_time > marks[n].time)
386 /* if mark is not END, fail */
387 if(strcmp(name, "END") != 0)
388 c_err("mark-overpassed", name, NULL);
390 else
391 cur_time = marks[n].time;
393 else
394 if(cur_time != marks[n].time)
395 c_err("mark-mismatch", name, NULL);
397 return;
400 c_err("mark-not-found", name, NULL);
404 /* arpeggiator */
406 static void arp_default(void)
407 /* resets arpeggiator values to the default ones */
409 arp_delay = 0.0;
410 arp_transpose = 0;
411 arp_volume = 1.0;
412 arp_track_off = 0;
416 static void add_arp(void)
417 /* adds an arpeggiator note */
419 struct arp * a;
421 /* if the note is exactly the same, do nothing */
422 if(arp_delay == 0.0 && arp_transpose == 0 &&
423 arp_volume == 1.0 && arp_track_off == 0)
424 return;
426 if(n_arps == arps_size)
428 GROW(arps, arps_size, struct arp);
429 arps_size ++;
432 a = &arps[n_arps];
434 a->delay = arp_delay;
435 a->transpose = arp_transpose;
436 a->volume = arp_volume;
437 a->track_off = arp_track_off;
439 n_arps++;
440 arp_default();
444 static void set_alteration(char * altstr)
445 /* sets the alterations from altstr */
447 int n, steps[] = { 2, 0, 2, 0, 1, 2, 0, 2, 0, 2, 0, 1 };
449 /* reset alterations */
450 for(n = 0;n < 12;n++) alterations[n] = 0;
452 /* changed according the altstr spec */
453 for(n = 0;*altstr != '\0' && n < 12;altstr++)
455 switch(*altstr)
457 case '&': alterations[n] = -1; break;
458 case '#': alterations[n] = 1; break;
461 /* move to next natural note */
462 n += steps[n];
467 /* song events */
469 static void add_note_event(int note)
470 /* adds a note event */
472 int n;
473 int np;
474 union song_ev e;
476 /* sum the alteration */
477 if((n = note % 12) < 0) n += 12;
478 note += alterations[n];
480 /* calculate the note */
481 np = note + transpose + (octave * 12);
483 /* is note out of range? */
484 if(np < 0 || np > 127)
486 c_err("note-out-of-range", NULL, NULL);
487 return;
490 e.note.trk_id = track;
491 e.note.note = np;
492 e.note.len = length * staccato;
493 e.note.vol = volume;
495 add_song_ev(SONG_EV_NOTE, cur_time, &e);
497 /* add arpeggiator repetitions */
498 for(n = 0;n < n_arps;n++)
500 e.note.trk_id = track + arps[n].track_off;
501 e.note.note = np + arps[n].transpose;
502 e.note.vol = volume * arps[n].volume;
504 add_song_ev(SONG_EV_NOTE, cur_time + arps[n].delay, &e);
509 static void add_back_event(void)
511 union song_ev e;
513 e.back.trk_id = track;
514 e.back.len = length;
515 add_song_ev(SONG_EV_BACK, cur_time, &e);
519 static void add_tempo_event(int trk_id, double tempo)
521 union song_ev e;
523 e.tempo.trk_id = trk_id;
524 e.tempo.tempo = tempo;
525 add_song_ev(SONG_EV_TEMPO, cur_time, &e);
529 static void add_meter_event(int trk_id, int num, int den)
531 union song_ev e;
533 e.meter.trk_id = trk_id;
534 e.meter.num = num;
535 e.meter.den = den;
536 add_song_ev(SONG_EV_METER, cur_time, &e);
539 static void add_measure_event(void)
541 union song_ev e;
543 e.measure.trk_id = -1;
544 e.measure.line = yyline;
546 add_song_ev(SONG_EV_MEASURE, cur_time, &e);
550 static void add_ss_sustain_event(double sustain)
552 union song_ev e;
554 e.ss_sustain.trk_id = track;
555 e.ss_sustain.sustain = sustain;
557 add_song_ev(SONG_EV_SS_SUSTAIN, cur_time, &e);
561 static void add_ss_vibrato_event(double depth, double freq)
563 union song_ev e;
565 e.ss_vibrato.trk_id = track;
566 e.ss_vibrato.vib_depth = depth;
567 e.ss_vibrato.vib_freq = freq;
569 add_song_ev(SONG_EV_SS_VIBRATO, cur_time, &e);
573 static void add_ss_portamento_event(double portamento)
575 union song_ev e;
577 e.ss_portamento.trk_id = track;
578 e.ss_portamento.portamento = portamento;
580 add_song_ev(SONG_EV_SS_PORTAMENTO, cur_time, &e);
584 static void add_ss_channel_event(int channel, float vol)
586 union song_ev e;
588 e.ss_channel.trk_id = track;
589 e.ss_channel.channel = channel;
590 e.ss_channel.vol = vol;
592 add_song_ev(SONG_EV_SS_CHANNEL, cur_time, &e);
596 static void add_ss_wav_event(char * wav_file, int base, int min, int max,
597 double loop_start, double loop_end, int first_channel, int skip_channels)
599 union song_ev e;
601 e.ss_wav.trk_id = track;
602 e.ss_wav.file = wav_file;
603 e.ss_wav.base = base;
604 e.ss_wav.min = min;
605 e.ss_wav.max = max;
606 e.ss_wav.loop_start = loop_start;
607 e.ss_wav.loop_end = loop_end;
608 e.ss_wav.first_channel = first_channel;
609 e.ss_wav.skip_channels = skip_channels;
611 add_song_ev(SONG_EV_SS_WAV, cur_time, &e);
615 static void add_ss_pat_event(char * pat_file)
617 union song_ev e;
619 e.ss_pat.trk_id = track;
620 e.ss_pat.file = pat_file;
622 add_song_ev(SONG_EV_SS_PAT, cur_time, &e);
626 static void add_ss_eff_event(int type, int channel, double size, float gain,
627 double depth, double freq, double phase, float initial, float final)
629 union song_ev e;
631 e.ss_eff.trk_id = track;
632 e.ss_eff.channel = channel;
633 e.ss_eff.size = size;
634 e.ss_eff.gain = gain;
635 e.ss_eff.depth = depth;
636 e.ss_eff.freq = freq;
637 e.ss_eff.phase = phase;
638 e.ss_eff.initial = initial;
639 e.ss_eff.final = final;
641 add_song_ev(type, cur_time, &e);
645 static void add_ss_pitch_stretch(int note, double len, float vol)
647 union song_ev e;
649 e.ss_pitch_stretch.trk_id = track;
650 e.ss_pitch_stretch.note = note;
651 e.ss_pitch_stretch.len = len;
652 e.ss_pitch_stretch.vol = vol;
654 add_song_ev(SONG_EV_SS_PITCH_STRETCH, cur_time, &e);
658 static void add_ss_print_wave_tempo(int note, double len)
660 union song_ev e;
662 e.ss_print_wave_tempo.trk_id = track;
663 e.ss_print_wave_tempo.note = note;
664 e.ss_print_wave_tempo.len = len;
666 add_song_ev(SONG_EV_SS_PRINT_WAVE_TEMPO, cur_time, &e);
670 static void add_midi_channel_event(int channel)
672 union song_ev e;
674 e.midi_channel.trk_id = track;
675 e.midi_channel.channel = channel - 1;
677 add_song_ev(SONG_EV_MIDI_CHANNEL, cur_time, &e);
681 static void add_midi_program_event(int program)
683 union song_ev e;
685 e.midi_program.trk_id = track;
686 e.midi_program.program = program;
688 add_song_ev(SONG_EV_MIDI_PROGRAM, cur_time, &e);
692 static void add_song_info_event(char * author, char * name)
694 union song_ev e;
696 e.song_info.trk_id = track;
697 e.song_info.author = author;
698 e.song_info.name = name;
700 add_song_ev(SONG_EV_SONG_INFO, cur_time, &e);
704 static void init_track(void)
705 /* sets the default values for a new track */
707 int n;
709 /* is there an end time? test if this is longer */
710 if(cur_time > end_time)
712 add_mark("END");
713 end_time = cur_time;
716 cur_time = 0.0;
717 length = 0.0;
718 transpose = 0;
719 staccato = 0.8;
720 volume = 0.75;
721 octave = 5;
722 gliss = 0;
724 /* groups should not cross track boundaries */
725 n_groups = 0;
727 /* reset arpeggiator */
728 n_arps = 0;
729 arp_default();
731 /* is there a START mark? if so, move there */
732 if((n = seek_mark("START")) != -1)
733 cur_time = marks[n].time;
735 /* reset alterations */
736 for(n = 0;n < 12;n++)
737 alterations[n] = 0;
743 %union {
744 int i;
745 double d;
746 char * p;
749 %token <i> P_INTEGER S_INTEGER
750 %token <d> P_REAL S_REAL
751 %token <i> NOTE_P NOTE_T3 NOTE_T5
752 %token <p> NEW_MARK GOTO_MARK ASSERT_MARK
754 %token <p> BLOCK BLK_ASSIGN BLK_INSERT FILE_INSERT
756 %token <p> ALTSTR
758 %token <p> XC_STR
759 %token <i> XC_ABSNOTE
760 %token <d> XC_MSECS
762 %token SS_SEP SS_WAV SS_LOOP_WAV SS_PAT
763 %token SS_SUSTAIN SS_VIBRATO SS_PORTAMENTO SS_CHANNEL SS_VOL
765 %token SS_EFF_DELAY SS_EFF_ECHO SS_EFF_COMB SS_EFF_ALLPASS SS_EFF_FLANGER
766 %token SS_EFF_WOBBLE SS_EFF_SQWOBBLE SS_EFF_HFWOBBLE
767 %token SS_EFF_FADER SS_EFF_REVERB SS_EFF_FOLDBACK SS_EFF_OFF
769 %token SS_PITCH_STRETCH SS_TIME_STRETCH SS_PRINT_WAVE_TEMPO
771 %token SONG_INFO
773 %token MIDI_CHANNEL MIDI_PROGRAM MIDI_GENERIC
775 %type <i> integer note note_pitch rest back
776 %type <d> real p_number number note_length
778 %type <d> arp_list arp_note
779 %type <i> xc_absnote
783 script:
784 script stmt { ; }
785 | /* NULL */
788 stmt:
789 note {
790 /* note event */
791 add_note_event($1);
792 forward(length);
794 | rest {
795 /* rest */
796 forward(length);
798 | back {
799 /* back */
800 add_back_event();
802 | 'z' note_length {
803 /* zero note */
804 length = $2;
806 | 'o' P_INTEGER {
807 /* absolute octave */
808 octave = $2;
810 | 'o' S_INTEGER {
811 /* relative octave */
812 octave += $2;
814 | 'v' P_INTEGER {
815 /* absolute volume */
816 volume = (float)$2;
818 | 'v' P_REAL {
819 /* absolute volume */
820 volume = (float)$2;
822 | 'v' S_REAL {
823 /* relative volume */
824 volume += (float)$2;
826 | 't' integer {
827 /* transpose */
828 transpose = $2;
830 | 's' p_number {
831 /* staccato */
832 staccato = $2;
835 | '<' {
836 /* start of group */
837 push_group();
839 | ';' {
840 /* group delimiter */
841 next_group_part();
843 | '>' {
844 /* end of group */
845 pop_group();
847 | 'l' note_length {
848 /* glissando */
849 gliss = $2;
852 | '|' {
853 /* measure mark event */
854 add_measure_event();
857 | NEW_MARK {
858 /* add new mark */
859 add_mark($1);
861 | GOTO_MARK {
862 /* go to mark */
863 find_mark($1, 1);
865 | ASSERT_MARK {
866 /* assert mark */
867 find_mark($1, 0);
870 | '\\' {
871 /* new track */
873 track++;
874 init_track();
876 | 'T' p_number {
877 /* tempo setting */
878 add_tempo_event(-1, $2);
880 | 'M' P_INTEGER '/' P_INTEGER {
881 /* meter (time signature) setting */
882 add_meter_event(-1, $2, $4);
884 | ALTSTR {
885 /* alteration string */
886 set_alteration($1);
889 | BLOCK '*' P_INTEGER {
890 /* repeat block */
891 int n;
893 /* store the block as <TMP> */
894 set_block("<TMP>", $1);
896 for(n = 0;n < $3;n++)
897 insert_block("<TMP>");
899 | BLOCK BLK_ASSIGN {
900 /* assign block */
901 set_block($2, $1);
903 | BLK_INSERT {
904 /* insert block */
905 insert_block($1);
907 | FILE_INSERT {
908 /* insert file */
909 insert_file($1);
912 | arp { ; }
914 | xc_cmd { ; }
918 integer:
919 P_INTEGER { $$ = $1; }
920 | S_INTEGER { $$ = $1; }
923 real:
924 P_REAL { $$ = $1; }
925 | S_REAL { $$ = $1; }
928 p_number:
929 P_INTEGER { $$ = (double) $1; }
930 | P_REAL { $$ = $1; }
933 number:
934 integer { $$ = (double) $1; }
935 | real { $$ = $1; }
938 note:
939 note_pitch { $$ = $1; }
940 | note note_length { $$ = $1; length=$2; }
941 | note '~' number { $$ = $1; DEBUGF("imm volume: %lf\n", $3); }
944 note_pitch:
945 NOTE_P { $$ = $1; }
946 | note_pitch '&' { $$ = $1 - 1; }
947 | note_pitch '#' { $$ = $1 + 1; }
948 | note_pitch '\'' { $$ = $1 + 12; }
949 | note_pitch ',' { $$ = $1 - 12; }
952 note_length:
953 P_INTEGER { $$ = 1 / (double) $1; }
954 | note_length NOTE_T3 { $$ = $1 * 2.0 / 3.0; }
955 | note_length NOTE_T5 { $$ = $1 * 4.0 / 5.0; }
956 | note_length '*' p_number { $$ = $1 * $3; }
957 | note_length '.' { $$ = $1 * 1.5; }
960 rest:
961 'r' { ; }
962 | rest note_length {
963 /* rest with length */
964 length = $2;
968 back:
969 'k' { ; }
970 | back note_length {
971 /* back with length */
972 length = $2;
976 arp:
977 'x' {
978 /* empty arpeggiator */
979 n_arps = 0;
980 arp_default();
982 | 'x' arp_list { ; }
985 arp_list:
986 arp_note {
987 /* first arpeggiator note */
988 n_arps = 0;
989 add_arp();
991 | arp_list ',' arp_note {
992 /* rest of arpeggiator notes */
993 add_arp();
997 arp_note:
998 note_length {
999 /* arpeggiator delay */
1000 arp_delay = $1;
1002 | arp_note '~' number {
1003 /* arpeggiator volume */
1004 arp_volume = (float)$3;
1006 | arp_note S_INTEGER {
1007 /* arpeggiator transpose */
1008 arp_transpose = $2;
1010 | arp_note '/' P_INTEGER {
1011 /* arpeggiator track offset */
1012 arp_track_off = $3;
1014 | arp_note NOTE_T3 {
1015 /* HACK: /3 */
1016 arp_track_off = 3;
1018 | arp_note NOTE_T5 {
1019 /* HACK: /5 */
1020 arp_track_off = 5;
1024 xc_absnote:
1025 P_INTEGER { $$ = $1; }
1026 | XC_ABSNOTE { $$ = $1; }
1029 xc_cmd:
1030 SS_WAV XC_STR xc_absnote {
1031 /* load .wav file with just one note */
1032 add_ss_wav_event($2, $3, $3, $3, -1.0, -1.0, 0, 0);
1034 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote {
1035 /* load .wav file */
1036 add_ss_wav_event($2, $3, $4, $5, -1.0, -1.0, 0, 0);
1038 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number {
1039 /* load .wav file, with loop boundaries */
1040 add_ss_wav_event($2, $3, $4, $5, $6, $7, 0, 0);
1042 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number number number {
1043 /* load .wav file, with loop boundaries,
1044 first channel and skip channels */
1045 add_ss_wav_event($2, $3, $4, $5, $6, $7, $8, $9);
1047 | SS_PAT XC_STR {
1048 /* load .pat file */
1049 add_ss_pat_event($2);
1051 | SS_SUSTAIN XC_MSECS {
1052 /* sets sustain */
1053 add_ss_sustain_event($2);
1055 | SS_VIBRATO XC_MSECS number {
1056 /* sets vibrato */
1057 add_ss_vibrato_event($2, $3);
1059 | SS_PORTAMENTO number {
1060 /* sets portamento */
1061 add_ss_portamento_event($2);
1063 | SS_CHANNEL integer number {
1064 /* sets volume for a channel */
1065 add_ss_channel_event($2, $3);
1067 | SS_VOL number number {
1068 /* set vol for 2 channels */
1069 add_ss_channel_event(0, $2);
1070 add_ss_channel_event(1, $3);
1072 | SS_VOL number number number {
1073 /* set vol for 3 channels */
1074 add_ss_channel_event(0, $2);
1075 add_ss_channel_event(1, $3);
1076 add_ss_channel_event(2, $4);
1078 | SS_VOL number number number number {
1079 /* set vol for 4 channels */
1080 add_ss_channel_event(0, $2);
1081 add_ss_channel_event(1, $3);
1082 add_ss_channel_event(2, $4);
1083 add_ss_channel_event(3, $5);
1085 | SS_VOL number number number number number number {
1086 /* set vol for 6 channels */
1087 add_ss_channel_event(0, $2);
1088 add_ss_channel_event(1, $3);
1089 add_ss_channel_event(2, $4);
1090 add_ss_channel_event(3, $5);
1091 add_ss_channel_event(4, $6);
1092 add_ss_channel_event(5, $7);
1094 | SS_EFF_DELAY integer XC_MSECS {
1095 /* delay effect */
1096 add_ss_eff_event(SONG_EV_SS_EFF_DELAY,
1097 $2, $3, 0, 0, 0, 0, 0, 0);
1100 | SS_EFF_ECHO integer XC_MSECS number {
1101 /* echo effect */
1102 add_ss_eff_event(SONG_EV_SS_EFF_ECHO,
1103 $2, $3, $4, 0, 0, 0, 0, 0);
1106 | SS_EFF_COMB integer XC_MSECS number {
1107 /* comb effect */
1108 add_ss_eff_event(SONG_EV_SS_EFF_COMB,
1109 $2, $3, $4, 0, 0, 0, 0, 0);
1112 | SS_EFF_ALLPASS integer XC_MSECS number {
1113 /* allpass effect */
1114 add_ss_eff_event(SONG_EV_SS_EFF_ALLPASS,
1115 $2, $3, $4, 0, 0, 0, 0, 0);
1118 | SS_EFF_FLANGER integer XC_MSECS number XC_MSECS number number {
1119 /* flanger effect */
1120 add_ss_eff_event(SONG_EV_SS_EFF_FLANGER,
1121 $2, $3, $4, $5, $6, $7, 0, 0);
1124 | SS_EFF_WOBBLE integer number number {
1125 /* wobble effect */
1126 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1127 $2, 0, 0.8, 0, $3, $4, 0, 0);
1130 | SS_EFF_WOBBLE integer number number number {
1131 /* wobble effect, with gain */
1132 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1133 $2, 0, $5, 0, $3, $4, 0, 0);
1136 | SS_EFF_SQWOBBLE integer number number {
1137 /* square wobble effect */
1138 add_ss_eff_event(SONG_EV_SS_EFF_SQWOBBLE,
1139 $2, 0, 0, 0, $3, $4, 0, 0);
1142 | SS_EFF_HFWOBBLE integer number number {
1143 /* half wobble effect */
1144 add_ss_eff_event(SONG_EV_SS_EFF_HFWOBBLE,
1145 $2, 0, 0, 0, $3, $4, 0, 0);
1148 | SS_EFF_FADER integer XC_MSECS number number {
1149 /* fader effect */
1150 add_ss_eff_event(SONG_EV_SS_EFF_FADER,
1151 $2, $3, 0, 0, 0, 0, $4, $5);
1154 | SS_EFF_REVERB integer {
1155 /* reverb effect */
1156 add_ss_eff_event(SONG_EV_SS_EFF_REVERB,
1157 $2, 0, 0, 0, 0, 0, 0, 0);
1160 | SS_EFF_FOLDBACK integer number {
1161 /* foldback distortion effect */
1162 add_ss_eff_event(SONG_EV_SS_EFF_FOLDBACK,
1163 $2, 0, $3, 0, 0, 0, 0, 0);
1165 | SS_EFF_OFF integer {
1166 /* off effect */
1167 add_ss_eff_event(SONG_EV_SS_EFF_OFF,
1168 $2, 0, 0, 0, 0, 0, 0, 0);
1171 | SS_PITCH_STRETCH xc_absnote number number {
1172 /* pitch stretch note */
1173 add_ss_pitch_stretch($2, $3, $4);
1175 forward($3);
1178 | SS_PRINT_WAVE_TEMPO xc_absnote number {
1179 /* print tempo from wave */
1180 add_ss_print_wave_tempo($2, $3);
1183 | SONG_INFO XC_STR XC_STR {
1184 /* add song info */
1185 add_song_info_event($2, $3);
1188 | MIDI_CHANNEL integer {
1189 /* midi channel */
1190 add_midi_channel_event($2);
1193 | MIDI_PROGRAM integer {
1194 /* midi program */
1195 add_midi_program_event($2);
1201 void yyerror(char * s)
1203 c_err(s, NULL, NULL);
1207 #define set_block_d(n,b) set_block(n,strdup(b))
1209 static void compile_startup(void)
1211 track = 0;
1212 yyline = 1;
1213 compiler_error = 0;
1215 /* default settings */
1216 add_tempo_event(-2, 120.0);
1217 add_meter_event(-2, 4, 4);
1218 init_track();
1220 /* standard tonalities */
1221 set_block_d("CM", "A"); set_block_d("Am", "$CM");
1222 set_block_d("C#M", "A#######"); set_block_d("A#m", "$C#M");
1223 set_block_d("DM", "A#--#---"); set_block_d("Bm", "$DM");
1224 set_block_d("E&M", "A--&--&&"); set_block_d("Cm", "$E&M");
1225 set_block_d("EM", "A##-##--"); set_block_d("C#m", "$EM");
1226 set_block_d("FM", "A------&"); set_block_d("Dm", "$FM");
1227 set_block_d("F#M", "A######-"); set_block_d("D#m", "$F#M");
1228 set_block_d("GM", "A---#---"); set_block_d("Em", "$GM");
1229 set_block_d("A&M", "A-&&--&&"); set_block_d("Fm", "$A&M");
1230 set_block_d("AM", "A#--##--"); set_block_d("F#m", "$AM");
1231 set_block_d("B&M", "A--&---&"); set_block_d("Gm", "$B&M");
1232 set_block_d("BM", "A##-###-"); set_block_d("G#m", "$BM");
1236 static int do_parse(void)
1238 int r = yyparse();
1240 return(r + compiler_error);
1244 int compile_ahs_string(char * code)
1246 compile_startup();
1248 push_code(strdup(code));
1250 return(do_parse());
1254 int compile_ahs(char * file)
1256 compile_startup();
1258 if(insert_file(file))
1259 return(1);
1261 return(do_parse());