packages feed

tidal-link 1.1.0 → 1.2.2

raw patch · 2 files changed

Files

src/hs/Sound/Tidal/Clock.hs view
@@ -42,12 +42,12 @@  -- | configuration of the clock data ClockConfig = ClockConfig-  { cQuantum :: CDouble,-    cBeatsPerCycle :: CDouble,-    cFrameTimespan :: Double,-    cEnableLink :: Bool,-    cSkipTicks :: Int64,-    cProcessAhead :: Double+  { clockQuantum :: CDouble,+    clockBeatsPerCycle :: CDouble,+    clockFrameTimespan :: Double,+    clockEnableLink :: Bool,+    clockSkipTicks :: Int64,+    clockProcessAhead :: Double   }  -- | action to be executed on a tick,@@ -68,12 +68,12 @@ defaultConfig :: ClockConfig defaultConfig =   ClockConfig-    { cFrameTimespan = 1 / 20,-      cEnableLink = False,-      cProcessAhead = 3 / 10,-      cSkipTicks = 10,-      cQuantum = 4,-      cBeatsPerCycle = 4+    { clockFrameTimespan = 1 / 20,+      clockEnableLink = False,+      clockProcessAhead = 3 / 10,+      clockSkipTicks = 10,+      clockQuantum = 4,+      clockBeatsPerCycle = 4     }  -- | creates a clock according to the config and runs it@@ -87,18 +87,18 @@ runClock config ac clock = do   (mem, st) <- initClock config ac   _ <- forkIO $ evalStateT (runReaderT clock mem) st-  return (clockRef mem)+  pure (clockRef mem)  -- | creates a ableton link instance and an MVar for interacting -- | with the clock from outside and computes the initial clock state initClock :: ClockConfig -> TickAction -> IO (ClockMemory, ClockState) initClock config ac = do   abletonLink <- Link.create bpm-  when (cEnableLink config) $ Link.enable abletonLink+  when (clockEnableLink config) $ Link.enable abletonLink   sessionState <- Link.createAndCaptureAppSessionState abletonLink   now <- Link.clock abletonLink   let startAt = now + processAhead-  Link.requestBeatAtTime sessionState 0 startAt (cQuantum config)+  Link.requestBeatAtTime sessionState 0 startAt (clockQuantum config)   Link.commitAndDestroyAppSessionState abletonLink sessionState   clockMV <- atomically $ newTVar NoAction   let st =@@ -108,10 +108,10 @@             nowArc = (0, 0),             nudged = 0           }-  return (ClockMemory config (ClockRef clockMV abletonLink) ac, st)+  pure (ClockMemory config (ClockRef clockMV abletonLink) ac, st)   where-    processAhead = round $ (cProcessAhead config) * 1000000-    bpm = (coerce defaultCps) * 60 * (cBeatsPerCycle config)+    processAhead = round $ (clockProcessAhead config) * 1000000+    bpm = (coerce defaultCps) * 60 * (clockBeatsPerCycle config)  -- The reference time Link uses, -- is the time the audio for a certain beat hits the speaker.@@ -149,13 +149,13 @@   (ClockMemory config (ClockRef _ abletonLink) _) <- ask   st <- get   now <- liftIO $ Link.clock abletonLink-  let processAhead = round $ (cProcessAhead config) * 1000000-      frameTimespan = round $ (cFrameTimespan config) * 1000000+  let processAhead = round $ (clockProcessAhead config) * 1000000+      frameTimespan = round $ (clockFrameTimespan config) * 1000000       preferredNewTick = ticks st + 1       logicalNow = logicalTime config (start st) preferredNewTick       aheadOfNow = now + processAhead       actualTick = (aheadOfNow - start st) `div` frameTimespan-      drifted = abs (actualTick - preferredNewTick) > (cSkipTicks config)+      drifted = abs (actualTick - preferredNewTick) > (clockSkipTicks config)       newTick         | drifted = actualTick         | otherwise = preferredNewTick@@ -189,7 +189,7 @@   tick  processAction :: ClockAction -> Clock ()-processAction NoAction = return ()+processAction NoAction = pure () processAction (SetNudge n) = modify (\st -> st {nudged = n}) processAction (SetTempo bpm) = do   (ClockMemory _ (ClockRef _ abletonLink) _) <- ask@@ -202,10 +202,10 @@   sessionState <- liftIO $ Link.createAndCaptureAppSessionState abletonLink    now <- liftIO $ Link.clock abletonLink-  let processAhead = round $ (cProcessAhead config) * 1000000+  let processAhead = round $ (clockProcessAhead config) * 1000000       startAt = now + processAhead-      beat = (fromRational cyc) * (cBeatsPerCycle config)-  liftIO $ Link.requestBeatAtTime sessionState beat startAt (cQuantum config)+      beat = (fromRational cyc) * (clockBeatsPerCycle config)+  liftIO $ Link.requestBeatAtTime sessionState beat startAt (clockQuantum config)   liftIO $ Link.commitAndDestroyAppSessionState abletonLink sessionState    modify (\st -> st {ticks = 0, start = now, nowArc = (cyc, cyc)})@@ -221,10 +221,10 @@ arcEnd = snd  beatToCycles :: ClockConfig -> Double -> Double-beatToCycles config beat = beat / (coerce $ cBeatsPerCycle config)+beatToCycles config beat = beat / (coerce $ clockBeatsPerCycle config)  cyclesToBeat :: ClockConfig -> Double -> Double-cyclesToBeat config cyc = cyc * (coerce $ cBeatsPerCycle config)+cyclesToBeat config cyc = cyc * (coerce $ clockBeatsPerCycle config)  getSessionState :: ClockRef -> IO Link.SessionState getSessionState (ClockRef _ abletonLink) = Link.createAndCaptureAppSessionState abletonLink@@ -236,10 +236,10 @@ getZeroedSessionState config (ClockRef _ abletonLink) = do   ss <- Link.createAndCaptureAppSessionState abletonLink   nowLink <- liftIO $ Link.clock abletonLink-  Link.forceBeatAtTime ss 0 (nowLink + processAhead) (cQuantum config)-  return ss+  Link.forceBeatAtTime ss 0 (nowLink + processAhead) (clockQuantum config)+  pure ss   where-    processAhead = round $ (cProcessAhead config) * 1000000+    processAhead = round $ (clockProcessAhead config) * 1000000  getTempo :: Link.SessionState -> IO Time getTempo ss = fmap toRational $ Link.getTempo ss@@ -248,24 +248,24 @@ setTempoCPS cps now conf ss = Link.setTempo ss (coerce $ cyclesToBeat conf ((fromRational cps) * 60)) now  timeAtBeat :: ClockConfig -> Link.SessionState -> Double -> IO Link.Micros-timeAtBeat config ss beat = Link.timeAtBeat ss (coerce beat) (cQuantum config)+timeAtBeat config ss beat = Link.timeAtBeat ss (coerce beat) (clockQuantum config)  timeToCycles :: ClockConfig -> Link.SessionState -> Link.Micros -> IO Time timeToCycles config ss time = do-  beat <- Link.beatAtTime ss time (cQuantum config)-  return $! (toRational beat) / (toRational (cBeatsPerCycle config))+  beat <- Link.beatAtTime ss time (clockQuantum config)+  pure $! (toRational beat) / (toRational (clockBeatsPerCycle config))  -- At what time does the cycle occur according to Link? cyclesToTime :: ClockConfig -> Link.SessionState -> Time -> IO Link.Micros cyclesToTime config ss cyc = do-  let beat = (fromRational cyc) * (cBeatsPerCycle config)-  Link.timeAtBeat ss beat (cQuantum config)+  let beat = (fromRational cyc) * (clockBeatsPerCycle config)+  Link.timeAtBeat ss beat (clockQuantum config)  linkToOscTime :: ClockRef -> Link.Micros -> IO O.Time linkToOscTime (ClockRef _ abletonLink) lt = do   nowOsc <- O.time   nowLink <- liftIO $ Link.clock abletonLink-  return $ addMicrosToOsc (lt - nowLink) nowOsc+  pure $ addMicrosToOsc (lt - nowLink) nowOsc  addMicrosToOsc :: Link.Micros -> O.Time -> O.Time addMicrosToOsc m t = ((fromIntegral m) / 1000000) + t@@ -276,7 +276,7 @@ logicalTime :: ClockConfig -> Link.Micros -> Int64 -> Link.Micros logicalTime config startTime ticks' = startTime + ticks' * frameTimespan   where-    frameTimespan = round $ (cFrameTimespan config) * 1000000+    frameTimespan = round $ (clockFrameTimespan config) * 1000000  --------------------------------------------------------------- ----------- functions for interacting with the clock ----------@@ -287,10 +287,10 @@   ss <- Link.createAndCaptureAppSessionState abletonLink   bpm <- Link.getTempo ss   Link.destroySessionState ss-  return $! toRational bpm+  pure $! toRational bpm  getCPS :: ClockConfig -> ClockRef -> IO Time-getCPS config ref = fmap (\bpm -> bpm / (toRational $ cBeatsPerCycle config) / 60) (getBPM ref)+getCPS config ref = fmap (\bpm -> bpm / (toRational $ clockBeatsPerCycle config) / 60) (getBPM ref)  getCycleTime :: ClockConfig -> ClockRef -> IO Time getCycleTime config (ClockRef _ abletonLink) = do@@ -298,7 +298,7 @@   ss <- Link.createAndCaptureAppSessionState abletonLink   c <- timeToCycles config ss now   Link.destroySessionState ss-  return $! c+  pure $! c  resetClock :: ClockRef -> IO () resetClock clock = setClock clock 0@@ -320,7 +320,7 @@ setCPS :: ClockConfig -> ClockRef -> Time -> IO () setCPS config ref cps = setBPM ref bpm   where-    bpm = cps * 60 * (toRational $ cBeatsPerCycle config)+    bpm = cps * 60 * (toRational $ clockBeatsPerCycle config)  setNudge :: ClockRef -> Double -> IO () setNudge (ClockRef clock _) n = atomically $ do
tidal-link.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.4 name:                tidal-link-version:             1.1.0+version:             1.2.2 synopsis:            Ableton Link integration for Tidal -- description: homepage:            http://tidalcycles.org/@@ -67,7 +67,7 @@  source-repository head   type:     git-  location: https://github.com/tidalcycles/Tidal+  location: https://codeberg.org/uzu/tidal  executable tidal-linktest   ghc-options: -Wall