From 2abcb70459499dc5d729ec47b39bc43718ac6ced Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 24 Apr 2023 19:13:03 +0200 Subject: Add contextual drawing of piano notes --- src/drawing.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/main.c | 16 +++------------- src/sequencer.c | 17 +++++------------ 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/src/drawing.c b/src/drawing.c index 149aa19..3264ad8 100644 --- a/src/drawing.c +++ b/src/drawing.c @@ -11,6 +11,10 @@ draw_channel_sprite(size_t x, size_t y, u8 clr, u8 idx) { void draw_channels(void) { + // NOTE: Different channel colors can be interesting. + u8 colors[] = { + 1, 1, 1, 1, + }; for (size_t i = 0; i < 4; i++) { bool active = false; switch (i) { @@ -19,7 +23,7 @@ draw_channels(void) { case 2: { active = patterns[pattern_selection_loc].ch3.active; } break; case 3: { active = patterns[pattern_selection_loc].ch4.active; } break; } - u8 clr = active ? COL_FG : COL_GREY; + u8 clr = active ? colors[i] : COL_GREY; size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; draw_channel_sprite(CHAN_START_X, y, clr, i); } @@ -1107,3 +1111,56 @@ draw_cursors(void) { draw_params_cursor(param_selection_loc, COL_CURSOR); } } + +TriggerNote * get_current_trig(void); + +void +draw_piano_notes(void) { + draw_piano(); + if (input_handler == handle_channel_selection) { + // Show note on current channel only. + Pattern *pat = &patterns[current_pattern]; + u8 step = (step_counter - 1) % 16; + switch (channel_selection_loc) { + case 0: { + if (pat->ch1.active && pat->ch1.notes[step].active) { + draw_note(pat->ch1.notes[step].note, COL_NOTE_PRESSED); + } + } break; + case 1: { + if (pat->ch2.active && pat->ch2.notes[step].active) { + draw_note(pat->ch2.notes[step].note, COL_NOTE_PRESSED); + } + } break; + case 2: { + if (pat->ch3.active && pat->ch3.notes[step].active) { + draw_note(pat->ch3.notes[step].note, COL_NOTE_PRESSED); + } + } break; + } + + } else 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) { + // Show currently selected trigger note. + TriggerNote *trig = get_current_trig(); + draw_note(trig->note, COL_NOTE_PRESSED); + } else { + // Show last/current played notes in all channels. + if (play_status == 1) { + Pattern *pat = &patterns[current_pattern]; + u8 step = (step_counter - 1) % 16; + if (pat->ch3.active && pat->ch3.notes[step].active) { + draw_note(pat->ch3.notes[step].note, COL_NOTE_PRESSED); + } + if (pat->ch2.active && pat->ch2.notes[step].active) { + draw_note(pat->ch2.notes[step].note, COL_NOTE_PRESSED); + } + if (pat->ch1.active && pat->ch1.notes[step].active) { + draw_note(pat->ch1.notes[step].note, COL_NOTE_PRESSED); + } + } + } +} diff --git a/src/main.c b/src/main.c index 2693d51..44e7718 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ WITH REGARD TO THIS SOFTWARE. // - Notification support for feedback when doing some operations // (copying/pasting) // - Animations for cursor movement/current step highlight. (A fade out maybe?) -// - Display played notes on all tonal channels when a trig or channel is not +// + Display played notes on all tonal channels when a trig or channel is not // selected. If a channel is selected show active note in that channel, if // a trig is selected behaved as usual. These could be highlighted in // different colors to make it easier on the eyes. If a pattern is selected, @@ -34,6 +34,7 @@ WITH REGARD TO THIS SOFTWARE. // - Pattern chaining for more than 1 queue and/or song mode. // - Undo/Redo. // - Add a settings page to change some configuration parameters. +// - Wrap around cursor left/right. // // Advanced // - Sync via MIDI via arduinoboy or something similar. @@ -85,18 +86,7 @@ render(void) { redraw_play_pause = false; } if (redraw_piano_note) { - PROF(draw_piano(), draw_piano_cycles); - 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) { - // TODO: Show last/current played notes in all channels. - } else { - // Show currently selected trigger note. - TriggerNote *trig = get_current_trig(); - PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles); - } + PROF(draw_piano_notes(), draw_piano_cycles); redraw_piano_note = false; } if (redraw_params) { diff --git a/src/sequencer.c b/src/sequencer.c index 9c92ef0..1d5b3d6 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -136,6 +136,7 @@ play_step(void) { SOUND_NOISE_FREQ = 0; } step_counter = (step_counter + 1) % 16; + redraw_piano_note = true; } void @@ -156,18 +157,10 @@ TriggerNote * get_current_trig(void) { Pattern *pat = &patterns[pattern_selection_loc]; switch (channel_selection_loc) { - case 0: { - return &pat->ch1.notes[trig_selection_loc]; - } break; - case 1: { - return &pat->ch2.notes[trig_selection_loc]; - } break; - case 2: { - return &pat->ch3.notes[trig_selection_loc]; - } break; - case 3: { - return &pat->ch4.notes[trig_selection_loc]; - } break; + case 0: { return &pat->ch1.notes[trig_selection_loc]; } break; + case 1: { return &pat->ch2.notes[trig_selection_loc]; } break; + case 2: { return &pat->ch3.notes[trig_selection_loc]; } break; + case 3: { return &pat->ch4.notes[trig_selection_loc]; } break; } return NULL; } -- cgit v1.2.1