aboutsummaryrefslogtreecommitdiffstats
path: root/src/sequencer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sequencer.c')
-rw-r--r--src/sequencer.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index 397d6f9..9c92ef0 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -462,7 +462,7 @@ handle_pattern_selection(void) {
462} 462}
463 463
464bool 464bool
465set_param_selection_sq1(size_t i, InputHandler return_handler) { 465set_param_selection_sq1(ChannelSquareParams *params, InputHandler return_handler) {
466 // Go back to trigger selection. 466 // Go back to trigger selection.
467 if (key_released(KEY_A)) { 467 if (key_released(KEY_A)) {
468 input_handler = return_handler; 468 input_handler = return_handler;
@@ -525,8 +525,6 @@ set_param_selection_sq1(size_t i, InputHandler return_handler) {
525 } else { 525 } else {
526 inc = 1; 526 inc = 1;
527 } 527 }
528 Pattern *pat = &patterns[pattern_selection_loc];
529 ChannelSquareParams *params = &pat->ch1.params[i];
530 switch (param_selection_loc) { 528 switch (param_selection_loc) {
531 case 0: { 529 case 0: {
532 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); 530 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3);
@@ -558,7 +556,7 @@ set_param_selection_sq1(size_t i, InputHandler return_handler) {
558} 556}
559 557
560bool 558bool
561set_param_selection_sq2(size_t i, InputHandler return_handler) { 559set_param_selection_sq2(ChannelSquareParams *params, InputHandler return_handler) {
562 // Go back to trigger selection. 560 // Go back to trigger selection.
563 if (key_released(KEY_A)) { 561 if (key_released(KEY_A)) {
564 input_handler = return_handler; 562 input_handler = return_handler;
@@ -588,8 +586,6 @@ set_param_selection_sq2(size_t i, InputHandler return_handler) {
588 } else { 586 } else {
589 inc = 1; 587 inc = 1;
590 } 588 }
591 Pattern *pat = &patterns[pattern_selection_loc];
592 ChannelSquareParams *params = &pat->ch2.params[i];
593 switch (param_selection_loc) { 589 switch (param_selection_loc) {
594 case 0: { 590 case 0: {
595 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); 591 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3);
@@ -612,9 +608,7 @@ set_param_selection_sq2(size_t i, InputHandler return_handler) {
612} 608}
613 609
614bool 610bool
615set_param_selection_wave(size_t i, InputHandler return_handler) { 611set_param_selection_wave(ChannelWaveParams *params, InputHandler return_handler) {
616 Pattern *pat = &patterns[pattern_selection_loc];
617
618 // Go back to trigger selection. 612 // Go back to trigger selection.
619 if (key_released(KEY_A)) { 613 if (key_released(KEY_A)) {
620 input_handler = return_handler; 614 input_handler = return_handler;
@@ -724,7 +718,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
724 if (param_selection_loc < 32) { 718 if (param_selection_loc < 32) {
725 // Draw on wave a. 719 // Draw on wave a.
726 u8 byte_number = param_selection_loc / 2; 720 u8 byte_number = param_selection_loc / 2;
727 u8 *byte = &pat->ch3.params[i].wave_a; 721 u8 *byte = &params->wave_a;
728 byte += byte_number; 722 byte += byte_number;
729 if (odd) { 723 if (odd) {
730 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); 724 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF);
@@ -734,7 +728,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
734 } else if (param_selection_loc < 64){ 728 } else if (param_selection_loc < 64){
735 // Draw on wave b. 729 // Draw on wave b.
736 u8 byte_number = (param_selection_loc - 32) / 2; 730 u8 byte_number = (param_selection_loc - 32) / 2;
737 u8 *byte = &pat->ch3.params[i].wave_b; 731 u8 *byte = &params->wave_b;
738 byte += byte_number; 732 byte += byte_number;
739 if (odd) { 733 if (odd) {
740 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); 734 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF);
@@ -743,8 +737,8 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
743 } 737 }
744 } else if (param_selection_loc < 72) { 738 } else if (param_selection_loc < 72) {
745 // Copy default waves. 739 // Copy default waves.
746 u32 *wave_a = &pat->ch3.params[i].wave_a; 740 u32 *wave_a = &params->wave_a;
747 u32 *wave_b = &pat->ch3.params[i].wave_b; 741 u32 *wave_b = &params->wave_b;
748 switch (param_selection_loc) { 742 switch (param_selection_loc) {
749 case 64: { memcpy32(wave_a, sine_wave, 16); } break; 743 case 64: { memcpy32(wave_a, sine_wave, 16); } break;
750 case 65: { memcpy32(wave_a, saw_wave, 16); } break; 744 case 65: { memcpy32(wave_a, saw_wave, 16); } break;
@@ -766,10 +760,10 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
766 } break; 760 } break;
767 } 761 }
768 } else if (param_selection_loc == 72) { 762 } else if (param_selection_loc == 72) {
769 u8 *wave_mode = &pat->ch3.params[i].wave_mode; 763 u8 *wave_mode = &params->wave_mode;
770 *wave_mode = CLAMP(*wave_mode + inc, 0, 2); 764 *wave_mode = CLAMP(*wave_mode + inc, 0, 2);
771 } else if (param_selection_loc == 73) { 765 } else if (param_selection_loc == 73) {
772 u8 *wave_volume = &pat->ch3.params[i].wave_volume; 766 u8 *wave_volume = &params->wave_volume;
773 *wave_volume = CLAMP(*wave_volume + inc, 0, 4); 767 *wave_volume = CLAMP(*wave_volume + inc, 0, 4);
774 } 768 }
775 redraw_params = true; 769 redraw_params = true;
@@ -780,7 +774,7 @@ set_param_selection_wave(size_t i, InputHandler return_handler) {
780} 774}
781 775
782bool 776bool
783set_param_selection_noise(size_t i, InputHandler return_handler) { 777set_param_selection_noise(ChannelNoiseParams *params, InputHandler return_handler) {
784 // Go back to trigger selection. 778 // Go back to trigger selection.
785 if (key_released(KEY_A)) { 779 if (key_released(KEY_A)) {
786 input_handler = return_handler; 780 input_handler = return_handler;
@@ -810,8 +804,6 @@ set_param_selection_noise(size_t i, InputHandler return_handler) {
810 } else { 804 } else {
811 inc = 1; 805 inc = 1;
812 } 806 }
813 Pattern *pat = &patterns[pattern_selection_loc];
814 ChannelNoiseParams *params = &pat->ch4.params[i];
815 switch (param_selection_loc) { 807 switch (param_selection_loc) {
816 case 0: { 808 case 0: {
817 params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1); 809 params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1);
@@ -836,9 +828,9 @@ set_param_selection_noise(size_t i, InputHandler return_handler) {
836void 828void
837handle_param_selection_ch1() { 829handle_param_selection_ch1() {
838 Pattern *pat = &patterns[pattern_selection_loc]; 830 Pattern *pat = &patterns[pattern_selection_loc];
839 if (set_param_selection_sq1(16, handle_channel_selection)) { 831 if (set_param_selection_sq1(&ch1_params, handle_channel_selection)) {
840 for (size_t i = 0; i < 16; i++) { 832 for (size_t i = 0; i < 16; i++) {
841 pat->ch1.params[i] = pat->ch1.params[16]; 833 pat->ch1.params[i] = ch1_params;
842 } 834 }
843 } 835 }
844} 836}
@@ -846,9 +838,9 @@ handle_param_selection_ch1() {
846void 838void
847handle_param_selection_ch2() { 839handle_param_selection_ch2() {
848 Pattern *pat = &patterns[pattern_selection_loc]; 840 Pattern *pat = &patterns[pattern_selection_loc];
849 if (set_param_selection_sq2(16, handle_channel_selection)) { 841 if (set_param_selection_sq2(&ch2_params, handle_channel_selection)) {
850 for (size_t i = 0; i < 16; i++) { 842 for (size_t i = 0; i < 16; i++) {
851 pat->ch2.params[i] = pat->ch2.params[16]; 843 pat->ch2.params[i] = ch2_params;
852 } 844 }
853 } 845 }
854} 846}
@@ -856,9 +848,9 @@ handle_param_selection_ch2() {
856void 848void
857handle_param_selection_ch3() { 849handle_param_selection_ch3() {
858 Pattern *pat = &patterns[pattern_selection_loc]; 850 Pattern *pat = &patterns[pattern_selection_loc];
859 if (set_param_selection_wave(16, handle_channel_selection)) { 851 if (set_param_selection_wave(&ch3_params, handle_channel_selection)) {
860 for (size_t i = 0; i < 16; i++) { 852 for (size_t i = 0; i < 16; i++) {
861 pat->ch3.params[i] = pat->ch3.params[16]; 853 pat->ch3.params[i] = ch3_params;
862 } 854 }
863 } 855 }
864} 856}
@@ -866,31 +858,35 @@ handle_param_selection_ch3() {
866void 858void
867handle_param_selection_ch4() { 859handle_param_selection_ch4() {
868 Pattern *pat = &patterns[pattern_selection_loc]; 860 Pattern *pat = &patterns[pattern_selection_loc];
869 if (set_param_selection_noise(16, handle_channel_selection)) { 861 if (set_param_selection_noise(&ch4_params, handle_channel_selection)) {
870 for (size_t i = 0; i < 16; i++) { 862 for (size_t i = 0; i < 16; i++) {
871 pat->ch4.params[i] = pat->ch4.params[16]; 863 pat->ch4.params[i] = ch4_params;
872 } 864 }
873 } 865 }
874} 866}
875 867
876void 868void
877handle_param_selection_sq1() { 869handle_param_selection_sq1() {
878 set_param_selection_sq1(trig_selection_loc, handle_trigger_selection); 870 ChannelSquareParams *params = &patterns[pattern_selection_loc].ch1.params[trig_selection_loc];
871 set_param_selection_sq1(params, handle_trigger_selection);
879} 872}
880 873
881void 874void
882handle_param_selection_sq2() { 875handle_param_selection_sq2() {
883 set_param_selection_sq2(trig_selection_loc, handle_trigger_selection); 876 ChannelSquareParams *params = &patterns[pattern_selection_loc].ch2.params[trig_selection_loc];
877 set_param_selection_sq2(params, handle_trigger_selection);
884} 878}
885 879
886void 880void
887handle_param_selection_wave() { 881handle_param_selection_wave() {
888 set_param_selection_wave(trig_selection_loc, handle_trigger_selection); 882 ChannelWaveParams *params = &patterns[pattern_selection_loc].ch3.params[trig_selection_loc];
883 set_param_selection_wave(params, handle_trigger_selection);
889} 884}
890 885
891void 886void
892handle_param_selection_noise() { 887handle_param_selection_noise() {
893 set_param_selection_noise(trig_selection_loc, handle_trigger_selection); 888 ChannelNoiseParams *params = &patterns[pattern_selection_loc].ch4.params[trig_selection_loc];
889 set_param_selection_noise(params, handle_trigger_selection);
894} 890}
895 891
896void 892void