module Sound.OpenSoundControl.Transport ( Transport(..)
, withTransport
, wait ) where
import Sound.OpenSoundControl.OSC
import Control.Exception
class Transport t where
send :: t -> OSC -> IO ()
recv :: t -> IO OSC
close :: t -> IO ()
hasAddress :: String -> OSC -> Bool
hasAddress addr o = maybe False (== addr) (address o)
untilM :: Monad m => (a -> Bool) -> m a -> m a
untilM p act = recurse
where recurse = act >>= (\r -> if p r then return r else recurse)
wait :: Transport t => t -> String -> IO OSC
wait t s = untilM (hasAddress s) (recv t)
withTransport :: Transport t => IO t -> (t -> IO a) -> IO a
withTransport u = bracket u close