Skip to content

Beat sync - #3

Open
sastraxi wants to merge 5 commits into
masterfrom
feat/beat-sync
Open

Beat sync#3
sastraxi wants to merge 5 commits into
masterfrom
feat/beat-sync

Conversation

@sastraxi

@sastraxisastraxi commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Problem

pi-Stomp (mod-host front-end) needs a synchronous time-base to drive a metronome or count-in LED at the correct tempo and position. Previously only LPB events (position transport) and MIDI beat clock were available, neither designed for this use case.

LPB events arrive only when JACK transport is rolling and are back-dated to the sample-accurate transport position — unsuitable for a low-latency UI that needs forward-extrapolated wall-clock position. MIDI beat clock is 24 PPQN, too coarse for a bar-position display.

Solution

Add a POSTPONED_BEAT_SYNC event type. When UpdateGlobalJackPosition runs — on transport state change, tempo change, or position change — a clock-sample (t_us, bpm, bpb, beat_in_bar) is queued into the postponed event ring buffer. The consumer forward-extrapolates pos(t) = beat_in_bar + (t - t_us) * bpm / 60.

This is not a back-dated transport position. Each sample fully replaces the prior anchor. Dropped or late events degrade gracefully: more extrapolation, no wrong lock. Timestamps use CLOCK_MONOTONIC (t_us at sampling time, not when engine runs the deferred event).

Changes

  • POSTPONED_BEAT_SYNC enum added to postponed event types
  • postponed_beat_sync_event_t struct with t_us, bpm, bpb, beat_in_bar
  • PostPonedEvents handler applies the clock-sample via a new mod_host_update_beat_sync() (exposed for pi-Stomp integration)
  • UpdateGlobalJackPosition gains do_post=true path that constructs and posts the beat-sync event
  • effects_set_beats_per_minute now passes do_post=true so tempo changes emit a beat_sync (previous code hard-bypassed postponed events for BPM changes)
  • Added time.h include
  • Switched field naming: bar replaced with beat_in_bar for clarity

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@sastraxi