summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-10 15:00:32 +0200
committerBad Diode <bd@badd10de.dev>2021-06-10 15:00:32 +0200
commit958d175aededa1f2c8cc8fc946fd6b36b5c1e8e9 (patch)
tree9163118dcf94c6ab08fc922020de79af3553b153
parentab60d99e2ef778842726660d9016ab05c61cd005 (diff)
downloadgba-sequencer-958d175aededa1f2c8cc8fc946fd6b36b5c1e8e9.tar.gz
gba-sequencer-958d175aededa1f2c8cc8fc946fd6b36b5c1e8e9.zip
Add color to current trig note
-rw-r--r--src/sequencer.c83
1 files changed, 64 insertions, 19 deletions
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) {
402 } 402 }
403 u8 clr = active ? COL_FG : COL_GREY; 403 u8 clr = active ? COL_FG : COL_GREY;
404 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y; 404 size_t y = CHAN_START_Y + i * CHAN_OFFSET_Y;
405 draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, true); 405 draw_tile(CHAN_START_X, y, channel_tiles + k++, clr, false);
406 draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, true); 406 draw_tile(CHAN_START_X + 8, y, channel_tiles + k++, clr, false);
407 draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, true); 407 draw_tile(CHAN_START_X + 16, y, channel_tiles + k++, clr, false);
408 } 408 }
409} 409}
410 410
@@ -517,9 +517,32 @@ draw_note(u8 note, u8 clr) {
517 y1 = y0 + 7; 517 y1 = y0 + 7;
518 draw_filled_rect(x0, y0, x1, y1, clr); 518 draw_filled_rect(x0, y0, x1, y1, clr);
519 } break; 519 } break;
520 default: 520 default: {
521 // TODO: 521 if (clr == COL_FG) {
522 return; 522 clr = COL_BG;
523 }
524 y0 = PIANO_START_Y + 2;
525 y1 = PIANO_START_Y - 2 + 11;
526 switch (value) {
527 case 1: {
528 x0 = PIANO_START_X + 2 + octave * 28 + 3;
529 } break;
530 case 3: {
531 x0 = PIANO_START_X + 2 + octave * 28 + 7;
532 } break;
533 case 6: {
534 x0 = PIANO_START_X + 2 + octave * 28 + 15;
535 } break;
536 case 8: {
537 x0 = PIANO_START_X + 2 + octave * 28 + 19;
538 } break;
539 case 10: {
540 x0 = PIANO_START_X + 2 + octave * 28 + 23;
541 } break;
542 }
543 x1 = x0;
544 draw_line(x0, y0, x1, y1, clr);
545 } break;
523 } 546 }
524} 547}
525 548
@@ -645,6 +668,21 @@ set_time(int bpm) {
645 TIMER_CTRL_0 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3; 668 TIMER_CTRL_0 = TIMER_CTRL_IRQ | TIMER_CTRL_ENABLE | TIMER_CTRL_FREQ_3;
646} 669}
647 670
671TriggerNote *
672get_current_trig(void) {
673 switch (channel_selection_loc) {
674 case 0: {
675 return &ch1.notes[trig_selection_loc];
676 } break;
677 case 1: {
678 return &ch2.notes[trig_selection_loc];
679 } break;
680 case 2: {
681 return &ch3.notes[trig_selection_loc];
682 } break;
683 }
684 return NULL;
685}
648 686
649// Input handling works using a FSM. The input handler is switched to whichever 687// Input handling works using a FSM. The input handler is switched to whichever
650// function controls each section. For example, channel selection or trigger 688// function controls each section. For example, channel selection or trigger
@@ -681,6 +719,8 @@ handle_channel_selection(void) {
681 input_handler = handle_trigger_selection; 719 input_handler = handle_trigger_selection;
682 draw_channel_cursor(channel_selection_loc, COL_GREY); 720 draw_channel_cursor(channel_selection_loc, COL_GREY);
683 draw_trig_cursor(trig_selection_loc, COL_BLUE); 721 draw_trig_cursor(trig_selection_loc, COL_BLUE);
722 TriggerNote *trig = get_current_trig();
723 draw_note(trig->note, COL_BLUE);
684 } else if (key_tap(KEY_UP)) { 724 } else if (key_tap(KEY_UP)) {
685 draw_channel_cursor(channel_selection_loc, COL_BG); 725 draw_channel_cursor(channel_selection_loc, COL_BG);
686 if (channel_selection_loc == 0) { 726 if (channel_selection_loc == 0) {
@@ -969,18 +1009,7 @@ handle_param_selection_ch3(void) {
969 1009
970void 1010void
971handle_trigger_selection(void) { 1011handle_trigger_selection(void) {
972 TriggerNote *trig; 1012 TriggerNote *trig = get_current_trig();
973 switch (channel_selection_loc) {
974 case 0: {
975 trig = &ch1.notes[trig_selection_loc];
976 } break;
977 case 1: {
978 trig = &ch2.notes[trig_selection_loc];
979 } break;
980 case 2: {
981 trig = &ch3.notes[trig_selection_loc];
982 } break;
983 }
984 1013
985 if (key_tap(KEY_B)) { 1014 if (key_tap(KEY_B)) {
986 // Toggle trigger. 1015 // Toggle trigger.
@@ -989,14 +1018,18 @@ handle_trigger_selection(void) {
989 } else if (key_tap(KEY_L)) { 1018 } else if (key_tap(KEY_L)) {
990 // Decrease note. 1019 // Decrease note.
991 if (trig->active) { 1020 if (trig->active) {
1021 draw_note(trig->note, COL_FG);
992 trig->note = MAX(trig->note - 1, NOTE_C_2); 1022 trig->note = MAX(trig->note - 1, NOTE_C_2);
1023 draw_note(trig->note, COL_BLUE);
993 clear_trigger(trig_selection_loc); 1024 clear_trigger(trig_selection_loc);
994 draw_trigger(channel_selection_loc, trig_selection_loc); 1025 draw_trigger(channel_selection_loc, trig_selection_loc);
995 } 1026 }
996 } else if (key_tap(KEY_R)) { 1027 } else if (key_tap(KEY_R)) {
997 // Increase note. 1028 // Increase note.
998 if (trig->active) { 1029 if (trig->active) {
999 trig->note = MIN( trig->note + 1, NOTE_C_8); 1030 draw_note(trig->note, COL_FG);
1031 trig->note = MIN( trig->note + 1, NOTE_C_8 - 1);
1032 draw_note(trig->note, COL_BLUE);
1000 clear_trigger(trig_selection_loc); 1033 clear_trigger(trig_selection_loc);
1001 draw_trigger(channel_selection_loc, trig_selection_loc); 1034 draw_trigger(channel_selection_loc, trig_selection_loc);
1002 } 1035 }
@@ -1007,23 +1040,33 @@ handle_trigger_selection(void) {
1007 if (trig_selection_loc == 0 || trig_selection_loc == 8) { 1040 if (trig_selection_loc == 0 || trig_selection_loc == 8) {
1008 // We are at the boundary, switch to channel selection. 1041 // We are at the boundary, switch to channel selection.
1009 draw_trig_cursor(trig_selection_loc, COL_BG); 1042 draw_trig_cursor(trig_selection_loc, COL_BG);
1043 draw_note(trig->note, COL_FG);
1010 input_handler = handle_channel_selection; 1044 input_handler = handle_channel_selection;
1011 draw_channel_cursor(channel_selection_loc, COL_BLUE); 1045 draw_channel_cursor(channel_selection_loc, COL_BLUE);
1012 } else { 1046 } else {
1013 draw_trig_cursor(trig_selection_loc, COL_BG); 1047 draw_trig_cursor(trig_selection_loc, COL_BG);
1048 draw_note(trig->note, COL_FG);
1014 trig_selection_loc = MAX(trig_selection_loc - 1, 0); 1049 trig_selection_loc = MAX(trig_selection_loc - 1, 0);
1050 trig = get_current_trig();
1015 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1051 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1052 draw_note(trig->note, COL_BLUE);
1016 } 1053 }
1017 } else if (key_tap(KEY_RIGHT)) { 1054 } else if (key_tap(KEY_RIGHT)) {
1018 if (trig_selection_loc != 7) { 1055 if (trig_selection_loc != 7) {
1019 draw_trig_cursor(trig_selection_loc, COL_BG); 1056 draw_trig_cursor(trig_selection_loc, COL_BG);
1057 draw_note(trig->note, COL_FG);
1020 trig_selection_loc = MIN(trig_selection_loc + 1, 15); 1058 trig_selection_loc = MIN(trig_selection_loc + 1, 15);
1059 trig = get_current_trig();
1021 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1060 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1061 draw_note(trig->note, COL_BLUE);
1022 } 1062 }
1023 } else if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) { 1063 } else if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
1024 draw_trig_cursor(trig_selection_loc, COL_BG); 1064 draw_trig_cursor(trig_selection_loc, COL_BG);
1065 draw_note(trig->note, COL_FG);
1025 trig_selection_loc = (trig_selection_loc + 8) % 16; 1066 trig_selection_loc = (trig_selection_loc + 8) % 16;
1067 trig = get_current_trig();
1026 draw_trig_cursor(trig_selection_loc, COL_BLUE); 1068 draw_trig_cursor(trig_selection_loc, COL_BLUE);
1069 draw_note(trig->note, COL_BLUE);
1027 } else if (key_tap(KEY_A)) { 1070 } else if (key_tap(KEY_A)) {
1028 // Switch to parameter selection. 1071 // Switch to parameter selection.
1029 switch (channel_selection_loc) { 1072 switch (channel_selection_loc) {
@@ -1081,6 +1124,8 @@ sequencer_init(void) {
1081 draw_triggers(); 1124 draw_triggers();
1082 draw_channels(); 1125 draw_channels();
1083 draw_piano(); 1126 draw_piano();
1127 TriggerNote *trig = get_current_trig();
1128 draw_note(trig->note, COL_BLUE);
1084 1129
1085 // Initialize input handler. 1130 // Initialize input handler.
1086 channel_selection_loc = 2; // DEBUG: Starting on CH3 1131 channel_selection_loc = 2; // DEBUG: Starting on CH3