aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-23 18:48:32 +0200
committerBad Diode <bd@badd10de.dev>2023-04-23 18:48:32 +0200
commitec5c1ad9f16772434f0f49811c87ec58a3569e83 (patch)
tree854894d7e4e9abb15eceb71332dd9678adc21506
parentef6af29d99f7df6acf088ee28dc026023258c10c (diff)
downloadstepper-ec5c1ad9f16772434f0f49811c87ec58a3569e83.tar.gz
stepper-ec5c1ad9f16772434f0f49811c87ec58a3569e83.zip
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.
-rw-r--r--src/drawing.c7
-rw-r--r--src/main.c64
-rw-r--r--src/sequencer.c36
3 files changed, 63 insertions, 44 deletions
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) {
29 } 29 }
30 u8 clr = active ? COL_FG : COL_GREY; 30 u8 clr = active ? COL_FG : COL_GREY;
31 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; 31 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y;
32 draw_channel_sprite(CHAN_START_X, y, active, i); 32 draw_channel_sprite(CHAN_START_X, y, clr, i);
33 } 33 }
34} 34}
35 35
@@ -175,8 +175,12 @@ draw_bank_buttons() {
175 175
176void 176void
177draw_pattern_buttons() { 177draw_pattern_buttons() {
178 // Clear patterns.
178 size_t x = PAT_START_X; 179 size_t x = PAT_START_X;
179 size_t y = PAT_START_Y; 180 size_t y = PAT_START_Y;
181
182 draw_filled_rect(x, y, x + PAT_W, y + PAT_H * 8, COL_BG);
183
180 txt_drawf_small("PAT", x, y - 10, COL_FG); 184 txt_drawf_small("PAT", x, y - 10, COL_FG);
181 char pat_names[] = { 185 char pat_names[] = {
182 'A', 'B', 'C', 'D', 186 'A', 'B', 'C', 'D',
@@ -190,7 +194,6 @@ draw_pattern_buttons() {
190 if (i == next_pattern && current_pattern != next_pattern) { 194 if (i == next_pattern && current_pattern != next_pattern) {
191 color = COL_BLUE; 195 color = COL_BLUE;
192 } 196 }
193 draw_filled_rect(x, y, x + PAT_W, y + PAT_H, COL_BG);
194 draw_rect(x, y, x + PAT_W, y + PAT_H, color); 197 draw_rect(x, y, x + PAT_W, y + PAT_H, color);
195 txt_drawc(pat_names[i], x + 4, y + 2, color); 198 txt_drawc(pat_names[i], x + 4, y + 2, color);
196 y += PAT_OFFSET_Y; 199 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.
21 21
22void 22void
23render(void) { 23render(void) {
24 // TODO: Make sure we are drawing the proper cursor color.
25 // TODO: Decouple update from rendering. 24 // TODO: Decouple update from rendering.
26 PROF(screen_fill(0), clear_cycles); 25 // PROF(screen_fill(0), clear_cycles);
27 PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); 26 PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles);
28 PROF(draw_triggers(), draw_trigs_cycles); 27 if (redraw_trigs) {
29 PROF(draw_channels(), draw_btn_cycles); 28 PROF(draw_triggers(), draw_trigs_cycles);
30 PROF(draw_pattern_buttons(), draw_btn_cycles); 29 redraw_trigs = false;
31 PROF(draw_bank_buttons(), draw_btn_cycles); 30 }
32 PROF(draw_bpm(), draw_btn_cycles); 31 if (redraw_channels) {
33 PROF(draw_play(), draw_btn_cycles); 32 PROF(draw_channels(), draw_btn_cycles);
34 PROF(draw_stop(), draw_btn_cycles); 33 redraw_channels = false;
35 PROF(draw_piano(), draw_piano_cycles); 34 }
36 // TODO: Draw the notes currently playing with a fade off animation for the 35 if (redraw_pattern_buttons) {
37 // first 3 channels. 36 PROF(draw_pattern_buttons(), draw_btn_cycles);
38 TriggerNote *trig = get_current_trig(); 37 redraw_pattern_buttons = false;
39 PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles); 38 }
40 PROF(draw_parameters(), draw_param_cycles); 39 if (redraw_bank_buttons) {
41 PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles); 40 PROF(draw_bank_buttons(), draw_btn_cycles);
42 PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles); 41 redraw_bank_buttons = false;
43 PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles); 42 }
44 PROF(draw_current_step(COL_RED), draw_cursor_cycles); 43 if (redraw_bpm) {
44 PROF(draw_bpm(), draw_btn_cycles);
45 redraw_bpm = false;
46 }
47 if (redraw_play_pause) {
48 PROF(draw_play(), draw_btn_cycles);
49 PROF(draw_stop(), draw_btn_cycles);
50 redraw_play_pause = false;
51 }
52 if (redraw_piano_note) {
53 PROF(draw_piano(), draw_piano_cycles);
54 // TODO: Draw the notes currently playing with a fade off animation for
55 // the first 3 channels.
56 TriggerNote *trig = get_current_trig();
57 PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles);
58 redraw_piano_note = false;
59 }
60 if (redraw_params) {
61 PROF(draw_parameters(), draw_param_cycles);
62 redraw_params = false;
63 }
64
65 // TODO: Make sure we are drawing the cursors properly.
66 // PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles);
67 // PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles);
68 // PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles);
69
70 // PROF(draw_current_step(COL_RED), draw_cursor_cycles);
45} 71}
46 72
47int 73int
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 @@
9 9
10void set_time(int bpm); 10void set_time(int bpm);
11 11
12bool redraw_pattern_buttons = false; 12bool redraw_pattern_buttons = true;
13bool redraw_play_pause = false; 13bool redraw_play_pause = true;
14bool redraw_trigs = false; 14bool redraw_trigs = true;
15bool redraw_channels = false; 15bool redraw_channels = true;
16bool redraw_bank_buttons = false; 16bool redraw_bank_buttons = true;
17bool redraw_params = false; 17bool redraw_params = true;
18bool redraw_bpm = false; 18bool redraw_bpm = true;
19bool redraw_piano_note = false; 19bool redraw_piano_note = true;
20 20
21void 21void
22irq_timer(void) { 22irq_timer(void) {
@@ -198,39 +198,30 @@ handle_channel_selection(void) {
198 patterns[pattern_selection_loc].ch4.active ^= 1; 198 patterns[pattern_selection_loc].ch4.active ^= 1;
199 } break; 199 } break;
200 } 200 }
201 draw_channels(); 201 redraw_channels = true;
202 } 202 }
203 if (key_tap(KEY_RIGHT)) { 203 if (key_tap(KEY_RIGHT)) {
204 trig_selection_loc = 0; 204 trig_selection_loc = 0;
205 param_selection_loc = 0; 205 param_selection_loc = 0;
206 input_handler = handle_trigger_selection; 206 input_handler = handle_trigger_selection;
207 draw_channel_cursor(channel_selection_loc, COL_GREY); 207 redraw_piano_note = true;
208 draw_trig_cursor(trig_selection_loc, COL_CURSOR); 208 redraw_params = true;
209 TriggerNote *trig = get_current_trig();
210 draw_note(trig->note, COL_NOTE_PRESSED);
211 draw_parameters();
212 } else if (key_tap(KEY_LEFT)) { 209 } else if (key_tap(KEY_LEFT)) {
213 input_handler = handle_pattern_selection; 210 input_handler = handle_pattern_selection;
214 draw_channel_cursor(channel_selection_loc, COL_GREY);
215 draw_pattern_cursor(pattern_selection_loc, COL_CURSOR);
216 } else if (key_tap(KEY_UP)) { 211 } else if (key_tap(KEY_UP)) {
217 draw_channel_cursor(channel_selection_loc, COL_BG);
218 if (channel_selection_loc == 0) { 212 if (channel_selection_loc == 0) {
219 channel_selection_loc = SEQ_N_CHANNELS - 1; 213 channel_selection_loc = SEQ_N_CHANNELS - 1;
220 } else { 214 } else {
221 channel_selection_loc = MAX(channel_selection_loc - 1, 0); 215 channel_selection_loc = MAX(channel_selection_loc - 1, 0);
222 } 216 }
223 draw_channel_cursor(channel_selection_loc, COL_CURSOR); 217 redraw_trigs = true;
224 draw_triggers();
225 } else if (key_tap(KEY_DOWN)) { 218 } else if (key_tap(KEY_DOWN)) {
226 draw_channel_cursor(channel_selection_loc, COL_BG);
227 if (channel_selection_loc == SEQ_N_CHANNELS - 1) { 219 if (channel_selection_loc == SEQ_N_CHANNELS - 1) {
228 channel_selection_loc = 0; 220 channel_selection_loc = 0;
229 } else { 221 } else {
230 channel_selection_loc = MIN(channel_selection_loc + 1, SEQ_N_CHANNELS); 222 channel_selection_loc = MIN(channel_selection_loc + 1, SEQ_N_CHANNELS);
231 } 223 }
232 draw_channel_cursor(channel_selection_loc, COL_CURSOR); 224 redraw_trigs = true;
233 draw_triggers();
234 } 225 }
235} 226}
236 227
@@ -384,7 +375,6 @@ handle_pattern_selection(void) {
384 } 375 }
385 } else if (key_tap(KEY_DOWN)) { 376 } else if (key_tap(KEY_DOWN)) {
386 if (pattern_selection_loc < 7) { 377 if (pattern_selection_loc < 7) {
387 draw_pattern_cursor(pattern_selection_loc, COL_BG);
388 pattern_selection_loc = pattern_selection_loc + 1; 378 pattern_selection_loc = pattern_selection_loc + 1;
389 redraw_channels = true; 379 redraw_channels = true;
390 redraw_trigs = true; 380 redraw_trigs = true;