3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2006 Angel Ortega <angel@triptico.com>
6 song.c - Device-independent 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
39 /* the song event stream */
40 union song_ev
* song
= NULL
;
42 /* number of song events */
45 /* solo track (-1, no solo) */
53 * song_clear - Clears the song stream
55 * Clears the song stream.
70 * add_song_ev - Adds a song event to the song stream
73 * Adds a song event to the song stream.
75 void add_song_ev(union song_ev
* ev
)
77 /* skip tracks if a solo is requested */
78 if(solo_track
!= -1 && ev
->generic
.trk_id
>= 0 &&
79 ev
->generic
.trk_id
!= solo_track
)
83 song
= (union song_ev
*)realloc(song
,
84 (n_song_ev
+ 1) * sizeof(union song_ev
));
86 ev
->generic
.event_id
= n_song_ev
;
89 memcpy(&song
[n_song_ev
], ev
, sizeof(union song_ev
));
95 static int song_ev_cmp(const void * v1
, const void * v2
)
97 struct song_ev_generic
* e1
;
98 struct song_ev_generic
* e2
;
101 e1
= (struct song_ev_generic
*)v1
; e2
= (struct song_ev_generic
*)v2
;
103 ret
= (int) ((e1
->time
* 10000.0) - (e2
->time
* 10000.0));
105 /* same time? order by type of event */
107 ret
= e1
->type
- e2
->type
;
109 /* same time and same event? order by event id */
111 ret
= e1
->event_id
- e2
->event_id
;
117 static void song_trace_events(void)
122 printf("** GENERIC SONG EVENT DUMP **\n\n");
123 printf("%9s %5s %5s Event and information\n",
124 "Time", "Track", "Ev.ID");
125 printf("---------------------------------------------------------------\n");
127 for(n
= 0, e
= song
;n
< n_song_ev
;n
++, e
++)
129 printf("%9.4lf %5d %5d ",
130 e
->generic
.time
, e
->generic
.trk_id
,
131 e
->generic
.event_id
);
133 switch(e
->generic
.type
)
137 printf("SONG_EV_TEMPO ");
138 printf("TEMPO:%lf", e
->tempo
.tempo
);
143 printf("SONG_EV_METER ");
144 printf("METER:%d/%d", e
->meter
.num
, e
->meter
.den
);
147 case SONG_EV_MEASURE
:
149 printf("SONG_EV_MEASURE ");
150 printf("LINE:%d", e
->measure
.line
);
153 case SONG_EV_SS_SUSTAIN
:
155 printf("SONG_EV_SS_SUSTAIN ");
156 printf("SUSTAIN:%lf", e
->ss_sustain
.sustain
);
159 case SONG_EV_SS_VIBRATO
:
161 printf("SONG_EV_SS_VIBRATO ");
162 printf("DEPTH:%lf FREQ:%lf",
163 e
->ss_vibrato
.vib_depth
,
164 e
->ss_vibrato
.vib_freq
);
167 case SONG_EV_SS_CHANNEL
:
169 printf("SONG_EV_SS_CHANNEL ");
170 printf("CHANNEL:%d VOL:%lf",
171 e
->ss_channel
.channel
,
177 printf("SONG_EV_SS_WAV ");
178 printf("FILE:'%s' BASE:%d MIN:%d MAX:%d START:%lf END:%lf",
179 e
->ss_wav
.file
, e
->ss_wav
.base
,
180 e
->ss_wav
.min
, e
->ss_wav
.max
,
181 e
->ss_wav
.loop_start
, e
->ss_wav
.loop_end
);
186 printf("SONG_EV_SS_PAT ");
187 printf("FILE:'%s'", e
->ss_pat
.file
);
190 case SONG_EV_SS_EFF_DELAY
:
192 printf("SONG_EV_SS_EFF_DELAY ");
193 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
194 printf("SIZE:%lf ", e
->ss_eff
.size
);
197 case SONG_EV_SS_EFF_ECHO
:
199 printf("SONG_EV_SS_EFF_ECHO ");
200 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
201 printf("SIZE:%lf ", e
->ss_eff
.size
);
202 printf("GAIN:%f ", e
->ss_eff
.gain
);
205 case SONG_EV_SS_EFF_COMB
:
207 printf("SONG_EV_SS_EFF_COMB ");
208 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
209 printf("SIZE:%lf ", e
->ss_eff
.size
);
210 printf("GAIN:%f ", e
->ss_eff
.gain
);
213 case SONG_EV_SS_EFF_ALLPASS
:
215 printf("SONG_EV_SS_EFF_ALLPASS ");
216 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
217 printf("SIZE:%lf ", e
->ss_eff
.size
);
218 printf("GAIN:%f ", e
->ss_eff
.gain
);
221 case SONG_EV_SS_EFF_FLANGER
:
223 printf("SONG_EV_SS_EFF_FLANGER ");
224 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
225 printf("SIZE:%lf ", e
->ss_eff
.size
);
226 printf("GAIN:%f ", e
->ss_eff
.gain
);
227 printf("DEPTH:%lf ", e
->ss_eff
.depth
);
228 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
232 case SONG_EV_SS_EFF_WOBBLE
:
234 printf("SONG_EV_SS_EFF_WOBBLE ");
235 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
236 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
240 case SONG_EV_SS_EFF_SQWOBBLE
:
242 printf("SONG_EV_SS_EFF_SQWOBBLE ");
243 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
244 printf("FREQ:%lf PHASE:%lf", e
->ss_eff
.freq
,
248 case SONG_EV_SS_EFF_FADER
:
250 printf("SONG_EV_SS_EFF_FADER ");
251 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
252 printf("SIZE:%lf ", e
->ss_eff
.size
);
253 printf("INITIAL:%f FINAL:%f", e
->ss_eff
.initial
,
257 case SONG_EV_SS_EFF_REVERB
:
259 printf("SONG_EV_SS_EFF_REVERB ");
260 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
263 case SONG_EV_SS_EFF_OFF
:
265 printf("SONG_EV_SS_EFF_OFF ");
266 printf("CHANNEL:%d ", e
->ss_eff
.channel
);
269 case SONG_EV_MIDI_CHANNEL
:
271 printf("SONG_EV_MIDI_CHANNEL ");
272 printf("CHANNEL:%d ", e
->midi_channel
.channel
);
275 case SONG_EV_MIDI_PROGRAM
:
277 printf("SONG_EV_MIDI_PROGRAM ");
278 printf("PROGRAM:%d ", e
->midi_program
.program
);
283 printf("SONG_EV_BACK ");
284 printf("LEN:%lf", e
->back
.len
);
289 printf("SONG_EV_NOTE ");
290 printf("MIDI:%d LEN:%lf VOL:%f",
291 e
->note
.note
, e
->note
.len
, e
->note
.vol
);
294 case SONG_EV_SS_PITCH_STRETCH
:
296 printf("SONG_EV_SS_PITCH_STRETCH ");
297 printf("MIDI:%d LEN:%lf VOL:%f",
298 e
->ss_pitch_stretch
.note
,
299 e
->ss_pitch_stretch
.len
,
300 e
->ss_pitch_stretch
.vol
);
303 case SONG_EV_SS_PRINT_WAVE_TEMPO
:
305 printf("SONG_EV_SS_PRINT_WAVE_TEMPO ");
306 printf("MIDI:%d LEN:%lf",
307 e
->ss_print_wave_tempo
.note
,
308 e
->ss_print_wave_tempo
.len
);
311 case SONG_EV_TRACK_INFO
:
313 printf("SONG_EV_TRACK_INFO ");
314 printf("AUTHOR:'%s' NAME:'%s'",
315 e
->track_info
.author
,
320 printf("** Unexpected event type: %d",
332 * song_sort - Sorts the song stream
334 * Sorts the song stream.
338 qsort(song
, n_song_ev
, sizeof(union song_ev
), song_ev_cmp
);
340 if(trace
) song_trace_events();
345 * song_test_measure_boundary - Does a measure boundary check
346 * @ev_time: event time
347 * @num: meter numerator
348 * @den: meter denominator
350 * Does a measure boundary check. Returns 0 if the event time falls
351 * exactly between two measures, or nonzero otherwise.
353 int song_test_measure_boundary(double ev_time
, int num
, int den
, int line
)
357 if((ret
= ((int)(ev_time
* (double) den
)) % num
))
358 printf("Measure boundary check failed in line %d\n", line
);