From e5d61a87ec41443a2e32cd8be1ecc62b8c590251 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 22 Aug 2023 12:28:10 +0200 Subject: Add pattern clearing with SEL+L+R on pattern view --- src/sequencer.c | 80 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 16 deletions(-) (limited to 'src/sequencer.c') diff --git a/src/sequencer.c b/src/sequencer.c index 4e3802f..3110c74 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -19,6 +19,22 @@ bool redraw_piano_note = true; bool update_bpm = false; u8 bar_counter = 0; +void +clear_pattern(size_t idx) { + Pattern *pat = &patterns[idx]; + *pat = (Pattern){default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0, false}; + for (size_t i = 0; i < 16; i++) { + pat->ch1.notes[i] = (TriggerNote){false, NOTE_C_4}; + pat->ch2.notes[i] = (TriggerNote){false, NOTE_C_4}; + pat->ch3.notes[i] = (TriggerNote){false, NOTE_C_4}; + pat->ch4.notes[i] = (TriggerNote){false, NOTE_C_4}; + } + redraw_pattern_buttons = true; + redraw_channels = true; + redraw_trigs = true; + redraw_bpm = true; +} + void gate_off(void) { SIO_MODE = SIO_MODE_GP @@ -117,7 +133,7 @@ play_step(void) { } chain.playing = true; } - if (pat->ch1.active) { + if (pat->ch1.active && !pat->empty) { TriggerNote *trig = &pat->ch1.notes[step_counter]; ChannelSquareParams *params = &pat->ch1.params[step_counter]; if (trig->active && should_play(params->prob)) { @@ -162,7 +178,7 @@ play_step(void) { SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET; SOUND_SQUARE1_CTRL = 0; } - if (pat->ch2.active) { + if (pat->ch2.active && !pat->empty) { TriggerNote *trig = &pat->ch2.notes[step_counter]; ChannelSquareParams *params = &pat->ch2.params[step_counter]; if (trig->active && should_play(params->prob)) { @@ -188,7 +204,7 @@ play_step(void) { SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET; SOUND_SQUARE2_CTRL = 0; } - if (pat->ch3.active) { + if (pat->ch3.active && !pat->empty) { TriggerNote *trig = &pat->ch3.notes[step_counter]; ChannelWaveParams *params = &pat->ch3.params[step_counter]; if (trig->active && should_play(params->prob)) { @@ -237,7 +253,7 @@ play_step(void) { SOUND_WAVE_FREQ = SOUND_FREQ_RESET; SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; } - if (pat->ch4.active) { + if (pat->ch4.active && !pat->empty) { TriggerNote *trig = &pat->ch4.notes[step_counter]; ChannelNoiseParams *params = &pat->ch4.params[step_counter]; if (trig->active && should_play(params->prob)) { @@ -347,6 +363,9 @@ handle_channel_selection(void) { if (key_hold(KEY_SELECT)) { clipboard_copy(); } else { + if (patterns[pattern_selection_loc].empty) { + clear_pattern(pattern_selection_loc); + } switch (channel_selection_loc) { case 0: { pat->ch1.active ^= 1; } break; case 1: { pat->ch2.active ^= 1; } break; @@ -358,6 +377,10 @@ handle_channel_selection(void) { } else if (key_tap(KEY_A)) { if (key_hold(KEY_SELECT)) { clipboard_paste(); + redraw_bpm = true; + redraw_trigs = true; + redraw_channels = true; + redraw_pattern_buttons = true; } else { switch (channel_selection_loc) { case 0: { input_handler = handle_param_selection_ch1; } break; @@ -645,6 +668,9 @@ handle_right_col_selection(void) { set_time(patterns[current_pattern].bpm); } redraw_bpm = true; + if (patterns[pattern_selection_loc].empty) { + clear_pattern(pattern_selection_loc); + } } break; // TODO: Scale. } @@ -664,6 +690,9 @@ handle_right_col_selection(void) { set_time(patterns[current_pattern].bpm); } redraw_bpm = true; + if (patterns[pattern_selection_loc].empty) { + clear_pattern(pattern_selection_loc); + } } break; // TODO: Scale. } @@ -748,20 +777,32 @@ handle_pattern_chain(void) { void handle_pattern_selection(void) { - if (key_tap(KEY_B)) { - if (key_hold(KEY_SELECT)) { + if (key_hold(KEY_SELECT)) { + if ((key_pressed(KEY_L) && key_tap(KEY_R)) + || (key_pressed(KEY_R) && key_tap(KEY_L))) { + patterns[pattern_selection_loc].empty ^= 1; + redraw_pattern_buttons = true; + redraw_channels = true; + redraw_trigs = true; + } + if (key_tap(KEY_B)) { clipboard_copy(); - } else { - next_pattern = pattern_selection_loc; + } + if (key_tap(KEY_A)) { + clipboard_paste(); + redraw_bpm = true; + redraw_trigs = true; + redraw_channels = true; redraw_pattern_buttons = true; } + return; + } + if (key_tap(KEY_B)) { + next_pattern = pattern_selection_loc; + redraw_pattern_buttons = true; } if (key_tap(KEY_A)) { - if (key_hold(KEY_SELECT)) { - clipboard_paste(); - } else { - input_handler = handle_pattern_chain; - } + input_handler = handle_pattern_chain; } if (key_tap(KEY_RIGHT)) { input_handler = handle_channel_selection; @@ -1214,11 +1255,14 @@ void handle_trigger_selection(void) { TriggerNote *trig = get_current_trig(); + bool empty = patterns[pattern_selection_loc].empty; if (key_tap(KEY_B)) { if (key_hold(KEY_SELECT)) { clipboard_copy(); } else { - // Toggle trigger. + if (empty) { + clear_pattern(pattern_selection_loc); + } trig->active ^= 1; redraw_trigs = true; } @@ -1228,7 +1272,7 @@ handle_trigger_selection(void) { inc = -12; } // Decrease note. - if (trig->active) { + if (trig->active && !empty) { trig->note = MAX((s32)trig->note + inc, (s32)NOTE_C_2); } redraw_trigs = true; @@ -1239,7 +1283,7 @@ handle_trigger_selection(void) { inc = 12; } // Increase note. - if (trig->active) { + if (trig->active && !empty) { trig->note = MIN((s32)trig->note + inc, (s32)NOTE_C_8 - 1); } redraw_trigs = true; @@ -1275,6 +1319,10 @@ handle_trigger_selection(void) { } else if (key_tap(KEY_A)) { if (key_hold(KEY_SELECT)) { clipboard_paste(); + redraw_bpm = true; + redraw_trigs = true; + redraw_channels = true; + redraw_pattern_buttons = true; } else { // Switch to parameter selection. switch (channel_selection_loc) { -- cgit v1.2.1