Skip to content

Instantly share code, notes, and snippets.

@yannxou
Created November 30, 2022 12:59
Show Gist options
  • Save yannxou/ebbc5df481e9d86f3f49c98d06d439f3 to your computer and use it in GitHub Desktop.
Save yannxou/ebbc5df481e9d86f3f49c98d06d439f3 to your computer and use it in GitHub Desktop.
Sonic Pi snippet for Ableton Link downbeat sync
# Credits: https://in-thread.sonic-pi.net/t/demo-of-experimental-ableton-link-with-sonic-pi/5869/28
# Call beat_fix with desired quantum just before defining your loops
use_bpm :link
sched_time = 0.5
$latency = 0 + sched_time*1000.00
def beat_fix(quantum=4)
diff = @tau_api.link_current_time_and_beat(false)[1] % quantum
x = ((quantum-diff) + 0 - rt($latency/1000.0)) % quantum
epsilon = 0.02
sleepytime = (x < epsilon or x > (quantum-epsilon)) ? 0 : x
sleep sleepytime
end
beat_fix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment