@hackage vivid-osc0.4.0.0

Open Sound Control encode/decode

vivid-osc

Example usage:

Sending it over UDP

E.g. to TidalCycles, using the 'network' package:

{-# LANGUAGE OverloadedStrings #-}


import Network.Socket
import Network.Socket.ByteString as SB

import Vivid.OSC

main = do
   -- Boring Network.Socket setup:
   (a:_) <- getAddrInfo Nothing (Just "127.0.0.1") (Just "57120")
   s <- socket (addrFamily a) Datagram defaultProtocol
   connect s (addrAddress a)

   -- The interesting part:
   SB.send s $ encodeOSC $
      OSC "/play2" [OSC_S "cps", OSC_F 1.2, OSC_S "s", OSC_S "bd"]

Receiving via UDP:

{-# LANGUAGE OverloadedStrings #-}


import Control.Monad (forever)
import Network.Socket
import Network.Socket.ByteString as SB

import Vivid.OSC

main = do
   -- Boring Network.Socket setup:
   (a:_) <- getAddrInfo Nothing (Just "127.0.0.1") (Just "57120")
   s <- socket (addrFamily a) Datagram defaultProtocol
   bind s (addrAddress a)

   forever $ do
      o <- decodeOSC <$> SB.recv s 4096
      case o of
         Right (OSC "/play2" [_, OSC_F vel, _, OSC_S "bd"]) ->
            putStrLn $ if vel < 1
               then "boom"
               else "BOOM!"
         _ -> putStrLn $ "Unexpected input: "++show o