From 7399fd06ad3e9682a619550c6de50a565ccc3a25 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 24 Apr 2023 14:49:38 +0200 Subject: Prepare for per-channel param adjustment --- src/sequencer.c | 104 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 29 deletions(-) (limited to 'src/sequencer.c') diff --git a/src/sequencer.c b/src/sequencer.c index 8f2b183..1280f5f 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -209,6 +209,14 @@ handle_channel_selection(void) { } else if (key_tap(KEY_A)) { if (key_hold(KEY_SELECT)) { clipboard_paste(); + } else { + switch (channel_selection_loc) { + case 0: { input_handler = handle_param_selection_ch1; } break; + case 1: { input_handler = handle_param_selection_ch2; } break; + case 2: { input_handler = handle_param_selection_ch3; } break; + case 3: { input_handler = handle_param_selection_ch4; } break; + } + redraw_params = true; } } else if (key_tap(KEY_L)) { s32 inc = -1; @@ -222,6 +230,7 @@ handle_channel_selection(void) { case 1: { trig = &pat->ch2.notes[i]; } break; case 2: { trig = &pat->ch3.notes[i]; } break; case 3: { trig = &pat->ch4.notes[i]; } break; + default: {trig = &pat->ch1.notes[i]; } break; } trig->note = MAX((s32)trig->note + inc, (s32)NOTE_C_2); } @@ -238,6 +247,7 @@ handle_channel_selection(void) { case 1: { trig = &pat->ch2.notes[i]; } break; case 2: { trig = &pat->ch3.notes[i]; } break; case 3: { trig = &pat->ch4.notes[i]; } break; + default: {trig = &pat->ch1.notes[i]; } break; } trig->note = MIN((s32)trig->note + inc, (s32)NOTE_C_8 - 1); } @@ -258,6 +268,7 @@ handle_channel_selection(void) { channel_selection_loc = MAX(channel_selection_loc - 1, 0); } redraw_trigs = true; + redraw_params = true; } else if (key_tap(KEY_DOWN)) { if (channel_selection_loc == SEQ_N_CHANNELS - 1) { channel_selection_loc = 0; @@ -265,6 +276,7 @@ handle_channel_selection(void) { channel_selection_loc = MIN(channel_selection_loc + 1, SEQ_N_CHANNELS); } redraw_trigs = true; + redraw_params = true; } } @@ -457,10 +469,10 @@ handle_pattern_selection(void) { } void -handle_param_selection_sq1(void) { +set_param_selection_sq1(size_t i, InputHandler return_handler) { // Go back to trigger selection. if (key_released(KEY_A)) { - input_handler = handle_trigger_selection; + input_handler = return_handler; redraw_params = true; return; } @@ -518,7 +530,7 @@ handle_param_selection_sq1(void) { inc = 1; } Pattern *pat = &patterns[pattern_selection_loc]; - ChannelSquareParams *params = &pat->ch1.params[trig_selection_loc]; + ChannelSquareParams *params = &pat->ch1.params[i]; switch (param_selection_loc) { case 0: { params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); @@ -547,10 +559,10 @@ handle_param_selection_sq1(void) { } void -handle_param_selection_sq2(void) { +set_param_selection_sq2(size_t i, InputHandler return_handler) { // Go back to trigger selection. if (key_released(KEY_A)) { - input_handler = handle_trigger_selection; + input_handler = return_handler; redraw_params = true; return; } @@ -577,7 +589,7 @@ handle_param_selection_sq2(void) { inc = 1; } Pattern *pat = &patterns[pattern_selection_loc]; - ChannelSquareParams *params = &pat->ch2.params[trig_selection_loc]; + ChannelSquareParams *params = &pat->ch2.params[i]; switch (param_selection_loc) { case 0: { params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); @@ -597,12 +609,12 @@ handle_param_selection_sq2(void) { } void -handle_param_selection_wave(void) { +set_param_selection_wave(size_t i, InputHandler return_handler) { Pattern *pat = &patterns[pattern_selection_loc]; // Go back to trigger selection. if (key_released(KEY_A)) { - input_handler = handle_trigger_selection; + input_handler = return_handler; redraw_params = true; return; } @@ -706,7 +718,7 @@ handle_param_selection_wave(void) { if (param_selection_loc < 32) { // Draw on wave a. u8 byte_number = param_selection_loc / 2; - u8 *byte = &pat->ch3.params[trig_selection_loc].wave_a; + u8 *byte = &pat->ch3.params[i].wave_a; byte += byte_number; if (odd) { *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); @@ -716,7 +728,7 @@ handle_param_selection_wave(void) { } else if (param_selection_loc < 64){ // Draw on wave b. u8 byte_number = (param_selection_loc - 32) / 2; - u8 *byte = &pat->ch3.params[trig_selection_loc].wave_b; + u8 *byte = &pat->ch3.params[i].wave_b; byte += byte_number; if (odd) { *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); @@ -725,8 +737,8 @@ handle_param_selection_wave(void) { } } else if (param_selection_loc < 72) { // Copy default waves. - u32 *wave_a = &pat->ch3.params[trig_selection_loc].wave_a; - u32 *wave_b = &pat->ch3.params[trig_selection_loc].wave_b; + u32 *wave_a = &pat->ch3.params[i].wave_a; + u32 *wave_b = &pat->ch3.params[i].wave_b; switch (param_selection_loc) { case 64: { memcpy32(wave_a, sine_wave, 16); @@ -760,10 +772,10 @@ handle_param_selection_wave(void) { } break; } } else if (param_selection_loc == 72) { - u8 *wave_mode = &pat->ch3.params[trig_selection_loc].wave_mode; + u8 *wave_mode = &pat->ch3.params[i].wave_mode; *wave_mode = CLAMP(*wave_mode + inc, 0, 2); } else if (param_selection_loc == 73) { - u8 *wave_volume = &pat->ch3.params[trig_selection_loc].wave_volume; + u8 *wave_volume = &pat->ch3.params[i].wave_volume; *wave_volume = CLAMP(*wave_volume + inc, 0, 4); } redraw_params = true; @@ -771,10 +783,11 @@ handle_param_selection_wave(void) { } void -handle_param_selection_noise(void) { +set_param_selection_noise(size_t i, InputHandler return_handler) { // Go back to trigger selection. if (key_released(KEY_A)) { - input_handler = handle_trigger_selection; + input_handler = return_handler; + redraw_params = true; return; } @@ -788,6 +801,7 @@ handle_param_selection_noise(void) { inc = -1; } param_selection_loc = CLAMP(loc + inc, 0, 3); + redraw_params = true; } // Adjust parameter. @@ -799,7 +813,7 @@ handle_param_selection_noise(void) { inc = 1; } Pattern *pat = &patterns[pattern_selection_loc]; - ChannelNoiseParams *params = &pat->ch4.params[trig_selection_loc]; + ChannelNoiseParams *params = &pat->ch4.params[i]; switch (param_selection_loc) { case 0: { params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1); @@ -818,6 +832,46 @@ handle_param_selection_noise(void) { } } +void +handle_param_selection_ch1() { + set_param_selection_sq1(16, handle_channel_selection); +} + +void +handle_param_selection_ch2() { + set_param_selection_sq2(16, handle_channel_selection); +} + +void +handle_param_selection_ch3() { + set_param_selection_wave(16, handle_channel_selection); +} + +void +handle_param_selection_ch4() { + set_param_selection_noise(16, handle_channel_selection); +} + +void +handle_param_selection_sq1() { + set_param_selection_sq1(trig_selection_loc, handle_trigger_selection); +} + +void +handle_param_selection_sq2() { + set_param_selection_sq2(trig_selection_loc, handle_trigger_selection); +} + +void +handle_param_selection_wave() { + set_param_selection_wave(trig_selection_loc, handle_trigger_selection); +} + +void +handle_param_selection_noise() { + set_param_selection_noise(trig_selection_loc, handle_trigger_selection); +} + void handle_trigger_selection(void) { TriggerNote *trig = get_current_trig(); @@ -886,18 +940,10 @@ handle_trigger_selection(void) { } else { // Switch to parameter selection. switch (channel_selection_loc) { - case 0: { - input_handler = handle_param_selection_sq1; - } break; - case 1: { - input_handler = handle_param_selection_sq2; - } break; - case 2: { - input_handler = handle_param_selection_wave; - } break; - case 3: { - input_handler = handle_param_selection_noise; - } break; + case 0: { input_handler = handle_param_selection_sq1; } break; + case 1: { input_handler = handle_param_selection_sq2; } break; + case 2: { input_handler = handle_param_selection_wave; } break; + case 3: { input_handler = handle_param_selection_noise; } break; } redraw_params = true; redraw_piano_note = true; -- cgit v1.2.1