2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 2010 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
22 evanrinehart@gmail.com
44 list
* immediate_events
;
47 list
* event_after_loop
;
51 void advance_event(event
* now
){
52 if(now
->type
== EVX_LOOPEND
){
53 next_event
= event_after_loop
;
57 next_event
= next_event
->next
;
61 event
* dequeue_event(){
62 if(next_event
== NULL
) return NULL
;
64 event
* e
= next_event
->item
;
68 if(e
->type
== EVX_TEMPOCHANGE
){
72 if(e
->type
== EVX_TICKSPERBEAT
){
76 if(e
->type
== EVX_LOOPSTART
){
78 event_after_loop
= next_event
;
88 int samples_until_next(int max
){
92 if(next_event
== NULL
) return max
;
94 event
* e
= next_event
->item
;
95 if(e
->tick
- tick
> max
* D
/ N
) return max
;
97 int d
= (e
->tick
-tick
)*N
/D
;
98 return d
< max
? d
: max
;
101 event
* seq_advance(int max
, int* used
){
102 int N
= bpm
*tpb
; // bpm * tpb
103 int D
= 2646000; // srate * 60
106 int u
= samples_until_next(max
);
127 static event
* make_event(int type
, int chan
, int val1
, int val2
){
129 if(blank_events
->next
){
130 e
= pop(blank_events
);
133 e
= xmalloc(sizeof(event
));
144 void recycle_event(event
* e
){
145 push(blank_events
, e
);
149 void seq_instant(int type
, int chan
, int val1
, int val2
){
150 event
* e
= make_event(type
, chan
, val1
, val2
);
152 append(immediate_events
, e
);
157 void seq_play_sound(int id
){
158 seq_instant(0x90, 15, id
, 0);
163 event
* seq_get_immediate(){
164 event
* e
= pop(immediate_events
);
176 void seq_enqueue(int when
, int type
, int chan
, int val1
, int val2
){
177 event
* e
= make_event(type
, chan
, val1
, val2
);
183 list
* ptr
= sequence
->next
;
193 void seq_append(event
* e
){
198 blank_events
= empty();
199 immediate_events
= empty();
204 next_event
= sequence
->next
;
207 void seq_load(list
* events
){
212 next_event
= sequence
->next
;
213 event_after_loop
= next_event
;
218 void seq_seek(list
* target
){
219 event
* e
= target
->item
;
235 seq_instant(EVX_MUSICCUT
, 0, 0, 0);