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:
32
transport.c
32
transport.c
@@ -22,7 +22,8 @@ void transport_init(Transport *transport, jack_nframes_t sample_rate) {
|
||||
atomic_store(&transport->bar_position_atomic, 0);
|
||||
atomic_store(&transport->sample_position_atomic, 0);
|
||||
atomic_store(&transport->clock_source_atomic, CLOCK_SOURCE_INTERNAL);
|
||||
atomic_store(&transport->bpm_atomic, DEFAULT_BPM);
|
||||
transport->bpm_atomic = DEFAULT_BPM;
|
||||
atomic_store(&transport->bpm_atomic_raw, (unsigned int)(DEFAULT_BPM * 100.0));
|
||||
}
|
||||
|
||||
void transport_cleanup(Transport *transport) {
|
||||
@@ -100,7 +101,8 @@ void transport_set_bpm(Transport *transport, double bpm) {
|
||||
|
||||
transport->bpm = bpm;
|
||||
transport->samples_per_beat = (transport->sample_rate * 60.0) / bpm;
|
||||
atomic_store(&transport->bpm_atomic, bpm);
|
||||
transport->bpm_atomic = bpm;
|
||||
atomic_store(&transport->bpm_atomic_raw, (unsigned int)(bpm * 100.0));
|
||||
}
|
||||
|
||||
double transport_get_bpm(Transport *transport) {
|
||||
@@ -221,32 +223,6 @@ void transport_reset(Transport *transport) {
|
||||
atomic_store(&transport->sample_position_atomic, 0);
|
||||
}
|
||||
|
||||
jack_nframes_t transport_get_next_quantize_frame(Transport *transport,
|
||||
jack_nframes_t current_frame,
|
||||
QuantizeMode mode) {
|
||||
if (!transport || transport->state != TRANSPORT_PLAYING || mode == QUANTIZE_OFF) {
|
||||
return current_frame;
|
||||
}
|
||||
|
||||
// Calculate frames per beat
|
||||
jack_nframes_t frames_per_beat = (jack_nframes_t)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 = transport->sample_position + current_frame;
|
||||
|
||||
if (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 - 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 - transport->sample_position;
|
||||
}
|
||||
}
|
||||
|
||||
const char* transport_state_to_string(TransportState state) {
|
||||
switch (state) {
|
||||
|
||||
Reference in New Issue
Block a user