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
){
69 //printf("tempo change to %d bpm\n", e->val1);
73 if(e
->type
== EVX_TICKSPERBEAT
){
74 //printf("setting tpb to %d\n", e->val1);
78 if(e
->type
== EVX_LOOPSTART
){
80 event_after_loop
= next_event
;
84 //printf("event (%d, %03x, %d, %d, %d)\n", e->tick, e->type, e->chan, e->val1, e->val2);
93 int samples_until_next(int max
){
97 if(next_event
== NULL
) return max
;
99 event
* e
= next_event
->item
;
100 if(e
->tick
- tick
> max
* D
/ N
) return max
;
102 int d
= (e
->tick
-tick
)*N
/D
;
103 return d
< max
? d
: max
;
106 event
* seq_advance(int max
, int* used
){
107 int N
= bpm
*tpb
; // bpm * tpb
108 int D
= 2646000; // srate * 60
111 int u
= samples_until_next(max
);
132 static event
* make_event(int type
, int chan
, int val1
, int val2
){
134 if(blank_events
->next
){
135 e
= pop(blank_events
);
138 e
= xmalloc(sizeof(event
));
149 void recycle_event(event
* e
){
150 push(blank_events
, e
);
154 void seq_instant(int type
, int chan
, int val1
, int val2
){
155 event
* e
= make_event(type
, chan
, val1
, val2
);
157 append(immediate_events
, e
);
162 void seq_play_sound(int id
){
163 seq_instant(0x90, 15, id
, 0);
168 event
* seq_get_immediate(){
169 event
* e
= pop(immediate_events
);
181 void seq_enqueue(int when
, int type
, int chan
, int val1
, int val2
){
182 event
* e
= make_event(type
, chan
, val1
, val2
);
188 list
* ptr
= sequence
->next
;
198 void seq_append(event
* e
){
203 blank_events
= empty();
204 immediate_events
= empty();
209 next_event
= sequence
->next
;
212 void seq_load(list
* events
){
217 next_event
= sequence
->next
;
218 event_after_loop
= next_event
;
223 void seq_seek(list
* target
){
224 event
* e
= target
->item
;
240 seq_instant(EVX_MUSICCUT
, 0, 0, 0);