summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-09 13:52:37 +0200
committerBad Diode <bd@badd10de.dev>2021-06-09 13:52:37 +0200
commitc7f40ebf4ace263037e87a41ac331080aee2db36 (patch)
treea556c6b12509befc96eeef582b724b83e400a559
parent76791d881a007074ec34f229d01feaef5cf03794 (diff)
downloadgba-sequencer-c7f40ebf4ace263037e87a41ac331080aee2db36.tar.gz
gba-sequencer-c7f40ebf4ace263037e87a41ac331080aee2db36.zip
Add stub input handlers for parameters
-rw-r--r--src/sequencer.c245
1 files changed, 173 insertions, 72 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index fa9b674..3e34d68 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -388,7 +388,7 @@ draw_channels(void) {
388 unpack_tiles(channel_buttons, channel_tiles, 3 * 4); 388 unpack_tiles(channel_buttons, channel_tiles, 3 * 4);
389 size_t k = 0; 389 size_t k = 0;
390 for (size_t i = 0; i < 4; i++) { 390 for (size_t i = 0; i < 4; i++) {
391 bool active; 391 bool active = false;
392 switch (i) { 392 switch (i) {
393 case 0: { 393 case 0: {
394 active = ch1.active; 394 active = ch1.active;
@@ -529,15 +529,21 @@ set_time(int bpm) {
529} 529}
530 530
531 531
532// Input handling works using a FSM. The input handler is switched to whichever
533// function controls each section. For example, channel selection or trigger
534// selection.
532void (*input_handler)(void); 535void (*input_handler)(void);
533 536
534#define SEQ_N_CHANNELS 3 537#define SEQ_N_CHANNELS 3
535 538
536void handle_trigger_cursor(void); 539void handle_trigger_selection(void);
537void handle_channel_cursor(void); 540void handle_channel_selection(void);
541void handle_param_selection_ch1(void);
542void handle_param_selection_ch2(void);
543void handle_param_selection_ch3(void);
538 544
539void 545void
540handle_channel_cursor(void) { 546handle_channel_selection(void) {
541 if (key_tap(KEY_B)) { 547 if (key_tap(KEY_B)) {
542 switch (channel_selection_loc) { 548 switch (channel_selection_loc) {
543 case 0: { 549 case 0: {
@@ -555,7 +561,7 @@ handle_channel_cursor(void) {
555 if (key_tap(KEY_RIGHT)) { 561 if (key_tap(KEY_RIGHT)) {
556 trig_selection_loc = 0; 562 trig_selection_loc = 0;
557 param_selection_loc = 0; 563 param_selection_loc = 0;
558 input_handler = handle_trigger_cursor; 564 input_handler = handle_trigger_selection;
559 draw_channel_cursor(channel_selection_loc, COL_GREY); 565 draw_channel_cursor(channel_selection_loc, COL_GREY);
560 draw_trig_cursor(trig_selection_loc, COL_BLUE); 566 draw_trig_cursor(trig_selection_loc, COL_BLUE);
561 } else if (key_tap(KEY_UP)) { 567 } else if (key_tap(KEY_UP)) {
@@ -580,75 +586,81 @@ handle_channel_cursor(void) {
580} 586}
581 587
582void 588void
583handle_trigger_cursor(void) { 589handle_param_selection_ch1(void) {
584 TriggerNote *trig; 590 if (key_tap(KEY_A)) {
585 switch (channel_selection_loc) { 591 // TODO: draw param cursor.
586 case 0: { 592 input_handler = handle_trigger_selection;
587 trig = &ch1.notes[trig_selection_loc];
588 } break;
589 case 1: {
590 trig = &ch2.notes[trig_selection_loc];
591 } break;
592 case 2: {
593 trig = &ch3.notes[trig_selection_loc];
594 } break;
595 }
596
597 if (key_tap(KEY_B)) {
598 // Toggle trigger.
599 trig->active ^= 1;
600 draw_trigger(channel_selection_loc, trig_selection_loc);
601 } else if (key_tap(KEY_A)) {
602 // Switch to parameter selection.
603 // current_selection = SEQ_SELECT_PARAMETER;
604 } else if (key_tap(KEY_L)) {
605 // Decrease note.
606 if (trig->active) {
607 trig->note = MAX(trig->note - 1, NOTE_C_2);
608 clear_trigger(trig_selection_loc);
609 draw_trigger(channel_selection_loc, trig_selection_loc);
610 }
611 } else if (key_tap(KEY_R)) {
612 // Increase note.
613 if (trig->active) {
614 trig->note = MIN( trig->note + 1, NOTE_C_8);
615 clear_trigger(trig_selection_loc);
616 draw_trigger(channel_selection_loc, trig_selection_loc);
617 }
618 }
619
620 // Move trigger cursor.
621 if (key_tap(KEY_LEFT)) {
622 if (trig_selection_loc == 0 || trig_selection_loc == 8) {
623 // We are at the boundary, switch to channel selection.
624 draw_trig_cursor(trig_selection_loc, COL_BG);
625 input_handler = handle_channel_cursor;
626 draw_channel_cursor(channel_selection_loc, COL_BLUE);
627 } else {
628 draw_trig_cursor(trig_selection_loc, COL_BG);
629 trig_selection_loc = MAX(trig_selection_loc - 1, 0);
630 draw_trig_cursor(trig_selection_loc, COL_BLUE);
631 }
632 } else if (key_tap(KEY_RIGHT)) {
633 if (trig_selection_loc != 7) {
634 draw_trig_cursor(trig_selection_loc, COL_BG);
635 trig_selection_loc = MIN(trig_selection_loc + 1, 15);
636 draw_trig_cursor(trig_selection_loc, COL_BLUE);
637 }
638 } else if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
639 draw_trig_cursor(trig_selection_loc, COL_BG);
640 trig_selection_loc = (trig_selection_loc + 8) % 16;
641 draw_trig_cursor(trig_selection_loc, COL_BLUE); 593 draw_trig_cursor(trig_selection_loc, COL_BLUE);
642 } 594 }
595 // // Move through the selected synth parameters.
596 // if (key_tap(KEY_LEFT)) {
597 // int max_param = 6;
598 // if (channel_selection_loc == 1) {
599 // max_param = 3;
600 // }
601 // if (param_selection_loc == 0) {
602 // param_selection_loc = max_param;
603 // } else {
604 // param_selection_loc = MAX(param_selection_loc - 1, 0);
605 // }
606 // }
607 // if (key_tap(KEY_RIGHT)) {
608 // int max_param = 6;
609 // if (channel_selection_loc == 1) {
610 // max_param = 3;
611 // }
612 // if (param_selection_loc == max_param) {
613 // param_selection_loc = 0;
614 // } else {
615 // param_selection_loc = MIN(param_selection_loc + 1, max_param);
616 // }
617 // }
618
619 // // Adjust the parameters up or down.
620 // if (key_tap(KEY_L) || key_tap(KEY_R)) {
621 // int inc;
622 // if (key_tap(KEY_L)) {
623 // inc = -1;
624 // } else {
625 // inc = 1;
626 // }
627 // switch (param_selection_loc) {
628 // case 0: {
629 // trig->env_volume = CLAMP(trig->env_volume + inc, 0, 15);
630 // } break;
631 // case 1: {
632 // trig->env_time = CLAMP(trig->env_time + inc, 0, 7);
633 // } break;
634 // case 2: {
635 // trig->env_direction ^= 1;
636 // } break;
637 // case 3: {
638 // trig->duty_cycle = CLAMP(trig->duty_cycle + inc, 0, 3);
639 // } break;
640 // case 4: {
641 // trig->sweep_number = CLAMP(trig->sweep_number + inc, 0, 7);
642 // } break;
643 // case 5: {
644 // trig->sweep_time = CLAMP(trig->sweep_time + inc, 0, 7);
645 // } break;
646 // case 6: {
647 // if (trig->sweep_direction == 0) {
648 // trig->sweep_direction = 1;
649 // } else {
650 // trig->sweep_direction = 0;
651 // }
652 // } break;
653 // }
654 // }
643} 655}
644 656
645void 657void
646handle_sequencer_input(void) { 658handle_param_selection_ch2(void) {
647 poll_keys(); 659 if (key_tap(KEY_A)) {
648 input_handler(); 660 // TODO: draw param cursor.
649 // SeqTrigger *trig = &sequences[channel_selection_loc][trig_selection_loc]; 661 input_handler = handle_trigger_selection;
650 // } else if (current_selection == SEQ_SELECT_PARAMETER) { 662 draw_trig_cursor(trig_selection_loc, COL_BLUE);
651 // if (channel_selection_loc < 2) { 663 }
652 // // Move through the selected synth parameters. 664 // // Move through the selected synth parameters.
653 // if (key_tap(KEY_LEFT)) { 665 // if (key_tap(KEY_LEFT)) {
654 // int max_param = 6; 666 // int max_param = 6;
@@ -709,7 +721,15 @@ handle_sequencer_input(void) {
709 // } break; 721 // } break;
710 // } 722 // }
711 // } 723 // }
712 // } else if (channel_selection_loc == 2) { 724}
725
726void
727handle_param_selection_ch3(void) {
728 if (key_tap(KEY_A)) {
729 // TODO: draw param cursor.
730 input_handler = handle_trigger_selection;
731 draw_trig_cursor(trig_selection_loc, COL_BLUE);
732 }
713 // if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) { 733 // if (key_tap(KEY_LEFT) || key_tap(KEY_RIGHT)) {
714 // int inc = 0; 734 // int inc = 0;
715 // int loc = param_selection_loc; 735 // int loc = param_selection_loc;
@@ -828,7 +848,87 @@ handle_sequencer_input(void) {
828 // dma_copy(&trig->wave_b, &rand_wave, 16); 848 // dma_copy(&trig->wave_b, &rand_wave, 16);
829 // } 849 // }
830 // } 850 // }
831 // } 851}
852
853void
854handle_trigger_selection(void) {
855 TriggerNote *trig;
856 switch (channel_selection_loc) {
857 case 0: {
858 trig = &ch1.notes[trig_selection_loc];
859 } break;
860 case 1: {
861 trig = &ch2.notes[trig_selection_loc];
862 } break;
863 case 2: {
864 trig = &ch3.notes[trig_selection_loc];
865 } break;
866 }
867
868 if (key_tap(KEY_B)) {
869 // Toggle trigger.
870 trig->active ^= 1;
871 draw_trigger(channel_selection_loc, trig_selection_loc);
872 } else if (key_tap(KEY_L)) {
873 // Decrease note.
874 if (trig->active) {
875 trig->note = MAX(trig->note - 1, NOTE_C_2);
876 clear_trigger(trig_selection_loc);
877 draw_trigger(channel_selection_loc, trig_selection_loc);
878 }
879 } else if (key_tap(KEY_R)) {
880 // Increase note.
881 if (trig->active) {
882 trig->note = MIN( trig->note + 1, NOTE_C_8);
883 clear_trigger(trig_selection_loc);
884 draw_trigger(channel_selection_loc, trig_selection_loc);
885 }
886 }
887
888 // Move trigger cursor.
889 if (key_tap(KEY_LEFT)) {
890 if (trig_selection_loc == 0 || trig_selection_loc == 8) {
891 // We are at the boundary, switch to channel selection.
892 draw_trig_cursor(trig_selection_loc, COL_BG);
893 input_handler = handle_channel_selection;
894 draw_channel_cursor(channel_selection_loc, COL_BLUE);
895 } else {
896 draw_trig_cursor(trig_selection_loc, COL_BG);
897 trig_selection_loc = MAX(trig_selection_loc - 1, 0);
898 draw_trig_cursor(trig_selection_loc, COL_BLUE);
899 }
900 } else if (key_tap(KEY_RIGHT)) {
901 if (trig_selection_loc != 7) {
902 draw_trig_cursor(trig_selection_loc, COL_BG);
903 trig_selection_loc = MIN(trig_selection_loc + 1, 15);
904 draw_trig_cursor(trig_selection_loc, COL_BLUE);
905 }
906 } else if (key_tap(KEY_UP) || key_tap(KEY_DOWN)) {
907 draw_trig_cursor(trig_selection_loc, COL_BG);
908 trig_selection_loc = (trig_selection_loc + 8) % 16;
909 draw_trig_cursor(trig_selection_loc, COL_BLUE);
910 } else if (key_tap(KEY_A)) {
911 // Switch to parameter selection.
912 switch (channel_selection_loc) {
913 case 0: {
914 input_handler = handle_param_selection_ch1;
915 } break;
916 case 1: {
917 input_handler = handle_param_selection_ch2;
918 } break;
919 case 2: {
920 input_handler = handle_param_selection_ch3;
921 } break;
922 }
923 // TODO: draw param cursor.
924 draw_trig_cursor(trig_selection_loc, COL_GREY);
925 }
926}
927
928void
929handle_sequencer_input(void) {
930 poll_keys();
931 input_handler();
832 932
833 if (key_tap(KEY_START)) { 933 if (key_tap(KEY_START)) {
834 // Stop the sequencer or start playing from the beginning. 934 // Stop the sequencer or start playing from the beginning.
@@ -865,7 +965,8 @@ sequencer_init(void) {
865 draw_channels(); 965 draw_channels();
866 966
867 // Initialize input handler. 967 // Initialize input handler.
868 input_handler = handle_trigger_cursor; 968 channel_selection_loc = 2; // DEBUG: Starting on CH3
969 input_handler = handle_trigger_selection;
869 draw_trig_cursor(trig_selection_loc, 3); 970 draw_trig_cursor(trig_selection_loc, 3);
870 draw_channel_cursor(channel_selection_loc, 5); 971 draw_channel_cursor(channel_selection_loc, 5);
871 972