From 53729509f4f39690f025902df07bc38fc898ec65 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 21 Jul 2023 13:13:10 +0200 Subject: Prepare for parameter UI rework --- src/drawing.c | 161 ++++++++++++++++++++++++++++++---------------------------- src/globals.c | 26 ++++++---- 2 files changed, 100 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/drawing.c b/src/drawing.c index b7d5421..c596995 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -316,6 +316,9 @@ draw_note(u8 note, u8 clr) { size_t octave = note / 12; size_t value = note % 12; + size_t base_x = PIANO_START_X + 2; + size_t base_y0 = PIANO_START_Y + 2; + size_t base_y1 = PIANO_START_Y - 2; size_t x0 = 0; size_t y0 = 0; size_t x1 = 0; @@ -323,99 +326,101 @@ draw_note(u8 note, u8 clr) { switch (value) { // White notes. case 0:{ - x0 = PIANO_START_X + 2 + octave * 28; + x0 = base_x + octave * 28; x1 = x0 + 1; - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + PIANO_H; + y0 = base_y0; + y1 = base_y1 + PIANO_H; draw_filled_rect(x0, y0, x1, y1, clr); - x0 = PIANO_START_X + 2 + octave * 28 + 2; + x0 = base_x + octave * 28 + 2; x1 = x0; - y0 = y0 + 9; + y0 = base_y1 + PIANO_BLACK_H; + y1 = y0 + PIANO_H - PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); } break; case 2:{ - x0 = PIANO_START_X + 2 + octave * 28 + 5; + x0 = base_x + octave * 28 + 5; x1 = x0; - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + 12; + y0 = base_y0; + y1 = base_y1 + PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); - x0 = PIANO_START_X + 2 + octave * 28 + 4; + x0 = base_x + octave * 28 + 4; x1 = x0 + 2; - y0 = PIANO_START_Y - 2 + 13; - y1 = y0 + 2; + y0 = base_y1 + PIANO_BLACK_H; + y1 = y0 + PIANO_H - PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); } break; case 4:{ - x0 = PIANO_START_X + 2 + octave * 28 + 9; + x0 = base_x + octave * 28 + 9; x1 = x0 + 1; - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + 12; + y0 = base_y0; + y1 = base_y1 + PIANO_H; draw_filled_rect(x0, y0, x1, y1, clr); - x0 = PIANO_START_X + 2 + octave * 28 + 8; + x0 = base_x + octave * 28 + 8; x1 = x0 + 2; - y0 = PIANO_START_Y - 2 + 13; - y1 = y0 + 2; + y0 = base_y1 + PIANO_BLACK_H; + y1 = y0 + PIANO_H - PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); } break; case 5:{ - x0 = PIANO_START_X + 2 + octave * 28 + 12; + x0 = base_x + octave * 28 + 12; x1 = x0 + 1; - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + PIANO_H; + y0 = base_y0; + y1 = base_y1 + PIANO_H; draw_filled_rect(x0, y0, x1, y1, clr); - x0 = PIANO_START_X + 2 + octave * 28 + 14; + x0 = base_x + octave * 28 + 14; x1 = x0; - y0 = y0 + 9; + y0 = base_y1 + PIANO_BLACK_H; + y1 = y0 + PIANO_H - PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); } break; case 7:{ - x0 = PIANO_START_X + 2 + octave * 28 + 17; + x0 = base_x + octave * 28 + 17; x1 = x0; - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + 12; + y0 = base_y0; + y1 = base_y1 + PIANO_H; draw_filled_rect(x0, y0, x1, y1, clr); - x0 = PIANO_START_X + 2 + octave * 28 + 16; + x0 = base_x + octave * 28 + 16; x1 = x0 + 2; - y0 = PIANO_START_Y - 2 + 13; - y1 = y0 + 2; + y0 = base_y1 + PIANO_BLACK_H; + y1 = y0 + PIANO_H - PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); } break; case 9:{ - x0 = PIANO_START_X + 2 + octave * 28 + 21; + x0 = base_x + octave * 28 + 21; x1 = x0; - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + 12; + y0 = base_y0; + y1 = base_y1 + PIANO_H; draw_filled_rect(x0, y0, x1, y1, clr); - x0 = PIANO_START_X + 2 + octave * 28 + 20; + x0 = base_x + octave * 28 + 20; x1 = x0 + 2; - y0 = PIANO_START_Y - 2 + 13; - y1 = y0 + 2; + y0 = base_y1 + PIANO_BLACK_H; + y1 = y0 + PIANO_H - PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); } break; case 11: { - x0 = PIANO_START_X + 2 + octave * 28 + 25; + x0 = base_x + octave * 28 + 25; x1 = x0 + 1; - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + 12; + y0 = base_y0; + y1 = base_y1 + PIANO_H; draw_filled_rect(x0, y0, x1, y1, clr); - x0 = PIANO_START_X + 2 + octave * 28 + 24; + x0 = base_x + octave * 28 + 24; x1 = x0 + 2; - y0 = PIANO_START_Y - 2 + 13; - y1 = y0 + 2; + y0 = base_y1 + PIANO_BLACK_H; + y1 = y0 + PIANO_H - PIANO_BLACK_H; draw_filled_rect(x0, y0, x1, y1, clr); } break; default: { if (clr == COL_FG) { clr = COL_BG; } - y0 = PIANO_START_Y + 2; - y1 = PIANO_START_Y - 2 + 11; + y0 = base_y0; + y1 = base_y1 + PIANO_BLACK_H - 2; switch (value) { - case 1: { x0 = PIANO_START_X + 2 + octave * 28 + 3; } break; - case 3: { x0 = PIANO_START_X + 2 + octave * 28 + 7; } break; - case 6: { x0 = PIANO_START_X + 2 + octave * 28 + 15; } break; - case 8: { x0 = PIANO_START_X + 2 + octave * 28 + 19; } break; - case 10: { x0 = PIANO_START_X + 2 + octave * 28 + 23; } break; + case 1: { x0 = base_x + octave * 28 + 3; } break; + case 3: { x0 = base_x + octave * 28 + 7; } break; + case 6: { x0 = base_x + octave * 28 + 15; } break; + case 8: { x0 = base_x + octave * 28 + 19; } break; + case 10: { x0 = base_x + octave * 28 + 23; } break; } x1 = x0; draw_line(x0, y0, x1, y1, clr); @@ -1112,32 +1117,34 @@ void draw_parameters(void) { clear_parameters(); Pattern *pat = &patterns[pattern_selection_loc]; - if (input_handler == handle_trigger_selection || - input_handler == handle_param_selection_sq1 || - input_handler == handle_param_selection_sq2 || - input_handler == handle_param_selection_wave || - input_handler == handle_param_selection_noise) { - switch (channel_selection_loc) { - case 0: { draw_parameters_square(&pat->ch1.params[trig_selection_loc], true, false); } break; - case 1: { draw_parameters_square(&pat->ch2.params[trig_selection_loc], false, false); } break; - case 2: { draw_parameters_wave(&pat->ch3.params[trig_selection_loc], false); } break; - case 3: { draw_parameters_noise(&pat->ch4.params[trig_selection_loc], false); } break; - } - return; - } - if (input_handler == handle_channel_selection || - input_handler == handle_param_selection_ch1 || - input_handler == handle_param_selection_ch2 || - input_handler == handle_param_selection_ch3 || - input_handler == handle_param_selection_ch4) { - switch (channel_selection_loc) { - case 0: { draw_parameters_square(&ch1_params, true, true); } break; - case 1: { draw_parameters_square(&ch2_params, false, true); } break; - case 2: { draw_parameters_wave(&ch3_params, true); } break; - case 3: { draw_parameters_noise(&ch4_params, true); } break; - } - return; - } + draw_rect(PARAMS_START_X, PARAMS_START_Y, PARAMS_START_X + PARAMS_W, PARAMS_START_Y + PARAMS_H, COL_OFF); + // DEBUG: Drawing the reference grid + // if (input_handler == handle_trigger_selection || + // input_handler == handle_param_selection_sq1 || + // input_handler == handle_param_selection_sq2 || + // input_handler == handle_param_selection_wave || + // input_handler == handle_param_selection_noise) { + // switch (channel_selection_loc) { + // case 0: { draw_parameters_square(&pat->ch1.params[trig_selection_loc], true, false); } break; + // case 1: { draw_parameters_square(&pat->ch2.params[trig_selection_loc], false, false); } break; + // case 2: { draw_parameters_wave(&pat->ch3.params[trig_selection_loc], false); } break; + // case 3: { draw_parameters_noise(&pat->ch4.params[trig_selection_loc], false); } break; + // } + // return; + // } + // if (input_handler == handle_channel_selection || + // input_handler == handle_param_selection_ch1 || + // input_handler == handle_param_selection_ch2 || + // input_handler == handle_param_selection_ch3 || + // input_handler == handle_param_selection_ch4) { + // switch (channel_selection_loc) { + // case 0: { draw_parameters_square(&ch1_params, true, true); } break; + // case 1: { draw_parameters_square(&ch2_params, false, true); } break; + // case 2: { draw_parameters_wave(&ch3_params, true); } break; + // case 3: { draw_parameters_noise(&ch4_params, true); } break; + // } + // return; + // } } void @@ -1262,10 +1269,10 @@ draw_piano_notes(void) { void draw_notif_bar() { - u8 x0 = PARAMS_START_X; - u8 y0 = PARAMS_START_Y - 7; - u8 x1 = PARAMS_START_X + PARAMS_W; - u8 y1 = y0 + 10; + u8 x0 = NOTIF_START_X; + u8 y0 = NOTIF_START_Y - 7; + u8 x1 = NOTIF_START_X + NOTIF_W; + u8 y1 = y0 + NOTIF_H; u8 color = COL_FG; draw_filled_rect(x0, y0, x1, y1, COL_BG); draw_rect(x0, y0, x1, y1, color); diff --git a/src/globals.c b/src/globals.c index 7a55f02..724ff10 100644 --- a/src/globals.c +++ b/src/globals.c @@ -33,32 +33,38 @@ bool clear_screen = true; #define CHAN_W 19 #define CHAN_H 8 #define CHAN_START_X 30 -#define CHAN_START_Y 97 +#define CHAN_START_Y 98 #define CHAN_OFFSET_Y 15 #define TRIG_W 15 #define TRIG_H 22 #define TRIG_START_X 59 -#define TRIG_START_Y 97 +#define TRIG_START_Y 98 #define TRIG_OFFSET_X (TRIG_W + 3) #define TRIG_OFFSET_Y (TRIG_H + 8) #define PIANO_W 170 -#define PIANO_H 15 +#define PIANO_H 12 +#define PIANO_BLACK_H 10 #define PIANO_START_X 30 -#define PIANO_START_Y 76 +#define PIANO_START_Y 80 #define PIANO_NOTE_W 2 -#define PARAMS_W 170 -#define PARAMS_H 60 -#define PARAMS_START_X 30 -#define PARAMS_START_Y 16 +#define NOTIF_W 170 +#define NOTIF_H 10 +#define NOTIF_START_X 30 +#define NOTIF_START_Y 13 + +#define PARAMS_W 166 +#define PARAMS_H 52 +#define PARAMS_START_X 32 +#define PARAMS_START_Y 22 #define R_SIDEBAR_X ((TRIG_START_X) + (TRIG_OFFSET_X) * 8 + 4) #define L_SIDEBAR_X ((CHAN_START_X) - 26) #define PAT_START_X (L_SIDEBAR_X + 4) -#define PAT_START_Y 20 +#define PAT_START_Y 21 #define PAT_W 14 #define PAT_H 10 #define PAT_OFFSET_Y 17 @@ -83,7 +89,7 @@ bool clear_screen = true; #define PAT_TRIG_W 14 #define PAT_TRIG_H 14 #define PAT_TRIG_START_X 35 -#define PAT_TRIG_START_Y 29 +#define PAT_TRIG_START_Y 30 #define PAT_TRIG_OFFSET_X (PAT_TRIG_W + 7) #define PAT_TRIG_OFFSET_Y (PAT_TRIG_H + 8) -- cgit v1.2.1