module Sound.SC3.Server.Play (stop,reset,send,async
,withSC3
,Audible(..)
,perform) where
import Sound.OpenSoundControl
import Sound.SC3.Server.Command
import Sound.SC3.Server.Synthdef
import Sound.SC3.UGen.UGen
stop :: Transport t => t -> IO ()
stop fd = send fd (g_freeAll [1])
async :: Transport t => t -> OSC -> IO OSC
async fd m = send fd m >> wait fd "/done"
reset :: Transport t => t -> IO ()
reset fd = do
send fd (g_freeAll [0])
send fd (g_new [(1,AddToTail,0),(2,AddToTail,0)])
withSC3 :: (UDP -> IO a) -> IO a
withSC3 = withTransport (openUDP "127.0.0.1" 57110)
playSynthdef :: Transport t => t -> Synthdef -> IO ()
playSynthdef fd s = do
_ <- async fd (d_recv s)
send fd (s_new (synthdefName s) (1) AddToTail 1 [])
playUGen :: Transport t => t -> UGen -> IO ()
playUGen fd = playSynthdef fd . synthdef "Anonymous"
class Audible e where
play :: Transport t => t -> e -> IO ()
audition :: e -> IO ()
audition e = withSC3 (`play` e)
instance Audible Synthdef where
play = playSynthdef
instance Audible UGen where
play = playUGen
run_bundle :: Transport t => t -> Double -> OSC -> IO ()
run_bundle fd i o =
let wr m = if isAsync m
then async fd m >> return ()
else send fd m
in case o of
Bundle (NTPr t) x' -> do
pauseThreadUntil (i + t)
mapM_ wr x'
_ -> error "run_bundle: non bundle or non-NTPr bundle"
perform :: [OSC] -> IO ()
perform s = do
let f i fd = run_bundle fd i
withSC3 (\fd -> utcr >>= \i -> mapM_ (f i fd) s)