From ec5c1ad9f16772434f0f49811c87ec58a3569e83 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 23 Apr 2023 18:48:32 +0200 Subject: Add conditional redrawing This covers most of the previous functionality, but separating the input handling and rendering functions. Only cursor drawing and a few corner cases missing. --- src/drawing.c | 7 +++++-- src/main.c | 64 ++++++++++++++++++++++++++++++++++++++++----------------- src/sequencer.c | 36 ++++++++++++-------------------- 3 files changed, 63 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/drawing.c b/src/drawing.c index b790595..89d3ef6 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -29,7 +29,7 @@ draw_channels(void) { } u8 clr = active ? COL_FG : COL_GREY; size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; - draw_channel_sprite(CHAN_START_X, y, active, i); + draw_channel_sprite(CHAN_START_X, y, clr, i); } } @@ -175,8 +175,12 @@ draw_bank_buttons() { void draw_pattern_buttons() { + // Clear patterns. size_t x = PAT_START_X; size_t y = PAT_START_Y; + + draw_filled_rect(x, y, x + PAT_W, y + PAT_H * 8, COL_BG); + txt_drawf_small("PAT", x, y - 10, COL_FG); char pat_names[] = { 'A', 'B', 'C', 'D', @@ -190,7 +194,6 @@ draw_pattern_buttons() { if (i == next_pattern && current_pattern != next_pattern) { color = COL_BLUE; } - draw_filled_rect(x, y, x + PAT_W, y + PAT_H, COL_BG); draw_rect(x, y, x + PAT_W, y + PAT_H, color); txt_drawc(pat_names[i], x + 4, y + 2, color); y += PAT_OFFSET_Y; diff --git a/src/main.c b/src/main.c index 8ee4945..b6be6b9 100644 --- a/src/main.c +++ b/src/main.c @@ -21,27 +21,53 @@ WITH REGARD TO THIS SOFTWARE. void render(void) { - // TODO: Make sure we are drawing the proper cursor color. // TODO: Decouple update from rendering. - PROF(screen_fill(0), clear_cycles); + // PROF(screen_fill(0), clear_cycles); PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); - PROF(draw_triggers(), draw_trigs_cycles); - PROF(draw_channels(), draw_btn_cycles); - PROF(draw_pattern_buttons(), draw_btn_cycles); - PROF(draw_bank_buttons(), draw_btn_cycles); - PROF(draw_bpm(), draw_btn_cycles); - PROF(draw_play(), draw_btn_cycles); - PROF(draw_stop(), draw_btn_cycles); - PROF(draw_piano(), draw_piano_cycles); - // TODO: Draw the notes currently playing with a fade off animation for the - // first 3 channels. - TriggerNote *trig = get_current_trig(); - PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles); - PROF(draw_parameters(), draw_param_cycles); - PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles); - PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles); - PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles); - PROF(draw_current_step(COL_RED), draw_cursor_cycles); + if (redraw_trigs) { + PROF(draw_triggers(), draw_trigs_cycles); + redraw_trigs = false; + } + if (redraw_channels) { + PROF(draw_channels(), draw_btn_cycles); + redraw_channels = false; + } + if (redraw_pattern_buttons) { + PROF(draw_pattern_buttons(), draw_btn_cycles); + redraw_pattern_buttons = false; + } + if (redraw_bank_buttons) { + PROF(draw_bank_buttons(), draw_btn_cycles); + redraw_bank_buttons = false; + } + if (redraw_bpm) { + PROF(draw_bpm(), draw_btn_cycles); + redraw_bpm = false; + } + if (redraw_play_pause) { + PROF(draw_play(), draw_btn_cycles); + PROF(draw_stop(), draw_btn_cycles); + redraw_play_pause = false; + } + if (redraw_piano_note) { + PROF(draw_piano(), draw_piano_cycles); + // TODO: Draw the notes currently playing with a fade off animation for + // the first 3 channels. + TriggerNote *trig = get_current_trig(); + PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles); + redraw_piano_note = false; + } + if (redraw_params) { + PROF(draw_parameters(), draw_param_cycles); + redraw_params = false; + } + + // TODO: Make sure we are drawing the cursors properly. + // PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles); + // PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles); + // PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles); + + // PROF(draw_current_step(COL_RED), draw_cursor_cycles); } int diff --git a/src/sequencer.c b/src/sequencer.c index b689bf5..a560bcb 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -9,14 +9,14 @@ void set_time(int bpm); -bool redraw_pattern_buttons = false; -bool redraw_play_pause = false; -bool redraw_trigs = false; -bool redraw_channels = false; -bool redraw_bank_buttons = false; -bool redraw_params = false; -bool redraw_bpm = false; -bool redraw_piano_note = false; +bool redraw_pattern_buttons = true; +bool redraw_play_pause = true; +bool redraw_trigs = true; +bool redraw_channels = true; +bool redraw_bank_buttons = true; +bool redraw_params = true; +bool redraw_bpm = true; +bool redraw_piano_note = true; void irq_timer(void) { @@ -198,39 +198,30 @@ handle_channel_selection(void) { patterns[pattern_selection_loc].ch4.active ^= 1; } break; } - draw_channels(); + redraw_channels = true; } if (key_tap(KEY_RIGHT)) { trig_selection_loc = 0; param_selection_loc = 0; input_handler = handle_trigger_selection; - draw_channel_cursor(channel_selection_loc, COL_GREY); - draw_trig_cursor(trig_selection_loc, COL_CURSOR); - TriggerNote *trig = get_current_trig(); - draw_note(trig->note, COL_NOTE_PRESSED); - draw_parameters(); + redraw_piano_note = true; + redraw_params = true; } else if (key_tap(KEY_LEFT)) { input_handler = handle_pattern_selection; - draw_channel_cursor(channel_selection_loc, COL_GREY); - draw_pattern_cursor(pattern_selection_loc, COL_CURSOR); } 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; } else { channel_selection_loc = MAX(channel_selection_loc - 1, 0); } - draw_channel_cursor(channel_selection_loc, COL_CURSOR); - draw_triggers(); + redraw_trigs = true; } 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; } else { channel_selection_loc = MIN(channel_selection_loc + 1, SEQ_N_CHANNELS); } - draw_channel_cursor(channel_selection_loc, COL_CURSOR); - draw_triggers(); + redraw_trigs = true; } } @@ -384,7 +375,6 @@ handle_pattern_selection(void) { } } else if (key_tap(KEY_DOWN)) { if (pattern_selection_loc < 7) { - draw_pattern_cursor(pattern_selection_loc, COL_BG); pattern_selection_loc = pattern_selection_loc + 1; redraw_channels = true; redraw_trigs = true; -- cgit v1.2.1