add_note_event() now uses add_song_ev(); everything is broken now.
[ahxm.git] / compiler.y
blobd3f351cf3f63d00cbc54ffc1ca1f4845cb62e238
1 %{
2 /*
4 Ann Hell Ex Machina - Music Software
5 Copyright (C) 2003/2007 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_from;
62 static float volume_to;
63 static double gliss;
65 /* parser debugging */
67 #define DEBUGF if(verbose >= 2)printf
69 /* blocks */
71 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 {
82 double start;
83 double gliss;
84 double max;
87 static struct group * groups = NULL;
88 static int n_groups = 0;
89 static int groups_size = 0;
91 /* mark info */
92 struct mark {
93 char * name;
94 double time;
97 static struct mark * marks = NULL;
98 static int n_marks = 0;
100 /* arpeggiator */
101 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;
126 unsigned long volume_seed = 0;
128 /* solo track (-1, no solo) */
129 int solo_track = -1;
131 /* number of tracks in song */
132 int n_song_tracks = 0;
134 /*******************
135 Code
136 ********************/
138 unsigned long ah_rnd(unsigned long * seed)
139 /* special randomizer */
141 *seed = (*seed * 58321) + 11113;
143 return *seed >> 16;
147 void c_err(char * e1, char * e2, char * e3)
148 /* reports an error from the compiler */
150 printf("ahxm:");
152 if (e1 != NULL)
153 printf(" %s", e1);
154 if (e2 != NULL)
155 printf(" %s", e2);
156 if (e3 != NULL)
157 printf(" %s", e3);
159 printf(" in line %d\n", yyline);
161 compiler_error++;
165 static void forward(double step)
166 /* moves forward current time */
168 /* add step */
169 cur_time += step;
171 /* quantizations could be done here */
175 static float volume(void)
177 float f;
179 if (volume_from == volume_to)
180 f = volume_from;
181 else {
182 unsigned long r = ah_rnd(&volume_seed) % 1000;
184 f = volume_from + (volume_to - volume_from) *
185 (((float)r) / 1000.0);
188 return f;
192 /* blocks */
194 static int find_block(char * name)
195 /* finds a block */
197 int n;
199 for (n = 0; n < n_blocks; n++) {
200 if (strcmp(name, blocks[n].name) == 0)
201 return n;
204 return -1;
208 static int set_block(char * name, char * block)
209 /* defines a block */
211 int n;
212 struct block * b;
213 char * start;
214 char * stop;
216 /* if block already exists, free it */
217 if ((n = find_block(name)) >= 0) {
218 b = &blocks[n];
220 /* free all subblocks */
221 for (n = 0; n < b->n_sblocks; n++)
222 free(b->sblocks[n]);
224 /* free the subblock array */
225 free(b->sblocks);
227 else {
228 GROW(blocks, n_blocks, struct block);
229 b = &blocks[n_blocks++];
231 b->name = strdup(name);
234 /* reset */
235 b->n_sblocks = 0;
236 b->sblocks = NULL;
238 /* now split in subblocks (delimited by : ) */
239 start = block;
241 while ((stop = strchr(start, ':')) != NULL) {
242 /* break there */
243 *stop = '\0';
245 /* add the subblock */
246 GROW(b->sblocks, b->n_sblocks, char *);
247 b->sblocks[b->n_sblocks++] = strdup(start);
249 start = stop + 1;
252 /* no more separators? store the rest */
253 GROW(b->sblocks, b->n_sblocks, char *);
254 b->sblocks[b->n_sblocks++] = strdup(start);
256 /* the original block is no longer needed */
257 free(block);
259 return 1;
263 static void insert_block(char * name)
264 /* inserts a block */
266 int n;
268 if ((n = find_block(name)) >= 0) {
269 struct block * b;
271 b = &blocks[n];
273 /* get one of them, randomly */
274 n = ah_rnd(&block_seed) % b->n_sblocks;
276 push_code(strdup(b->sblocks[n]));
278 else
279 c_err("block-not-found", name, NULL);
283 static int insert_file(char * filename)
285 if (!push_code_from_file(filename)) {
286 c_err("script-not-found", filename, NULL);
287 return 1;
290 return 0;
294 /* groups */
296 static int push_group(void)
297 /* starts a new group of notes */
299 struct group * g;
301 if (n_groups == groups_size) {
302 GROW(groups, groups_size, struct group);
303 groups_size ++;
306 g = &groups[n_groups++];
308 g->start = cur_time;
309 g->gliss = 0.0;
310 g->max = 0.0;
312 return 1;
316 static int next_group_part(void)
317 /* part delimiter */
319 struct group * g;
321 if (n_groups == 0) {
322 c_err("missing-start-of-group", NULL, NULL);
323 return 0;
326 g = &groups[n_groups - 1];
328 /* store maximum frame */
329 if (g->max < cur_time)
330 g->max = cur_time;
332 /* add glissando delay */
333 g->gliss += gliss;
335 /* rewind */
336 cur_time = g->start + g->gliss;
338 return 1;
342 static int pop_group(void)
343 /* finishes a group, moving the frame to the end of the longer part */
345 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 int seek_mark(char * name)
364 /* seeks a mark by name; returns its offset or -1 */
366 int n;
368 for (n = 0; n < n_marks; n++)
369 if (strcmp(marks[n].name, name) == 0)
370 return n;
372 return -1;
376 static void add_mark(char * name)
377 /* creates a new mark */
379 int n;
381 if ((n = seek_mark(name)) == -1) {
382 n = n_marks++;
383 GROW(marks, n, struct mark);
384 marks[n].name = strdup(name);
387 marks[n].time = cur_time;
391 static void find_mark(char * name, int set)
392 /* finds a mark by name, optionally moving time cursor there */
394 int n;
396 if ((n = seek_mark(name)) != -1) {
397 if (set) {
398 if (cur_time > marks[n].time) {
399 /* if mark is not END, fail */
400 if (strcmp(name, "END") != 0)
401 c_err("mark-overpassed", name, NULL);
403 else
404 cur_time = marks[n].time;
406 else
407 if (cur_time != marks[n].time)
408 c_err("mark-mismatch", name, NULL);
410 return;
413 c_err("mark-not-found", name, NULL);
417 /* arpeggiator */
419 static void arp_default(void)
420 /* resets arpeggiator values to the default ones */
422 arp_delay = 0.0;
423 arp_transpose = 0;
424 arp_volume = 1.0;
425 arp_track_off = 0;
429 static void add_arp(void)
430 /* adds an arpeggiator note */
432 struct arp * a;
434 /* if the note is exactly the same, do nothing */
435 if (arp_delay == 0.0 && arp_transpose == 0 &&
436 arp_volume == 1.0 && arp_track_off == 0)
437 return;
439 if (n_arps == arps_size) {
440 GROW(arps, arps_size, struct arp);
441 arps_size ++;
444 a = &arps[n_arps];
446 a->delay = arp_delay;
447 a->transpose = arp_transpose;
448 a->volume = arp_volume;
449 a->track_off = arp_track_off;
451 n_arps++;
452 arp_default();
456 static void set_alteration(char * altstr)
457 /* sets the alterations from altstr */
459 int n, steps[] = { 2, 0, 2, 0, 1, 2, 0, 2, 0, 2, 0, 1 };
461 /* reset alterations */
462 for (n = 0; n < 12; n++)
463 alterations[n] = 0;
465 /* changed according the altstr spec */
466 for (n = 0; *altstr != '\0' && n < 12; altstr++) {
467 switch (*altstr) {
468 case '&':
469 alterations[n] = -1;
470 break;
472 case '#':
473 alterations[n] = 1;
474 break;
477 /* move to next natural note */
478 n += steps[n];
483 /* song events */
485 static struct song_ev * add_song_ev(song_ev_type type)
487 struct song_ev * r;
489 /* FIXME: solo tracks don't work */
490 /* if (solo_track != -1 && ev->trk_id >= 0 && ev->trk_id != solo_track)
491 return NULL; */
493 /* FIXME: account number of tracks */
494 /* if (n_song_tracks < ev->trk_id + 1)
495 n_song_tracks = ev->trk_id + 1;
497 r = add_event(&song, &n_song_ev);
499 r->type = type;
500 r->time = cur_time;
501 r->trk_id = track;
503 return r;
507 static void copy_song_ev(song_ev_type type, double time, struct song_ev *ev)
509 /* skip tracks if a solo is requested */
510 if (solo_track != -1 && ev->trk_id >= 0 && ev->trk_id != solo_track)
511 return;
513 /* account number of tracks */
514 if (n_song_tracks < ev->trk_id + 1)
515 n_song_tracks = ev->trk_id + 1;
517 ev->type = type;
518 ev->time = time;
519 ev->event_id = n_song_ev;
521 copy_event(&song, &n_song_ev, ev);
525 static void add_note_event(int note)
526 /* adds a note event */
528 int n;
529 int np;
530 struct song_ev *e;
532 /* sum the alteration */
533 if ((n = note % 12) < 0)
534 n += 12;
536 note += alterations[n];
538 /* calculate the note */
539 np = note + transpose + (octave * 12);
541 /* is note out of range? */
542 if (np < 0 || np > 127) {
543 c_err("note-out-of-range", NULL, NULL);
544 return;
547 e = add_song_ev(SONG_EV_NOTE);
549 e->value = np;
550 e->len = length * staccato;
551 e->vol = volume();
553 /* add arpeggiator repetitions */
554 for (n = 0; n < n_arps; n++) {
556 e = add_song_ev(SONG_EV_NOTE);
558 e->time = cur_time + arps[n].delay;
559 e->trk_id = track + arps[n].track_off;
560 e->value = np + arps[n].transpose;
561 e->len = length * staccato;
562 e->vol = volume() * arps[n].volume;
567 static void add_back_event(void)
569 struct song_ev *e = add_song_ev(SONG_EV_BACK);
571 e->len = length;
575 static void add_tempo_event(int trk_id, double tempo)
577 struct song_ev *e = add_song_ev(SONG_EV_TEMPO);
579 e->trk_id = trk_id;
580 e->amount = tempo;
584 static void add_meter_event(int trk_id, int num, int den)
586 struct song_ev *e = add_song_ev(SONG_EV_METER);
588 e->trk_id = trk_id;
589 e->min = num;
590 e->max = den;
593 static void add_measure_event(void)
595 struct song_ev *e = add_song_ev(SONG_EV_MEASURE);
597 e->trk_id = -1;
598 e->value = yyline;
602 static void add_ss_sustain_event(double sustain)
604 struct song_ev *e = add_song_ev(SONG_EV_SS_SUSTAIN);
606 e->amount = sustain;
610 static void add_ss_attack_event(double attack)
612 struct song_ev *e = add_song_ev(SONG_EV_SS_ATTACK);
614 e->amount = attack;
618 static void add_ss_vibrato_event(double depth, double freq)
620 struct song_ev *e = add_song_ev(SONG_EV_SS_VIBRATO);
622 e->depth = depth;
623 e->freq = freq;
627 static void add_ss_portamento_event(double portamento)
629 struct song_ev *e = add_song_ev(SONG_EV_SS_PORTAMENTO);
631 e->amount = portamento;
635 static void add_ss_channel_event(int channel, float vol)
637 struct song_ev *e = add_song_ev(SONG_EV_SS_CHANNEL);
639 e->channel = channel;
640 e->vol = vol;
644 static void add_ss_wav_event(char * wav_file, int base, int min, int max,
645 double loop_start, double loop_end, int first_channel, int skip_channels)
647 struct song_ev *e = add_song_ev(SONG_EV_SS_WAV);
649 e->name = wav_file;
650 e->value = base;
651 e->min = min;
652 e->max = max;
653 e->start = loop_start;
654 e->end = loop_end;
655 e->channel = first_channel;
656 e->skip_channels = skip_channels;
660 static void add_ss_pat_event(char * pat_file)
662 struct song_ev *e = add_song_ev(SONG_EV_SS_PAT);
664 e->name = pat_file;
668 static void add_ss_eff_event(int type, int channel, double size, float gain,
669 double depth, double freq, double phase, float initial, float final)
671 struct song_ev *e = add_song_ev(type);
673 e->channel = channel;
674 e->len = size;
675 e->vol = gain;
676 e->depth = depth;
677 e->freq = freq;
678 e->phase = phase;
679 e->initial = initial;
680 e->final = final;
684 static void add_ss_pitch_stretch(int note, double len, float vol)
686 struct song_ev *e = add_song_ev(SONG_EV_SS_PITCH_STRETCH);
688 e->value = note;
689 e->len = len;
690 e->vol = vol;
694 static void add_ss_print_wave_tempo(int note, double len)
696 struct song_ev *e = add_song_ev(SONG_EV_SS_PRINT_WAVE_TEMPO);
698 e->value = note;
699 e->len = len;
703 static void add_midi_channel_event(int channel)
705 struct song_ev *e = add_song_ev(SONG_EV_MIDI_CHANNEL);
707 e->channel = channel - 1;
711 static void add_midi_program_event(int program)
713 struct song_ev *e = add_song_ev(SONG_EV_MIDI_PROGRAM);
715 e->value = program;
719 static void add_song_info_event(char * author, char * name)
721 struct song_ev *e = add_song_ev(SONG_EV_SONG_INFO);
723 e->author = author;
724 e->name = name;
728 static void init_track(void)
729 /* sets the default values for a new track */
731 int n;
733 /* is there an end time? test if this is longer */
734 if (cur_time > end_time) {
735 add_mark("END");
736 end_time = cur_time;
739 cur_time = 0.0;
740 length = 0.0;
741 transpose = 0;
742 staccato = 0.8;
743 volume_from = volume_to = 0.75;
744 octave = 5;
745 gliss = 0;
747 /* groups should not cross track boundaries */
748 n_groups = 0;
750 /* reset arpeggiator */
751 n_arps = 0;
752 arp_default();
754 /* is there a START mark? if so, move there */
755 if ((n = seek_mark("START")) != -1)
756 cur_time = marks[n].time;
758 /* reset alterations */
759 for (n = 0; n < 12; n++)
760 alterations[n] = 0;
766 %union {
767 int i;
768 double d;
769 char * p;
772 %token <i> P_INTEGER S_INTEGER
773 %token <d> P_REAL S_REAL
774 %token <i> NOTE_P NOTE_T3 NOTE_T5
775 %token <p> NEW_MARK GOTO_MARK ASSERT_MARK
777 %token <p> BLOCK BLK_ASSIGN BLK_INSERT FILE_INSERT
779 %token <p> ALTSTR
781 %token <p> XC_STR
782 %token <i> XC_ABSNOTE
783 %token <d> XC_MSECS
785 %token SS_SEP SS_WAV SS_LOOP_WAV SS_PAT
786 %token SS_SUSTAIN SS_ATTACK SS_VIBRATO SS_PORTAMENTO SS_CHANNEL SS_VOL
788 %token SS_EFF_DELAY SS_EFF_ECHO SS_EFF_COMB SS_EFF_ALLPASS SS_EFF_FLANGER
789 %token SS_EFF_WOBBLE SS_EFF_SQWOBBLE SS_EFF_HFWOBBLE
790 %token SS_EFF_FADER SS_EFF_REVERB
791 %token SS_EFF_FOLDBACK SS_EFF_ATAN SS_EFF_DISTORT SS_EFF_OVERDRIVE
792 %token SS_EFF_OFF
794 %token SS_PITCH_STRETCH SS_TIME_STRETCH SS_PRINT_WAVE_TEMPO
796 %token SONG_INFO
798 %token MIDI_CHANNEL MIDI_PROGRAM MIDI_GENERIC
800 %type <i> integer note note_pitch rest back
801 %type <d> real p_number number note_length
803 %type <d> arp_list arp_note
804 %type <i> xc_absnote
808 script:
809 script stmt { ; }
810 | /* NULL */
813 stmt:
814 note {
815 /* note event */
816 add_note_event($1);
817 forward(length);
819 | rest {
820 /* rest */
821 forward(length);
823 | back {
824 /* back */
825 add_back_event();
827 | 'z' note_length {
828 /* zero note */
829 length = $2;
831 | 'o' P_INTEGER {
832 /* absolute octave */
833 octave = $2;
835 | 'o' S_INTEGER {
836 /* relative octave */
837 octave += $2;
839 | 'v' P_INTEGER {
840 /* absolute volume */
841 volume_from = volume_to = (float)$2;
843 | 'v' P_REAL {
844 /* absolute volume */
845 volume_from = volume_to = (float)$2;
847 | 'v' S_REAL {
848 /* relative volume */
849 volume_from += (float)$2;
850 volume_to += (float)$2;
852 | 'v' P_REAL ',' P_REAL {
853 /* absolute volume ranges */
854 volume_from = (float)$2;
855 volume_to = (float)$4;
857 | 't' integer {
858 /* transpose */
859 transpose = $2;
861 | 's' p_number {
862 /* staccato */
863 staccato = $2;
866 | '<' {
867 /* start of group */
868 push_group();
870 | ';' {
871 /* group delimiter */
872 next_group_part();
874 | '>' {
875 /* end of group */
876 pop_group();
878 | 'l' note_length {
879 /* glissando */
880 gliss = $2;
883 | '|' {
884 /* measure mark event */
885 add_measure_event();
888 | NEW_MARK {
889 /* add new mark */
890 add_mark($1);
892 | GOTO_MARK {
893 /* go to mark */
894 find_mark($1, 1);
896 | ASSERT_MARK {
897 /* assert mark */
898 find_mark($1, 0);
901 | '\\' {
902 /* new track */
904 track++;
905 init_track();
907 | 'T' p_number {
908 /* tempo setting */
909 add_tempo_event(-1, $2);
911 | 'M' P_INTEGER '/' P_INTEGER {
912 /* meter (time signature) setting */
913 add_meter_event(-1, $2, $4);
915 | ALTSTR {
916 /* alteration string */
917 set_alteration($1);
920 | BLOCK '*' P_INTEGER {
921 /* repeat block */
922 int n;
924 /* store the block as <TMP> */
925 set_block("<TMP>", $1);
927 for(n = 0;n < $3;n++)
928 insert_block("<TMP>");
930 | BLOCK BLK_ASSIGN {
931 /* assign block */
932 set_block($2, $1);
934 | BLK_INSERT {
935 /* insert block */
936 insert_block($1);
938 | FILE_INSERT {
939 /* insert file */
940 insert_file($1);
943 | arp { ; }
945 | xc_cmd { ; }
949 integer:
950 P_INTEGER { $$ = $1; }
951 | S_INTEGER { $$ = $1; }
954 real:
955 P_REAL { $$ = $1; }
956 | S_REAL { $$ = $1; }
959 p_number:
960 P_INTEGER { $$ = (double) $1; }
961 | P_REAL { $$ = $1; }
964 number:
965 integer { $$ = (double) $1; }
966 | real { $$ = $1; }
969 note:
970 note_pitch { $$ = $1; }
971 | note note_length { $$ = $1; length=$2; }
972 | note '~' number { $$ = $1; DEBUGF("imm volume: %lf\n", $3); }
975 note_pitch:
976 NOTE_P { $$ = $1; }
977 | note_pitch '&' { $$ = $1 - 1; }
978 | note_pitch '#' { $$ = $1 + 1; }
979 | note_pitch '\'' { $$ = $1 + 12; }
980 | note_pitch ',' { $$ = $1 - 12; }
983 note_length:
984 P_INTEGER { $$ = 1 / (double) $1; }
985 | note_length NOTE_T3 { $$ = $1 * 2.0 / 3.0; }
986 | note_length NOTE_T5 { $$ = $1 * 4.0 / 5.0; }
987 | note_length '*' p_number { $$ = $1 * $3; }
988 | note_length '.' { $$ = $1 * 1.5; }
991 rest:
992 'r' { ; }
993 | rest note_length {
994 /* rest with length */
995 length = $2;
999 back:
1000 'k' { ; }
1001 | back note_length {
1002 /* back with length */
1003 length = $2;
1007 arp:
1008 'x' {
1009 /* empty arpeggiator */
1010 n_arps = 0;
1011 arp_default();
1013 | 'x' arp_list { ; }
1016 arp_list:
1017 arp_note {
1018 /* first arpeggiator note */
1019 n_arps = 0;
1020 add_arp();
1022 | arp_list ',' arp_note {
1023 /* rest of arpeggiator notes */
1024 add_arp();
1028 arp_note:
1029 note_length {
1030 /* arpeggiator delay */
1031 arp_delay = $1;
1033 | arp_note '~' number {
1034 /* arpeggiator volume */
1035 arp_volume = (float)$3;
1037 | arp_note S_INTEGER {
1038 /* arpeggiator transpose */
1039 arp_transpose = $2;
1041 | arp_note '/' P_INTEGER {
1042 /* arpeggiator track offset */
1043 arp_track_off = $3;
1045 | arp_note NOTE_T3 {
1046 /* HACK: /3 */
1047 arp_track_off = 3;
1049 | arp_note NOTE_T5 {
1050 /* HACK: /5 */
1051 arp_track_off = 5;
1055 xc_absnote:
1056 P_INTEGER { $$ = $1; }
1057 | XC_ABSNOTE { $$ = $1; }
1060 xc_cmd:
1061 SS_WAV XC_STR xc_absnote {
1062 /* load .wav file with just one note */
1063 add_ss_wav_event($2, $3, $3, $3, -1.0, -1.0, 0, 0);
1065 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote {
1066 /* load .wav file */
1067 add_ss_wav_event($2, $3, $4, $5, -1.0, -1.0, 0, 0);
1069 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number {
1070 /* load .wav file, with loop boundaries */
1071 add_ss_wav_event($2, $3, $4, $5, $6, $7, 0, 0);
1073 | SS_WAV XC_STR xc_absnote xc_absnote xc_absnote number number number number {
1074 /* load .wav file, with loop boundaries,
1075 first channel and skip channels */
1076 add_ss_wav_event($2, $3, $4, $5, $6, $7, $8, $9);
1078 | SS_PAT XC_STR {
1079 /* load .pat file */
1080 add_ss_pat_event($2);
1082 | SS_SUSTAIN XC_MSECS {
1083 /* sets sustain */
1084 add_ss_sustain_event($2);
1086 | SS_ATTACK XC_MSECS {
1087 /* sets attack */
1088 add_ss_attack_event($2);
1090 | SS_VIBRATO XC_MSECS number {
1091 /* sets vibrato */
1092 add_ss_vibrato_event($2, $3);
1094 | SS_PORTAMENTO number {
1095 /* sets portamento */
1096 add_ss_portamento_event($2);
1098 | SS_CHANNEL integer number {
1099 /* sets volume for a channel */
1100 add_ss_channel_event($2, $3);
1102 | SS_VOL number number {
1103 /* set vol for 2 channels */
1104 add_ss_channel_event(0, $2);
1105 add_ss_channel_event(1, $3);
1107 | SS_VOL number number number {
1108 /* set vol for 3 channels */
1109 add_ss_channel_event(0, $2);
1110 add_ss_channel_event(1, $3);
1111 add_ss_channel_event(2, $4);
1113 | SS_VOL number number number number {
1114 /* set vol for 4 channels */
1115 add_ss_channel_event(0, $2);
1116 add_ss_channel_event(1, $3);
1117 add_ss_channel_event(2, $4);
1118 add_ss_channel_event(3, $5);
1120 | SS_VOL number number number number number number {
1121 /* set vol for 6 channels */
1122 add_ss_channel_event(0, $2);
1123 add_ss_channel_event(1, $3);
1124 add_ss_channel_event(2, $4);
1125 add_ss_channel_event(3, $5);
1126 add_ss_channel_event(4, $6);
1127 add_ss_channel_event(5, $7);
1129 | SS_EFF_DELAY integer XC_MSECS {
1130 /* delay effect */
1131 add_ss_eff_event(SONG_EV_SS_EFF_DELAY,
1132 $2, $3, 0, 0, 0, 0, 0, 0);
1135 | SS_EFF_ECHO integer XC_MSECS number {
1136 /* echo effect */
1137 add_ss_eff_event(SONG_EV_SS_EFF_ECHO,
1138 $2, $3, $4, 0, 0, 0, 0, 0);
1141 | SS_EFF_COMB integer XC_MSECS number {
1142 /* comb effect */
1143 add_ss_eff_event(SONG_EV_SS_EFF_COMB,
1144 $2, $3, $4, 0, 0, 0, 0, 0);
1147 | SS_EFF_ALLPASS integer XC_MSECS number {
1148 /* allpass effect */
1149 add_ss_eff_event(SONG_EV_SS_EFF_ALLPASS,
1150 $2, $3, $4, 0, 0, 0, 0, 0);
1153 | SS_EFF_FLANGER integer XC_MSECS number XC_MSECS number number {
1154 /* flanger effect */
1155 add_ss_eff_event(SONG_EV_SS_EFF_FLANGER,
1156 $2, $3, $4, $5, $6, $7, 0, 0);
1159 | SS_EFF_WOBBLE integer number number {
1160 /* wobble effect */
1161 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1162 $2, 0, 0.8, 0, $3, $4, 0, 0);
1165 | SS_EFF_WOBBLE integer number number number {
1166 /* wobble effect, with gain */
1167 add_ss_eff_event(SONG_EV_SS_EFF_WOBBLE,
1168 $2, 0, $5, 0, $3, $4, 0, 0);
1171 | SS_EFF_SQWOBBLE integer number number {
1172 /* square wobble effect */
1173 add_ss_eff_event(SONG_EV_SS_EFF_SQWOBBLE,
1174 $2, 0, 0, 0, $3, $4, 0, 0);
1177 | SS_EFF_HFWOBBLE integer number number {
1178 /* half wobble effect */
1179 add_ss_eff_event(SONG_EV_SS_EFF_HFWOBBLE,
1180 $2, 0, 0, 0, $3, $4, 0, 0);
1183 | SS_EFF_FADER integer XC_MSECS number number {
1184 /* fader effect */
1185 add_ss_eff_event(SONG_EV_SS_EFF_FADER,
1186 $2, $3, 0, 0, 0, 0, $4, $5);
1189 | SS_EFF_REVERB integer {
1190 /* reverb effect */
1191 add_ss_eff_event(SONG_EV_SS_EFF_REVERB,
1192 $2, 0, 0, 0, 0, 0, 0, 0);
1195 | SS_EFF_FOLDBACK integer number {
1196 /* foldback distortion effect */
1197 add_ss_eff_event(SONG_EV_SS_EFF_FOLDBACK,
1198 $2, 0, $3, 0, 0, 0, 0, 0);
1200 | SS_EFF_ATAN integer number {
1201 /* atan distortion effect */
1202 add_ss_eff_event(SONG_EV_SS_EFF_ATAN,
1203 $2, 0, $3, 0, 0, 0, 0, 0);
1205 | SS_EFF_DISTORT integer number {
1206 /* distort distortion effect */
1207 add_ss_eff_event(SONG_EV_SS_EFF_DISTORT,
1208 $2, 0, $3, 0, 0, 0, 0, 0);
1210 | SS_EFF_OVERDRIVE integer number {
1211 /* overdrive distortion effect */
1212 add_ss_eff_event(SONG_EV_SS_EFF_OVERDRIVE,
1213 $2, 0, $3, 0, 0, 0, 0, 0);
1216 | SS_EFF_OFF integer {
1217 /* off effect */
1218 add_ss_eff_event(SONG_EV_SS_EFF_OFF,
1219 $2, 0, 0, 0, 0, 0, 0, 0);
1222 | SS_PITCH_STRETCH xc_absnote number number {
1223 /* pitch stretch note */
1224 add_ss_pitch_stretch($2, $3, $4);
1226 forward($3);
1229 | SS_PRINT_WAVE_TEMPO xc_absnote number {
1230 /* print tempo from wave */
1231 add_ss_print_wave_tempo($2, $3);
1234 | SONG_INFO XC_STR XC_STR {
1235 /* add song info */
1236 add_song_info_event($2, $3);
1239 | MIDI_CHANNEL integer {
1240 /* midi channel */
1241 add_midi_channel_event($2);
1244 | MIDI_PROGRAM integer {
1245 /* midi program */
1246 add_midi_program_event($2);
1252 void yyerror(char * s)
1254 c_err(s, NULL, NULL);
1258 #define set_block_d(n,b) set_block(n,strdup(b))
1260 static void compile_startup(void)
1262 track = 0;
1263 yyline = 1;
1264 compiler_error = 0;
1266 /* default settings */
1267 add_tempo_event(-2, 120.0);
1268 add_meter_event(-2, 4, 4);
1269 init_track();
1271 /* standard tonalities */
1272 set_block_d("CM", "A"); set_block_d("Am", "$CM");
1273 set_block_d("C#M", "A#######"); set_block_d("A#m", "$C#M");
1274 set_block_d("DM", "A#--#---"); set_block_d("Bm", "$DM");
1275 set_block_d("E&M", "A--&--&&"); set_block_d("Cm", "$E&M");
1276 set_block_d("EM", "A##-##--"); set_block_d("C#m", "$EM");
1277 set_block_d("FM", "A------&"); set_block_d("Dm", "$FM");
1278 set_block_d("F#M", "A######-"); set_block_d("D#m", "$F#M");
1279 set_block_d("GM", "A---#---"); set_block_d("Em", "$GM");
1280 set_block_d("A&M", "A-&&--&&"); set_block_d("Fm", "$A&M");
1281 set_block_d("AM", "A#--##--"); set_block_d("F#m", "$AM");
1282 set_block_d("B&M", "A--&---&"); set_block_d("Gm", "$B&M");
1283 set_block_d("BM", "A##-###-"); set_block_d("G#m", "$BM");
1287 static int do_parse(void)
1289 int r = yyparse();
1291 return r + compiler_error;
1295 int compile_ahs_string(char * code)
1297 compile_startup();
1299 push_code(strdup(code));
1301 return do_parse();
1305 int compile_ahs(char * file)
1307 compile_startup();
1309 if (insert_file(file))
1310 return 1;
1312 return do_parse();