Volumes in instruments are really applied (Closes: #1050).
[ahxm.git] / song.c
blob72dae75264649254011d96ac71395f3ac4775b50
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 "ss_core.h"
34 #include "song.h"
36 /*******************
37 Data
38 ********************/
40 /* the song event stream */
41 union song_ev * _song=NULL;
43 /* number of song events */
44 int _n_song_ev=0;
46 /*******************
47 Code
48 ********************/
50 /**
51 * song_clear - Clears the song stream
53 * Clears the song stream.
55 void song_clear(void)
57 if(_song != NULL)
59 free(_song);
60 _song=NULL;
63 _n_song_ev=0;
67 /**
68 * add_song_ev - Adds a song event to the song stream
69 * @ev: the event
71 * Adds a song event to the song stream.
73 void add_song_ev(union song_ev * ev)
75 _n_song_ev++;
77 /* reallocs */
78 _song=(union song_ev *)realloc(_song,
79 _n_song_ev * sizeof(union song_ev));
81 /* store */
82 memcpy(&_song[_n_song_ev - 1], ev, sizeof(union song_ev));
86 static int song_ev_cmp(const void * v1, const void * v2)
88 struct song_ev_generic * e1;
89 struct song_ev_generic * e2;
91 e1=(struct song_ev_generic *)v1; e2=(struct song_ev_generic *)v2;
93 if(e1->time == e2->time)
94 return(e1->type - e2->type);
96 return(e1->time - e2->time);
101 * song_sort - Sorts the song stream
103 * Sorts the song stream.
105 void song_sort(void)
107 qsort(_song, _n_song_ev, sizeof(union song_ev), song_ev_cmp);