Uh oh!
There was an error while loading. Please reload this page.
Beat sync - #3
Open
sastraxi wants to merge 5 commits into
Open
Conversation
This was referenced Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_SYNCevent type. WhenUpdateGlobalJackPositionruns — 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-extrapolatespos(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_SYNCenum added to postponed event typespostponed_beat_sync_event_tstruct with t_us, bpm, bpb, beat_in_barPostPonedEventshandler applies the clock-sample via a newmod_host_update_beat_sync()(exposed for pi-Stomp integration)UpdateGlobalJackPositiongainsdo_post=truepath that constructs and posts the beat-sync eventeffects_set_beats_per_minutenow passesdo_post=trueso tempo changes emit a beat_sync (previous code hard-bypassed postponed events for BPM changes)time.hincludebarreplaced withbeat_in_barfor clarity