From 371b4523a400d0c888dbefb7111a467e1f86c0f7 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 8 Jun 2021 14:53:21 +0200 Subject: Add channel muting --- src/sequencer.c | 65 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'src/sequencer.c') 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 @@ // // Color indexes. // + #define COL_BG 0 #define COL_FG 1 #define COL_RED 2 @@ -104,15 +105,6 @@ static const u32 channel_buttons[] = { 0x0f080808, 0x0808080f, }; -// -// Globals. -// -static int bpm = 115; -static int step_counter = 0; -int trig_selection_loc = 0; -int param_selection_loc = 64; -int channel_selection_loc = 0; - // // Wave data. // @@ -139,6 +131,16 @@ static const u8 square_wave[16] = { 0x00, 0x00, 0x00, 0x00, }; +// +// Globals. +// + +static int bpm = 115; +static int step_counter = 0; +int trig_selection_loc = 0; +int param_selection_loc = 64; +int channel_selection_loc = 0; + // TODO: Split into individual trigger types. typedef struct SeqTrigger { bool trigger; @@ -216,6 +218,11 @@ static SeqTrigger sequences[3][16] = { }, }; +static bool active_channels[4] = {true, true, true, true}; + +// +// Trigger render functions. +// #define TRIG_W 15 #define TRIG_H 24 @@ -276,6 +283,10 @@ draw_triggers(void) { } } +// +// Channel render functions. +// + #define CHAN_W 19 #define CHAN_H 8 #define CHAN_START_X 35 @@ -290,10 +301,11 @@ draw_channels(void) { unpack_tiles(channel_buttons, channel_tiles, 3 * 4); size_t k = 0; for (size_t i = 0; i < 4; i++) { + u8 clr = active_channels[i] ? COL_FG : COL_GREY; size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; - draw_tile(CHAN_START_X, y, channel_tiles + k++, COL_FG, false); - draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, COL_FG, false); - draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, COL_FG, false); + draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, false); + draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, false); + draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, false); } } @@ -308,9 +320,9 @@ draw_channel_cursor(size_t i, u8 clr) { } void -irq_timer_0(void) { +irq_timer(void) { Note active_note; - { + if (active_channels[0]) { SeqTrigger *trig = &sequences[0][step_counter]; active_note = trig->note; if (trig->trigger) { @@ -324,8 +336,11 @@ irq_timer_0(void) { SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET | sound_rates[active_note]; } + } else { + SOUND_SQUARE1_CTRL = 0; + SOUND_SQUARE1_FREQ = 0; } - { + if (active_channels[1]) { SeqTrigger *trig = &sequences[1][step_counter]; active_note = trig->note; if (trig->trigger) { @@ -336,8 +351,11 @@ irq_timer_0(void) { SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET | sound_rates[active_note]; } + } else { + SOUND_SQUARE2_CTRL = 0; + SOUND_SQUARE2_FREQ = 0; } - { + if (active_channels[2]) { SeqTrigger *trig = &sequences[2][step_counter]; active_note = trig->note; if (trig->trigger) { @@ -391,6 +409,9 @@ irq_timer_0(void) { SOUND_WAVE_FREQ = SOUND_FREQ_RESET | sound_rates[active_note]; } + } else { + SOUND_WAVE_CTRL = 0; + SOUND_WAVE_FREQ = 0; } step_counter = (step_counter + 1) % 16; } @@ -404,7 +425,7 @@ set_time(int bpm) { // We have to operate on integer values, so the numbers have been // precalculated to `n_ticks = 244181 / bmp` int n_ticks = -244181 / bpm; - irs_set(IRQ_TIMER_0, irq_timer_0); + irs_set(IRQ_TIMER_0, irq_timer); TIMER_DATA_0 = n_ticks; TIMER_CTRL_0 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; } @@ -419,14 +440,17 @@ void handle_channel_cursor(void); void handle_channel_cursor(void) { + if (key_tap(KEY_B)) { + active_channels[channel_selection_loc] ^= 1; + draw_channels(); + } if (key_tap(KEY_RIGHT)) { trig_selection_loc = 0; param_selection_loc = 0; input_handler = handle_trigger_cursor; draw_channel_cursor(channel_selection_loc, COL_GREY); draw_trig_cursor(trig_selection_loc, COL_BLUE); - } - if (key_tap(KEY_UP)) { + } else if (key_tap(KEY_UP)) { draw_channel_cursor(channel_selection_loc, COL_BG); if (channel_selection_loc == 0) { channel_selection_loc = SEQ_N_CHANNELS - 1; @@ -435,8 +459,7 @@ handle_channel_cursor(void) { } draw_channel_cursor(channel_selection_loc, COL_BLUE); draw_triggers(); - } - if (key_tap(KEY_DOWN)) { + } else if (key_tap(KEY_DOWN)) { draw_channel_cursor(channel_selection_loc, COL_BG); if (channel_selection_loc == SEQ_N_CHANNELS - 1) { channel_selection_loc = 0; -- cgit v1.2.1