Skip to content

Commit 8d84faa

Browse files
authored
feat: zeptocore page lock
1 parent f203a08 commit 8d84faa

4 files changed

Lines changed: 104 additions & 37 deletions

File tree

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ dev/sdcards6/
8080
dev/sdcards5/sdcard_timings5.png
8181
ezeptocore.uf2
8282
.codex
83+
dev/sdcards7/gigastone32gb_1.txt
84+
dev/sdcards7/kexing16gb_1.txt
85+
dev/sdcards7/kexing16gb_2.txt
86+
dev/sdcards7/kexing16gb_3.txt
87+
dev/sdcards7/kexing16gb_4.txt
88+
dev/sdcards7/kootion16gb_1.txt
89+
dev/sdcards7/kootion16gb_2.txt
90+
dev/sdcards7/kootion16gb_4.txt
91+
dev/analyze_sdcards7.py
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
+++
2+
title = 'Jump page lock'
3+
date = 2024-02-01T12:33:06-08:00
4+
short = 'Lock jump buttons to a slice page'
5+
buttons = ['D']
6+
weight = 11
7+
mode = 'jump'
8+
icon = 'lock'
9+
+++
10+
11+
In `JUMP` mode, press **D** by itself to cycle where the **1-16** jump buttons point: current page, first page, second page, third page.
12+
13+
The top **C** and **D** lights show the lock: both off follows the current page, **C** is first page, **D** is second page, and both lit is third page. Locked pages wrap around if the sample has fewer slices.

lib/button_handler.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,21 @@ int16_t key_on_buttons_last[BUTTONMATRIX_BUTTONS_MAX];
2121
bool key_did_go_off[BUTTONMATRIX_BUTTONS_MAX];
2222
uint16_t key_num_presses;
2323
bool KEY_C_sample_select = false;
24+
bool jump_page_lock_d_alone_candidate = false;
2425

2526
bool button_is_pressed(uint8_t key) { return key_on_buttons[key] > 0; }
2627

28+
void maybe_toggle_jump_page_lock_on_d_release(uint8_t key) {
29+
if (key != KEY_D) {
30+
return;
31+
}
32+
if (jump_page_lock_d_alone_candidate && mode_buttons16 == MODE_JUMP) {
33+
jump_page_lock = (jump_page_lock + 1) % 4;
34+
printf("[button_handler] jump_page_lock: %d\n", jump_page_lock);
35+
}
36+
jump_page_lock_d_alone_candidate = false;
37+
}
38+
2739
int8_t single_step_pressed() {
2840
uint8_t pressed = 0;
2941
int8_t val = -1;
@@ -258,7 +270,7 @@ void button_key_on_single(uint8_t key) {
258270
// 1-16 (jump mode)
259271
// do jump
260272
debounce_quantize = 2;
261-
key_do_jump(key - 4);
273+
key_do_physical_jump(key - 4);
262274
dub_step_break = 0;
263275
dub_step_divider = 0;
264276
dub_step_beat = beat_current;
@@ -849,6 +861,7 @@ bool button_handler(ButtonMatrix *bm) {
849861
if (bm->off[i] == KEY_A || bm->off[i] == KEY_D) {
850862
cued_sound_selector = false;
851863
}
864+
maybe_toggle_jump_page_lock_on_d_release(bm->off[i]);
852865
// printf("turned off %d\n", bm->off[i]);
853866
if (key_held_on && (bm->off[i] == key_held_num)) {
854867
button_key_off_held(bm->off[i]);
@@ -894,6 +907,12 @@ bool button_handler(ButtonMatrix *bm) {
894907
if (key_total_pressed == 1) {
895908
key_timer_on = 0;
896909
}
910+
if (bm->on[i] == KEY_D) {
911+
jump_page_lock_d_alone_candidate =
912+
mode_buttons16 == MODE_JUMP && key_total_pressed == 1;
913+
} else if (key_on_buttons[KEY_D] > 0) {
914+
jump_page_lock_d_alone_candidate = false;
915+
}
897916
if (!key_held_on) {
898917
key_held_on = true;
899918
key_held_num = bm->on[i];
@@ -1329,8 +1348,12 @@ bool button_handler(ButtonMatrix *bm) {
13291348
} else if (mode_buttons16 == MODE_JUMP) {
13301349
LEDS_set(leds, 0, LED_BRIGHT);
13311350
LEDS_set(leds, 1, LED_BLINK);
1332-
LEDS_set(leds, 2, 0);
1333-
LEDS_set(leds, 3, 0);
1351+
LEDS_set(leds, 2,
1352+
(jump_page_lock & JUMP_PAGE_LOCK_FIRST) ? LED_BRIGHT
1353+
: LED_NONE);
1354+
LEDS_set(leds, 3,
1355+
(jump_page_lock & JUMP_PAGE_LOCK_SECOND) ? LED_BRIGHT
1356+
: LED_NONE);
13341357
} else if (mode_buttons16 == MODE_BASS) {
13351358
LEDS_set(leds, 0, LED_BRIGHT);
13361359
LEDS_set(leds, 1, 0);

lib/globals.h

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ void regenerate_random_sequence_arr() {
130130
// mode toggles
131131
// mode ==0 ==1
132132
uint8_t mode_buttons16 = 0;
133+
#ifdef INCLUDE_ZEPTOCORE
134+
#define JUMP_PAGE_LOCK_DEFAULT 0
135+
#define JUMP_PAGE_LOCK_FIRST 1
136+
#define JUMP_PAGE_LOCK_SECOND 2
137+
#define JUMP_PAGE_LOCK_THIRD 3
138+
uint8_t jump_page_lock = JUMP_PAGE_LOCK_DEFAULT;
139+
#endif
133140
bool mode_mute = 0;
134141
bool mode_play = 0;
135142
bool mute_because_of_playback_type = false;
@@ -632,46 +639,61 @@ void do_update_phase_from_beat_current() {
632639
jump_precedence = false;
633640
}
634641

635-
void key_do_jump(uint8_t beat) {
636-
if (beat >= 0 && beat < 16) {
642+
void key_do_jump_to_slice(int32_t slice, uint8_t sequencer_beat) {
637643
#ifdef INCLUDE_ZEPTOCORE
638-
if (clock_in_do && clock_input_absent_zeptocore &&
639-
clock_in_activator >= 3) {
640-
// reset beats
641-
bpm_timer_counter = 0;
642-
beat_total = 0;
643-
key_jump_debounce = 0;
644-
dub_step_break = -1;
645-
retrig_beat_num = 0;
646-
beat_current = 0;
647-
playback_stopped = false;
648-
clock_in_ready = false;
649-
clock_in_activator = 0;
650-
clock_in_do = false;
651-
}
644+
if (clock_in_do && clock_input_absent_zeptocore && clock_in_activator >= 3) {
645+
// reset beats
646+
bpm_timer_counter = 0;
647+
beat_total = 0;
648+
key_jump_debounce = 0;
649+
dub_step_break = -1;
650+
retrig_beat_num = 0;
651+
beat_current = 0;
652+
playback_stopped = false;
653+
clock_in_ready = false;
654+
clock_in_activator = 0;
655+
clock_in_do = false;
656+
}
652657
#endif
653-
// printf("key_do_jump %d\n", beat);
654-
// TODO: [0] should be which sequencer it is on
655-
if (sequencerhandler[0].recording) {
656-
Sequencer_add(sf->sequencers[0][sf->sequence_sel[0]], beat,
657-
bpm_timer_counter);
658+
// TODO: [0] should be which sequencer it is on
659+
if (sequencerhandler[0].recording) {
660+
Sequencer_add(sf->sequencers[0][sf->sequence_sel[0]], sequencer_beat,
661+
bpm_timer_counter);
662+
}
663+
key_jump_debounce = 1;
664+
beat_current = slice;
665+
retrig_pitch = PITCH_VAL_MID;
666+
// reset filter
667+
if (global_filter_index != retrig_filter_original &&
668+
retrig_filter_original > 0) {
669+
global_filter_index = retrig_filter_original;
670+
for (uint8_t channel = 0; channel < 2; channel++) {
671+
ResonantFilter_setFc(resFilter[channel], global_filter_index);
658672
}
659-
key_jump_debounce = 1;
660-
beat_current = floor(beat_current / 16) * 16 + beat;
661-
retrig_pitch = PITCH_VAL_MID;
662-
// reset filter
663-
if (global_filter_index != retrig_filter_original &&
664-
retrig_filter_original > 0) {
665-
global_filter_index = retrig_filter_original;
666-
for (uint8_t channel = 0; channel < 2; channel++) {
667-
ResonantFilter_setFc(resFilter[channel], global_filter_index);
668-
}
669-
retrig_filter_original = 0;
673+
retrig_filter_original = 0;
674+
}
675+
jump_precedence = true;
676+
do_update_phase_from_beat_current();
677+
}
678+
679+
void key_do_jump(uint8_t beat) {
680+
if (beat < 16) {
681+
// printf("key_do_jump %d\n", beat);
682+
key_do_jump_to_slice(floor(beat_current / 16) * 16 + beat, beat);
683+
}
684+
}
685+
686+
#ifdef INCLUDE_ZEPTOCORE
687+
void key_do_physical_jump(uint8_t beat) {
688+
if (beat < 16) {
689+
int32_t slice = floor(beat_current / 16) * 16 + beat;
690+
if (jump_page_lock > JUMP_PAGE_LOCK_DEFAULT) {
691+
slice = (jump_page_lock - 1) * 16 + beat;
670692
}
671-
jump_precedence = true;
672-
do_update_phase_from_beat_current();
693+
key_do_jump_to_slice(slice, beat);
673694
}
674695
}
696+
#endif
675697

676698
void step_sequencer_emit(uint8_t key) {
677699
#ifdef INCLUDE_MIDI

0 commit comments

Comments
 (0)