EOT events can't disable the instrument / track this happily, because
[ahxm.git] / ahxm.h
blob02f97aeb3999cc15123c7268506450a289211971
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2006 Angel Ortega <angel@triptico.com>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 http://www.triptico.com
24 /* HARD LIMITS */
26 #ifndef SS_MAX_CHANNELS
27 #define SS_MAX_CHANNELS 16
28 #endif
30 #ifndef SS_MAX_GENERATORS
31 #define SS_MAX_GENERATORS 256
32 #endif
34 #ifndef SS_MAX_INSTRUMENTS
35 #define SS_MAX_INSTRUMENTS 256
36 #endif
38 /* STRUCTURES AND TYPES */
40 /* samples */
42 typedef double sample_t;
44 /* waves */
46 struct ss_wave
48 double size; /* size in frames of full wave */
49 int p_size; /* size in frames of the page */
50 int n_channels; /* # of channels */
51 sample_t ** wave; /* the PCM waves */
52 int s_rate; /* original sample rate */
54 double loop_start; /* start of loop (-1, no loop) */
55 double loop_end; /* end of loop */
57 double base_freq; /* base frequency */
58 double min_freq; /* minimum frequency */
59 double max_freq; /* maximum frequency */
61 int first_channel; /* first channel to spread into */
62 int skip_channels; /* channels to skip when spreading */
64 char * filename; /* filename (for paged files) */
65 long f_pos; /* file position where the PCM files */
66 int p_offset; /* offset in frames of the page */
67 int bits; /* bits of the PCM wave (8, 16) */
68 int sign; /* sign of the PCM wave (1, -1) */
70 int page_faults; /* number of times ss_load_page() was called */
73 /* generators */
75 struct ss_gen
77 int note_id; /* note ID */
78 sample_t vol; /* volume */
79 struct ss_wave * w; /* the wave data */
81 double cursor; /* offset to next sample */
82 double inc; /* increment (frequency) */
84 int sustain; /* number of frames to play after release */
85 sample_t dvol; /* volume decrement in sustain */
87 double vibrato; /* vibrato oscillator */
88 double vib_depth; /* vibrato depth */
89 double vib_inc; /* increment for vibrato oscillator */
91 double portamento; /* portamento sum to inc */
93 struct ss_gen * next;
94 struct ss_gen * prev;
97 /* software syntesizer instruments */
99 struct ss_ins
101 int n_layers; /* # of layers */
102 struct ss_wave ** layers; /* layers */
104 struct ss_gen * gens; /* generator queue */
106 int n_channels; /* number of channels */
107 sample_t * vols; /* volumes (1 per channel) */
108 struct ss_eff ** effs; /* effect chains (1 per channel) */
110 double sustain; /* sustain in msecs */
111 double vib_depth; /* vibrato depth */
112 double vib_freq; /* vibrato frequency */
114 int disabled; /* if set, no processing is done */
116 double portamento; /* portamento */
119 /* digital effects */
121 struct ss_eff
123 struct ss_wave * wave; /* wave buffer */
124 sample_t gain; /* effect gain */
125 sample_t igain; /* gain increment */
127 double lfo; /* lfo value */
128 double lfo_depth; /* lfo depth */
129 double lfo_inc; /* lfo increment */
131 double cursor; /* current buffer position */
133 sample_t (* func)(struct ss_eff *, sample_t); /* processing function */
135 struct ss_eff * next; /* next in chain */
138 /* song events */
140 typedef enum
142 SONG_EV_TEMPO,
143 SONG_EV_METER,
144 SONG_EV_MEASURE,
146 SONG_EV_SS_SUSTAIN,
147 SONG_EV_SS_VIBRATO,
148 SONG_EV_SS_PORTAMENTO,
149 SONG_EV_SS_CHANNEL,
151 SONG_EV_SS_WAV,
152 SONG_EV_SS_PAT,
154 SONG_EV_SS_EFF_OFF,
155 SONG_EV_SS_EFF_DELAY,
156 SONG_EV_SS_EFF_ECHO,
157 SONG_EV_SS_EFF_COMB,
158 SONG_EV_SS_EFF_ALLPASS,
159 SONG_EV_SS_EFF_FLANGER,
160 SONG_EV_SS_EFF_WOBBLE,
161 SONG_EV_SS_EFF_SQWOBBLE,
162 SONG_EV_SS_EFF_HFWOBBLE,
163 SONG_EV_SS_EFF_FADER,
164 SONG_EV_SS_EFF_REVERB,
165 SONG_EV_SS_EFF_FOLDBACK,
167 SONG_EV_MIDI_CHANNEL,
168 SONG_EV_MIDI_PROGRAM,
170 SONG_EV_BACK,
171 SONG_EV_NOTE,
172 SONG_EV_SS_PITCH_STRETCH,
173 SONG_EV_SS_PRINT_WAVE_TEMPO,
175 SONG_EV_SONG_INFO,
177 SONG_EV_NOTE_OFF,
178 SONG_EV_NOTE_ON,
180 SONG_EV_EOT,
181 SONG_EV_END
183 } song_ev_type;
185 struct song_ev_generic
187 song_ev_type type; /* event type */
188 double time; /* event time (1: whole note) */
189 int trk_id; /* track id */
190 int event_id; /* event id */
193 struct song_ev_note
195 song_ev_type type; /* SONG_EV_NOTE */
196 double time;
197 int trk_id;
198 int event_id;
199 int note; /* MIDI-like note */
200 double len; /* note length (1: whole note) */
201 sample_t vol; /* note volume (1: full volume) */
204 struct song_ev_back
206 song_ev_type type; /* SONG_EV_BACK */
207 double time;
208 int trk_id;
209 int event_id;
210 double len; /* note length (1: whole note) */
213 struct song_ev_tempo
215 song_ev_type type; /* SONG_EV_TEMPO */
216 double time;
217 int trk_id; /* always < 0 */
218 int event_id;
219 double tempo; /* tempo in bpm */
222 struct song_ev_meter
224 song_ev_type type; /* SONG_EV_METER */
225 double time;
226 int trk_id; /* always < 0 */
227 int event_id;
228 int num; /* meter numerator */
229 int den; /* meter denominator */
232 struct song_ev_measure
234 song_ev_type type; /* SONG_EV_MEASURE */
235 double time;
236 int trk_id;
237 int event_id;
238 int line; /* line number */
241 struct song_ev_ss_pitch_stretch
243 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
244 double time;
245 int trk_id;
246 int event_id;
247 int note; /* MIDI-like note (to find the wave) */
248 double len; /* note length (1: whole note) */
249 sample_t vol; /* note volume (1: full volume) */
252 struct song_ev_ss_print_wave_tempo
254 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
255 double time;
256 int trk_id;
257 int event_id;
258 int note; /* MIDI-like note (to find the wave) */
259 double len; /* note length (1: whole note) */
262 struct song_ev_ss_sustain
264 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
265 double time;
266 int trk_id;
267 int event_id;
268 double sustain; /* sustain time (in msecs) */
271 struct song_ev_ss_vibrato
273 song_ev_type type; /* SONG_EV_SS_VIBRATO */
274 double time;
275 int trk_id;
276 int event_id;
277 double vib_depth; /* vibrato depth (in msecs) */
278 double vib_freq; /* vibrato frequency (in Hzs) */
281 struct song_ev_ss_portamento
283 song_ev_type type; /* SONG_EV_SS_PORTAMENTO */
284 double time;
285 int trk_id;
286 int event_id;
287 double portamento; /* portamento */
290 struct song_ev_ss_channel
292 song_ev_type type; /* SONG_EV_SS_CHANNEL */
293 double time;
294 int trk_id;
295 int event_id;
296 int channel; /* channel */
297 sample_t vol; /* volume */
300 struct song_ev_ss_wav
302 song_ev_type type; /* SONG_EV_SS_WAV */
303 double time;
304 int trk_id;
305 int event_id;
306 char * file; /* path to .wav file */
307 int base; /* MIDI-like base note */
308 int min; /* MIDI-like minimum note */
309 int max; /* MIDI-like maximum note */
310 double loop_start; /* start of loop */
311 double loop_end; /* end of loop */
312 int first_channel; /* first channel to start spreading */
313 int skip_channels; /* channels to skip when spreading */
316 struct song_ev_ss_pat
318 song_ev_type type; /* SONG_EV_SS_PAT */
319 double time;
320 int trk_id;
321 int event_id;
322 char * file; /* path to .pat file */
325 struct song_ev_ss_eff
327 song_ev_type type; /* effect type */
328 double time;
329 int trk_id;
330 int event_id;
331 int channel; /* channel */
332 double size; /* size of effect */
333 sample_t gain; /* gain */
334 double depth; /* depth */
335 double freq; /* freq */
336 double phase; /* phase */
337 sample_t initial; /* initial vol */
338 sample_t final; /* final vol */
341 struct song_ev_midi_channel
343 song_ev_type type; /* SONG_EV_MIDI_CHANNEL */
344 double time;
345 int trk_id;
346 int event_id;
347 int channel; /* midi channel (1-16) */
350 struct song_ev_midi_program
352 song_ev_type type; /* SONG_EV_MIDI_PROGRAM */
353 double time;
354 int trk_id;
355 int event_id;
356 int program; /* midi program (0-127) */
359 struct song_ev_song_info
361 song_ev_type type; /* SONG_EV_SONG_INFO */
362 double time;
363 int trk_id;
364 int event_id;
365 char * author; /* track author */
366 char * name; /* track name */
369 union song_ev
371 struct song_ev_generic generic;
373 struct song_ev_tempo tempo;
374 struct song_ev_meter meter;
375 struct song_ev_measure measure;
377 struct song_ev_note note;
378 struct song_ev_back back;
380 struct song_ev_ss_pitch_stretch ss_pitch_stretch;
381 struct song_ev_ss_print_wave_tempo ss_print_wave_tempo;
383 struct song_ev_ss_sustain ss_sustain;
384 struct song_ev_ss_vibrato ss_vibrato;
385 struct song_ev_ss_portamento ss_portamento;
386 struct song_ev_ss_channel ss_channel;
388 struct song_ev_ss_wav ss_wav;
389 struct song_ev_ss_pat ss_pat;
391 struct song_ev_ss_eff ss_eff;
393 struct song_ev_midi_channel midi_channel;
394 struct song_ev_midi_program midi_program;
396 struct song_ev_song_info song_info;
400 /* GLOBALS */
402 /* in ss_core.c */
404 extern int ss_frequency;
405 extern int ss_interpolation;
406 extern int ss_nchannels;
408 /* in ss_input.c */
410 extern int ss_page_size;
412 /* in ss_output.c */
414 extern sample_t ss_master_volume;
415 extern int ss_output_clipped;
416 extern sample_t ss_optimal_volume;
417 extern char * ss_cue_file_name;
419 /* in song.c */
421 extern union song_ev * song;
422 extern int n_song_ev;
423 extern int solo_track;
425 /* in support.c */
427 extern int verbose;
428 extern int trace;
430 /* MACROS */
432 /* milliseconds to frames conversion */
433 #define MS2F(ms) ((ms / 1000.0) * ss_frequency)
435 /* grows a dynamic array */
436 #define GROW(b,n,t) b = (t *)realloc(b,((n) + 1) * sizeof(t))
438 /* PROTOTYPES */
440 /* in ss_core.c */
442 double ss_note_frequency(int note);
443 struct ss_wave * ss_alloc_wave(int size, int n_channels, int s_rate, int p_size);
444 void ss_free_wave(struct ss_wave * w);
445 void ss_prepare_wave(struct ss_wave * w);
446 sample_t ss_get_sample(struct ss_wave * w, int channel, double offset);
447 double ss_tempo_from_wave(struct ss_wave * w, int note, double len);
448 double ss_pitch_from_tempo(struct ss_wave * w, double tempo, double len);
450 /* in ss_gen.c */
452 void ss_gen_init(void);
453 struct ss_gen * ss_gen_alloc(struct ss_gen ** q);
454 void ss_gen_free(struct ss_gen ** q, struct ss_gen * g);
455 void ss_gen_sustain(struct ss_gen * g, double sustain);
456 void ss_gen_vibrato(struct ss_gen * g, double depth, double freq);
457 void ss_gen_portamento(struct ss_gen * g, double portamento);
458 void ss_gen_play(struct ss_gen * g, double freq, sample_t vol, int note_id,
459 struct ss_wave * w);
460 void ss_gen_release(struct ss_gen * g);
461 int ss_gen_frame(struct ss_gen * g, int n_channels, sample_t frame[]);
463 /* in ss_ins.c */
465 void ss_ins_init(struct ss_ins * i);
466 void ss_ins_disable(struct ss_ins * i);
467 void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w);
468 struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off);
469 void ss_ins_set_channel(struct ss_ins * i, int channel, sample_t vol);
470 void ss_ins_set_sustain(struct ss_ins * i, double sustain);
471 void ss_ins_set_vibrato(struct ss_ins * i, double depth, double freq);
472 void ss_ins_set_portamento(struct ss_ins * i, double portamento);
473 int ss_ins_play(struct ss_ins * i, double freq, sample_t vol, int note_id,
474 struct ss_wave * w);
475 int ss_ins_note_on(struct ss_ins * i, int note, sample_t vol, int note_id);
476 void ss_ins_note_off(struct ss_ins * i, int note_id);
477 void ss_ins_frame(struct ss_ins * i, sample_t frame[]);
479 /* in ss_output.c */
481 int ss_output_open(char * drvname, char * filename);
482 void ss_output_init_frame(sample_t frame[]);
483 int ss_output_write(sample_t frame[]);
484 void ss_output_close(void);
485 int cue_file_song_info(int frame, char * author, char * name);
487 /* in ss_input.c */
489 void load_pcm_wave(FILE * f, struct ss_wave * w);
490 struct ss_wave * ss_load_wav_file(char * file,
491 double base_freq, double min_freq, double max_freq,
492 double loop_start, double loop_end,
493 int first_channel, int skip_channels);
494 int ss_load_pat_file(struct ss_ins * i, char * file);
496 /* in ss_eff.c */
498 void ss_eff_delay(struct ss_eff ** ec, double size);
499 void ss_eff_echo(struct ss_eff ** ec, double size, sample_t gain);
500 void ss_eff_comb(struct ss_eff ** ec, double size, sample_t gain);
501 void ss_eff_allpass(struct ss_eff ** ec, double size, sample_t gain);
502 void ss_eff_flanger(struct ss_eff ** ec, double size, sample_t gain,
503 double depth, double freq, double phase);
504 void ss_eff_wobble(struct ss_eff ** ec, double freq, double phase, sample_t gain);
505 void ss_eff_square_wobble(struct ss_eff ** ec, double freq, double phase);
506 void ss_eff_half_wobble(struct ss_eff ** ec, double freq, double phase);
507 void ss_eff_fader(struct ss_eff ** ec, double size, sample_t initial, sample_t final);
508 void ss_eff_reverb(struct ss_eff ** ec);
509 void ss_eff_foldback(struct ss_eff ** ec, sample_t threshold);
511 sample_t ss_eff_process(struct ss_eff * e, sample_t s);
512 void ss_eff_off(struct ss_eff ** ec);
514 /* in song.c */
516 void song_clear(void);
517 void add_song_ev(song_ev_type type, double time, union song_ev * ev);
518 void song_sort(void);
519 int song_test_measure_boundary(double ev_time, int num, int den, int line);
521 /* in ss_song.c */
523 int ss_song_render(int skip_secs, char * driver, char * devfile);
525 /* in midi_song.c */
527 int midi_song_play(int skip_secs);
528 int midi_device_open(char * devfile);
529 void midi_device_close(void);
531 /* in compiler.y */
533 int compile_ahs_string(char * code);
534 int compile_ahs(char * file);
536 /* in support.c */
538 void libpath_add(char * path, int strip);
539 FILE * libpath_fopen(char * filename, char * mode);
540 char * libpath_locate(char * filename);
541 void transconv_add(char * from, char * to, char * convcmd);
542 char * transconv(char * file, char * ext, char * dir);