Updated TODO.
[ahxm.git] / ss_song.c
blob4181f03e65c38fb71f6b07c98d6fcb95ca9735ea
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_song_info
169 song_ev_type type; /* SONG_EV_SONG_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_song_info song_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];
204 /*******************
205 Code
206 ********************/
208 static void add_ss_ev(union ss_ev * e)
209 /* adds a softsynth song event */
211 /* reallocs */
212 ss_song = (union ss_ev *)realloc(ss_song,
213 (n_ss_ev + 1) * sizeof(union ss_ev));
215 /* store */
216 memcpy(&ss_song[n_ss_ev], e, sizeof(union ss_ev));
218 n_ss_ev++;
222 static int ss_ev_cmp(const void * v1, const void * v2)
223 /* softsynth song event compare function for qsort() */
225 struct ss_ev_generic * e1;
226 struct ss_ev_generic * e2;
227 int ret;
229 e1 = (struct ss_ev_generic *)v1; e2 = (struct ss_ev_generic *)v2;
231 ret = e1->frame - e2->frame;
233 if(ret == 0)
234 ret = e1->type - e2->type;
236 if(ret == 0)
237 ret = e1->event_id - e2->event_id;
239 return(ret);
243 static int ss_song_convert_events(void)
244 /* converts generic song_ev events to softsynth events */
246 int note_id = 1;
247 union song_ev * e;
248 union ss_ev sse;
249 int frame, frame_ac, f_frame;
250 double fpw, time_ac, time_ac_m;
251 int num, den;
252 int n;
253 int b_track = -1;
255 /* resets the ss stream */
256 if(ss_song != NULL)
258 free(ss_song);
259 ss_song = NULL;
262 n_ss_ev = 0;
264 /* sorts the song */
265 song_sort();
267 fpw = 0;
268 frame = frame_ac = f_frame = 0;
269 time_ac = time_ac_m = 0;
270 num = den = 4;
272 /* travels the song events generating softsynth song events */
273 for(n = 0;n < n_song_ev;n++)
275 /* gets the song event */
276 e = &song[n];
278 /* calculates the frame */
279 frame = ((e->generic.time - time_ac) * fpw) + frame_ac;
281 /* generic event data */
282 sse.generic.type = e->generic.type;
283 sse.generic.frame = frame;
284 sse.generic.trk_id = e->generic.trk_id;
285 sse.generic.event_id = e->generic.event_id;
287 /* account the biggest track seen */
288 if(b_track < e->generic.trk_id) b_track = e->generic.trk_id;
290 switch(e->generic.type)
292 case SONG_EV_TEMPO:
294 /* updates accumulations */
295 frame_ac = frame;
296 time_ac = e->generic.time;
298 /* calculates frames-per-whole based on new tempo */
299 fpw = (double) ss_frequency * 60.0;
300 fpw /= e->tempo.tempo / 4.0;
302 /* adds an event */
303 sse.tempo.tempo = e->tempo.tempo;
304 add_ss_ev(&sse);
306 break;
308 case SONG_EV_METER:
310 /* just store the values */
311 num = e->meter.num;
312 den = e->meter.den;
313 time_ac_m = e->meter.time;
315 break;
317 case SONG_EV_MEASURE:
319 song_test_measure_boundary(e->measure.time - time_ac_m,
320 num, den, e->measure.line);
321 break;
323 case SONG_EV_NOTE:
325 /* convert to note on / off pairs */
327 sse.note_on.type = SONG_EV_NOTE_ON;
328 sse.note_on.note_id = note_id++;
329 sse.note_on.note = e->note.note;
330 sse.note_on.vol = e->note.vol;
332 add_ss_ev(&sse);
334 frame += (int)(e->note.len * fpw);
336 sse.note_off.type = SONG_EV_NOTE_OFF;
337 sse.note_off.frame = frame;
339 add_ss_ev(&sse);
340 break;
342 case SONG_EV_BACK:
344 /* move the cursor back */
346 frame_ac -= (int)(e->back.len * fpw);
348 break;
350 case SONG_EV_SS_PITCH_STRETCH:
352 sse.ss_pitch_stretch.note_id = note_id++;
353 sse.ss_pitch_stretch.note = e->ss_pitch_stretch.note;
354 sse.ss_pitch_stretch.len = e->ss_pitch_stretch.len;
355 sse.ss_pitch_stretch.vol = e->ss_pitch_stretch.vol;
357 add_ss_ev(&sse);
359 frame += (int)(e->ss_pitch_stretch.len * fpw);
361 sse.note_off.type = SONG_EV_NOTE_OFF;
362 sse.note_off.frame = frame;
364 add_ss_ev(&sse);
365 break;
367 case SONG_EV_SS_PRINT_WAVE_TEMPO:
369 sse.ss_print_wave_tempo.note = e->ss_print_wave_tempo.note;
370 sse.ss_print_wave_tempo.len = e->ss_print_wave_tempo.len;
372 add_ss_ev(&sse);
373 break;
375 case SONG_EV_SS_WAV:
377 sse.ss_wav.file = e->ss_wav.file;
378 sse.ss_wav.base = e->ss_wav.base;
379 sse.ss_wav.min = e->ss_wav.min;
380 sse.ss_wav.max = e->ss_wav.max;
381 sse.ss_wav.loop_start = e->ss_wav.loop_start;
382 sse.ss_wav.loop_end = e->ss_wav.loop_end;
384 add_ss_ev(&sse);
385 break;
387 case SONG_EV_SS_PAT:
389 sse.ss_pat.file = e->ss_pat.file;
391 add_ss_ev(&sse);
392 break;
394 case SONG_EV_SS_SUSTAIN:
396 sse.ss_sustain.sustain = e->ss_sustain.sustain;
398 add_ss_ev(&sse);
399 break;
401 case SONG_EV_SS_VIBRATO:
403 sse.ss_vibrato.vib_depth = e->ss_vibrato.vib_depth;
404 sse.ss_vibrato.vib_freq = e->ss_vibrato.vib_freq;
406 add_ss_ev(&sse);
407 break;
409 case SONG_EV_SS_CHANNEL:
411 sse.ss_channel.channel = e->ss_channel.channel;
412 sse.ss_channel.vol = e->ss_channel.vol;
414 add_ss_ev(&sse);
415 break;
417 case SONG_EV_SS_EFF_DELAY:
418 case SONG_EV_SS_EFF_ECHO:
419 case SONG_EV_SS_EFF_COMB:
420 case SONG_EV_SS_EFF_ALLPASS:
421 case SONG_EV_SS_EFF_FLANGER:
422 case SONG_EV_SS_EFF_WOBBLE:
423 case SONG_EV_SS_EFF_SQWOBBLE:
424 case SONG_EV_SS_EFF_FADER:
425 case SONG_EV_SS_EFF_REVERB:
426 case SONG_EV_SS_EFF_OFF:
428 sse.ss_eff.channel = e->ss_eff.channel;
429 sse.ss_eff.size = e->ss_eff.size;
430 sse.ss_eff.gain = e->ss_eff.gain;
431 sse.ss_eff.depth = e->ss_eff.depth;
432 sse.ss_eff.freq = e->ss_eff.freq;
433 sse.ss_eff.phase = e->ss_eff.phase;
434 sse.ss_eff.initial = e->ss_eff.initial;
435 sse.ss_eff.final = e->ss_eff.final;
437 add_ss_ev(&sse);
438 break;
440 case SONG_EV_SONG_INFO:
442 sse.song_info.author = e->song_info.author;
443 sse.song_info.name = e->song_info.name;
445 add_ss_ev(&sse);
446 break;
448 case SONG_EV_MIDI_CHANNEL:
449 case SONG_EV_MIDI_PROGRAM:
451 /* ignored */
452 break;
454 case SONG_EV_NOTE_ON:
455 case SONG_EV_NOTE_OFF:
456 case SONG_EV_END:
458 /* never found in generic song streams */
459 break;
462 /* store the further frame seen */
463 if(f_frame < frame) f_frame = frame;
466 /* generates an end of event mark, a time after the last one */
467 sse.generic.type = SONG_EV_END;
468 sse.generic.frame = f_frame + ss_frequency;
469 sse.generic.event_id = -1;
470 add_ss_ev(&sse);
472 /* finally sort */
473 qsort(ss_song, n_ss_ev, sizeof(union ss_ev), ss_ev_cmp);
475 /* return the number of tracks */
476 return(b_track + 1);
480 static void ss_song_trace_events(void)
482 union ss_ev * e;
483 int n;
485 printf("** SOFTWARE SYNTHESIZER EVENT DUMP **\n\n");
486 printf("%10s %5s %5s Event and information\n",
487 "Frame", "Track", "Ev.ID");
488 printf("------------------------------------------------------------\n");
490 for(n = 0, e = ss_song;n < n_ss_ev;n++, e++)
492 printf("%10d %5d %5d ",
493 e->generic.frame, e->generic.trk_id, e->generic.event_id);
495 switch(e->generic.type)
497 case SONG_EV_TEMPO:
499 printf("SONG_EV_TEMPO ");
500 printf("%lf", e->tempo.tempo);
501 break;
503 case SONG_EV_SS_SUSTAIN:
505 printf("SONG_EV_SS_SUSTAIN ");
506 printf("SUSTAIN:%lf", e->ss_sustain.sustain);
507 break;
509 case SONG_EV_SS_VIBRATO:
511 printf("SONG_EV_SS_VIBRATO ");
512 printf("DEPTH:%lf FREQ:%lf",
513 e->ss_vibrato.vib_depth,
514 e->ss_vibrato.vib_freq);
515 break;
517 case SONG_EV_SS_CHANNEL:
519 printf("SONG_EV_SS_CHANNEL ");
520 printf("CHANNEL:%d VOL:%lf",
521 e->ss_channel.channel,
522 e->ss_channel.vol);
523 break;
525 case SONG_EV_SS_WAV:
527 printf("SONG_EV_SS_WAV ");
528 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
529 e->ss_wav.file, e->ss_wav.base,
530 e->ss_wav.min, e->ss_wav.max,
531 e->ss_wav.loop_start, e->ss_wav.loop_end);
532 break;
534 case SONG_EV_SS_PAT:
536 printf("SONG_EV_SS_PAT ");
537 printf("FILE:'%s'", e->ss_pat.file);
538 break;
540 case SONG_EV_SS_EFF_DELAY:
542 printf("SONG_EV_SS_EFF_DELAY ");
543 printf("CHANNEL:%d ", e->ss_eff.channel);
544 printf("SIZE:%lf ", e->ss_eff.size);
545 break;
547 case SONG_EV_SS_EFF_ECHO:
549 printf("SONG_EV_SS_EFF_ECHO ");
550 printf("CHANNEL:%d ", e->ss_eff.channel);
551 printf("SIZE:%lf ", e->ss_eff.size);
552 printf("GAIN:%f ", e->ss_eff.gain);
553 break;
555 case SONG_EV_SS_EFF_COMB:
557 printf("SONG_EV_SS_EFF_COMB ");
558 printf("CHANNEL:%d ", e->ss_eff.channel);
559 printf("SIZE:%lf ", e->ss_eff.size);
560 printf("GAIN:%f ", e->ss_eff.gain);
561 break;
563 case SONG_EV_SS_EFF_ALLPASS:
565 printf("SONG_EV_SS_EFF_ALLPASS ");
566 printf("CHANNEL:%d ", e->ss_eff.channel);
567 printf("SIZE:%lf ", e->ss_eff.size);
568 printf("GAIN:%f ", e->ss_eff.gain);
569 break;
571 case SONG_EV_SS_EFF_FLANGER:
573 printf("SONG_EV_SS_EFF_FLANGER ");
574 printf("CHANNEL:%d ", e->ss_eff.channel);
575 printf("SIZE:%lf ", e->ss_eff.size);
576 printf("GAIN:%f ", e->ss_eff.gain);
577 printf("DEPTH:%lf ", e->ss_eff.depth);
578 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
579 e->ss_eff.phase);
580 break;
582 case SONG_EV_SS_EFF_WOBBLE:
584 printf("SONG_EV_SS_EFF_WOBBLE ");
585 printf("CHANNEL:%d ", e->ss_eff.channel);
586 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
587 e->ss_eff.phase);
588 break;
590 case SONG_EV_SS_EFF_SQWOBBLE:
592 printf("SONG_EV_SS_EFF_SQWOBBLE ");
593 printf("CHANNEL:%d ", e->ss_eff.channel);
594 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
595 e->ss_eff.phase);
596 break;
598 case SONG_EV_SS_EFF_FADER:
600 printf("SONG_EV_SS_EFF_FADER ");
601 printf("CHANNEL:%d ", e->ss_eff.channel);
602 printf("SIZE:%lf ", e->ss_eff.size);
603 printf("INITIAL:%f FINAL:%f", e->ss_eff.initial,
604 e->ss_eff.final);
605 break;
607 case SONG_EV_SS_EFF_REVERB:
609 printf("SONG_EV_SS_EFF_REVERB ");
610 printf("CHANNEL:%d ", e->ss_eff.channel);
611 break;
613 case SONG_EV_SS_EFF_OFF:
615 printf("SONG_EV_SS_EFF_OFF ");
616 printf("CHANNEL:%d ", e->ss_eff.channel);
617 break;
619 case SONG_EV_SS_PITCH_STRETCH:
621 printf("SONG_EV_SS_PITCH_STRETCH ");
622 printf("MIDI:%d LEN:%lf VOL:%f",
623 e->ss_pitch_stretch.note,
624 e->ss_pitch_stretch.len,
625 e->ss_pitch_stretch.vol);
627 break;
629 case SONG_EV_SS_PRINT_WAVE_TEMPO:
631 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
632 printf("MIDI:%d LEN:%lf",
633 e->ss_print_wave_tempo.note,
634 e->ss_print_wave_tempo.len);
635 break;
637 case SONG_EV_SONG_INFO:
639 printf("SONG_EV_SONG_INFO ");
640 printf("AUTHOR:'%s' NAME:'%s'",
641 e->song_info.author,
642 e->song_info.name);
643 break;
645 case SONG_EV_NOTE_ON:
647 printf("SONG_EV_NOTE_ON ");
648 printf("ID:%d MIDI:%d VOL:%f",
649 e->note_on.note_id, e->note_on.note,
650 e->note_on.vol);
651 break;
653 case SONG_EV_NOTE_OFF:
655 printf("SONG_EV_NOTE_OFF ");
656 printf("ID:%d", e->note_off.note_id);
657 break;
659 case SONG_EV_END:
661 printf("SONG_EV_END ");
662 break;
664 default:
665 printf("** Unexpected type: %d",
666 e->generic.type);
669 printf("\n");
672 printf("\n");
676 int ss_song_render(int skip_secs)
678 union ss_ev * e;
679 int frame;
680 int go;
681 int n;
682 sample_t output[SS_MAX_CHANNELS];
683 int n_tracks;
684 struct ss_ins * i;
685 double tempo = 120.0;
686 int skip_frames;
687 struct ss_wave * w;
688 double freq;
690 /* convert the song to ss events */
691 n_tracks = ss_song_convert_events();
693 if(trace)
695 ss_song_trace_events();
696 return(0);
699 frame = 0;
700 go = 1;
701 e = ss_song;
703 /* init the generators */
704 ss_gen_init();
706 /* init the instruments */
707 for(n = 0;n < n_tracks;n++)
708 ss_ins_init(&ss_song_ins[n]);
710 /* calculate the frame to start playing */
711 skip_frames = skip_secs * ss_frequency;
713 /* loop the events */
714 while(go)
716 if(verbose >= 1)
718 if(frame % ss_frequency == 0)
720 int m = frame / ss_frequency;
721 printf("[%02d:%02d]\r", m / 60, m % 60);
722 fflush(stdout);
726 /* process all events for this exact frame */
727 while(go && e->generic.frame == frame)
729 if(e->generic.type == SONG_EV_NOTE_ON ||
730 e->generic.type == SONG_EV_NOTE_OFF ||
731 e->generic.type == SONG_EV_SS_PITCH_STRETCH)
733 if(frame < skip_frames)
735 e++;
736 frame = e->generic.frame;
737 continue;
741 /* take the instrument */
742 if(e->generic.trk_id < 0)
743 i = NULL;
744 else
745 i = &ss_song_ins[e->generic.trk_id];
747 switch(e->generic.type)
749 case SONG_EV_NOTE_ON:
751 ss_ins_note_on(i, e->note_on.note,
752 e->note_on.vol, e->note_on.note_id);
754 break;
756 case SONG_EV_NOTE_OFF:
758 ss_ins_note_off(i, e->note_off.note_id);
760 break;
762 case SONG_EV_SS_SUSTAIN:
764 ss_ins_set_sustain(i, e->ss_sustain.sustain);
766 break;
768 case SONG_EV_SS_VIBRATO:
770 ss_ins_set_vibrato(i, e->ss_vibrato.vib_depth,
771 e->ss_vibrato.vib_freq);
773 break;
775 case SONG_EV_SS_CHANNEL:
777 ss_ins_set_channel(i, e->ss_channel.channel,
778 e->ss_channel.vol);
780 break;
782 case SONG_EV_SS_WAV:
784 w=ss_load_wave_file(e->ss_wav.file,
785 ss_note_frequency(e->ss_wav.base),
786 ss_note_frequency(e->ss_wav.min),
787 ss_note_frequency(e->ss_wav.max),
788 e->ss_wav.loop_start, e->ss_wav.loop_end);
790 /* fail if can't open wav */
791 if(w == NULL)
793 printf("Can't load wav '%s'\n", e->ss_wav.file);
794 go = 0;
796 else
797 ss_ins_add_layer(i, w);
799 break;
801 case SONG_EV_SS_PAT:
803 if(ss_load_pat_file(i, e->ss_pat.file) < 0)
805 printf("Can't load pat '%s'\n", e->ss_pat.file);
806 go = 0;
809 break;
811 case SONG_EV_SS_EFF_DELAY:
813 ss_eff_delay(&i->effs[e->ss_eff.channel],
814 e->ss_eff.size);
815 break;
817 case SONG_EV_SS_EFF_ECHO:
819 ss_eff_echo(&i->effs[e->ss_eff.channel],
820 e->ss_eff.size, e->ss_eff.gain);
821 break;
823 case SONG_EV_SS_EFF_COMB:
825 ss_eff_comb(&i->effs[e->ss_eff.channel],
826 e->ss_eff.size, e->ss_eff.gain);
827 break;
829 case SONG_EV_SS_EFF_ALLPASS:
831 ss_eff_allpass(&i->effs[e->ss_eff.channel],
832 e->ss_eff.size, e->ss_eff.gain);
833 break;
835 case SONG_EV_SS_EFF_FLANGER:
837 ss_eff_flanger(&i->effs[e->ss_eff.channel],
838 e->ss_eff.size, e->ss_eff.gain,
839 e->ss_eff.depth, e->ss_eff.freq,
840 e->ss_eff.phase);
841 break;
843 case SONG_EV_SS_EFF_WOBBLE:
845 ss_eff_wobble(&i->effs[e->ss_eff.channel],
846 e->ss_eff.freq, e->ss_eff.phase);
848 break;
850 case SONG_EV_SS_EFF_SQWOBBLE:
852 ss_eff_square_wobble(&i->effs[e->ss_eff.channel],
853 e->ss_eff.freq, e->ss_eff.phase);
855 break;
857 case SONG_EV_SS_EFF_FADER:
859 ss_eff_fader(&i->effs[e->ss_eff.channel],
860 e->ss_eff.size, e->ss_eff.initial,
861 e->ss_eff.final);
862 break;
864 case SONG_EV_SS_EFF_REVERB:
866 ss_eff_reverb(&i->effs[e->ss_eff.channel]);
867 break;
869 case SONG_EV_SS_EFF_OFF:
871 ss_eff_off(&i->effs[e->ss_eff.channel]);
872 break;
874 case SONG_EV_TEMPO:
876 /* just store the last tempo */
877 tempo = e->tempo.tempo;
878 break;
880 case SONG_EV_SS_PITCH_STRETCH:
882 /* find the wave */
883 freq = ss_note_frequency(e->ss_pitch_stretch.note);
884 w = ss_ins_find_layer(i, freq, NULL);
886 /* calculate optimal frequency */
887 freq = ss_pitch_from_tempo(w, tempo,
888 e->ss_pitch_stretch.len);
890 /* play the note */
891 ss_ins_play(i, freq, e->ss_pitch_stretch.vol,
892 e->ss_pitch_stretch.note_id, w);
894 break;
896 case SONG_EV_SS_PRINT_WAVE_TEMPO:
898 /* find the wave */
899 freq = ss_note_frequency(e->ss_print_wave_tempo.note);
900 w = ss_ins_find_layer(i, freq, NULL);
902 /* print the optimal tempo */
903 printf("Optimal tempo: %lf\n",
904 ss_tempo_from_wave(w,
905 e->ss_print_wave_tempo.note,
906 e->ss_print_wave_tempo.len));
908 break;
910 case SONG_EV_SONG_INFO:
912 /* add a new song (track) */
913 cue_file_song_info(frame, e->song_info.author,
914 e->song_info.name);
915 break;
917 case SONG_EV_END:
919 go = 0;
920 break;
922 case SONG_EV_BACK:
923 case SONG_EV_MIDI_CHANNEL:
924 case SONG_EV_MIDI_PROGRAM:
925 case SONG_EV_NOTE:
926 case SONG_EV_METER:
927 case SONG_EV_MEASURE:
929 /* never found in ss song streams */
930 break;
933 /* next event */
934 e++;
937 /* reset frame samples */
938 ss_output_init_frame(output);
940 /* generate output from all instruments */
941 for(n = 0;n < n_tracks;n++)
942 ss_ins_frame(&ss_song_ins[n], output);
944 /* dump to sampling driver */
945 ss_output_write(output);
947 /* next frame */
948 frame++;
951 if(verbose >= 1) printf("\n");
953 return(0);