When doubling the page size, the new page size is never bigger
[ahxm.git] / compiler.y
blobaa7fffd35d7251270f480a83595cd22d54224785
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 #ifdef TONALITIES
122 int tonality = 0; /* C Major */
124 int tonalities[12][12] = {
125 /* C C# D D# E F F# G G# A A# B */
126 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* CM / Am */
127 { 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 }, /* C#M / A#m */
128 { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, /* DM / Bm */
129 { 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, -1 }, /* E&M / Cm */
130 { 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0 }, /* EM / C#m */
131 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 }, /* FM / Dm */
132 { 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0 }, /* F#M / D#m */
133 { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, /* GM / Em */
134 { 0, 0, -1, 0, -1, 0, 0, 0, 0, -1, 0, -1 }, /* A&M / Fm */
135 { 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0 }, /* AM / F#m */
136 { 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1 }, /* B&M / Gm */
137 { 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0 } /* BM / G#m */
139 #endif /* TONALITIES */
141 /* alterations for each note */
142 int alterations[12];
144 /* random seeds */
145 unsigned long block_seed = 0;
147 /*******************
148 Code
149 ********************/
151 unsigned long ah_rnd(unsigned long * seed)
152 /* special randomizer */
154 *seed = (*seed * 58321) + 11113;
156 return(*seed >> 16);
160 void c_err(char * e1, char * e2, char * e3)
161 /* reports an error from the compiler */
163 printf("ahxm:");
164 if(e1 != NULL) printf(" %s", e1);
165 if(e2 != NULL) printf(" %s", e2);
166 if(e3 != NULL) printf(" %s", e3);
167 printf(" in line %d\n", yyline);
169 compiler_error++;
173 static void forward(double step)
174 /* moves forward current time */
176 /* add step */
177 cur_time += step;
179 /* quantizations could be done here */
183 /* blocks */
185 static int find_block(char * name)
186 /* finds a block */
188 int n;
190 for(n = 0;n < n_blocks;n++)
192 if(strcmp(name, blocks[n].name) == 0)
193 return(n);
196 return(-1);
200 static int set_block(char * name, char * block)
201 /* defines a block */
203 int n;
204 struct block * b;
205 char * start;
206 char * stop;
208 /* if block already exists, free it */
209 if((n = find_block(name)) >= 0)
211 b = &blocks[n];
213 /* free all subblocks */
214 for(n = 0;n < b->n_sblocks;n++)
215 free(b->sblocks[n]);
217 /* free the subblock array */
218 free(b->sblocks);
220 else
222 GROW(blocks, n_blocks, struct block);
223 b = &blocks[n_blocks++];
225 b->name = strdup(name);
228 /* reset */
229 b->n_sblocks = 0;
230 b->sblocks = NULL;
232 /* now split in subblocks (delimited by : ) */
233 start = block;
235 while((stop = strchr(start, ':')) != NULL)
237 /* break there */
238 *stop = '\0';
240 /* add the subblock */
241 GROW(b->sblocks, b->n_sblocks, char *);
242 b->sblocks[b->n_sblocks++] = strdup(start);
244 start = stop + 1;
247 /* no more separators? store the rest */
248 GROW(b->sblocks, b->n_sblocks, char *);
249 b->sblocks[b->n_sblocks++] = strdup(start);
251 /* the original block is no longer needed */
252 free(block);
254 return(1);
258 static void insert_block(char * name)
259 /* inserts a block */
261 int n;
263 if((n = find_block(name)) >= 0)
265 struct block * b;
267 b = &blocks[n];
269 /* get one of them, randomly */
270 n = ah_rnd(&block_seed) % b->n_sblocks;
272 push_code(strdup(b->sblocks[n]));
274 else
275 c_err("block-not-found", name, NULL);
279 static int insert_file(char * filename)
281 if(!push_code_from_file(filename))
283 c_err("script-not-found", filename, NULL);
284 return(1);
287 return(0);
291 /* groups */
293 static int push_group(void)
294 /* starts a new group of notes */
296 struct group * g;
298 if(n_groups == groups_size)
300 GROW(groups, groups_size, struct group);
301 groups_size ++;
304 g = &groups[n_groups++];
306 g->start = cur_time;
307 g->gliss = 0.0;
308 g->max = 0.0;
310 return(1);
314 static int next_group_part(void)
315 /* part delimiter */
317 struct group * g;
319 if(n_groups == 0)
321 c_err("missing-start-of-group", NULL, NULL);
322 return(0);
325 g = &groups[n_groups - 1];
327 /* store maximum frame */
328 if(g->max < cur_time)
329 g->max = cur_time;
331 /* add glissando delay */
332 g->gliss += gliss;
334 /* rewind */
335 cur_time = g->start + g->gliss;
337 return(1);
341 static int pop_group(void)
342 /* finishes a group, moving the frame to the end of the longer part */
344 if(n_groups == 0)
346 c_err("missing-start-of-group", NULL, NULL);
347 return(0);
350 n_groups--;
352 /* if other parts of group were longer than the last one,
353 move pointer there */
354 if(groups[n_groups].max > cur_time)
355 cur_time = groups[n_groups].max;
357 return(1);
361 /* marks */
363 static void add_mark(char * name)
364 /* creates a new mark */
366 GROW(marks, n_marks, struct mark);
368 marks[n_marks].name = strdup(name);
369 marks[n_marks].time = cur_time;
371 n_marks++;
375 static void find_mark(char * name, int set)
376 /* finds a mark by name, optionally moving time cursor there */
378 int n;
380 for(n = 0;n < n_marks;n++)
382 if(strcmp(marks[n].name, name) == 0)
384 if(set)
386 if(cur_time > marks[n].time)
387 c_err("mark-overpassed", name, NULL);
388 else
389 cur_time = marks[n].time;
391 else
392 if(cur_time != marks[n].time)
393 c_err("mark-mismatch", name, NULL);
395 return;
399 c_err("mark-not-found", name, NULL);
403 /* arpeggiator */
405 static void arp_default(void)
406 /* resets arpeggiator values to the default ones */
408 arp_delay = 0.0;
409 arp_transpose = 0;
410 arp_volume = 1.0;
411 arp_track_off = 0;
415 static void add_arp(void)
416 /* adds an arpeggiator note */
418 struct arp * a;
420 /* if the note is exactly the same, do nothing */
421 if(arp_delay == 0.0 && arp_transpose == 0 &&
422 arp_volume == 1.0 && arp_track_off == 0)
423 return;
425 if(n_arps == arps_size)
427 GROW(arps, arps_size, struct arp);
428 arps_size ++;
431 a = &arps[n_arps];
433 a->delay = arp_delay;
434 a->transpose = arp_transpose;
435 a->volume = arp_volume;
436 a->track_off = arp_track_off;
438 n_arps++;
439 arp_default();
443 static void set_alteration(char * altstr)
444 /* sets the alterations from altstr */
446 int n, steps[] = { 2, 0, 2, 0, 1, 2, 0, 2, 0, 2, 0, 1 };
448 /* reset alterations */
449 for(n = 0;n < 12;n++) alterations[n] = 0;
451 /* changed according the altstr spec */
452 for(n = 0;*altstr != '\0' && n < 12;altstr++)
454 switch(*altstr)
456 case '&': alterations[n] = -1; break;
457 case '#': alterations[n] = 1; break;
460 /* move to next natural note */
461 n += steps[n];
466 /* song events */
468 static void add_note_event(int note)
469 /* adds a note event */
471 int n;
472 int np;
473 union song_ev e;
475 /* sum the tonality alteration */
476 /* note += tonalities[tonality][((unsigned) note) % 12];*/
478 /* sum the alteration */
479 note += alterations[((unsigned) note) % 12];
481 /* calculate the note */
482 np = note + transpose + (octave * 12);
484 /* is note out of range? */
485 if(np < 0 || np > 127)
487 c_err("note-out-of-range", NULL, NULL);
488 return;
491 e.note.trk_id = track;
492 e.note.note = np;
493 e.note.len = length * staccato;
494 e.note.vol = volume;
496 add_song_ev(SONG_EV_NOTE, cur_time, &e);
498 /* add arpeggiator repetitions */
499 for(n = 0;n < n_arps;n++)
501 e.note.trk_id = track + arps[n].track_off;
502 e.note.note = np + arps[n].transpose;
503 e.note.vol = volume * arps[n].volume;
505 add_song_ev(SONG_EV_NOTE, cur_time + arps[n].delay, &e);
510 static void add_back_event(void)
512 union song_ev e;
514 e.back.trk_id = track;
515 e.back.len = length;
516 add_song_ev(SONG_EV_BACK, cur_time, &e);
520 static void add_tempo_event(int trk_id, double tempo)
522 union song_ev e;
524 e.tempo.trk_id = trk_id;
525 e.tempo.tempo = tempo;
526 add_song_ev(SONG_EV_TEMPO, cur_time, &e);
530 static void add_meter_event(int trk_id, int num, int den)
532 union song_ev e;
534 e.meter.trk_id = trk_id;
535 e.meter.num = num;
536 e.meter.den = den;
537 add_song_ev(SONG_EV_METER, cur_time, &e);
540 static void add_measure_event(void)
542 union song_ev e;
544 e.measure.trk_id = -1;
545 e.measure.line = yyline;
547 add_song_ev(SONG_EV_MEASURE, cur_time, &e);
551 static void add_ss_sustain_event(double sustain)
553 union song_ev e;
555 e.ss_sustain.trk_id = track;
556 e.ss_sustain.sustain = sustain;
558 add_song_ev(SONG_EV_SS_SUSTAIN, cur_time, &e);
562 static void add_ss_vibrato_event(double depth, double freq)
564 union song_ev e;
566 e.ss_vibrato.trk_id = track;
567 e.ss_vibrato.vib_depth = depth;
568 e.ss_vibrato.vib_freq = freq;
570 add_song_ev(SONG_EV_SS_VIBRATO, cur_time, &e);
574 static void add_ss_portamento_event(double portamento)
576 union song_ev e;
578 e.ss_portamento.trk_id = track;
579 e.ss_portamento.portamento = portamento;
581 add_song_ev(SONG_EV_SS_PORTAMENTO, cur_time, &e);
585 static void add_ss_channel_event(int channel, float vol)
587 union song_ev e;
589 e.ss_channel.trk_id = track;
590 e.ss_channel.channel = channel;
591 e.ss_channel.vol = vol;
593 add_song_ev(SONG_EV_SS_CHANNEL, cur_time, &e);
597 static void add_ss_wav_event(char * wav_file, int base, int min, int max,
598 double loop_start, double loop_end, int first_channel, int skip_channels)
600 union song_ev e;
602 e.ss_wav.trk_id = track;
603 e.ss_wav.file = wav_file;
604 e.ss_wav.base = base;
605 e.ss_wav.min = min;
606 e.ss_wav.max = max;
607 e.ss_wav.loop_start = loop_start;
608 e.ss_wav.loop_end = loop_end;
609 e.ss_wav.first_channel = first_channel;
610 e.ss_wav.skip_channels = skip_channels;
612 add_song_ev(SONG_EV_SS_WAV, cur_time, &e);
616 static void add_ss_pat_event(char * pat_file)
618 union song_ev e;
620 e.ss_pat.trk_id = track;
621 e.ss_pat.file = pat_file;
623 add_song_ev(SONG_EV_SS_PAT, cur_time, &e);
627 static void add_ss_eff_event(int type, int channel, double size, float gain,
628 double depth, double freq, double phase, float initial, float final)
630 union song_ev e;
632 e.ss_eff.trk_id = track;
633 e.ss_eff.channel = channel;
634 e.ss_eff.size = size;
635 e.ss_eff.gain = gain;
636 e.ss_eff.depth = depth;
637 e.ss_eff.freq = freq;
638 e.ss_eff.phase = phase;
639 e.ss_eff.initial = initial;
640 e.ss_eff.final = final;
642 add_song_ev(type, cur_time, &e);
646 static void add_ss_pitch_stretch(int note, double len, float vol)
648 union song_ev e;
650 e.ss_pitch_stretch.trk_id = track;
651 e.ss_pitch_stretch.note = note;
652 e.ss_pitch_stretch.len = len;
653 e.ss_pitch_stretch.vol = vol;
655 add_song_ev(SONG_EV_SS_PITCH_STRETCH, cur_time, &e);
659 static void add_ss_print_wave_tempo(int note, double len)
661 union song_ev e;
663 e.ss_print_wave_tempo.trk_id = track;
664 e.ss_print_wave_tempo.note = note;
665 e.ss_print_wave_tempo.len = len;
667 add_song_ev(SONG_EV_SS_PRINT_WAVE_TEMPO, cur_time, &e);
671 static void add_midi_channel_event(int channel)
673 union song_ev e;
675 e.midi_channel.trk_id = track;
676 e.midi_channel.channel = channel - 1;
678 add_song_ev(SONG_EV_MIDI_CHANNEL, cur_time, &e);
682 static void add_midi_program_event(int program)
684 union song_ev e;
686 e.midi_program.trk_id = track;
687 e.midi_program.program = program;
689 add_song_ev(SONG_EV_MIDI_PROGRAM, cur_time, &e);
693 static void add_song_info_event(char * author, char * name)
695 union song_ev e;
697 e.song_info.trk_id = track;
698 e.song_info.author = author;
699 e.song_info.name = name;
701 add_song_ev(SONG_EV_SONG_INFO, cur_time, &e);
705 static void init_track(void)
706 /* sets the default values for a new track */
708 int n;
710 cur_time = 0.0;
711 length = 0.0;
712 transpose = 0;
713 staccato = 0.8;
714 volume = 0.75;
715 octave = 5;
716 gliss = 0;
718 /* groups should not cross track boundaries */
719 n_groups = 0;
721 /* reset arpeggiator */
722 n_arps = 0;
723 arp_default();
725 /* reset alterations */
726 for(n = 0;n < 12;n++)
727 alterations[n] = 0;
733 %union {
734 int i;
735 double d;
736 char * p;
739 %token <i> P_INTEGER S_INTEGER
740 %token <d> P_REAL S_REAL
741 %token <i> NOTE_P NOTE_T3 NOTE_T5
742 %token <p> NEW_MARK GOTO_MARK ASSERT_MARK
744 %token <p> BLOCK BLK_ASSIGN BLK_INSERT FILE_INSERT
746 %token <p> ALTSTR
748 %token <p> XC_STR
749 %token <i> XC_ABSNOTE
750 %token <d> XC_MSECS
752 %token SS_SEP SS_WAV SS_LOOP_WAV SS_PAT
753 %token SS_SUSTAIN SS_VIBRATO SS_PORTAMENTO SS_CHANNEL SS_VOL
755 %token SS_EFF_DELAY SS_EFF_ECHO SS_EFF_COMB SS_EFF_ALLPASS SS_EFF_FLANGER
756 %token SS_EFF_WOBBLE SS_EFF_SQWOBBLE SS_EFF_HFWOBBLE
757 %token SS_EFF_FADER SS_EFF_REVERB SS_EFF_FOLDBACK SS_EFF_OFF
759 %token SS_PITCH_STRETCH SS_TIME_STRETCH SS_PRINT_WAVE_TEMPO
761 %token SONG_INFO
763 %token MIDI_CHANNEL MIDI_PROGRAM MIDI_GENERIC
765 %type <i> integer note note_pitch rest back
766 %type <d> real p_number number note_length
768 %type <d> arp_list arp_note
769 %type <i> xc_absnote
773 script:
774 script stmt { ; }
775 | /* NULL */
778 stmt:
779 note {
780 /* note event */
781 add_note_event($1);
782 forward(length);
784 | rest {
785 /* rest */
786 forward(length);
788 | back {
789 /* back */
790 add_back_event();
792 | 'z' note_length {
793 /* zero note */
794 length = $2;
796 | 'o' P_INTEGER {
797 /* absolute octave */
798 octave = $2;
800 | 'o' S_INTEGER {
801 /* relative octave */
802 octave += $2;
804 | 'v' P_INTEGER {
805 /* absolute volume */
806 volume = (float)$2;
808 | 'v' P_REAL {
809 /* absolute volume */
810 volume = (float)$2;
812 | 'v' S_REAL {
813 /* relative volume */
814 volume += (float)$2;
816 | 't' integer {
817 /* transpose */
818 transpose = $2;
820 | 's' p_number {
821 /* staccato */
822 staccato = $2;
825 | '<' {
826 /* start of group */
827 push_group();
829 | ';' {
830 /* group delimiter */
831 next_group_part();
833 | '>' {
834 /* end of group */
835 pop_group();
837 | 'l' note_length {
838 /* glissando */
839 gliss = $2;
842 | '|' {
843 /* measure mark event */
844 add_measure_event();
847 | NEW_MARK {
848 /* add new mark */
849 add_mark($1);
851 | GOTO_MARK {
852 /* go to mark */
853 find_mark($1, 1);
855 | ASSERT_MARK {
856 /* assert mark */
857 find_mark($1, 0);
860 | '\\' {
861 /* new track */
863 track++;
864 init_track();
866 | 'T' p_number {
867 /* tempo setting */
868 add_tempo_event(-1, $2);
870 | 'M' P_INTEGER '/' P_INTEGER {
871 /* meter (time signature) setting */
872 add_meter_event(-1, $2, $4);
874 | ALTSTR {
875 /* alteration string */
876 set_alteration($1);
879 | BLOCK '*' P_INTEGER {
880 /* repeat block */
881 int n;
883 /* store the block as <TMP> */
884 set_block("<TMP>", $1);
886 for(n = 0;n < $3;n++)
887 insert_block("<TMP>");
889 | BLOCK BLK_ASSIGN {
890 /* assign block */
891 set_block($2, $1);
893 | BLK_INSERT {
894 /* insert block */
895 insert_block($1);
897 | FILE_INSERT {
898 /* insert file */
899 insert_file($1);
902 | arp { ; }
904 | xc_cmd { ; }
908 integer:
909 P_INTEGER { $$ = $1; }
910 | S_INTEGER { $$ = $1; }
913 real:
914 P_REAL { $$ = $1; }
915 | S_REAL { $$ = $1; }
918 p_number:
919 P_INTEGER { $$ = (double) $1; }
920 | P_REAL { $$ = $1; }
923 number:
924 integer { $$ = (double) $1; }
925 | real { $$ = $1; }
928 note:
929 note_pitch { $$ = $1; }
930 | note note_length { $$ = $1; length=$2; }
931 | note '~' number { $$ = $1; DEBUGF("imm volume: %lf\n", $3); }
934 note_pitch:
935 NOTE_P { $$ = $1; }
936 | note_pitch '&' { $$ = $1 - 1; }
937 | note_pitch '#' { $$ = $1 + 1; }
938 | note_pitch '\'' { $$ = $1 + 12; }
939 | note_pitch ',' { $$ = $1 - 12; }
942 note_length:
943 P_INTEGER { $$ = 1 / (double) $1; }
944 | note_length NOTE_T3 { $$ = $1 * 2.0 / 3.0; }
945 | note_length NOTE_T5 { $$ = $1 * 4.0 / 5.0; }
946 | note_length '*' p_number { $$ = $1 * $3; }
947 | note_length '.' { $$ = $1 * 1.5; }
950 rest:
951 'r' { ; }
952 | rest note_length {
953 /* rest with length */
954 length = $2;
958 back:
959 'k' { ; }
960 | back note_length {
961 /* back with length */
962 length = $2;
966 arp:
967 'x' {
968 /* empty arpeggiator */
969 n_arps = 0;
970 arp_default();
972 | 'x' arp_list { ; }
975 arp_list:
976 arp_note {
977 /* first arpeggiator note */
978 n_arps = 0;
979 add_arp();
981 | arp_list ',' arp_note {
982 /* rest of arpeggiator notes */
983 add_arp();
987 arp_note:
988 note_length {
989 /* arpeggiator delay */
990 arp_delay = $1;
992 | arp_note '~' number {
993 /* arpeggiator volume */
994 arp_volume = (float)$3;
996 | arp_note S_INTEGER {
997 /* arpeggiator transpose */
998 arp_transpose = $2;
1000 | arp_note '/' P_INTEGER {
1001 /* arpeggiator track offset */
1002 arp_track_off = $3;
1004 | arp_note NOTE_T3 {
1005 /* HACK: /3 */
1006 arp_track_off = 3;
1008 | arp_note NOTE_T5 {
1009 /* HACK: /5 */
1010 arp_track_off = 5;
1014 xc_absnote:
1015 P_INTEGER { $$ = $1; }
1016 | XC_ABSNOTE { $$ = $1; }
1019 xc_cmd:
1020 SS_WAV XC_STR xc_absnote {
1021 /* load .wav file with just one note */
1022 add_ss_wav_event($2, $3, $3, $3, -1.0, -1.0, 0, 0);
1024 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote {
1025 /* load .wav file */
1026 add_ss_wav_event($2, $3, $4, $5, -1.0, -1.0, 0, 0);
1028 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number {
1029 /* load .wav file, with loop boundaries */
1030 add_ss_wav_event($2, $3, $4, $5, $6, $7, 0, 0);
1032 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number number number {
1033 /* load .wav file, with loop boundaries,
1034 first channel and skip channels */
1035 add_ss_wav_event($2, $3, $4, $5, $6, $7, $8, $9);
1037 | SS_PAT XC_STR {
1038 /* load .pat file */
1039 add_ss_pat_event($2);
1041 | SS_SUSTAIN XC_MSECS {
1042 /* sets sustain */
1043 add_ss_sustain_event($2);
1045 | SS_VIBRATO XC_MSECS number {
1046 /* sets vibrato */
1047 add_ss_vibrato_event($2, $3);
1049 | SS_PORTAMENTO number {
1050 /* sets portamento */
1051 add_ss_portamento_event($2);
1053 | SS_CHANNEL integer number {
1054 /* sets volume for a channel */
1055 add_ss_channel_event($2, $3);
1057 | SS_VOL number number {
1058 /* set vol for 2 channels */
1059 add_ss_channel_event(0, $2);
1060 add_ss_channel_event(1, $3);
1062 | SS_VOL number number number {
1063 /* set vol for 3 channels */
1064 add_ss_channel_event(0, $2);
1065 add_ss_channel_event(1, $3);
1066 add_ss_channel_event(2, $4);
1068 | SS_VOL number number number number {
1069 /* set vol for 4 channels */
1070 add_ss_channel_event(0, $2);
1071 add_ss_channel_event(1, $3);
1072 add_ss_channel_event(2, $4);
1073 add_ss_channel_event(3, $5);
1075 | SS_VOL number number number number number number {
1076 /* set vol for 6 channels */
1077 add_ss_channel_event(0, $2);
1078 add_ss_channel_event(1, $3);
1079 add_ss_channel_event(2, $4);
1080 add_ss_channel_event(3, $5);
1081 add_ss_channel_event(4, $6);
1082 add_ss_channel_event(5, $7);
1084 | SS_EFF_DELAY integer XC_MSECS {
1085 /* delay effect */
1086 add_ss_eff_event(SONG_EV_SS_EFF_DELAY,
1087 $2, $3, 0, 0, 0, 0, 0, 0);
1090 | SS_EFF_ECHO integer XC_MSECS number {
1091 /* echo effect */
1092 add_ss_eff_event(SONG_EV_SS_EFF_ECHO,
1093 $2, $3, $4, 0, 0, 0, 0, 0);
1096 | SS_EFF_COMB integer XC_MSECS number {
1097 /* comb effect */
1098 add_ss_eff_event(SONG_EV_SS_EFF_COMB,
1099 $2, $3, $4, 0, 0, 0, 0, 0);
1102 | SS_EFF_ALLPASS integer XC_MSECS number {
1103 /* allpass effect */
1104 add_ss_eff_event(SONG_EV_SS_EFF_ALLPASS,
1105 $2, $3, $4, 0, 0, 0, 0, 0);
1108 | SS_EFF_FLANGER integer XC_MSECS number XC_MSECS number number {
1109 /* flanger effect */
1110 add_ss_eff_event(SONG_EV_SS_EFF_FLANGER,
1111 $2, $3, $4, $5, $6, $7, 0, 0);
1114 | SS_EFF_WOBBLE integer number number {
1115 /* wobble effect */
1116 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1117 $2, 0, 0, 0, $3, $4, 0, 0);
1120 | SS_EFF_SQWOBBLE integer number number {
1121 /* square wobble effect */
1122 add_ss_eff_event(SONG_EV_SS_EFF_SQWOBBLE,
1123 $2, 0, 0, 0, $3, $4, 0, 0);
1126 | SS_EFF_HFWOBBLE integer number number {
1127 /* half wobble effect */
1128 add_ss_eff_event(SONG_EV_SS_EFF_HFWOBBLE,
1129 $2, 0, 0, 0, $3, $4, 0, 0);
1132 | SS_EFF_FADER integer XC_MSECS number number {
1133 /* fader effect */
1134 add_ss_eff_event(SONG_EV_SS_EFF_FADER,
1135 $2, $3, 0, 0, 0, 0, $4, $5);
1138 | SS_EFF_REVERB integer {
1139 /* reverb effect */
1140 add_ss_eff_event(SONG_EV_SS_EFF_REVERB,
1141 $2, 0, 0, 0, 0, 0, 0, 0);
1144 | SS_EFF_FOLDBACK integer number {
1145 /* foldback distortion effect */
1146 add_ss_eff_event(SONG_EV_SS_EFF_FOLDBACK,
1147 $2, 0, $3, 0, 0, 0, 0, 0);
1149 | SS_EFF_OFF integer {
1150 /* off effect */
1151 add_ss_eff_event(SONG_EV_SS_EFF_OFF,
1152 $2, 0, 0, 0, 0, 0, 0, 0);
1155 | SS_PITCH_STRETCH xc_absnote number number {
1156 /* pitch stretch note */
1157 add_ss_pitch_stretch($2, $3, $4);
1159 forward($3);
1162 | SS_PRINT_WAVE_TEMPO xc_absnote number {
1163 /* print tempo from wave */
1164 add_ss_print_wave_tempo($2, $3);
1167 | SONG_INFO XC_STR XC_STR {
1168 /* add song info */
1169 add_song_info_event($2, $3);
1172 | MIDI_CHANNEL integer {
1173 /* midi channel */
1174 add_midi_channel_event($2);
1177 | MIDI_PROGRAM integer {
1178 /* midi program */
1179 add_midi_program_event($2);
1185 void yyerror(char * s)
1187 c_err(s, NULL, NULL);
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();
1204 int compile_ahs_string(char * code)
1206 compile_startup();
1208 push_code(strdup(code));
1210 return(yyparse() + compiler_error);
1214 int compile_ahs(char * file)
1216 compile_startup();
1218 if(insert_file(file))
1219 return(1);
1221 return(yyparse() + compiler_error);