diff options
Diffstat (limited to 'src/sequencer.c')
-rw-r--r-- | src/sequencer.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/src/sequencer.c b/src/sequencer.c index 266db94..512555a 100644 --- a/src/sequencer.c +++ b/src/sequencer.c | |||
@@ -805,13 +805,12 @@ handle_pattern_chain(void) { | |||
805 | switch (param_selection_loc) { | 805 | switch (param_selection_loc) { |
806 | case CHAIN_BTN_ENABLE: { | 806 | case CHAIN_BTN_ENABLE: { |
807 | chain.enabled ^= 1; | 807 | chain.enabled ^= 1; |
808 | chain.current = 15; | 808 | chain.playing ^= 1; |
809 | chain.current = find_next_pattern(); | ||
810 | chain.playing = false; | ||
811 | } break; | 809 | } break; |
812 | case CHAIN_BTN_CLEAR: { | 810 | case CHAIN_BTN_CLEAR: { |
813 | chain.len = 0; | 811 | chain.len = 0; |
814 | chain.playing = false; | 812 | chain.playing = false; |
813 | chain.enabled = 0; | ||
815 | for (size_t i = 0; i < MAX_CHAIN; i++) { | 814 | for (size_t i = 0; i < MAX_CHAIN; i++) { |
816 | chain.active[i] = false; | 815 | chain.active[i] = false; |
817 | chain.chain[i] = 0; | 816 | chain.chain[i] = 0; |
@@ -821,18 +820,49 @@ handle_pattern_chain(void) { | |||
821 | } break; | 820 | } break; |
822 | case CHAIN_BTN_RANDOM: { | 821 | case CHAIN_BTN_RANDOM: { |
823 | u8 cur = chain.current % 16; | 822 | u8 cur = chain.current % 16; |
823 | chain.len = 0; | ||
824 | for (size_t i = 0; i < MAX_CHAIN; i++) { | 824 | for (size_t i = 0; i < MAX_CHAIN; i++) { |
825 | if (i == cur && chain.playing) { | 825 | if (i == cur && chain.playing) { |
826 | chain.len++; | ||
826 | continue; | 827 | continue; |
827 | } | 828 | } |
828 | if (rng16() < 32765) { | 829 | if (rng16() < 32765) { |
830 | u16 idx = 0; | ||
831 | for (size_t i = 0; i < 8; i++) { | ||
832 | u16 val = rng16(); | ||
833 | if (val < 1 * 65530 / 8 && !patterns[0].empty) { idx = 0; break; } | ||
834 | if (val < 2 * 65530 / 8 && !patterns[1].empty) { idx = 1; break; } | ||
835 | if (val < 3 * 65530 / 8 && !patterns[2].empty) { idx = 2; break; } | ||
836 | if (val < 4 * 65530 / 8 && !patterns[3].empty) { idx = 3; break; } | ||
837 | if (val < 5 * 65530 / 8 && !patterns[4].empty) { idx = 4; break; } | ||
838 | if (val < 6 * 65530 / 8 && !patterns[5].empty) { idx = 5; break; } | ||
839 | if (val < 7 * 65530 / 8 && !patterns[6].empty) { idx = 6; break; } | ||
840 | if (val < 8 * 65530 / 8 && !patterns[7].empty) { idx = 7; break; } | ||
841 | } | ||
842 | chain.chain[i] = idx; | ||
843 | if (!chain.playing && chain.len == 0) { | ||
844 | chain.chain[i] = current_pattern; | ||
845 | chain.current = current_pattern; | ||
846 | } | ||
829 | chain.active[i] = true; | 847 | chain.active[i] = true; |
848 | chain.len++; | ||
830 | } else { | 849 | } else { |
831 | chain.active[i] = false; | 850 | chain.active[i] = false; |
832 | } | 851 | } |
833 | // NOTE: Should we also randomize the patterns or isn't it | ||
834 | // necessary? | ||
835 | } | 852 | } |
853 | |||
854 | // Make sure at least one chain step is set. | ||
855 | if (chain.len == 0) { | ||
856 | chain.chain[0] = current_pattern; | ||
857 | chain.active[0] = true; | ||
858 | chain.len++; | ||
859 | } | ||
860 | if (!chain.playing) { | ||
861 | chain.current = 15; | ||
862 | chain.current = find_next_pattern(); | ||
863 | } | ||
864 | chain.enabled = 1; | ||
865 | chain.playing = true; | ||
836 | } break; | 866 | } break; |
837 | default: { | 867 | default: { |
838 | if (chain.active[param_selection_loc]) { | 868 | if (chain.active[param_selection_loc]) { |
@@ -902,6 +932,7 @@ handle_pattern_selection(void) { | |||
902 | input_handler = handle_pattern_chain; | 932 | input_handler = handle_pattern_chain; |
903 | } | 933 | } |
904 | if (key_tap(KEY_RIGHT)) { | 934 | if (key_tap(KEY_RIGHT)) { |
935 | param_selection_loc = 0; | ||
905 | input_handler = handle_channel_selection; | 936 | input_handler = handle_channel_selection; |
906 | redraw_params = true; | 937 | redraw_params = true; |
907 | } else if (key_tap(KEY_UP)) { | 938 | } else if (key_tap(KEY_UP)) { |
@@ -922,6 +953,7 @@ handle_pattern_selection(void) { | |||
922 | if (key_tap(KEY_LEFT)) { | 953 | if (key_tap(KEY_LEFT)) { |
923 | redraw_params = true; | 954 | redraw_params = true; |
924 | input_handler = handle_right_col_selection; | 955 | input_handler = handle_right_col_selection; |
956 | param_selection_loc = 0; | ||
925 | right_col_selection_loc = R_COL_BPM; | 957 | right_col_selection_loc = R_COL_BPM; |
926 | switch (pattern_selection_loc) { | 958 | switch (pattern_selection_loc) { |
927 | case 0: { right_col_selection_loc = R_COL_BANK_B; } break; | 959 | case 0: { right_col_selection_loc = R_COL_BANK_B; } break; |
@@ -949,6 +981,7 @@ handle_pattern_selection(void) { | |||
949 | } | 981 | } |
950 | chain.chain[slot] = pattern_selection_loc; | 982 | chain.chain[slot] = pattern_selection_loc; |
951 | chain.active[slot] = 1; | 983 | chain.active[slot] = 1; |
984 | chain.enabled = 1; | ||
952 | chain.len++; | 985 | chain.len++; |
953 | } | 986 | } |
954 | } | 987 | } |
@@ -976,6 +1009,9 @@ handle_pattern_selection(void) { | |||
976 | chain.current = find_prev_pattern(); | 1009 | chain.current = find_prev_pattern(); |
977 | } | 1010 | } |
978 | } | 1011 | } |
1012 | if (chain.len == 0) { | ||
1013 | chain.enabled = 0; | ||
1014 | } | ||
979 | } | 1015 | } |
980 | } | 1016 | } |
981 | 1017 | ||