Skip to content

Commit ec97fee

Browse files
committed
fix: variable mode
1 parent 4e739db commit ec97fee

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

lib/clockhandling.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ void clock_in_do_update() {
1616
if (playback_stopped) {
1717
playback_was_stopped_clock = true;
1818
clock_in_beat_total = 0;
19+
clock_in_beat_last = 0;
1920
} else if (playback_was_stopped_clock) {
2021
playback_was_stopped_clock = false;
2122
clock_in_beat_total = 0;
23+
clock_in_beat_last = 0;
2224
}
2325
}
2426

@@ -49,6 +51,7 @@ void clock_handling_start() {
4951
clock_in_last_last_time = clock_in_last_time;
5052
clock_in_last_time = time_us_32();
5153
clock_in_beat_total = 0;
54+
clock_in_beat_last = 0;
5255
clock_in_ready = true;
5356
cancel_repeating_timer(&timer);
5457
do_restart_playback = true;

lib/ectocore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,11 +1337,13 @@ void __not_in_flash_func(input_handling)() {
13371337
// the next clock is going to be the first beat
13381338
// reset it to -1, so that when it increments it will be at 0
13391339
clock_in_beat_total = -1;
1340+
clock_in_beat_last = -1;
13401341
} else {
13411342
// we are in the first half
13421343
// the next clock is going to be the second beat
13431344
// reset it to 0, so that when it increments it will be at 1
13441345
clock_in_beat_total = 0;
1346+
clock_in_beat_last = 0;
13451347
}
13461348
} else {
13471349
// reset tempo to the tempo of the current sample

lib/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ bool clock_input_absent_zeptocore = false;
186186
bool clock_in_ready = false;
187187
uint8_t clock_in_activator = 0;
188188
int32_t clock_in_beat_total = 0;
189+
int32_t clock_in_beat_last = 0;
190+
bool should_skip_clock_pulse = false;
189191
volatile uint32_t clock_in_diff_2x = 0;
190192
volatile uint32_t clock_in_last_time = 0;
191193
uint32_t clock_in_last_last_time = 0;

lib/midicallback.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void midi_timing() {
100100
printf("[midicallback] midi resetting\n");
101101
#endif
102102
clock_in_beat_total = -1;
103+
clock_in_beat_last = -1;
103104
}
104105
if (midi_timing_count % (midi_timing_modulus / MIDI_CLOCK_MULTIPLIER) == 0) {
105106
// soft sync

main.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,39 @@ bool __not_in_flash_func(timer_step)() {
360360
// num_slices, bpm_timer_counter, (float)bpm_timer_counter_last);
361361
bpm_timer_counter_last = bpm_timer_counter;
362362
}
363+
364+
// In variable mode with clock input, check if enough pulses accumulated
365+
if (clock_in_do && clock_in_ready) {
366+
// Calculate expected pulses for this slice based on num_slices
367+
// num_slices is in timer ticks (192 per quarter note)
368+
// splice_trigger is pulses per quarter note (typically 24)
369+
float expected_pulses = num_slices *
370+
(float)banks[sel_bank_cur]
371+
->sample[sel_sample_cur]
372+
.snd[FILEZERO]
373+
->splice_trigger / 192.0f;
374+
int32_t pulses_accumulated = clock_in_beat_total - clock_in_beat_last;
375+
376+
if (pulses_accumulated < (int32_t)roundf(expected_pulses)) {
377+
// Not enough pulses accumulated for this slice yet
378+
should_skip_clock_pulse = true;
379+
} else {
380+
// Enough pulses accumulated, allow trigger and reset counter
381+
should_skip_clock_pulse = false;
382+
clock_in_beat_last = clock_in_beat_total;
383+
}
384+
}
385+
} else {
386+
// Not in variable mode, reset the skip flag
387+
should_skip_clock_pulse = false;
363388
}
364389

365390
if (sequencerhandler[0].playing) {
366391
// already done
367-
} else if ((clock_in_do && clock_in_ready) || do_splice_trigger) {
392+
} else if (((clock_in_do && clock_in_ready && !should_skip_clock_pulse) ||
393+
do_splice_trigger)) {
368394
clock_in_ready = false;
395+
should_skip_clock_pulse = false;
369396
mem_use = false;
370397
// keep to the beat
371398
if (fil_is_open && debounce_quantize == 0) {

0 commit comments

Comments
 (0)