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
41 list
* immediate_events
;
44 list
* event_after_loop
;
48 void advance_event(event
* now
){
49 if(now
->type
== 0x100 && looping
){
50 next_event
= event_after_loop
;
54 next_event
= next_event
->next
;
58 event
* dequeue_event(){
59 if(next_event
== NULL
) return NULL
;
61 event
* e
= next_event
->item
;
71 int samples_until_next(int max
){
75 if(next_event
== NULL
) return max
;
77 event
* e
= next_event
->item
;
78 if(e
->tick
- tick
> max
* D
/ N
) return max
;
80 int d
= (e
->tick
-tick
)*N
/D
;
81 return d
< max
? d
: max
;
84 event
* seq_advance(int max
, int* used
){
85 int N
= 46080; // bpm * tpb
86 int D
= 2646000; // srate * 60
88 int u
= samples_until_next(max
);
95 return dequeue_event();
102 static event
* make_event(int type
, int chan
, int val1
, int val2
){
104 if(blank_events
->next
){
105 e
= pop(blank_events
);
108 e
= xmalloc(sizeof(event
));
119 void recycle_event(event
* e
){
120 push(blank_events
, e
);
124 void seq_instant(int type
, int chan
, int val1
, int val2
){
125 event
* e
= make_event(type
, chan
, val1
, val2
);
127 append(immediate_events
, e
);
132 void seq_play_sound(int id
){
133 seq_instant(0x90, 15, id
, 0);
138 event
* seq_get_immediate(){
139 event
* e
= pop(immediate_events
);
151 void seq_enqueue(int when
, int type
, int chan
, int val1
, int val2
){
152 event
* e
= make_event(type
, chan
, val1
, val2
);
158 list
* ptr
= sequence
->next
;
168 void seq_append(event
* e
){
173 printf(" sequencer: ... ");
175 blank_events
= empty();
176 immediate_events
= empty();
181 seq_enqueue(0, 0x90, 1, 0, 0);
182 seq_enqueue(384, 0x80, 1, 0, 0);
183 seq_enqueue(384, 0x90, 1, 2, 0);
184 seq_enqueue(384*2, 0x80, 1, 2, 0);
185 seq_enqueue(384*2, 0x90, 1, 4, 0);
186 seq_enqueue(384*3, 0x80, 1, 4, 0);
187 seq_enqueue(384*3, 0x90, 1, 0, 0);
188 seq_enqueue(384*4, 0x80, 1, 0, 0);
189 seq_enqueue(384*4, 0x90, 1, 0, 0);
190 seq_enqueue(384*5, 0x80, 1, 0, 0);
191 seq_enqueue(384*5, 0x90, 1, 2, 0);
192 seq_enqueue(384*6, 0x80, 1, 2, 0);
193 seq_enqueue(384*6, 0x90, 1, 4, 0);
194 seq_enqueue(384*7, 0x80, 1, 4, 0);
195 seq_enqueue(384*7, 0x90, 1, 0, 0);
196 seq_enqueue(384*8, 0x80, 1, 0, 0);
197 seq_enqueue(384*8, 0x100, 0, 0, 0);
201 event_after_loop
= sequence
->next
;
203 next_event
= sequence
->next
;