refactor: replace atomic_double with fixed-point BPM and remove circular dependency

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-01 21:27:38 +00:00
parent 6d52e076dc
commit d9de05b1da
4 changed files with 30 additions and 36 deletions

View File

@@ -157,8 +157,29 @@ static void shutdown_callback(void *arg) {
// Get the next quantization boundary frame
static jack_nframes_t get_next_quantize_frame(Engine *engine, jack_nframes_t current_frame) {
if (!engine->transport) return current_frame;
return transport_get_next_quantize_frame(engine->transport, current_frame, engine->quantize_mode);
if (!engine->transport || engine->transport->state != TRANSPORT_PLAYING ||
engine->quantize_mode == QUANTIZE_OFF) {
return current_frame;
}
// Calculate frames per beat
jack_nframes_t frames_per_beat = (jack_nframes_t)engine->transport->samples_per_beat;
jack_nframes_t frames_per_bar = frames_per_beat * BEATS_PER_BAR;
// Current position in frames
jack_nframes_t current_pos = engine->transport->sample_position + current_frame;
if (engine->quantize_mode == QUANTIZE_BEAT) {
// Next beat boundary
jack_nframes_t beat_frames = frames_per_beat;
jack_nframes_t next_beat = ((current_pos / beat_frames) + 1) * beat_frames;
return next_beat - engine->transport->sample_position;
} else { // QUANTIZE_BAR
// Next bar boundary
jack_nframes_t bar_frames = frames_per_bar;
jack_nframes_t next_bar = ((current_pos / bar_frames) + 1) * bar_frames;
return next_bar - engine->transport->sample_position;
}
}
// Queue a trigger for quantization