module Sound.SC3.Server.Command.Core where
import Sound.OSC.Core
import Sound.SC3.Server.Enum
import Sound.SC3.Server.Synthdef
d_recv :: Synthdef -> Message
d_recv d = message "/d_recv" [Blob (synthdefData d)]
d_load :: String -> Message
d_load p = message "/d_load" [string p]
d_loadDir :: String -> Message
d_loadDir p = message "/d_loadDir" [string p]
d_free :: [String] -> Message
d_free = message "/d_free" . map string
cmd :: String -> [Datum] -> Message
cmd name = message "/cmd" . (string name :)
clearSched :: Message
clearSched = message "/clearSched" []
dumpOSC :: PrintLevel -> Message
dumpOSC c = message "/dumpOSC" [int32 (fromEnum c)]
notify :: Bool -> Message
notify c = message "/notify" [int32 (fromEnum c)]
quit :: Message
quit = message "/quit" []
status :: Message
status = message "/status" []
errorMode :: ErrorScope -> ErrorMode -> Message
errorMode scope mode =
let e = case scope of
Globally -> fromEnum mode
Locally -> 1 fromEnum mode
in message "/error" [int32 e]
async_cmds :: [String]
async_cmds =
["/b_alloc"
,"/b_allocRead"
,"/b_allocReadChannel"
,"/b_close"
,"/b_free"
,"/b_read"
,"/b_readChannel"
,"/b_write"
,"/b_zero"
,"/d_load"
,"/d_loadDir"
,"/d_recv"
,"/notify"
,"/quit"
,"/sync"]
isAsync :: Message -> Bool
isAsync (Message a _) = a `elem` async_cmds
withCM :: OSC o => Message -> o -> Message
withCM (Message c xs) cm =
if c `elem` async_cmds
then let xs' = xs ++ [Blob (encodeOSC cm)]
in Message c xs'
else error ("withCM: not async: " ++ c)