summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-08 14:53:21 +0200
committerBad Diode <bd@badd10de.dev>2021-06-08 14:53:21 +0200
commit371b4523a400d0c888dbefb7111a467e1f86c0f7 (patch)
treecff132a41e19fea4deac3432644ada84b4082ad3
parent2faf84d78bf261b6f02648e66f0c84efc1eefd05 (diff)
downloadgba-sequencer-371b4523a400d0c888dbefb7111a467e1f86c0f7.tar.gz
gba-sequencer-371b4523a400d0c888dbefb7111a467e1f86c0f7.zip
Add channel muting
-rw-r--r--src/sequencer.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index dc3249c..526680a 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -4,6 +4,7 @@
4// 4//
5// Color indexes. 5// Color indexes.
6// 6//
7
7#define COL_BG 0 8#define COL_BG 0
8#define COL_FG 1 9#define COL_FG 1
9#define COL_RED 2 10#define COL_RED 2
@@ -105,15 +106,6 @@ static const u32 channel_buttons[] = {
105}; 106};
106 107
107// 108//
108// Globals.
109//
110static int bpm = 115;
111static int step_counter = 0;
112int trig_selection_loc = 0;
113int param_selection_loc = 64;
114int channel_selection_loc = 0;
115
116//
117// Wave data. 109// Wave data.
118// 110//
119 111
@@ -139,6 +131,16 @@ static const u8 square_wave[16] = {
139 0x00, 0x00, 0x00, 0x00, 131 0x00, 0x00, 0x00, 0x00,
140}; 132};
141 133
134//
135// Globals.
136//
137
138static int bpm = 115;
139static int step_counter = 0;
140int trig_selection_loc = 0;
141int param_selection_loc = 64;
142int channel_selection_loc = 0;
143
142// TODO: Split into individual trigger types. 144// TODO: Split into individual trigger types.
143typedef struct SeqTrigger { 145typedef struct SeqTrigger {
144 bool trigger; 146 bool trigger;
@@ -216,6 +218,11 @@ static SeqTrigger sequences[3][16] = {
216 }, 218 },
217}; 219};
218 220
221static bool active_channels[4] = {true, true, true, true};
222
223//
224// Trigger render functions.
225//
219 226
220#define TRIG_W 15 227#define TRIG_W 15
221#define TRIG_H 24 228#define TRIG_H 24
@@ -276,6 +283,10 @@ draw_triggers(void) {
276 } 283 }
277} 284}
278 285
286//
287// Channel render functions.
288//
289
279#define CHAN_W 19 290#define CHAN_W 19
280#define CHAN_H 8 291#define CHAN_H 8
281#define CHAN_START_X 35 292#define CHAN_START_X 35
@@ -290,10 +301,11 @@ draw_channels(void) {
290 unpack_tiles(channel_buttons, channel_tiles, 3 * 4); 301 unpack_tiles(channel_buttons, channel_tiles, 3 * 4);
291 size_t k = 0; 302 size_t k = 0;
292 for (size_t i = 0; i < 4; i++) { 303 for (size_t i = 0; i < 4; i++) {
304 u8 clr = active_channels[i] ? COL_FG : COL_GREY;
293 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; 305 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y;
294 draw_tile(CHAN_START_X, y, channel_tiles + k++, COL_FG, false); 306 draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, false);
295 draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, COL_FG, false); 307 draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, false);
296 draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, COL_FG, false); 308 draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, false);
297 } 309 }
298} 310}
299 311
@@ -308,9 +320,9 @@ draw_channel_cursor(size_t i, u8 clr) {
308} 320}
309 321
310void 322void
311irq_timer_0(void) { 323irq_timer(void) {
312 Note active_note; 324 Note active_note;
313 { 325 if (active_channels[0]) {
314 SeqTrigger *trig = &sequences[0][step_counter]; 326 SeqTrigger *trig = &sequences[0][step_counter];
315 active_note = trig->note; 327 active_note = trig->note;
316 if (trig->trigger) { 328 if (trig->trigger) {
@@ -324,8 +336,11 @@ irq_timer_0(void) {
324 SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET 336 SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET
325 | sound_rates[active_note]; 337 | sound_rates[active_note];
326 } 338 }
339 } else {
340 SOUND_SQUARE1_CTRL = 0;
341 SOUND_SQUARE1_FREQ = 0;
327 } 342 }
328 { 343 if (active_channels[1]) {
329 SeqTrigger *trig = &sequences[1][step_counter]; 344 SeqTrigger *trig = &sequences[1][step_counter];
330 active_note = trig->note; 345 active_note = trig->note;
331 if (trig->trigger) { 346 if (trig->trigger) {
@@ -336,8 +351,11 @@ irq_timer_0(void) {
336 SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET 351 SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET
337 | sound_rates[active_note]; 352 | sound_rates[active_note];
338 } 353 }
354 } else {
355 SOUND_SQUARE2_CTRL = 0;
356 SOUND_SQUARE2_FREQ = 0;
339 } 357 }
340 { 358 if (active_channels[2]) {
341 SeqTrigger *trig = &sequences[2][step_counter]; 359 SeqTrigger *trig = &sequences[2][step_counter];
342 active_note = trig->note; 360 active_note = trig->note;
343 if (trig->trigger) { 361 if (trig->trigger) {
@@ -391,6 +409,9 @@ irq_timer_0(void) {
391 SOUND_WAVE_FREQ = SOUND_FREQ_RESET 409 SOUND_WAVE_FREQ = SOUND_FREQ_RESET
392 | sound_rates[active_note]; 410 | sound_rates[active_note];
393 } 411 }
412 } else {
413 SOUND_WAVE_CTRL = 0;
414 SOUND_WAVE_FREQ = 0;
394 } 415 }
395 step_counter = (step_counter + 1) % 16; 416 step_counter = (step_counter + 1) % 16;
396} 417}
@@ -404,7 +425,7 @@ set_time(int bpm) {
404 // We have to operate on integer values, so the numbers have been 425 // We have to operate on integer values, so the numbers have been
405 // precalculated to `n_ticks = 244181 / bmp` 426 // precalculated to `n_ticks = 244181 / bmp`
406 int n_ticks = -244181 / bpm; 427 int n_ticks = -244181 / bpm;
407 irs_set(IRQ_TIMER_0, irq_timer_0); 428 irs_set(IRQ_TIMER_0, irq_timer);
408 TIMER_DATA_0 = n_ticks; 429 TIMER_DATA_0 = n_ticks;
409 TIMER_CTRL_0 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; 430 TIMER_CTRL_0 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3;
410} 431}
@@ -419,14 +440,17 @@ void handle_channel_cursor(void);
419 440
420void 441void
421handle_channel_cursor(void) { 442handle_channel_cursor(void) {
443 if (key_tap(KEY_B)) {
444 active_channels[channel_selection_loc] ^= 1;
445 draw_channels();
446 }
422 if (key_tap(KEY_RIGHT)) { 447 if (key_tap(KEY_RIGHT)) {
423 trig_selection_loc = 0; 448 trig_selection_loc = 0;
424 param_selection_loc = 0; 449 param_selection_loc = 0;
425 input_handler = handle_trigger_cursor; 450 input_handler = handle_trigger_cursor;
426 draw_channel_cursor(channel_selection_loc, COL_GREY); 451 draw_channel_cursor(channel_selection_loc, COL_GREY);
427 draw_trig_cursor(trig_selection_loc, COL_BLUE); 452 draw_trig_cursor(trig_selection_loc, COL_BLUE);
428 } 453 } else if (key_tap(KEY_UP)) {
429 if (key_tap(KEY_UP)) {
430 draw_channel_cursor(channel_selection_loc, COL_BG); 454 draw_channel_cursor(channel_selection_loc, COL_BG);
431 if (channel_selection_loc == 0) { 455 if (channel_selection_loc == 0) {
432 channel_selection_loc = SEQ_N_CHANNELS - 1; 456 channel_selection_loc = SEQ_N_CHANNELS - 1;
@@ -435,8 +459,7 @@ handle_channel_cursor(void) {
435 } 459 }
436 draw_channel_cursor(channel_selection_loc, COL_BLUE); 460 draw_channel_cursor(channel_selection_loc, COL_BLUE);
437 draw_triggers(); 461 draw_triggers();
438 } 462 } else if (key_tap(KEY_DOWN)) {
439 if (key_tap(KEY_DOWN)) {
440 draw_channel_cursor(channel_selection_loc, COL_BG); 463 draw_channel_cursor(channel_selection_loc, COL_BG);
441 if (channel_selection_loc == SEQ_N_CHANNELS - 1) { 464 if (channel_selection_loc == SEQ_N_CHANNELS - 1) {
442 channel_selection_loc = 0; 465 channel_selection_loc = 0;