Cue commands are indented.
[ahxm.git] / ss_song.c
blob5529a321c55150547b18a8df97ae4414e366277a
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2006 Angel Ortega <angel@triptico.com>
6 ss_song.c - Software synth song event stream management
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
26 #include "config.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <math.h>
33 #include "annhell.h"
35 /*******************
36 Data
37 ********************/
39 struct ss_ev_generic
41 song_ev_type type; /* event type */
42 int frame; /* frame number (time) */
43 int trk_id; /* track id */
44 int event_id; /* event id */
47 struct ss_ev_note_off
49 song_ev_type type; /* SONG_EV_NOTE_OFF */
50 int frame;
51 int trk_id;
52 int event_id;
53 int note_id; /* note id */
56 struct ss_ev_note_on
58 song_ev_type type; /* SONG_EV_NOTE_ON */
59 int frame;
60 int trk_id;
61 int event_id;
62 int note_id; /* note id */
63 int note; /* MIDI-like note */
64 sample_t vol; /* volume */
67 struct ss_ev_ss_sustain
69 song_ev_type type; /* SONG_EV_SS_SUSTAIN */
70 int frame;
71 int trk_id;
72 int event_id;
73 double sustain; /* sustain time (in frames) */
76 struct ss_ev_ss_vibrato
78 song_ev_type type; /* SONG_EV_SS_VIBRATO */
79 int frame;
80 int trk_id;
81 int event_id;
82 double vib_depth; /* vibrato depth (in msecs) */
83 double vib_freq; /* vibrato frequency (in Hzs) */
86 struct ss_ev_ss_channel
88 song_ev_type type; /* SONG_EV_SS_CHANNEL */
89 int frame;
90 int trk_id;
91 int event_id;
92 int channel; /* channel */
93 sample_t vol; /* volume */
96 struct ss_ev_ss_wav
98 song_ev_type type; /* SONG_EV_SS_WAV */
99 int frame;
100 int trk_id;
101 int event_id;
102 char * file; /* path to .wav file */
103 int base; /* MIDI-like base note */
104 int min; /* MIDI-like minimum note */
105 int max; /* MIDI-like maximum note */
106 double loop_start; /* loop start */
107 double loop_end; /* loop end */
110 struct ss_ev_ss_pat
112 song_ev_type type; /* SONG_EV_SS_PAT */
113 int frame;
114 int trk_id;
115 int event_id;
116 char * file; /* path to .pat file */
119 struct ss_ev_tempo
121 song_ev_type type; /* SONG_EV_TEMPO */
122 int frame;
123 int trk_id;
124 int event_id;
125 double tempo; /* tempo in bmp */
128 struct ss_ev_pitch_stretch
130 song_ev_type type; /* SONG_EV_SS_PITCH_STRETCH */
131 int frame;
132 int trk_id;
133 int event_id;
134 int note_id; /* note id */
135 int note; /* MIDI-like note (to find the wave) */
136 double len; /* note length (1: whole note) */
137 sample_t vol; /* note volume (1: full volume) */
140 struct ss_ev_print_wave_tempo
142 song_ev_type type; /* SONG_EV_SS_PRINT_WAVE_TEMPO */
143 int frame;
144 int trk_id;
145 int event_id;
146 int note_id; /* note id */
147 int note; /* MIDI-like note (to find the wave) */
148 double len; /* note length (1: whole note) */
151 struct ss_ev_ss_eff
153 song_ev_type type; /* effect type */
154 int frame;
155 int trk_id;
156 int event_id;
157 int channel; /* channel */
158 double size; /* size of effect */
159 sample_t gain; /* gain */
160 double depth; /* depth */
161 double freq; /* freq */
162 double phase; /* phase */
163 sample_t initial; /* initial vol */
164 sample_t final; /* final vol */
167 struct ss_ev_track_info
169 song_ev_type type; /* SONG_EV_TRACK_INFO */
170 int frame;
171 int trk_id;
172 int event_id;
173 char * author; /* track author */
174 char * name; /* track name */
177 union ss_ev
179 struct ss_ev_generic generic;
180 struct ss_ev_note_on note_on;
181 struct ss_ev_note_off note_off;
182 struct ss_ev_ss_sustain ss_sustain;
183 struct ss_ev_ss_vibrato ss_vibrato;
184 struct ss_ev_ss_channel ss_channel;
185 struct ss_ev_ss_wav ss_wav;
186 struct ss_ev_ss_pat ss_pat;
187 struct ss_ev_ss_eff ss_eff;
188 struct ss_ev_tempo tempo;
189 struct ss_ev_pitch_stretch ss_pitch_stretch;
190 struct ss_ev_print_wave_tempo ss_print_wave_tempo;
191 struct ss_ev_track_info track_info;
194 /* the softsynth song stream */
196 static union ss_ev * ss_song = NULL;
197 static int n_ss_ev = 0;
200 /* the instruments */
202 struct ss_ins ss_song_ins[SS_MAX_INSTRUMENTS];
205 /*******************
206 Code
207 ********************/
209 static void add_ss_ev(union ss_ev * e)
210 /* adds a softsynth song event */
212 /* reallocs */
213 ss_song = (union ss_ev *)realloc(ss_song,
214 (n_ss_ev + 1) * sizeof(union ss_ev));
216 /* store */
217 memcpy(&ss_song[n_ss_ev], e, sizeof(union ss_ev));
219 n_ss_ev++;
223 static int ss_ev_cmp(const void * v1, const void * v2)
224 /* softsynth song event compare function for qsort() */
226 struct ss_ev_generic * e1;
227 struct ss_ev_generic * e2;
228 int ret;
230 e1 = (struct ss_ev_generic *)v1; e2 = (struct ss_ev_generic *)v2;
232 ret = e1->frame - e2->frame;
234 if(ret == 0)
235 ret = e1->type - e2->type;
237 if(ret == 0)
238 ret = e1->event_id - e2->event_id;
240 return(ret);
244 static int ss_song_convert_events(void)
245 /* converts generic song_ev events to softsynth events */
247 int note_id = 1;
248 union song_ev * e;
249 union ss_ev sse;
250 int frame, frame_ac, f_frame;
251 double fpw, time_ac, time_ac_m;
252 int num, den;
253 int n;
254 int b_track = -1;
256 /* resets the ss stream */
257 if(ss_song != NULL)
259 free(ss_song);
260 ss_song = NULL;
263 n_ss_ev = 0;
265 /* sorts the song */
266 song_sort();
268 fpw = 0;
269 frame = frame_ac = f_frame = 0;
270 time_ac = time_ac_m = 0;
271 num = den = 4;
273 /* travels the song events generating softsynth song events */
274 for(n = 0;n < n_song_ev;n++)
276 /* gets the song event */
277 e = &song[n];
279 /* calculates the frame */
280 frame = ((e->generic.time - time_ac) * fpw) + frame_ac;
282 /* generic event data */
283 sse.generic.type = e->generic.type;
284 sse.generic.frame = frame;
285 sse.generic.trk_id = e->generic.trk_id;
286 sse.generic.event_id = e->generic.event_id;
288 /* account the biggest track seen */
289 if(b_track < e->generic.trk_id) b_track = e->generic.trk_id;
291 switch(e->generic.type)
293 case SONG_EV_TEMPO:
295 /* updates accumulations */
296 frame_ac = frame;
297 time_ac = e->generic.time;
299 /* calculates frames-per-whole based on new tempo */
300 fpw = (double) ss_frequency * 60.0;
301 fpw /= e->tempo.tempo / 4.0;
303 /* adds an event */
304 sse.tempo.tempo = e->tempo.tempo;
305 add_ss_ev(&sse);
307 break;
309 case SONG_EV_METER:
311 /* just store the values */
312 num = e->meter.num;
313 den = e->meter.den;
314 time_ac_m = e->meter.time;
316 break;
318 case SONG_EV_MEASURE:
320 song_test_measure_boundary(e->measure.time - time_ac_m,
321 num, den, e->measure.line);
322 break;
324 case SONG_EV_NOTE:
326 /* convert to note on / off pairs */
328 sse.note_on.type = SONG_EV_NOTE_ON;
329 sse.note_on.note_id = note_id++;
330 sse.note_on.note = e->note.note;
331 sse.note_on.vol = e->note.vol;
333 add_ss_ev(&sse);
335 frame += (int)(e->note.len * fpw);
337 sse.note_off.type = SONG_EV_NOTE_OFF;
338 sse.note_off.frame = frame;
340 add_ss_ev(&sse);
341 break;
343 case SONG_EV_BACK:
345 /* move the cursor back */
347 frame_ac -= (int)(e->back.len * fpw);
349 break;
351 case SONG_EV_SS_PITCH_STRETCH:
353 sse.ss_pitch_stretch.note_id = note_id++;
354 sse.ss_pitch_stretch.note = e->ss_pitch_stretch.note;
355 sse.ss_pitch_stretch.len = e->ss_pitch_stretch.len;
356 sse.ss_pitch_stretch.vol = e->ss_pitch_stretch.vol;
358 add_ss_ev(&sse);
360 frame += (int)(e->ss_pitch_stretch.len * fpw);
362 sse.note_off.type = SONG_EV_NOTE_OFF;
363 sse.note_off.frame = frame;
365 add_ss_ev(&sse);
366 break;
368 case SONG_EV_SS_PRINT_WAVE_TEMPO:
370 sse.ss_print_wave_tempo.note = e->ss_print_wave_tempo.note;
371 sse.ss_print_wave_tempo.len = e->ss_print_wave_tempo.len;
373 add_ss_ev(&sse);
374 break;
376 case SONG_EV_SS_WAV:
378 sse.ss_wav.file = e->ss_wav.file;
379 sse.ss_wav.base = e->ss_wav.base;
380 sse.ss_wav.min = e->ss_wav.min;
381 sse.ss_wav.max = e->ss_wav.max;
382 sse.ss_wav.loop_start = e->ss_wav.loop_start;
383 sse.ss_wav.loop_end = e->ss_wav.loop_end;
385 add_ss_ev(&sse);
386 break;
388 case SONG_EV_SS_PAT:
390 sse.ss_pat.file = e->ss_pat.file;
392 add_ss_ev(&sse);
393 break;
395 case SONG_EV_SS_SUSTAIN:
397 sse.ss_sustain.sustain = e->ss_sustain.sustain;
399 add_ss_ev(&sse);
400 break;
402 case SONG_EV_SS_VIBRATO:
404 sse.ss_vibrato.vib_depth = e->ss_vibrato.vib_depth;
405 sse.ss_vibrato.vib_freq = e->ss_vibrato.vib_freq;
407 add_ss_ev(&sse);
408 break;
410 case SONG_EV_SS_CHANNEL:
412 sse.ss_channel.channel = e->ss_channel.channel;
413 sse.ss_channel.vol = e->ss_channel.vol;
415 add_ss_ev(&sse);
416 break;
418 case SONG_EV_SS_EFF_DELAY:
419 case SONG_EV_SS_EFF_ECHO:
420 case SONG_EV_SS_EFF_COMB:
421 case SONG_EV_SS_EFF_ALLPASS:
422 case SONG_EV_SS_EFF_FLANGER:
423 case SONG_EV_SS_EFF_WOBBLE:
424 case SONG_EV_SS_EFF_SQWOBBLE:
425 case SONG_EV_SS_EFF_FADER:
426 case SONG_EV_SS_EFF_REVERB:
427 case SONG_EV_SS_EFF_OFF:
429 sse.ss_eff.channel = e->ss_eff.channel;
430 sse.ss_eff.size = e->ss_eff.size;
431 sse.ss_eff.gain = e->ss_eff.gain;
432 sse.ss_eff.depth = e->ss_eff.depth;
433 sse.ss_eff.freq = e->ss_eff.freq;
434 sse.ss_eff.phase = e->ss_eff.phase;
435 sse.ss_eff.initial = e->ss_eff.initial;
436 sse.ss_eff.final = e->ss_eff.final;
438 add_ss_ev(&sse);
439 break;
441 case SONG_EV_TRACK_INFO:
443 sse.track_info.author = e->track_info.author;
444 sse.track_info.name = e->track_info.name;
446 add_ss_ev(&sse);
447 break;
449 case SONG_EV_MIDI_CHANNEL:
450 case SONG_EV_MIDI_PROGRAM:
452 /* ignored */
453 break;
455 case SONG_EV_NOTE_ON:
456 case SONG_EV_NOTE_OFF:
457 case SONG_EV_END:
459 /* never found in generic song streams */
460 break;
463 /* store the further frame seen */
464 if(f_frame < frame) f_frame = frame;
467 /* generates an end of event mark, a time after the last one */
468 sse.generic.type = SONG_EV_END;
469 sse.generic.frame = f_frame + ss_frequency;
470 sse.generic.event_id = -1;
471 add_ss_ev(&sse);
473 /* finally sort */
474 qsort(ss_song, n_ss_ev, sizeof(union ss_ev), ss_ev_cmp);
476 /* return the number of tracks */
477 return(b_track + 1);
481 static void ss_song_trace_events(void)
483 union ss_ev * e;
484 int n;
486 printf("** SOFTWARE SYNTHESIZER EVENT DUMP **\n\n");
487 printf("%10s %5s %5s Event and information\n",
488 "Frame", "Track", "Ev.ID");
489 printf("------------------------------------------------------------\n");
491 for(n = 0, e = ss_song;n < n_ss_ev;n++, e++)
493 printf("%10d %5d %5d ",
494 e->generic.frame, e->generic.trk_id, e->generic.event_id);
496 switch(e->generic.type)
498 case SONG_EV_TEMPO:
500 printf("SONG_EV_TEMPO ");
501 printf("%lf", e->tempo.tempo);
502 break;
504 case SONG_EV_SS_SUSTAIN:
506 printf("SONG_EV_SS_SUSTAIN ");
507 printf("SUSTAIN:%lf", e->ss_sustain.sustain);
508 break;
510 case SONG_EV_SS_VIBRATO:
512 printf("SONG_EV_SS_VIBRATO ");
513 printf("DEPTH:%lf FREQ:%lf",
514 e->ss_vibrato.vib_depth,
515 e->ss_vibrato.vib_freq);
516 break;
518 case SONG_EV_SS_CHANNEL:
520 printf("SONG_EV_SS_CHANNEL ");
521 printf("CHANNEL:%d VOL:%lf",
522 e->ss_channel.channel,
523 e->ss_channel.vol);
524 break;
526 case SONG_EV_SS_WAV:
528 printf("SONG_EV_SS_WAV ");
529 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
530 e->ss_wav.file, e->ss_wav.base,
531 e->ss_wav.min, e->ss_wav.max,
532 e->ss_wav.loop_start, e->ss_wav.loop_end);
533 break;
535 case SONG_EV_SS_PAT:
537 printf("SONG_EV_SS_PAT ");
538 printf("FILE:'%s'", e->ss_pat.file);
539 break;
541 case SONG_EV_SS_EFF_DELAY:
543 printf("SONG_EV_SS_EFF_DELAY ");
544 printf("CHANNEL:%d ", e->ss_eff.channel);
545 printf("SIZE:%lf ", e->ss_eff.size);
546 break;
548 case SONG_EV_SS_EFF_ECHO:
550 printf("SONG_EV_SS_EFF_ECHO ");
551 printf("CHANNEL:%d ", e->ss_eff.channel);
552 printf("SIZE:%lf ", e->ss_eff.size);
553 printf("GAIN:%f ", e->ss_eff.gain);
554 break;
556 case SONG_EV_SS_EFF_COMB:
558 printf("SONG_EV_SS_EFF_COMB ");
559 printf("CHANNEL:%d ", e->ss_eff.channel);
560 printf("SIZE:%lf ", e->ss_eff.size);
561 printf("GAIN:%f ", e->ss_eff.gain);
562 break;
564 case SONG_EV_SS_EFF_ALLPASS:
566 printf("SONG_EV_SS_EFF_ALLPASS ");
567 printf("CHANNEL:%d ", e->ss_eff.channel);
568 printf("SIZE:%lf ", e->ss_eff.size);
569 printf("GAIN:%f ", e->ss_eff.gain);
570 break;
572 case SONG_EV_SS_EFF_FLANGER:
574 printf("SONG_EV_SS_EFF_FLANGER ");
575 printf("CHANNEL:%d ", e->ss_eff.channel);
576 printf("SIZE:%lf ", e->ss_eff.size);
577 printf("GAIN:%f ", e->ss_eff.gain);
578 printf("DEPTH:%lf ", e->ss_eff.depth);
579 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
580 e->ss_eff.phase);
581 break;
583 case SONG_EV_SS_EFF_WOBBLE:
585 printf("SONG_EV_SS_EFF_WOBBLE ");
586 printf("CHANNEL:%d ", e->ss_eff.channel);
587 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
588 e->ss_eff.phase);
589 break;
591 case SONG_EV_SS_EFF_SQWOBBLE:
593 printf("SONG_EV_SS_EFF_SQWOBBLE ");
594 printf("CHANNEL:%d ", e->ss_eff.channel);
595 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
596 e->ss_eff.phase);
597 break;
599 case SONG_EV_SS_EFF_FADER:
601 printf("SONG_EV_SS_EFF_FADER ");
602 printf("CHANNEL:%d ", e->ss_eff.channel);
603 printf("SIZE:%lf ", e->ss_eff.size);
604 printf("INITIAL:%f FINAL:%f", e->ss_eff.initial,
605 e->ss_eff.final);
606 break;
608 case SONG_EV_SS_EFF_REVERB:
610 printf("SONG_EV_SS_EFF_REVERB ");
611 printf("CHANNEL:%d ", e->ss_eff.channel);
612 break;
614 case SONG_EV_SS_EFF_OFF:
616 printf("SONG_EV_SS_EFF_OFF ");
617 printf("CHANNEL:%d ", e->ss_eff.channel);
618 break;
620 case SONG_EV_SS_PITCH_STRETCH:
622 printf("SONG_EV_SS_PITCH_STRETCH ");
623 printf("MIDI:%d LEN:%lf VOL:%f",
624 e->ss_pitch_stretch.note,
625 e->ss_pitch_stretch.len,
626 e->ss_pitch_stretch.vol);
628 break;
630 case SONG_EV_SS_PRINT_WAVE_TEMPO:
632 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
633 printf("MIDI:%d LEN:%lf",
634 e->ss_print_wave_tempo.note,
635 e->ss_print_wave_tempo.len);
636 break;
638 case SONG_EV_TRACK_INFO:
640 printf("SONG_EV_TRACK_INFO ");
641 printf("AUTHOR:'%s' NAME:'%s'",
642 e->track_info.author,
643 e->track_info.name);
644 break;
646 case SONG_EV_NOTE_ON:
648 printf("SONG_EV_NOTE_ON ");
649 printf("ID:%d MIDI:%d VOL:%f",
650 e->note_on.note_id, e->note_on.note,
651 e->note_on.vol);
652 break;
654 case SONG_EV_NOTE_OFF:
656 printf("SONG_EV_NOTE_OFF ");
657 printf("ID:%d", e->note_off.note_id);
658 break;
660 case SONG_EV_END:
662 printf("SONG_EV_END ");
663 break;
665 default:
666 printf("** Unexpected type: %d",
667 e->generic.type);
670 printf("\n");
673 printf("\n");
677 int ss_song_render(int skip_secs)
679 union ss_ev * e;
680 int frame;
681 int go;
682 int n;
683 sample_t output[SS_MAX_CHANNELS];
684 int n_tracks;
685 struct ss_ins * i;
686 double tempo = 120.0;
687 int skip_frames;
688 struct ss_wave * w;
689 double freq;
691 /* convert the song to ss events */
692 n_tracks = ss_song_convert_events();
694 if(trace)
696 ss_song_trace_events();
697 return(0);
700 frame = 0;
701 go = 1;
702 e = ss_song;
704 /* init the generators */
705 ss_gen_init();
707 /* init the instruments */
708 for(n = 0;n < n_tracks;n++)
709 ss_ins_init(&ss_song_ins[n]);
711 /* calculate the frame to start playing */
712 skip_frames = skip_secs * ss_frequency;
714 /* loop the events */
715 while(go)
717 if(verbose >= 1)
719 if(frame % ss_frequency == 0)
721 int m = frame / ss_frequency;
722 printf("[%02d:%02d]\r", m / 60, m % 60);
723 fflush(stdout);
727 /* process all events for this exact frame */
728 while(go && e->generic.frame == frame)
730 if(e->generic.type == SONG_EV_NOTE_ON ||
731 e->generic.type == SONG_EV_NOTE_OFF ||
732 e->generic.type == SONG_EV_SS_PITCH_STRETCH)
734 if(frame < skip_frames)
736 e++;
737 frame = e->generic.frame;
738 continue;
742 /* take the instrument */
743 if(e->generic.trk_id < 0)
744 i = NULL;
745 else
746 i = &ss_song_ins[e->generic.trk_id];
748 switch(e->generic.type)
750 case SONG_EV_NOTE_ON:
752 ss_ins_note_on(i, e->note_on.note,
753 e->note_on.vol, e->note_on.note_id);
755 break;
757 case SONG_EV_NOTE_OFF:
759 ss_ins_note_off(i, e->note_off.note_id);
761 break;
763 case SONG_EV_SS_SUSTAIN:
765 ss_ins_set_sustain(i, e->ss_sustain.sustain);
767 break;
769 case SONG_EV_SS_VIBRATO:
771 ss_ins_set_vibrato(i, e->ss_vibrato.vib_depth,
772 e->ss_vibrato.vib_freq);
774 break;
776 case SONG_EV_SS_CHANNEL:
778 ss_ins_set_channel(i, e->ss_channel.channel,
779 e->ss_channel.vol);
781 break;
783 case SONG_EV_SS_WAV:
785 w=ss_load_wave_file(e->ss_wav.file,
786 ss_note_frequency(e->ss_wav.base),
787 ss_note_frequency(e->ss_wav.min),
788 ss_note_frequency(e->ss_wav.max),
789 e->ss_wav.loop_start, e->ss_wav.loop_end);
791 /* fail if can't open wav */
792 if(w == NULL)
794 printf("Can't load wav '%s'\n", e->ss_wav.file);
795 go = 0;
797 else
798 ss_ins_add_layer(i, w);
800 break;
802 case SONG_EV_SS_PAT:
804 if(ss_load_pat_file(i, e->ss_pat.file) < 0)
806 printf("Can't load pat '%s'\n", e->ss_pat.file);
807 go = 0;
810 break;
812 case SONG_EV_SS_EFF_DELAY:
814 ss_eff_delay(&i->effs[e->ss_eff.channel],
815 e->ss_eff.size);
816 break;
818 case SONG_EV_SS_EFF_ECHO:
820 ss_eff_echo(&i->effs[e->ss_eff.channel],
821 e->ss_eff.size, e->ss_eff.gain);
822 break;
824 case SONG_EV_SS_EFF_COMB:
826 ss_eff_comb(&i->effs[e->ss_eff.channel],
827 e->ss_eff.size, e->ss_eff.gain);
828 break;
830 case SONG_EV_SS_EFF_ALLPASS:
832 ss_eff_allpass(&i->effs[e->ss_eff.channel],
833 e->ss_eff.size, e->ss_eff.gain);
834 break;
836 case SONG_EV_SS_EFF_FLANGER:
838 ss_eff_flanger(&i->effs[e->ss_eff.channel],
839 e->ss_eff.size, e->ss_eff.gain,
840 e->ss_eff.depth, e->ss_eff.freq,
841 e->ss_eff.phase);
842 break;
844 case SONG_EV_SS_EFF_WOBBLE:
846 ss_eff_wobble(&i->effs[e->ss_eff.channel],
847 e->ss_eff.freq, e->ss_eff.phase);
849 break;
851 case SONG_EV_SS_EFF_SQWOBBLE:
853 ss_eff_square_wobble(&i->effs[e->ss_eff.channel],
854 e->ss_eff.freq, e->ss_eff.phase);
856 break;
858 case SONG_EV_SS_EFF_FADER:
860 ss_eff_fader(&i->effs[e->ss_eff.channel],
861 e->ss_eff.size, e->ss_eff.initial,
862 e->ss_eff.final);
863 break;
865 case SONG_EV_SS_EFF_REVERB:
867 ss_eff_reverb(&i->effs[e->ss_eff.channel]);
868 break;
870 case SONG_EV_SS_EFF_OFF:
872 ss_eff_off(&i->effs[e->ss_eff.channel]);
873 break;
875 case SONG_EV_TEMPO:
877 /* just store the last tempo */
878 tempo = e->tempo.tempo;
879 break;
881 case SONG_EV_SS_PITCH_STRETCH:
883 /* find the wave */
884 freq = ss_note_frequency(e->ss_pitch_stretch.note);
885 w = ss_ins_find_layer(i, freq, NULL);
887 /* calculate optimal frequency */
888 freq = ss_pitch_from_tempo(w, tempo,
889 e->ss_pitch_stretch.len);
891 /* play the note */
892 ss_ins_play(i, freq, e->ss_pitch_stretch.vol,
893 e->ss_pitch_stretch.note_id, w);
895 break;
897 case SONG_EV_SS_PRINT_WAVE_TEMPO:
899 /* find the wave */
900 freq = ss_note_frequency(e->ss_print_wave_tempo.note);
901 w = ss_ins_find_layer(i, freq, NULL);
903 /* print the optimal tempo */
904 printf("Optimal tempo: %lf\n",
905 ss_tempo_from_wave(w,
906 e->ss_print_wave_tempo.note,
907 e->ss_print_wave_tempo.len));
909 break;
911 case SONG_EV_TRACK_INFO:
913 /* FIXME */
915 int h, m, s;
917 s = frame / ss_frequency;
918 h = s / 3600;
919 s %= 3600;
920 m = s / 60;
921 s %= 60;
923 fprintf(stderr, "TRACK NN AUDIO\n");
924 fprintf(stderr, " PERFORMER \"%s\"\n",
925 e->track_info.author);
926 fprintf(stderr, " TITLE \"%s\"\n",
927 e->track_info.name);
928 fprintf(stderr, " INDEX 01 %02d:%02d:%02d\n", h, m, s);
931 break;
933 case SONG_EV_END:
935 go = 0;
936 break;
938 case SONG_EV_BACK:
939 case SONG_EV_MIDI_CHANNEL:
940 case SONG_EV_MIDI_PROGRAM:
941 case SONG_EV_NOTE:
942 case SONG_EV_METER:
943 case SONG_EV_MEASURE:
945 /* never found in ss song streams */
946 break;
949 /* next event */
950 e++;
953 /* reset frame samples */
954 ss_output_init_frame(output);
956 /* generate output from all instruments */
957 for(n = 0;n < n_tracks;n++)
958 ss_ins_frame(&ss_song_ins[n], output);
960 /* dump to sampling driver */
961 ss_output_write(output);
963 /* next frame */
964 frame++;
967 if(verbose >= 1) printf("\n");
969 return(0);