Ask Your Question

How to control Tidal with Open Sound Control?

asked 2016-07-30 08:10:15 -0500

yaxu gravatar image

updated 2016-09-06 17:56:50 -0500

lennart gravatar image

Originally a question posed by @kindohm on the TOPLAP slack - how to get Tidal to modify a live coded pattern based on OSC messages received from a co-performer?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-07-30 08:19:42 -0500

yaxu gravatar image

Here's my answer.. First you need to load a library:

import Sound.OSC.FD

Then run this code:

let startServ port d = do x <- udpServer "" port
                          mPatF <- newMVar (silence, id)
                          forkIO $ loop x d mPatF
                          return $ \pat -> do (_, f) <- takeMVar mPatF
                                              putMVar mPatF (pat, f)
                                              d $ f pat
    loop :: UDP -> (ParamPattern -> IO ()) -> MVar (ParamPattern, ParamPattern -> ParamPattern) -> IO ()
    loop x d mPatF = do m <- recvMessage x
                        act m d mPatF
                        loop x d mPatF
    act (Just (Message "/density" [Float n])) d mPatF = 
      do  (pat, f) <- takeMVar mPatF
          let f' = density (toRational n) . f
          putMVar mPatF (pat, f')
          d $ f' pat
          return ()
    act (Just (Message "/speed" [Float n])) d mPatF = 
      do  (pat, f) <- takeMVar mPatF
          let f' = (|*| speed (pure $ GHC.Float.float2Double n)) . f
          putMVar mPatF (pat, f')
          d $ f' pat
          return ()
    act (Just (Message "/clear" [])) d mPatF = 
      do  (pat, _) <- takeMVar mPatF
          putMVar mPatF (pat, id)
          d pat
          return ()
    act _ _ _ = return ()

Here's some commands to demonstrate this in use, by sending OSC messages from Haskell:

-- Turn the Tidal stream `d1` into one called `d1'` that can be manipulated over OSC (listening on port 4040):
d1' <- startServ 4040 d1

-- Start a pattern going..
d1' $ sound "bd cp"

-- Open an OSC connection from Haskell:
client <- openUDP "" 4040

-- Send a command to triple the `density`:
sendOSC client $ Message "/density" [Float 3]

-- double the `speed`
sendOSC client $ Message "/speed" [Float 2]

-- clear both to return the pattern to the original:
sendOSC client $ Message "/clear" []

You can make further manipulations available by adding an act function to the code.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-07-30 08:10:15 -0500

Seen: 234 times

Last updated: Jul 30 '16

Related questions