aboutsummaryrefslogtreecommitdiffstats
path: root/src/sequencer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sequencer.c')
-rw-r--r--src/sequencer.c104
1 files changed, 75 insertions, 29 deletions
diff --git a/src/sequencer.c b/src/sequencer.c
index 8f2b183..1280f5f 100644
--- a/src/sequencer.c
+++ b/src/sequencer.c
@@ -209,6 +209,14 @@ handle_channel_selection(void) {
209 } else if (key_tap(KEY_A)) { 209 } else if (key_tap(KEY_A)) {
210 if (key_hold(KEY_SELECT)) { 210 if (key_hold(KEY_SELECT)) {
211 clipboard_paste(); 211 clipboard_paste();
212 } else {
213 switch (channel_selection_loc) {
214 case 0: { input_handler = handle_param_selection_ch1; } break;
215 case 1: { input_handler = handle_param_selection_ch2; } break;
216 case 2: { input_handler = handle_param_selection_ch3; } break;
217 case 3: { input_handler = handle_param_selection_ch4; } break;
218 }
219 redraw_params = true;
212 } 220 }
213 } else if (key_tap(KEY_L)) { 221 } else if (key_tap(KEY_L)) {
214 s32 inc = -1; 222 s32 inc = -1;
@@ -222,6 +230,7 @@ handle_channel_selection(void) {
222 case 1: { trig = &pat->ch2.notes[i]; } break; 230 case 1: { trig = &pat->ch2.notes[i]; } break;
223 case 2: { trig = &pat->ch3.notes[i]; } break; 231 case 2: { trig = &pat->ch3.notes[i]; } break;
224 case 3: { trig = &pat->ch4.notes[i]; } break; 232 case 3: { trig = &pat->ch4.notes[i]; } break;
233 default: {trig = &pat->ch1.notes[i]; } break;
225 } 234 }
226 trig->note = MAX((s32)trig->note + inc, (s32)NOTE_C_2); 235 trig->note = MAX((s32)trig->note + inc, (s32)NOTE_C_2);
227 } 236 }
@@ -238,6 +247,7 @@ handle_channel_selection(void) {
238 case 1: { trig = &pat->ch2.notes[i]; } break; 247 case 1: { trig = &pat->ch2.notes[i]; } break;
239 case 2: { trig = &pat->ch3.notes[i]; } break; 248 case 2: { trig = &pat->ch3.notes[i]; } break;
240 case 3: { trig = &pat->ch4.notes[i]; } break; 249 case 3: { trig = &pat->ch4.notes[i]; } break;
250 default: {trig = &pat->ch1.notes[i]; } break;
241 } 251 }
242 trig->note = MIN((s32)trig->note + inc, (s32)NOTE_C_8 - 1); 252 trig->note = MIN((s32)trig->note + inc, (s32)NOTE_C_8 - 1);
243 } 253 }
@@ -258,6 +268,7 @@ handle_channel_selection(void) {
258 channel_selection_loc = MAX(channel_selection_loc - 1, 0); 268 channel_selection_loc = MAX(channel_selection_loc - 1, 0);
259 } 269 }
260 redraw_trigs = true; 270 redraw_trigs = true;
271 redraw_params = true;
261 } else if (key_tap(KEY_DOWN)) { 272 } else if (key_tap(KEY_DOWN)) {
262 if (channel_selection_loc == SEQ_N_CHANNELS - 1) { 273 if (channel_selection_loc == SEQ_N_CHANNELS - 1) {
263 channel_selection_loc = 0; 274 channel_selection_loc = 0;
@@ -265,6 +276,7 @@ handle_channel_selection(void) {
265 channel_selection_loc = MIN(channel_selection_loc + 1, SEQ_N_CHANNELS); 276 channel_selection_loc = MIN(channel_selection_loc + 1, SEQ_N_CHANNELS);
266 } 277 }
267 redraw_trigs = true; 278 redraw_trigs = true;
279 redraw_params = true;
268 } 280 }
269} 281}
270 282
@@ -457,10 +469,10 @@ handle_pattern_selection(void) {
457} 469}
458 470
459void 471void
460handle_param_selection_sq1(void) { 472set_param_selection_sq1(size_t i, InputHandler return_handler) {
461 // Go back to trigger selection. 473 // Go back to trigger selection.
462 if (key_released(KEY_A)) { 474 if (key_released(KEY_A)) {
463 input_handler = handle_trigger_selection; 475 input_handler = return_handler;
464 redraw_params = true; 476 redraw_params = true;
465 return; 477 return;
466 } 478 }
@@ -518,7 +530,7 @@ handle_param_selection_sq1(void) {
518 inc = 1; 530 inc = 1;
519 } 531 }
520 Pattern *pat = &patterns[pattern_selection_loc]; 532 Pattern *pat = &patterns[pattern_selection_loc];
521 ChannelSquareParams *params = &pat->ch1.params[trig_selection_loc]; 533 ChannelSquareParams *params = &pat->ch1.params[i];
522 switch (param_selection_loc) { 534 switch (param_selection_loc) {
523 case 0: { 535 case 0: {
524 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); 536 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3);
@@ -547,10 +559,10 @@ handle_param_selection_sq1(void) {
547} 559}
548 560
549void 561void
550handle_param_selection_sq2(void) { 562set_param_selection_sq2(size_t i, InputHandler return_handler) {
551 // Go back to trigger selection. 563 // Go back to trigger selection.
552 if (key_released(KEY_A)) { 564 if (key_released(KEY_A)) {
553 input_handler = handle_trigger_selection; 565 input_handler = return_handler;
554 redraw_params = true; 566 redraw_params = true;
555 return; 567 return;
556 } 568 }
@@ -577,7 +589,7 @@ handle_param_selection_sq2(void) {
577 inc = 1; 589 inc = 1;
578 } 590 }
579 Pattern *pat = &patterns[pattern_selection_loc]; 591 Pattern *pat = &patterns[pattern_selection_loc];
580 ChannelSquareParams *params = &pat->ch2.params[trig_selection_loc]; 592 ChannelSquareParams *params = &pat->ch2.params[i];
581 switch (param_selection_loc) { 593 switch (param_selection_loc) {
582 case 0: { 594 case 0: {
583 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3); 595 params->duty_cycle = CLAMP(params->duty_cycle + inc, 0, 3);
@@ -597,12 +609,12 @@ handle_param_selection_sq2(void) {
597} 609}
598 610
599void 611void
600handle_param_selection_wave(void) { 612set_param_selection_wave(size_t i, InputHandler return_handler) {
601 Pattern *pat = &patterns[pattern_selection_loc]; 613 Pattern *pat = &patterns[pattern_selection_loc];
602 614
603 // Go back to trigger selection. 615 // Go back to trigger selection.
604 if (key_released(KEY_A)) { 616 if (key_released(KEY_A)) {
605 input_handler = handle_trigger_selection; 617 input_handler = return_handler;
606 redraw_params = true; 618 redraw_params = true;
607 return; 619 return;
608 } 620 }
@@ -706,7 +718,7 @@ handle_param_selection_wave(void) {
706 if (param_selection_loc < 32) { 718 if (param_selection_loc < 32) {
707 // Draw on wave a. 719 // Draw on wave a.
708 u8 byte_number = param_selection_loc / 2; 720 u8 byte_number = param_selection_loc / 2;
709 u8 *byte = &pat->ch3.params[trig_selection_loc].wave_a; 721 u8 *byte = &pat->ch3.params[i].wave_a;
710 byte += byte_number; 722 byte += byte_number;
711 if (odd) { 723 if (odd) {
712 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); 724 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF);
@@ -716,7 +728,7 @@ handle_param_selection_wave(void) {
716 } else if (param_selection_loc < 64){ 728 } else if (param_selection_loc < 64){
717 // Draw on wave b. 729 // Draw on wave b.
718 u8 byte_number = (param_selection_loc - 32) / 2; 730 u8 byte_number = (param_selection_loc - 32) / 2;
719 u8 *byte = &pat->ch3.params[trig_selection_loc].wave_b; 731 u8 *byte = &pat->ch3.params[i].wave_b;
720 byte += byte_number; 732 byte += byte_number;
721 if (odd) { 733 if (odd) {
722 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF); 734 *byte = (~0xF & *byte) | ((*byte + inc) & 0xF);
@@ -725,8 +737,8 @@ handle_param_selection_wave(void) {
725 } 737 }
726 } else if (param_selection_loc < 72) { 738 } else if (param_selection_loc < 72) {
727 // Copy default waves. 739 // Copy default waves.
728 u32 *wave_a = &pat->ch3.params[trig_selection_loc].wave_a; 740 u32 *wave_a = &pat->ch3.params[i].wave_a;
729 u32 *wave_b = &pat->ch3.params[trig_selection_loc].wave_b; 741 u32 *wave_b = &pat->ch3.params[i].wave_b;
730 switch (param_selection_loc) { 742 switch (param_selection_loc) {
731 case 64: { 743 case 64: {
732 memcpy32(wave_a, sine_wave, 16); 744 memcpy32(wave_a, sine_wave, 16);
@@ -760,10 +772,10 @@ handle_param_selection_wave(void) {
760 } break; 772 } break;
761 } 773 }
762 } else if (param_selection_loc == 72) { 774 } else if (param_selection_loc == 72) {
763 u8 *wave_mode = &pat->ch3.params[trig_selection_loc].wave_mode; 775 u8 *wave_mode = &pat->ch3.params[i].wave_mode;
764 *wave_mode = CLAMP(*wave_mode + inc, 0, 2); 776 *wave_mode = CLAMP(*wave_mode + inc, 0, 2);
765 } else if (param_selection_loc == 73) { 777 } else if (param_selection_loc == 73) {
766 u8 *wave_volume = &pat->ch3.params[trig_selection_loc].wave_volume; 778 u8 *wave_volume = &pat->ch3.params[i].wave_volume;
767 *wave_volume = CLAMP(*wave_volume + inc, 0, 4); 779 *wave_volume = CLAMP(*wave_volume + inc, 0, 4);
768 } 780 }
769 redraw_params = true; 781 redraw_params = true;
@@ -771,10 +783,11 @@ handle_param_selection_wave(void) {
771} 783}
772 784
773void 785void
774handle_param_selection_noise(void) { 786set_param_selection_noise(size_t i, InputHandler return_handler) {
775 // Go back to trigger selection. 787 // Go back to trigger selection.
776 if (key_released(KEY_A)) { 788 if (key_released(KEY_A)) {
777 input_handler = handle_trigger_selection; 789 input_handler = return_handler;
790 redraw_params = true;
778 return; 791 return;
779 } 792 }
780 793
@@ -788,6 +801,7 @@ handle_param_selection_noise(void) {
788 inc = -1; 801 inc = -1;
789 } 802 }
790 param_selection_loc = CLAMP(loc + inc, 0, 3); 803 param_selection_loc = CLAMP(loc + inc, 0, 3);
804 redraw_params = true;
791 } 805 }
792 806
793 // Adjust parameter. 807 // Adjust parameter.
@@ -799,7 +813,7 @@ handle_param_selection_noise(void) {
799 inc = 1; 813 inc = 1;
800 } 814 }
801 Pattern *pat = &patterns[pattern_selection_loc]; 815 Pattern *pat = &patterns[pattern_selection_loc];
802 ChannelNoiseParams *params = &pat->ch4.params[trig_selection_loc]; 816 ChannelNoiseParams *params = &pat->ch4.params[i];
803 switch (param_selection_loc) { 817 switch (param_selection_loc) {
804 case 0: { 818 case 0: {
805 params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1); 819 params->bit_mode = CLAMP(params->bit_mode + inc, 0, 1);
@@ -819,6 +833,46 @@ handle_param_selection_noise(void) {
819} 833}
820 834
821void 835void
836handle_param_selection_ch1() {
837 set_param_selection_sq1(16, handle_channel_selection);
838}
839
840void
841handle_param_selection_ch2() {
842 set_param_selection_sq2(16, handle_channel_selection);
843}
844
845void
846handle_param_selection_ch3() {
847 set_param_selection_wave(16, handle_channel_selection);
848}
849
850void
851handle_param_selection_ch4() {
852 set_param_selection_noise(16, handle_channel_selection);
853}
854
855void
856handle_param_selection_sq1() {
857 set_param_selection_sq1(trig_selection_loc, handle_trigger_selection);
858}
859
860void
861handle_param_selection_sq2() {
862 set_param_selection_sq2(trig_selection_loc, handle_trigger_selection);
863}
864
865void
866handle_param_selection_wave() {
867 set_param_selection_wave(trig_selection_loc, handle_trigger_selection);
868}
869
870void
871handle_param_selection_noise() {
872 set_param_selection_noise(trig_selection_loc, handle_trigger_selection);
873}
874
875void
822handle_trigger_selection(void) { 876handle_trigger_selection(void) {
823 TriggerNote *trig = get_current_trig(); 877 TriggerNote *trig = get_current_trig();
824 878
@@ -886,18 +940,10 @@ handle_trigger_selection(void) {
886 } else { 940 } else {
887 // Switch to parameter selection. 941 // Switch to parameter selection.
888 switch (channel_selection_loc) { 942 switch (channel_selection_loc) {
889 case 0: { 943 case 0: { input_handler = handle_param_selection_sq1; } break;
890 input_handler = handle_param_selection_sq1; 944 case 1: { input_handler = handle_param_selection_sq2; } break;
891 } break; 945 case 2: { input_handler = handle_param_selection_wave; } break;
892 case 1: { 946 case 3: { input_handler = handle_param_selection_noise; } break;
893 input_handler = handle_param_selection_sq2;
894 } break;
895 case 2: {
896 input_handler = handle_param_selection_wave;
897 } break;
898 case 3: {
899 input_handler = handle_param_selection_noise;
900 } break;
901 } 947 }
902 redraw_params = true; 948 redraw_params = true;
903 redraw_piano_note = true; 949 redraw_piano_note = true;