module Sound.OpenSoundControl.Transport ( Transport(..)
, withTransport
, wait ) where
import Control.Exception
import Sound.OpenSoundControl.OSC
class Transport t where
send :: t -> OSC -> IO ()
recv :: t -> IO OSC
close :: t -> IO ()
has_address :: String -> OSC -> Bool
has_address x (Message y _) = x == y
has_address _ _ = False
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 (has_address s) (recv t)
withTransport :: Transport t => IO t -> (t -> IO a) -> IO a
withTransport u = bracket u close