From 4cde886bc202d0c8c0ee52279cd4c653829afc09 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 20 Jun 2021 12:10:53 +0200 Subject: Add initial parameter display for square channels --- src/sequencer.c | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 260 insertions(+), 14 deletions(-) diff --git a/src/sequencer.c b/src/sequencer.c index a5addf4..41d8ee7 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -574,7 +574,7 @@ draw_piano(void) { #define PARAMS_START_Y 8 void -draw_params_cursor_ch3(size_t i, u8 clr) { +draw_params_cursor_wave(size_t i, u8 clr) { u8 x_positions[] = { // 32 half bytes (Wave A). 0, 4, 8, 12, 16, 20, 24, 28, @@ -632,11 +632,13 @@ void draw_params_cursor(size_t i, u8 clr) { switch (channel_selection_loc) { case 0: { + // draw_params_cursor_ch1(i, clr); } break; case 1: { + // draw_params_cursor_ch2(i, clr); } break; case 2: { - draw_params_cursor_ch3(i, clr); + draw_params_cursor_wave(i, clr); } break; case 3: { } break; @@ -671,9 +673,7 @@ clear_parameters(void) { IWRAM_CODE void -draw_parameters_ch3(void) { - clear_parameters(); - +draw_parameters_wave(void) { // Draw current wave data. { u8 *wave_a = ch3.params[trig_selection_loc].wave_a; @@ -778,15 +778,262 @@ draw_parameters_ch3(void) { } } +void +draw_parameters_square(ChannelSquareParams *params, bool sweep) { + // DEBUG: Bounding box. + { + size_t x0 = PARAMS_START_X; + size_t y0 = PARAMS_START_Y; + size_t x1 = PARAMS_START_X + PARAMS_W; + size_t y1 = PARAMS_START_Y + PARAMS_H - 5; + // draw_rect(x0, y0, x1, y1, COL_FG); + } + + // Duty cycle. + { + size_t x = PARAMS_START_X; + size_t y = PARAMS_START_Y + PARAMS_H - 25; + draw_line(x, y + 7, x + 2, y + 7, COL_FG); + draw_line(x + 22, y + 7, x + 24, y + 7, COL_FG); + draw_line(x, y + 8, x, y + 19, COL_FG); + draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG); + draw_line(x, y + 20, x + 24, y + 20, COL_FG); + txt_drawf_small("duty", x + 3, y + 3, 4, COL_FG); + + switch (params->duty_cycle) { + case 0: { + txt_drawf("0", x + 9, y + 10, 6, COL_FG); + } break; + case 1: { + txt_drawf("25", x + 6, y + 10, 6, COL_FG); + } break; + case 2: { + txt_drawf("50", x + 6, y + 10, 6, COL_FG); + } break; + case 3: { + txt_drawf("75", x + 6, y + 10, 6, COL_FG); + } break; + case 4: { + txt_drawf("100", x + 3, y + 10, 6, COL_FG); + } break; + } + } + + // Env. volume. + { + size_t x = PARAMS_START_X + 31; + size_t y = PARAMS_START_Y + PARAMS_H - 25; + draw_line(x, y + 7, x + 4, y + 7, COL_FG); + draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG); + draw_line(x, y + 8, x, y + 19, COL_FG); + draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG); + draw_line(x, y + 20, x + 24, y + 20, COL_FG); + txt_drawf_small("vol", x + 5, y + 3, 4, COL_FG); + + switch (params->env_volume) { + case 0: { + txt_drawf("0", x + 9, y + 10, 6, COL_FG); + } break; + case 1: { + txt_drawf("6", x + 9, y + 10, 6, COL_FG); + } break; + case 2: { + txt_drawf("13", x + 6, y + 10, 6, COL_FG); + } break; + case 3: { + txt_drawf("20", x + 6, y + 10, 6, COL_FG); + } break; + case 4: { + txt_drawf("26", x + 6, y + 10, 6, COL_FG); + } break; + case 5: { + txt_drawf("33", x + 6, y + 10, 6, COL_FG); + } break; + case 6: { + txt_drawf("40", x + 6, y + 10, 6, COL_FG); + } break; + case 7: { + txt_drawf("46", x + 6, y + 10, 6, COL_FG); + } break; + case 8: { + txt_drawf("53", x + 6, y + 10, 6, COL_FG); + } break; + case 9: { + txt_drawf("60", x + 6, y + 10, 6, COL_FG); + } break; + case 10: { + txt_drawf("66", x + 6, y + 10, 6, COL_FG); + } break; + case 11: { + txt_drawf("73", x + 6, y + 10, 6, COL_FG); + } break; + case 12: { + txt_drawf("80", x + 6, y + 10, 6, COL_FG); + } break; + case 13: { + txt_drawf("86", x + 6, y + 10, 6, COL_FG); + } break; + case 14: { + txt_drawf("93", x + 6, y + 10, 6, COL_FG); + } break; + case 15: { + txt_drawf("100", x + 3, y + 10, 6, COL_FG); + } break; + } + } + + // Env. direction + { + size_t x = PARAMS_START_X + 59; + size_t y = PARAMS_START_Y + PARAMS_H - 25; + draw_line(x, y + 7, x + 4, y + 7, COL_FG); + draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG); + draw_line(x, y + 8, x, y + 19, COL_FG); + draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG); + draw_line(x, y + 20, x + 24, y + 20, COL_FG); + txt_drawf_small("dir", x + 5, y + 3, 4, COL_FG); + + char arr_up[2] = { 0x19, 0 }; + char arr_down[2] = { 0x18, 0 }; + switch (params->env_direction) { + case 0: { + txt_drawf(arr_down, x + 9, y + 11, 6, COL_FG); + } break; + case 1: { + txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG); + } break; + } + } + + // Env. time. + { + size_t x = PARAMS_START_X + 87; + size_t y = PARAMS_START_Y + PARAMS_H - 25; + draw_line(x, y + 7, x + 2, y + 7, COL_FG); + draw_line(x + 22, y + 7, x + 24, y + 7, COL_FG); + draw_line(x, y + 8, x, y + 19, COL_FG); + draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG); + draw_line(x, y + 20, x + 24, y + 20, COL_FG); + txt_drawf_small("time", x + 3, y + 3, 4, COL_FG); + + switch (params->env_time) { + case 0: { + txt_drawf("0", x + 9, y + 10, 6, COL_FG); + } break; + case 1: { + txt_drawf("14", x + 6, y + 10, 6, COL_FG); + } break; + case 2: { + txt_drawf("28", x + 6, y + 10, 6, COL_FG); + } break; + case 3: { + txt_drawf("42", x + 6, y + 10, 6, COL_FG); + } break; + case 4: { + txt_drawf("57", x + 6, y + 10, 6, COL_FG); + } break; + case 5: { + txt_drawf("71", x + 6, y + 10, 6, COL_FG); + } break; + case 6: { + txt_drawf("85", x + 6, y + 10, 6, COL_FG); + } break; + case 7: { + txt_drawf("100", x + 3, y + 10, 6, COL_FG); + } break; + } + } + + // Sweep number. + { + size_t x = PARAMS_START_X + 118; + size_t y = PARAMS_START_Y + PARAMS_H - 25; + draw_line(x, y + 7, x + 4, y + 7, COL_FG); + draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG); + draw_line(x, y + 8, x, y + 19, COL_FG); + draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG); + draw_line(x, y + 20, x + 24, y + 20, COL_FG); + txt_drawf_small("num", x + 5, y + 3, 4, COL_FG); + + switch (params->sweep_number) { + case 0: { + txt_drawf("0", x + 9, y + 10, 6, COL_FG); + } break; + case 1: { + txt_drawf("1", x + 9, y + 10, 6, COL_FG); + } break; + case 2: { + txt_drawf("2", x + 9, y + 10, 6, COL_FG); + } break; + case 3: { + txt_drawf("3", x + 9, y + 10, 6, COL_FG); + } break; + } + } + + // Sweep time. + { + size_t x = PARAMS_START_X + 146; + size_t y = PARAMS_START_Y + PARAMS_H - 25; + draw_line(x, y + 7, x + 2, y + 7, COL_FG); + draw_line(x + 22, y + 7, x + 24, y + 7, COL_FG); + draw_line(x, y + 8, x, y + 19, COL_FG); + draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG); + draw_line(x, y + 20, x + 24, y + 20, COL_FG); + txt_drawf_small("time", x + 3, y + 3, 4, COL_FG); + + switch (params->sweep_time) { + case 0: { + txt_drawf("0", x + 9, y + 10, 6, COL_FG); + } break; + case 1: { + txt_drawf("1", x + 9, y + 10, 6, COL_FG); + } break; + case 2: { + txt_drawf("2", x + 9, y + 10, 6, COL_FG); + } break; + case 3: { + txt_drawf("3", x + 9, y + 10, 6, COL_FG); + } break; + } + } + + // Sweep direction. + { + size_t x = PARAMS_START_X + 132; + size_t y = PARAMS_START_Y + PARAMS_H - 45; + draw_line(x, y + 7, x + 4, y + 7, COL_FG); + draw_line(x + 20, y + 7, x + 24, y + 7, COL_FG); + draw_line(x, y + 8, x, y + 19, COL_FG); + draw_line(x + 24, y + 8, x + 24, y + 19, COL_FG); + draw_line(x, y + 20, x + 24, y + 20, COL_FG); + txt_drawf_small("dir", x + 5, y + 3, 4, COL_FG); + + char arr_up[2] = { 0x19, 0 }; + char arr_down[2] = { 0x18, 0 }; + switch (params->env_direction) { + case 0: { + txt_drawf(arr_up, x + 9, y + 11, 6, COL_FG); + } break; + case 1: { + txt_drawf(arr_down, x + 9, y + 11, 6, COL_FG); + } break; + } + } +} + void draw_parameters(void) { + clear_parameters(); switch (channel_selection_loc) { case 0: { + draw_parameters_square(&ch1.params[trig_selection_loc], true); } break; case 1: { + draw_parameters_square(&ch2.params[trig_selection_loc], false); } break; case 2: { - draw_parameters_ch3(); + draw_parameters_wave(); } break; case 3: { } break; @@ -924,7 +1171,7 @@ void handle_trigger_selection(void); void handle_channel_selection(void); void handle_param_selection_ch1(void); void handle_param_selection_ch2(void); -void handle_param_selection_ch3(void); +void handle_param_selection_wave(void); void handle_channel_selection(void) { @@ -1111,7 +1358,7 @@ handle_param_selection_ch2(void) { } void -handle_param_selection_ch3(void) { +handle_param_selection_wave(void) { if (key_tap(KEY_A)) { // Go back to trigger selection. draw_params_cursor(param_selection_loc, COL_BG); @@ -1140,9 +1387,9 @@ handle_param_selection_ch3(void) { inc = -1; } } - draw_params_cursor_ch3(param_selection_loc, COL_BG); + draw_params_cursor_wave(param_selection_loc, COL_BG); param_selection_loc = CLAMP(loc + inc, 0, 73); - draw_params_cursor_ch3(param_selection_loc, COL_CURSOR); + draw_params_cursor_wave(param_selection_loc, COL_CURSOR); } if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { int inc = 0; @@ -1196,9 +1443,9 @@ handle_param_selection_ch3(void) { inc = -1; } } - draw_params_cursor_ch3(param_selection_loc, COL_BG); + draw_params_cursor_wave(param_selection_loc, COL_BG); param_selection_loc = CLAMP(loc + inc, 0, 73); - draw_params_cursor_ch3(param_selection_loc, COL_CURSOR); + draw_params_cursor_wave(param_selection_loc, COL_CURSOR); } if (key_tap(KEY_R) || key_tap(KEY_L)) { int odd = param_selection_loc & 0x1; @@ -1355,7 +1602,7 @@ handle_trigger_selection(void) { input_handler = handle_param_selection_ch2; } break; case 2: { - input_handler = handle_param_selection_ch3; + input_handler = handle_param_selection_wave; } break; } draw_params_cursor(param_selection_loc, COL_CURSOR); @@ -1408,7 +1655,6 @@ sequencer_init(void) { draw_note(trig->note, COL_NOTE_PRESSED); // Initialize input handler. - channel_selection_loc = 2; // DEBUG: Starting on CH3 input_handler = handle_trigger_selection; draw_trig_cursor(trig_selection_loc, COL_CURSOR); draw_channel_cursor(channel_selection_loc, COL_CURRENT_CHANNEL); -- cgit v1.2.1