func_fader() no longer changes the size (Closes: #1107).
[ahxm.git] / ss_song.c
blobb4e5788b3edc5ccdb0e318c4e46e3cdacfc3a3ca
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 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 union ss_ev
169 struct ss_ev_generic generic;
170 struct ss_ev_note_on note_on;
171 struct ss_ev_note_off note_off;
172 struct ss_ev_ss_sustain ss_sustain;
173 struct ss_ev_ss_vibrato ss_vibrato;
174 struct ss_ev_ss_channel ss_channel;
175 struct ss_ev_ss_wav ss_wav;
176 struct ss_ev_ss_pat ss_pat;
177 struct ss_ev_ss_eff ss_eff;
178 struct ss_ev_tempo tempo;
179 struct ss_ev_pitch_stretch ss_pitch_stretch;
180 struct ss_ev_print_wave_tempo ss_print_wave_tempo;
183 /* the softsynth song stream */
185 static union ss_ev * ss_song = NULL;
186 static int n_ss_ev = 0;
189 /* the instruments */
191 struct ss_ins ss_song_ins[SS_MAX_INSTRUMENTS];
194 /*******************
195 Code
196 ********************/
198 static void add_ss_ev(union ss_ev * e)
199 /* adds a softsynth song event */
201 /* reallocs */
202 ss_song = (union ss_ev *)realloc(ss_song,
203 (n_ss_ev + 1) * sizeof(union ss_ev));
205 /* store */
206 memcpy(&ss_song[n_ss_ev], e, sizeof(union ss_ev));
208 n_ss_ev++;
212 static int ss_ev_cmp(const void * v1, const void * v2)
213 /* softsynth song event compare function for qsort() */
215 struct ss_ev_generic * e1;
216 struct ss_ev_generic * e2;
217 int ret;
219 e1 = (struct ss_ev_generic *)v1; e2 = (struct ss_ev_generic *)v2;
221 ret = e1->frame - e2->frame;
223 if(ret == 0)
224 ret = e1->type - e2->type;
226 if(ret == 0)
227 ret = e1->event_id - e2->event_id;
229 return(ret);
233 static int ss_song_convert_events(void)
234 /* converts generic song_ev events to softsynth events */
236 int note_id = 1;
237 union song_ev * e;
238 union ss_ev sse;
239 int frame, frame_ac, f_frame;
240 double fpw, time_ac, time_ac_m;
241 int num, den;
242 int n;
243 int b_track = -1;
245 /* resets the ss stream */
246 if(ss_song != NULL)
248 free(ss_song);
249 ss_song = NULL;
252 n_ss_ev = 0;
254 /* sorts the song */
255 song_sort();
257 fpw = 0;
258 frame = frame_ac = f_frame = 0;
259 time_ac = time_ac_m = 0;
260 num = den = 4;
262 /* travels the song events generating softsynth song events */
263 for(n = 0;n < n_song_ev;n++)
265 /* gets the song event */
266 e = &song[n];
268 /* calculates the frame */
269 frame = ((e->generic.time - time_ac) * fpw) + frame_ac;
271 /* generic event data */
272 sse.generic.type = e->generic.type;
273 sse.generic.frame = frame;
274 sse.generic.trk_id = e->generic.trk_id;
275 sse.generic.event_id = e->generic.event_id;
277 /* account the biggest track seen */
278 if(b_track < e->generic.trk_id) b_track = e->generic.trk_id;
280 switch(e->generic.type)
282 case SONG_EV_TEMPO:
284 /* updates accumulations */
285 frame_ac = frame;
286 time_ac = e->generic.time;
288 /* calculates frames-per-whole based on new tempo */
289 fpw = (double) ss_frequency * 60.0;
290 fpw /= e->tempo.tempo / 4.0;
292 /* adds an event */
293 sse.tempo.tempo = e->tempo.tempo;
294 add_ss_ev(&sse);
296 break;
298 case SONG_EV_METER:
300 /* just store the values */
301 num = e->meter.num;
302 den = e->meter.den;
303 time_ac_m = e->meter.time;
305 break;
307 case SONG_EV_MEASURE:
309 song_test_measure_boundary(e->measure.time - time_ac_m,
310 num, den, e->measure.line);
311 break;
313 case SONG_EV_NOTE:
315 /* convert to note on / off pairs */
317 sse.note_on.type = SONG_EV_NOTE_ON;
318 sse.note_on.note_id = note_id++;
319 sse.note_on.note = e->note.note;
320 sse.note_on.vol = e->note.vol;
322 add_ss_ev(&sse);
324 frame += (int)(e->note.len * fpw);
326 sse.note_off.type = SONG_EV_NOTE_OFF;
327 sse.note_off.frame = frame;
329 add_ss_ev(&sse);
330 break;
332 case SONG_EV_BACK:
334 /* move the cursor back */
336 frame_ac -= (int)(e->back.len * fpw);
338 break;
340 case SONG_EV_SS_PITCH_STRETCH:
342 sse.ss_pitch_stretch.note_id = note_id++;
343 sse.ss_pitch_stretch.note = e->ss_pitch_stretch.note;
344 sse.ss_pitch_stretch.len = e->ss_pitch_stretch.len;
345 sse.ss_pitch_stretch.vol = e->ss_pitch_stretch.vol;
347 add_ss_ev(&sse);
349 frame += (int)(e->ss_pitch_stretch.len * fpw);
351 sse.note_off.type = SONG_EV_NOTE_OFF;
352 sse.note_off.frame = frame;
354 add_ss_ev(&sse);
355 break;
357 case SONG_EV_SS_PRINT_WAVE_TEMPO:
359 sse.ss_print_wave_tempo.note = e->ss_print_wave_tempo.note;
360 sse.ss_print_wave_tempo.len = e->ss_print_wave_tempo.len;
362 add_ss_ev(&sse);
363 break;
365 case SONG_EV_SS_WAV:
367 sse.ss_wav.file = e->ss_wav.file;
368 sse.ss_wav.base = e->ss_wav.base;
369 sse.ss_wav.min = e->ss_wav.min;
370 sse.ss_wav.max = e->ss_wav.max;
371 sse.ss_wav.loop_start = e->ss_wav.loop_start;
372 sse.ss_wav.loop_end = e->ss_wav.loop_end;
374 add_ss_ev(&sse);
375 break;
377 case SONG_EV_SS_PAT:
379 sse.ss_pat.file = e->ss_pat.file;
381 add_ss_ev(&sse);
382 break;
384 case SONG_EV_SS_SUSTAIN:
386 sse.ss_sustain.sustain = e->ss_sustain.sustain;
388 add_ss_ev(&sse);
389 break;
391 case SONG_EV_SS_VIBRATO:
393 sse.ss_vibrato.vib_depth = e->ss_vibrato.vib_depth;
394 sse.ss_vibrato.vib_freq = e->ss_vibrato.vib_freq;
396 add_ss_ev(&sse);
397 break;
399 case SONG_EV_SS_CHANNEL:
401 sse.ss_channel.channel = e->ss_channel.channel;
402 sse.ss_channel.vol = e->ss_channel.vol;
404 add_ss_ev(&sse);
405 break;
407 case SONG_EV_SS_EFF_DELAY:
408 case SONG_EV_SS_EFF_ECHO:
409 case SONG_EV_SS_EFF_COMB:
410 case SONG_EV_SS_EFF_ALLPASS:
411 case SONG_EV_SS_EFF_FLANGER:
412 case SONG_EV_SS_EFF_WOBBLE:
413 case SONG_EV_SS_EFF_SQWOBBLE:
414 case SONG_EV_SS_EFF_FADER:
415 case SONG_EV_SS_EFF_REVERB:
416 case SONG_EV_SS_EFF_OFF:
418 sse.ss_eff.channel = e->ss_eff.channel;
419 sse.ss_eff.size = e->ss_eff.size;
420 sse.ss_eff.gain = e->ss_eff.gain;
421 sse.ss_eff.depth = e->ss_eff.depth;
422 sse.ss_eff.freq = e->ss_eff.freq;
423 sse.ss_eff.phase = e->ss_eff.phase;
424 sse.ss_eff.initial = e->ss_eff.initial;
425 sse.ss_eff.final = e->ss_eff.final;
427 add_ss_ev(&sse);
428 break;
430 case SONG_EV_MIDI_CHANNEL:
431 case SONG_EV_MIDI_PROGRAM:
433 /* ignored */
434 break;
436 case SONG_EV_NOTE_ON:
437 case SONG_EV_NOTE_OFF:
438 case SONG_EV_END:
440 /* never found in generic song streams */
441 break;
444 /* store the further frame seen */
445 if(f_frame < frame) f_frame = frame;
448 /* generates an end of event mark, a time after the last one */
449 sse.generic.type = SONG_EV_END;
450 sse.generic.frame = f_frame + ss_frequency;
451 sse.generic.event_id = -1;
452 add_ss_ev(&sse);
454 /* finally sort */
455 qsort(ss_song, n_ss_ev, sizeof(union ss_ev), ss_ev_cmp);
457 /* return the number of tracks */
458 return(b_track + 1);
462 static void ss_song_trace_events(void)
464 union ss_ev * e;
465 int n;
467 printf("** SOFTWARE SYNTHESIZER EVENT DUMP **\n\n");
468 printf("%10s %5s %5s Event and information\n",
469 "Frame", "Track", "Ev.ID");
470 printf("------------------------------------------------------------\n");
472 for(n = 0, e = ss_song;n < n_ss_ev;n++, e++)
474 printf("%10d %5d %5d ",
475 e->generic.frame, e->generic.trk_id, e->generic.event_id);
477 switch(e->generic.type)
479 case SONG_EV_TEMPO:
481 printf("SONG_EV_TEMPO ");
482 printf("%lf", e->tempo.tempo);
483 break;
485 case SONG_EV_SS_SUSTAIN:
487 printf("SONG_EV_SS_SUSTAIN ");
488 printf("SUSTAIN:%lf", e->ss_sustain.sustain);
489 break;
491 case SONG_EV_SS_VIBRATO:
493 printf("SONG_EV_SS_VIBRATO ");
494 printf("DEPTH:%lf FREQ:%lf",
495 e->ss_vibrato.vib_depth,
496 e->ss_vibrato.vib_freq);
497 break;
499 case SONG_EV_SS_CHANNEL:
501 printf("SONG_EV_SS_CHANNEL ");
502 printf("CHANNEL:%d VOL:%lf",
503 e->ss_channel.channel,
504 e->ss_channel.vol);
505 break;
507 case SONG_EV_SS_WAV:
509 printf("SONG_EV_SS_WAV ");
510 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
511 e->ss_wav.file, e->ss_wav.base,
512 e->ss_wav.min, e->ss_wav.max,
513 e->ss_wav.loop_start, e->ss_wav.loop_end);
514 break;
516 case SONG_EV_SS_PAT:
518 printf("SONG_EV_SS_PAT ");
519 printf("FILE:'%s'", e->ss_pat.file);
520 break;
522 case SONG_EV_SS_EFF_DELAY:
524 printf("SONG_EV_SS_EFF_DELAY ");
525 printf("CHANNEL:%d ", e->ss_eff.channel);
526 printf("SIZE:%lf ", e->ss_eff.size);
527 break;
529 case SONG_EV_SS_EFF_ECHO:
531 printf("SONG_EV_SS_EFF_ECHO ");
532 printf("CHANNEL:%d ", e->ss_eff.channel);
533 printf("SIZE:%lf ", e->ss_eff.size);
534 printf("GAIN:%f ", e->ss_eff.gain);
535 break;
537 case SONG_EV_SS_EFF_COMB:
539 printf("SONG_EV_SS_EFF_COMB ");
540 printf("CHANNEL:%d ", e->ss_eff.channel);
541 printf("SIZE:%lf ", e->ss_eff.size);
542 printf("GAIN:%f ", e->ss_eff.gain);
543 break;
545 case SONG_EV_SS_EFF_ALLPASS:
547 printf("SONG_EV_SS_EFF_ALLPASS ");
548 printf("CHANNEL:%d ", e->ss_eff.channel);
549 printf("SIZE:%lf ", e->ss_eff.size);
550 printf("GAIN:%f ", e->ss_eff.gain);
551 break;
553 case SONG_EV_SS_EFF_FLANGER:
555 printf("SONG_EV_SS_EFF_FLANGER ");
556 printf("CHANNEL:%d ", e->ss_eff.channel);
557 printf("SIZE:%lf ", e->ss_eff.size);
558 printf("GAIN:%f ", e->ss_eff.gain);
559 printf("DEPTH:%lf ", e->ss_eff.depth);
560 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
561 e->ss_eff.phase);
562 break;
564 case SONG_EV_SS_EFF_WOBBLE:
566 printf("SONG_EV_SS_EFF_WOBBLE ");
567 printf("CHANNEL:%d ", e->ss_eff.channel);
568 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
569 e->ss_eff.phase);
570 break;
572 case SONG_EV_SS_EFF_SQWOBBLE:
574 printf("SONG_EV_SS_EFF_SQWOBBLE ");
575 printf("CHANNEL:%d ", e->ss_eff.channel);
576 printf("FREQ:%lf PHASE:%lf", e->ss_eff.freq,
577 e->ss_eff.phase);
578 break;
580 case SONG_EV_SS_EFF_FADER:
582 printf("SONG_EV_SS_EFF_FADER ");
583 printf("CHANNEL:%d ", e->ss_eff.channel);
584 printf("SIZE:%lf ", e->ss_eff.size);
585 printf("INITIAL:%f FINAL:%f", e->ss_eff.initial,
586 e->ss_eff.final);
587 break;
589 case SONG_EV_SS_EFF_REVERB:
591 printf("SONG_EV_SS_EFF_REVERB ");
592 printf("CHANNEL:%d ", e->ss_eff.channel);
593 break;
595 case SONG_EV_SS_EFF_OFF:
597 printf("SONG_EV_SS_EFF_OFF ");
598 printf("CHANNEL:%d ", e->ss_eff.channel);
599 break;
601 case SONG_EV_SS_PITCH_STRETCH:
603 printf("SONG_EV_SS_PITCH_STRETCH ");
604 printf("MIDI:%d LEN:%lf VOL:%f",
605 e->ss_pitch_stretch.note,
606 e->ss_pitch_stretch.len,
607 e->ss_pitch_stretch.vol);
609 break;
611 case SONG_EV_SS_PRINT_WAVE_TEMPO:
613 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
614 printf("MIDI:%d LEN:%lf",
615 e->ss_print_wave_tempo.note,
616 e->ss_print_wave_tempo.len);
617 break;
619 case SONG_EV_NOTE_ON:
621 printf("SONG_EV_NOTE_ON ");
622 printf("ID:%d MIDI:%d VOL:%f",
623 e->note_on.note_id, e->note_on.note,
624 e->note_on.vol);
625 break;
627 case SONG_EV_NOTE_OFF:
629 printf("SONG_EV_NOTE_OFF ");
630 printf("ID:%d", e->note_off.note_id);
631 break;
633 case SONG_EV_END:
635 printf("SONG_EV_END ");
636 break;
638 default:
639 printf("** Unexpected type: %d",
640 e->generic.type);
643 printf("\n");
646 printf("\n");
650 int ss_song_render(int skip_secs)
652 union ss_ev * e;
653 int frame;
654 int go;
655 int n;
656 sample_t output[SS_MAX_CHANNELS];
657 int n_tracks;
658 struct ss_ins * i;
659 double tempo = 120.0;
660 int skip_frames;
661 struct ss_wave * w;
662 double freq;
664 /* convert the song to ss events */
665 n_tracks = ss_song_convert_events();
667 if(trace)
669 ss_song_trace_events();
670 return(0);
673 frame = 0;
674 go = 1;
675 e = ss_song;
677 /* init the generators */
678 ss_gen_init();
680 /* init the instruments */
681 for(n = 0;n < n_tracks;n++)
682 ss_ins_init(&ss_song_ins[n]);
684 /* calculate the frame to start playing */
685 skip_frames = skip_secs * ss_frequency;
687 /* loop the events */
688 while(go)
690 if(show_progress)
692 if(frame % ss_frequency == 0)
694 int m = frame / ss_frequency;
695 printf("[%02d:%02d]\r", m / 60, m % 60);
696 fflush(stdout);
700 /* process all events for this exact frame */
701 while(go && e->generic.frame == frame)
703 if(e->generic.type == SONG_EV_NOTE_ON ||
704 e->generic.type == SONG_EV_NOTE_OFF ||
705 e->generic.type == SONG_EV_SS_PITCH_STRETCH)
707 if(frame < skip_frames)
709 e++;
710 frame = e->generic.frame;
711 continue;
715 /* take the instrument */
716 if(e->generic.trk_id < 0)
717 i = NULL;
718 else
719 i = &ss_song_ins[e->generic.trk_id];
721 switch(e->generic.type)
723 case SONG_EV_NOTE_ON:
725 ss_ins_note_on(i, e->note_on.note,
726 e->note_on.vol, e->note_on.note_id);
728 break;
730 case SONG_EV_NOTE_OFF:
732 ss_ins_note_off(i, e->note_off.note_id);
734 break;
736 case SONG_EV_SS_SUSTAIN:
738 ss_ins_set_sustain(i, e->ss_sustain.sustain);
740 break;
742 case SONG_EV_SS_VIBRATO:
744 ss_ins_set_vibrato(i, e->ss_vibrato.vib_depth,
745 e->ss_vibrato.vib_freq);
747 break;
749 case SONG_EV_SS_CHANNEL:
751 ss_ins_set_channel(i, e->ss_channel.channel,
752 e->ss_channel.vol);
754 break;
756 case SONG_EV_SS_WAV:
758 w=ss_load_wave_file(e->ss_wav.file,
759 ss_note_frequency(e->ss_wav.base),
760 ss_note_frequency(e->ss_wav.min),
761 ss_note_frequency(e->ss_wav.max),
762 e->ss_wav.loop_start, e->ss_wav.loop_end);
764 /* fail if can't open wav */
765 if(w == NULL)
767 printf("Can't load wav '%s'\n", e->ss_wav.file);
768 go = 0;
770 else
771 ss_ins_add_layer(i, w);
773 break;
775 case SONG_EV_SS_PAT:
777 if(ss_load_pat_file(i, e->ss_pat.file) < 0)
779 printf("Can't load pat '%s'\n", e->ss_pat.file);
780 go = 0;
783 break;
785 case SONG_EV_SS_EFF_DELAY:
787 ss_eff_delay(&i->effs[e->ss_eff.channel],
788 e->ss_eff.size);
789 break;
791 case SONG_EV_SS_EFF_ECHO:
793 ss_eff_echo(&i->effs[e->ss_eff.channel],
794 e->ss_eff.size, e->ss_eff.gain);
795 break;
797 case SONG_EV_SS_EFF_COMB:
799 ss_eff_comb(&i->effs[e->ss_eff.channel],
800 e->ss_eff.size, e->ss_eff.gain);
801 break;
803 case SONG_EV_SS_EFF_ALLPASS:
805 ss_eff_allpass(&i->effs[e->ss_eff.channel],
806 e->ss_eff.size, e->ss_eff.gain);
807 break;
809 case SONG_EV_SS_EFF_FLANGER:
811 ss_eff_flanger(&i->effs[e->ss_eff.channel],
812 e->ss_eff.size, e->ss_eff.gain,
813 e->ss_eff.depth, e->ss_eff.freq,
814 e->ss_eff.phase);
815 break;
817 case SONG_EV_SS_EFF_WOBBLE:
819 ss_eff_wobble(&i->effs[e->ss_eff.channel],
820 e->ss_eff.freq, e->ss_eff.phase);
822 break;
824 case SONG_EV_SS_EFF_SQWOBBLE:
826 ss_eff_square_wobble(&i->effs[e->ss_eff.channel],
827 e->ss_eff.freq, e->ss_eff.phase);
829 break;
831 case SONG_EV_SS_EFF_FADER:
833 ss_eff_fader(&i->effs[e->ss_eff.channel],
834 e->ss_eff.size, e->ss_eff.initial,
835 e->ss_eff.final);
836 break;
838 case SONG_EV_SS_EFF_REVERB:
840 ss_eff_reverb(&i->effs[e->ss_eff.channel]);
841 break;
843 case SONG_EV_SS_EFF_OFF:
845 ss_eff_off(&i->effs[e->ss_eff.channel]);
846 break;
848 case SONG_EV_TEMPO:
850 /* just store the last tempo */
851 tempo = e->tempo.tempo;
852 break;
854 case SONG_EV_SS_PITCH_STRETCH:
856 /* find the wave */
857 freq = ss_note_frequency(e->ss_pitch_stretch.note);
858 w = ss_ins_find_layer(i, freq, NULL);
860 /* calculate optimal frequency */
861 freq = ss_pitch_from_tempo(w, tempo,
862 e->ss_pitch_stretch.len);
864 /* play the note */
865 ss_ins_play(i, freq, e->ss_pitch_stretch.vol,
866 e->ss_pitch_stretch.note_id, w);
868 break;
870 case SONG_EV_SS_PRINT_WAVE_TEMPO:
872 /* find the wave */
873 freq = ss_note_frequency(e->ss_print_wave_tempo.note);
874 w = ss_ins_find_layer(i, freq, NULL);
876 /* print the optimal tempo */
877 printf("Optimal tempo: %lf\n",
878 ss_tempo_from_wave(w,
879 e->ss_print_wave_tempo.note,
880 e->ss_print_wave_tempo.len));
882 break;
884 case SONG_EV_END:
886 go = 0;
887 break;
889 case SONG_EV_BACK:
890 case SONG_EV_MIDI_CHANNEL:
891 case SONG_EV_MIDI_PROGRAM:
892 case SONG_EV_NOTE:
893 case SONG_EV_METER:
894 case SONG_EV_MEASURE:
896 /* never found in ss song streams */
897 break;
900 /* next event */
901 e++;
904 /* reset frame samples */
905 ss_output_init_frame(output);
907 /* generate output from all instruments */
908 for(n = 0;n < n_tracks;n++)
909 ss_ins_frame(&ss_song_ins[n], output);
911 /* dump to sampling driver */
912 ss_output_write(output);
914 /* next frame */
915 frame++;
918 if(show_progress) printf("\n");
920 return(0);