Skip to content

Commit

Permalink
Use target latency in all send modes
Browse files Browse the repository at this point in the history
Enables moving the scheduling of tidal,
back and foreward on the Ableton Link timelime.
  • Loading branch information
Zalastax committed Jul 15, 2022
1 parent 7b1192b commit e3b1d61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Sound/Tidal/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/Sound/Tidal/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e3b1d61

Please sign in to comment.