Updated TODO.
[ahxm.git] / song.c
blob5ad4bbcd5ac135c2b12a9f83e5d21b8fbc1243b0
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 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
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 /* the song event stream */
40 union song_ev * song=NULL;
42 /* number of song events */
43 int n_song_ev=0;
45 /*******************
46 Code
47 ********************/
49 /**
50 * song_clear - Clears the song stream
52 * Clears the song stream.
54 void song_clear(void)
56 if(song != NULL)
58 free(song);
59 song=NULL;
62 n_song_ev=0;
66 /**
67 * add_song_ev - Adds a song event to the song stream
68 * @ev: the event
70 * Adds a song event to the song stream.
72 void add_song_ev(union song_ev * ev)
74 /* reallocs */
75 song=(union song_ev *)realloc(song,
76 (n_song_ev + 1) * sizeof(union song_ev));
78 /* store */
79 memcpy(&song[n_song_ev], ev, sizeof(union song_ev));
81 n_song_ev++;
85 static int song_ev_cmp(const void * v1, const void * v2)
87 struct song_ev_generic * e1;
88 struct song_ev_generic * e2;
90 e1=(struct song_ev_generic *)v1; e2=(struct song_ev_generic *)v2;
92 if(e1->time == e2->time)
93 return(e1->type - e2->type);
95 return(e1->time - e2->time);
99 /**
100 * song_sort - Sorts the song stream
102 * Sorts the song stream.
104 void song_sort(void)
106 qsort(song, n_song_ev, sizeof(union song_ev), song_ev_cmp);