Revert "Fix: try to fix the non working sync"
This reverts commit 1513d80a8d.
This commit is contained in:
@@ -299,7 +299,6 @@ struct ActivePattern {
|
||||
step_index: usize,
|
||||
iter: usize,
|
||||
last_step_beat: f64,
|
||||
activation_beat: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -491,30 +490,6 @@ fn check_quantization_boundary(
|
||||
}
|
||||
}
|
||||
|
||||
fn quantization_boundary_beat(
|
||||
quantization: LaunchQuantization,
|
||||
prev_beat: f64,
|
||||
quantum: f64,
|
||||
) -> Option<f64> {
|
||||
match quantization {
|
||||
LaunchQuantization::Immediate => None,
|
||||
LaunchQuantization::Beat => Some(prev_beat.floor() + 1.0),
|
||||
LaunchQuantization::Bar => Some(((prev_beat / quantum).floor() + 1.0) * quantum),
|
||||
LaunchQuantization::Bars2 => {
|
||||
let q = quantum * 2.0;
|
||||
Some(((prev_beat / q).floor() + 1.0) * q)
|
||||
}
|
||||
LaunchQuantization::Bars4 => {
|
||||
let q = quantum * 4.0;
|
||||
Some(((prev_beat / q).floor() + 1.0) * q)
|
||||
}
|
||||
LaunchQuantization::Bars8 => {
|
||||
let q = quantum * 8.0;
|
||||
Some(((prev_beat / q).floor() + 1.0) * q)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type StepKey = (usize, usize, usize);
|
||||
|
||||
struct RunsCounter {
|
||||
@@ -917,8 +892,6 @@ impl SequencerState {
|
||||
}
|
||||
}
|
||||
};
|
||||
let boundary =
|
||||
quantization_boundary_beat(pending.quantization, prev_beat, quantum);
|
||||
self.runs_counter
|
||||
.clear_pattern(pending.id.bank, pending.id.pattern);
|
||||
self.audio_state.active_patterns.insert(
|
||||
@@ -929,7 +902,6 @@ impl SequencerState {
|
||||
step_index: start_step,
|
||||
iter: 0,
|
||||
last_step_beat: beat,
|
||||
activation_beat: boundary,
|
||||
},
|
||||
);
|
||||
self.buf_activated.push(pending.id);
|
||||
@@ -1010,13 +982,8 @@ impl SequencerState {
|
||||
.unwrap_or_else(|| pattern.speed.multiplier());
|
||||
|
||||
let step_beats = substeps_in_window(frontier, lookahead_end, speed_mult);
|
||||
let activation = active.activation_beat.take();
|
||||
let skip = activation.map_or(0, |ab| {
|
||||
step_beats.iter().take_while(|&&b| b < ab).count()
|
||||
});
|
||||
|
||||
for step_beat in &step_beats[skip..] {
|
||||
let step_beat = *step_beat;
|
||||
for step_beat in step_beats {
|
||||
result.any_step_fired = true;
|
||||
active.last_step_beat = step_beat;
|
||||
let step_idx = active.step_index % pattern.length;
|
||||
@@ -2424,118 +2391,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quantization_boundary_beat() {
|
||||
let quantum = 4.0;
|
||||
|
||||
// Immediate → None
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Immediate, 1.5, quantum),
|
||||
None
|
||||
);
|
||||
|
||||
// Beat → next integer beat
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Beat, 1.5, quantum),
|
||||
Some(2.0)
|
||||
);
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Beat, 3.0, quantum),
|
||||
Some(4.0)
|
||||
);
|
||||
|
||||
// Bar → next multiple of quantum
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Bar, 3.9, quantum),
|
||||
Some(4.0)
|
||||
);
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Bar, 0.0, quantum),
|
||||
Some(4.0)
|
||||
);
|
||||
|
||||
// Bars2 → next multiple of quantum*2
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Bars2, 3.9, quantum),
|
||||
Some(8.0)
|
||||
);
|
||||
|
||||
// Bars4 → next multiple of quantum*4
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Bars4, 3.9, quantum),
|
||||
Some(16.0)
|
||||
);
|
||||
|
||||
// Bars8 → next multiple of quantum*8
|
||||
assert_eq!(
|
||||
quantization_boundary_beat(LaunchQuantization::Bars8, 3.9, quantum),
|
||||
Some(32.0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_activation_beat_prevents_early_substeps() {
|
||||
let mut state = make_state();
|
||||
|
||||
state.tick(tick_with(
|
||||
vec![SeqCommand::PatternUpdate {
|
||||
bank: 0,
|
||||
pattern: 0,
|
||||
data: simple_pattern(16),
|
||||
}],
|
||||
0.0,
|
||||
));
|
||||
|
||||
// Queue Bar-quantized start (boundary at beat 4.0, quantum=4)
|
||||
state.tick(tick_with(
|
||||
vec![SeqCommand::PatternStart {
|
||||
bank: 0,
|
||||
pattern: 0,
|
||||
quantization: LaunchQuantization::Bar,
|
||||
sync_mode: SyncMode::Reset,
|
||||
}],
|
||||
3.5,
|
||||
));
|
||||
assert!(!state.audio_state.active_patterns.contains_key(&pid(0, 0)));
|
||||
|
||||
// Simulate a wide lookahead window that crosses the bar boundary:
|
||||
// frontier=3.875, lookahead_end=4.125 — spans both sides of beat 4.0
|
||||
// Without activation_beat filtering, substeps before 4.0 would fire.
|
||||
state.tick(TickInput {
|
||||
commands: Vec::new(),
|
||||
playing: true,
|
||||
beat: 4.125,
|
||||
lookahead_end: 4.125,
|
||||
tempo: 120.0,
|
||||
quantum: 4.0,
|
||||
fill: false,
|
||||
nudge_secs: 0.0,
|
||||
current_time_us: 0,
|
||||
audio_sample_pos: 0,
|
||||
sr: 48000.0,
|
||||
mouse_x: 0.5,
|
||||
mouse_y: 0.5,
|
||||
mouse_down: 0.0,
|
||||
});
|
||||
|
||||
// Pattern should be active
|
||||
assert!(state.audio_state.active_patterns.contains_key(&pid(0, 0)));
|
||||
|
||||
// The activation_beat should have been consumed (set to None)
|
||||
let ap = state.audio_state.active_patterns.get(&pid(0, 0)).unwrap();
|
||||
assert!(ap.activation_beat.is_none(), "activation_beat should be consumed after first execute");
|
||||
|
||||
// Step index should reflect only substeps at/after beat 4.0, not before
|
||||
// At 1x speed: substeps at 0.25-beat intervals. From frontier 3.875 to 4.125:
|
||||
// substeps_in_window yields beats at 4.0 (= 16/4). Pre-4.0 substeps should be skipped.
|
||||
assert_eq!(ap.step_index, 1, "Only substep at beat 4.0 should fire, not pre-boundary ones");
|
||||
|
||||
// Second tick: activation_beat already consumed, all substeps should fire normally
|
||||
let _output2 = state.tick(tick_at(4.375, true));
|
||||
let ap2 = state.audio_state.active_patterns.get(&pid(0, 0)).unwrap();
|
||||
assert_eq!(ap2.step_index, 2, "Second tick should advance normally");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_false_boundary_after_pause_within_same_bar() {
|
||||
let mut state = make_state();
|
||||
|
||||
Reference in New Issue
Block a user