diff options
author | Bad Diode <bd@badd10de.dev> | 2023-08-22 12:28:10 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-08-22 12:28:10 +0200 |
commit | e5d61a87ec41443a2e32cd8be1ecc62b8c590251 (patch) | |
tree | 26b832481fcb0e93d843e9fe5d4f875e2e5d2232 /src/sequencer.c | |
parent | 8fc5cc7f53ea3874bae5389f489814869d2abd04 (diff) | |
download | stepper-e5d61a87ec41443a2e32cd8be1ecc62b8c590251.tar.gz stepper-e5d61a87ec41443a2e32cd8be1ecc62b8c590251.zip |
Add pattern clearing with SEL+L+R on pattern view
Diffstat (limited to 'src/sequencer.c')
-rw-r--r-- | src/sequencer.c | 80 |
1 files changed, 64 insertions, 16 deletions
diff --git a/src/sequencer.c b/src/sequencer.c index 4e3802f..3110c74 100644 --- a/src/sequencer.c +++ b/src/sequencer.c | |||
@@ -20,6 +20,22 @@ bool update_bpm = false; | |||
20 | u8 bar_counter = 0; | 20 | u8 bar_counter = 0; |
21 | 21 | ||
22 | void | 22 | void |
23 | clear_pattern(size_t idx) { | ||
24 | Pattern *pat = &patterns[idx]; | ||
25 | *pat = (Pattern){default_ch1, default_ch2, default_ch3, default_ch4, default_bpm, 0, false}; | ||
26 | for (size_t i = 0; i < 16; i++) { | ||
27 | pat->ch1.notes[i] = (TriggerNote){false, NOTE_C_4}; | ||
28 | pat->ch2.notes[i] = (TriggerNote){false, NOTE_C_4}; | ||
29 | pat->ch3.notes[i] = (TriggerNote){false, NOTE_C_4}; | ||
30 | pat->ch4.notes[i] = (TriggerNote){false, NOTE_C_4}; | ||
31 | } | ||
32 | redraw_pattern_buttons = true; | ||
33 | redraw_channels = true; | ||
34 | redraw_trigs = true; | ||
35 | redraw_bpm = true; | ||
36 | } | ||
37 | |||
38 | void | ||
23 | gate_off(void) { | 39 | gate_off(void) { |
24 | SIO_MODE = SIO_MODE_GP | 40 | SIO_MODE = SIO_MODE_GP |
25 | | SIO_SC_OUT(1) | 41 | | SIO_SC_OUT(1) |
@@ -117,7 +133,7 @@ play_step(void) { | |||
117 | } | 133 | } |
118 | chain.playing = true; | 134 | chain.playing = true; |
119 | } | 135 | } |
120 | if (pat->ch1.active) { | 136 | if (pat->ch1.active && !pat->empty) { |
121 | TriggerNote *trig = &pat->ch1.notes[step_counter]; | 137 | TriggerNote *trig = &pat->ch1.notes[step_counter]; |
122 | ChannelSquareParams *params = &pat->ch1.params[step_counter]; | 138 | ChannelSquareParams *params = &pat->ch1.params[step_counter]; |
123 | if (trig->active && should_play(params->prob)) { | 139 | if (trig->active && should_play(params->prob)) { |
@@ -162,7 +178,7 @@ play_step(void) { | |||
162 | SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET; | 178 | SOUND_SQUARE1_FREQ = SOUND_FREQ_RESET; |
163 | SOUND_SQUARE1_CTRL = 0; | 179 | SOUND_SQUARE1_CTRL = 0; |
164 | } | 180 | } |
165 | if (pat->ch2.active) { | 181 | if (pat->ch2.active && !pat->empty) { |
166 | TriggerNote *trig = &pat->ch2.notes[step_counter]; | 182 | TriggerNote *trig = &pat->ch2.notes[step_counter]; |
167 | ChannelSquareParams *params = &pat->ch2.params[step_counter]; | 183 | ChannelSquareParams *params = &pat->ch2.params[step_counter]; |
168 | if (trig->active && should_play(params->prob)) { | 184 | if (trig->active && should_play(params->prob)) { |
@@ -188,7 +204,7 @@ play_step(void) { | |||
188 | SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET; | 204 | SOUND_SQUARE2_FREQ = SOUND_FREQ_RESET; |
189 | SOUND_SQUARE2_CTRL = 0; | 205 | SOUND_SQUARE2_CTRL = 0; |
190 | } | 206 | } |
191 | if (pat->ch3.active) { | 207 | if (pat->ch3.active && !pat->empty) { |
192 | TriggerNote *trig = &pat->ch3.notes[step_counter]; | 208 | TriggerNote *trig = &pat->ch3.notes[step_counter]; |
193 | ChannelWaveParams *params = &pat->ch3.params[step_counter]; | 209 | ChannelWaveParams *params = &pat->ch3.params[step_counter]; |
194 | if (trig->active && should_play(params->prob)) { | 210 | if (trig->active && should_play(params->prob)) { |
@@ -237,7 +253,7 @@ play_step(void) { | |||
237 | SOUND_WAVE_FREQ = SOUND_FREQ_RESET; | 253 | SOUND_WAVE_FREQ = SOUND_FREQ_RESET; |
238 | SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; | 254 | SOUND_WAVE_CTRL = SOUND_WAVE_MUTE; |
239 | } | 255 | } |
240 | if (pat->ch4.active) { | 256 | if (pat->ch4.active && !pat->empty) { |
241 | TriggerNote *trig = &pat->ch4.notes[step_counter]; | 257 | TriggerNote *trig = &pat->ch4.notes[step_counter]; |
242 | ChannelNoiseParams *params = &pat->ch4.params[step_counter]; | 258 | ChannelNoiseParams *params = &pat->ch4.params[step_counter]; |
243 | if (trig->active && should_play(params->prob)) { | 259 | if (trig->active && should_play(params->prob)) { |
@@ -347,6 +363,9 @@ handle_channel_selection(void) { | |||
347 | if (key_hold(KEY_SELECT)) { | 363 | if (key_hold(KEY_SELECT)) { |
348 | clipboard_copy(); | 364 | clipboard_copy(); |
349 | } else { | 365 | } else { |
366 | if (patterns[pattern_selection_loc].empty) { | ||
367 | clear_pattern(pattern_selection_loc); | ||
368 | } | ||
350 | switch (channel_selection_loc) { | 369 | switch (channel_selection_loc) { |
351 | case 0: { pat->ch1.active ^= 1; } break; | 370 | case 0: { pat->ch1.active ^= 1; } break; |
352 | case 1: { pat->ch2.active ^= 1; } break; | 371 | case 1: { pat->ch2.active ^= 1; } break; |
@@ -358,6 +377,10 @@ handle_channel_selection(void) { | |||
358 | } else if (key_tap(KEY_A)) { | 377 | } else if (key_tap(KEY_A)) { |
359 | if (key_hold(KEY_SELECT)) { | 378 | if (key_hold(KEY_SELECT)) { |
360 | clipboard_paste(); | 379 | clipboard_paste(); |
380 | redraw_bpm = true; | ||
381 | redraw_trigs = true; | ||
382 | redraw_channels = true; | ||
383 | redraw_pattern_buttons = true; | ||
361 | } else { | 384 | } else { |
362 | switch (channel_selection_loc) { | 385 | switch (channel_selection_loc) { |
363 | case 0: { input_handler = handle_param_selection_ch1; } break; | 386 | case 0: { input_handler = handle_param_selection_ch1; } break; |
@@ -645,6 +668,9 @@ handle_right_col_selection(void) { | |||
645 | set_time(patterns[current_pattern].bpm); | 668 | set_time(patterns[current_pattern].bpm); |
646 | } | 669 | } |
647 | redraw_bpm = true; | 670 | redraw_bpm = true; |
671 | if (patterns[pattern_selection_loc].empty) { | ||
672 | clear_pattern(pattern_selection_loc); | ||
673 | } | ||
648 | } break; | 674 | } break; |
649 | // TODO: Scale. | 675 | // TODO: Scale. |
650 | } | 676 | } |
@@ -664,6 +690,9 @@ handle_right_col_selection(void) { | |||
664 | set_time(patterns[current_pattern].bpm); | 690 | set_time(patterns[current_pattern].bpm); |
665 | } | 691 | } |
666 | redraw_bpm = true; | 692 | redraw_bpm = true; |
693 | if (patterns[pattern_selection_loc].empty) { | ||
694 | clear_pattern(pattern_selection_loc); | ||
695 | } | ||
667 | } break; | 696 | } break; |
668 | // TODO: Scale. | 697 | // TODO: Scale. |
669 | } | 698 | } |
@@ -748,20 +777,32 @@ handle_pattern_chain(void) { | |||
748 | 777 | ||
749 | void | 778 | void |
750 | handle_pattern_selection(void) { | 779 | handle_pattern_selection(void) { |
751 | if (key_tap(KEY_B)) { | 780 | if (key_hold(KEY_SELECT)) { |
752 | if (key_hold(KEY_SELECT)) { | 781 | if ((key_pressed(KEY_L) && key_tap(KEY_R)) |
782 | || (key_pressed(KEY_R) && key_tap(KEY_L))) { | ||
783 | patterns[pattern_selection_loc].empty ^= 1; | ||
784 | redraw_pattern_buttons = true; | ||
785 | redraw_channels = true; | ||
786 | redraw_trigs = true; | ||
787 | } | ||
788 | if (key_tap(KEY_B)) { | ||
753 | clipboard_copy(); | 789 | clipboard_copy(); |
754 | } else { | 790 | } |
755 | next_pattern = pattern_selection_loc; | 791 | if (key_tap(KEY_A)) { |
792 | clipboard_paste(); | ||
793 | redraw_bpm = true; | ||
794 | redraw_trigs = true; | ||
795 | redraw_channels = true; | ||
756 | redraw_pattern_buttons = true; | 796 | redraw_pattern_buttons = true; |
757 | } | 797 | } |
798 | return; | ||
799 | } | ||
800 | if (key_tap(KEY_B)) { | ||
801 | next_pattern = pattern_selection_loc; | ||
802 | redraw_pattern_buttons = true; | ||
758 | } | 803 | } |
759 | if (key_tap(KEY_A)) { | 804 | if (key_tap(KEY_A)) { |
760 | if (key_hold(KEY_SELECT)) { | 805 | input_handler = handle_pattern_chain; |
761 | clipboard_paste(); | ||
762 | } else { | ||
763 | input_handler = handle_pattern_chain; | ||
764 | } | ||
765 | } | 806 | } |
766 | if (key_tap(KEY_RIGHT)) { | 807 | if (key_tap(KEY_RIGHT)) { |
767 | input_handler = handle_channel_selection; | 808 | input_handler = handle_channel_selection; |
@@ -1214,11 +1255,14 @@ void | |||
1214 | handle_trigger_selection(void) { | 1255 | handle_trigger_selection(void) { |
1215 | TriggerNote *trig = get_current_trig(); | 1256 | TriggerNote *trig = get_current_trig(); |
1216 | 1257 | ||
1258 | bool empty = patterns[pattern_selection_loc].empty; | ||
1217 | if (key_tap(KEY_B)) { | 1259 | if (key_tap(KEY_B)) { |
1218 | if (key_hold(KEY_SELECT)) { | 1260 | if (key_hold(KEY_SELECT)) { |
1219 | clipboard_copy(); | 1261 | clipboard_copy(); |
1220 | } else { | 1262 | } else { |
1221 | // Toggle trigger. | 1263 | if (empty) { |
1264 | clear_pattern(pattern_selection_loc); | ||
1265 | } | ||
1222 | trig->active ^= 1; | 1266 | trig->active ^= 1; |
1223 | redraw_trigs = true; | 1267 | redraw_trigs = true; |
1224 | } | 1268 | } |
@@ -1228,7 +1272,7 @@ handle_trigger_selection(void) { | |||
1228 | inc = -12; | 1272 | inc = -12; |
1229 | } | 1273 | } |
1230 | // Decrease note. | 1274 | // Decrease note. |
1231 | if (trig->active) { | 1275 | if (trig->active && !empty) { |
1232 | trig->note = MAX((s32)trig->note + inc, (s32)NOTE_C_2); | 1276 | trig->note = MAX((s32)trig->note + inc, (s32)NOTE_C_2); |
1233 | } | 1277 | } |
1234 | redraw_trigs = true; | 1278 | redraw_trigs = true; |
@@ -1239,7 +1283,7 @@ handle_trigger_selection(void) { | |||
1239 | inc = 12; | 1283 | inc = 12; |
1240 | } | 1284 | } |
1241 | // Increase note. | 1285 | // Increase note. |
1242 | if (trig->active) { | 1286 | if (trig->active && !empty) { |
1243 | trig->note = MIN((s32)trig->note + inc, (s32)NOTE_C_8 - 1); | 1287 | trig->note = MIN((s32)trig->note + inc, (s32)NOTE_C_8 - 1); |
1244 | } | 1288 | } |
1245 | redraw_trigs = true; | 1289 | redraw_trigs = true; |
@@ -1275,6 +1319,10 @@ handle_trigger_selection(void) { | |||
1275 | } else if (key_tap(KEY_A)) { | 1319 | } else if (key_tap(KEY_A)) { |
1276 | if (key_hold(KEY_SELECT)) { | 1320 | if (key_hold(KEY_SELECT)) { |
1277 | clipboard_paste(); | 1321 | clipboard_paste(); |
1322 | redraw_bpm = true; | ||
1323 | redraw_trigs = true; | ||
1324 | redraw_channels = true; | ||
1325 | redraw_pattern_buttons = true; | ||
1278 | } else { | 1326 | } else { |
1279 | // Switch to parameter selection. | 1327 | // Switch to parameter selection. |
1280 | switch (channel_selection_loc) { | 1328 | switch (channel_selection_loc) { |