From 958d175aededa1f2c8cc8fc946fd6b36b5c1e8e9 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 10 Jun 2021 15:00:32 +0200 Subject: Add color to current trig note --- src/sequencer.c | 83 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 19 deletions(-) (limited to 'src/sequencer.c') diff --git a/src/sequencer.c b/src/sequencer.c index 205cb73..56d8089 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -402,9 +402,9 @@ draw_channels(void) { } u8 clr = active ? COL_FG : COL_GREY; size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; - draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, true); - draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, true); - draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, true); + draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, false); + draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, false); + draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, false); } } @@ -517,9 +517,32 @@ draw_note(u8 note, u8 clr) { y1 = y0 + 7; draw_filled_rect(x0, y0, x1, y1, clr); } break; - default: - // TODO: - return; + default: { + if (clr == COL_FG) { + clr = COL_BG; + } + y0 = PIANO_START_Y + 2; + y1 = PIANO_START_Y - 2 + 11; + 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; + } + x1 = x0; + draw_line(x0, y0, x1, y1, clr); + } break; } } @@ -645,6 +668,21 @@ set_time(int bpm) { TIMER_CTRL_0 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; } +TriggerNote * +get_current_trig(void) { + switch (channel_selection_loc) { + case 0: { + return &ch1.notes[trig_selection_loc]; + } break; + case 1: { + return &ch2.notes[trig_selection_loc]; + } break; + case 2: { + return &ch3.notes[trig_selection_loc]; + } break; + } + return NULL; +} // Input handling works using a FSM. The input handler is switched to whichever // function controls each section. For example, channel selection or trigger @@ -681,6 +719,8 @@ handle_channel_selection(void) { input_handler = handle_trigger_selection; draw_channel_cursor(channel_selection_loc, COL_GREY); draw_trig_cursor(trig_selection_loc, COL_BLUE); + TriggerNote *trig = get_current_trig(); + draw_note(trig->note, COL_BLUE); } else if (key_tap(KEY_UP)) { draw_channel_cursor(channel_selection_loc, COL_BG); if (channel_selection_loc == 0) { @@ -969,18 +1009,7 @@ handle_param_selection_ch3(void) { void handle_trigger_selection(void) { - TriggerNote *trig; - switch (channel_selection_loc) { - case 0: { - trig = &ch1.notes[trig_selection_loc]; - } break; - case 1: { - trig = &ch2.notes[trig_selection_loc]; - } break; - case 2: { - trig = &ch3.notes[trig_selection_loc]; - } break; - } + TriggerNote *trig = get_current_trig(); if (key_tap(KEY_B)) { // Toggle trigger. @@ -989,14 +1018,18 @@ handle_trigger_selection(void) { } else if (key_tap(KEY_L)) { // Decrease note. if (trig->active) { + draw_note(trig->note, COL_FG); trig->note = MAX(trig->note - 1, NOTE_C_2); + draw_note(trig->note, COL_BLUE); clear_trigger(trig_selection_loc); draw_trigger(channel_selection_loc, trig_selection_loc); } } else if (key_tap(KEY_R)) { // Increase note. if (trig->active) { - trig->note = MIN( trig->note + 1, NOTE_C_8); + draw_note(trig->note, COL_FG); + trig->note = MIN( trig->note + 1, NOTE_C_8 - 1); + draw_note(trig->note, COL_BLUE); clear_trigger(trig_selection_loc); draw_trigger(channel_selection_loc, trig_selection_loc); } @@ -1007,23 +1040,33 @@ handle_trigger_selection(void) { if (trig_selection_loc == 0 || trig_selection_loc == 8) { // We are at the boundary, switch to channel selection. draw_trig_cursor(trig_selection_loc, COL_BG); + draw_note(trig->note, COL_FG); input_handler = handle_channel_selection; draw_channel_cursor(channel_selection_loc, COL_BLUE); } else { draw_trig_cursor(trig_selection_loc, COL_BG); + draw_note(trig->note, COL_FG); trig_selection_loc = MAX(trig_selection_loc - 1, 0); + trig = get_current_trig(); draw_trig_cursor(trig_selection_loc, COL_BLUE); + draw_note(trig->note, COL_BLUE); } } else if (key_tap(KEY_RIGHT)) { if (trig_selection_loc != 7) { draw_trig_cursor(trig_selection_loc, COL_BG); + draw_note(trig->note, COL_FG); trig_selection_loc = MIN(trig_selection_loc + 1, 15); + trig = get_current_trig(); draw_trig_cursor(trig_selection_loc, COL_BLUE); + draw_note(trig->note, COL_BLUE); } } else if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { draw_trig_cursor(trig_selection_loc, COL_BG); + draw_note(trig->note, COL_FG); trig_selection_loc = (trig_selection_loc + 8) % 16; + trig = get_current_trig(); draw_trig_cursor(trig_selection_loc, COL_BLUE); + draw_note(trig->note, COL_BLUE); } else if (key_tap(KEY_A)) { // Switch to parameter selection. switch (channel_selection_loc) { @@ -1081,6 +1124,8 @@ sequencer_init(void) { draw_triggers(); draw_channels(); draw_piano(); + TriggerNote *trig = get_current_trig(); + draw_note(trig->note, COL_BLUE); // Initialize input handler. channel_selection_loc = 2; // DEBUG: Starting on CH3 -- cgit v1.2.1