From e3b1d6142d1c8b1d527c9147569c8f199c6cf477 Mon Sep 17 00:00:00 2001 From: Pierre Krafft Date: Thu, 14 Jul 2022 16:13:28 +0200 Subject: [PATCH] Use target latency in all send modes Enables moving the scheduling of tidal, back and foreward on the Ableton Link timelime. --- src/Sound/Tidal/Config.hs | 2 +- src/Sound/Tidal/Stream.hs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Sound/Tidal/Config.hs b/src/Sound/Tidal/Config.hs index 7fac843c2..c9d2e9f00 100644 --- a/src/Sound/Tidal/Config.hs +++ b/src/Sound/Tidal/Config.hs @@ -45,7 +45,7 @@ defaultConfig = Config {cCtrlListen = True, cCtrlBroadcast = False, cFrameTimespan = 1/20, cEnableLink = True, - cProcessAhead = 1/4, + cProcessAhead = 3/10, cTempoAddr = "127.0.0.1", cTempoPort = 9160, cTempoClientPort = 0, -- choose at random diff --git a/src/Sound/Tidal/Stream.hs b/src/Sound/Tidal/Stream.hs index 6044fccdf..db9577e2d 100644 --- a/src/Sound/Tidal/Stream.hs +++ b/src/Sound/Tidal/Stream.hs @@ -551,19 +551,20 @@ setPreviousPatternOrSilence stream = -- Send events live by delaying the thread send :: Maybe O.UDP -> Cx -> Double -> Double -> (Double, Bool, O.Message) -> IO () send listen cx latency extraLatency (time, isBusMsg, m) - | oSchedule target == Pre BundleStamp = sendBndl isBusMsg listen cx $ O.Bundle (time + extraLatency) [m] + | oSchedule target == Pre BundleStamp = sendBndl isBusMsg listen cx $ O.Bundle timeWithLatency [m] | oSchedule target == Pre MessageStamp = sendO isBusMsg listen cx $ addtime m | otherwise = do _ <- forkOS $ do now <- O.time - threadDelay $ floor $ (time - now - latency + extraLatency) * 1000000 + threadDelay $ floor $ (timeWithLatency - now) * 1000000 sendO isBusMsg listen cx m return () where addtime (O.Message mpath params) = O.Message mpath ((O.int32 sec):((O.int32 usec):params)) - ut = O.ntpr_to_ut (time + extraLatency) + ut = O.ntpr_to_ut timeWithLatency sec :: Int sec = floor ut usec :: Int usec = floor $ 1000000 * (ut - (fromIntegral sec)) target = cxTarget cx + timeWithLatency = time - latency + extraLatency -- Interaction