module Sound.Sc3.Server.Transport.Monad where
import Control.Monad
import Data.List
import Data.Maybe
import System.Directory
import System.FilePath
import qualified Data.ByteString.Lazy as L
import qualified Data.List.Split as Split
import qualified Data.Tree as Tree
import qualified Safe
import Sound.Osc
import qualified Sound.Osc.Time.Timeout
import qualified Sound.Sc3.Common.Base.System as System
import qualified Sound.Sc3.Server.Command as Command
import qualified Sound.Sc3.Server.Command.Generic as Generic
import qualified Sound.Sc3.Server.Enum as Enum
import qualified Sound.Sc3.Server.Graphdef as Graphdef
import qualified Sound.Sc3.Server.Graphdef.Binary as Graphdef
import qualified Sound.Sc3.Server.Nrt as Nrt
import qualified Sound.Sc3.Server.Status as Status
import qualified Sound.Sc3.Server.Synthdef as Synthdef
import qualified Sound.Sc3.Ugen.Bindings.Composite as Composite
import qualified Sound.Sc3.Ugen.Ugen as Ugen
async :: DuplexOsc m => Message -> m Message
async :: forall (m :: * -> *). DuplexOsc m => Message -> m Message
async Message
m = Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage Message
m m () -> m Message -> m Message
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Address_Pattern -> m Message
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m Message
waitReply Address_Pattern
"/done"
async_ :: DuplexOsc m => Message -> m ()
async_ :: forall (m :: * -> *). DuplexOsc m => Message -> m ()
async_ = m Message -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m Message -> m ()) -> (Message -> m Message) -> Message -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Message -> m Message
forall (m :: * -> *). DuplexOsc m => Message -> m Message
async
maybe_async :: DuplexOsc m => Message -> m ()
maybe_async :: forall (m :: * -> *). DuplexOsc m => Message -> m ()
maybe_async Message
m = if Message -> Bool
Command.isAsync Message
m then Message -> m ()
forall (m :: * -> *). DuplexOsc m => Message -> m ()
async_ Message
m else Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage Message
m
maybe_async_at :: DuplexOsc m => Time -> Message -> m ()
maybe_async_at :: forall (m :: * -> *). DuplexOsc m => Double -> Message -> m ()
maybe_async_at Double
t Message
m =
if Message -> Bool
Command.isAsync Message
m
then Message -> m ()
forall (m :: * -> *). DuplexOsc m => Message -> m ()
async_ Message
m
else BundleOf Message -> m ()
forall (m :: * -> *). SendOsc m => BundleOf Message -> m ()
sendBundle (Double -> [Message] -> BundleOf Message
forall t. Double -> [t] -> BundleOf t
bundle Double
t [Message
m])
type Sc3_Address = OscSocketAddress
sc3_default_address :: Sc3_Address
sc3_default_address :: Sc3_Address
sc3_default_address = (OscProtocol
Tcp, Address_Pattern
"127.0.0.1", Node_Id
57110)
sc3_env_or_default_address :: IO Sc3_Address
sc3_env_or_default_address :: IO Sc3_Address
sc3_env_or_default_address = do
Address_Pattern
protocol <- Address_Pattern -> Address_Pattern -> IO Address_Pattern
System.lookup_env_default Address_Pattern
"ScProtocol" Address_Pattern
"Tcp"
Address_Pattern
hostname <- Address_Pattern -> Address_Pattern -> IO Address_Pattern
System.lookup_env_default Address_Pattern
"ScHostname" Address_Pattern
"127.0.0.1"
Address_Pattern
port <- Address_Pattern -> Address_Pattern -> IO Address_Pattern
System.lookup_env_default Address_Pattern
"ScPort" Address_Pattern
"57110"
Sc3_Address -> IO Sc3_Address
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Address_Pattern -> OscProtocol
forall a. Read a => Address_Pattern -> a
read Address_Pattern
protocol, Address_Pattern
hostname, Address_Pattern -> Node_Id
forall a. Read a => Address_Pattern -> a
read Address_Pattern
port)
sc3_udp_limit :: Num n => n
sc3_udp_limit :: forall n. Num n => n
sc3_udp_limit = n
65507
withSc3At :: Sc3_Address -> Connection OscSocket a -> IO a
withSc3At :: forall a. Sc3_Address -> Connection OscSocket a -> IO a
withSc3At Sc3_Address
address = IO OscSocket -> Connection OscSocket a -> IO a
forall t r. Transport t => IO t -> Connection t r -> IO r
withTransport (Sc3_Address -> IO OscSocket
openOscSocket Sc3_Address
address)
withSc3 :: Connection OscSocket a -> IO a
withSc3 :: forall a. Connection OscSocket a -> IO a
withSc3 Connection OscSocket a
f = do
Sc3_Address
addr <- IO Sc3_Address
sc3_env_or_default_address
Sc3_Address -> Connection OscSocket a -> IO a
forall a. Sc3_Address -> Connection OscSocket a -> IO a
withSc3At Sc3_Address
addr Connection OscSocket a
f
withSc3_ :: Connection OscSocket a -> IO ()
withSc3_ :: forall a. Connection OscSocket a -> IO ()
withSc3_ = IO a -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO a -> IO ())
-> (Connection OscSocket a -> IO a)
-> Connection OscSocket a
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection OscSocket a -> IO a
forall a. Connection OscSocket a -> IO a
withSc3
withSc3_tm :: Double -> Connection OscSocket a -> IO (Maybe a)
withSc3_tm :: forall a. Double -> Connection OscSocket a -> IO (Maybe a)
withSc3_tm Double
tm = Double -> IO a -> IO (Maybe a)
forall a. Double -> IO a -> IO (Maybe a)
Sound.Osc.Time.Timeout.timeout_r Double
tm (IO a -> IO (Maybe a))
-> (Connection OscSocket a -> IO a)
-> Connection OscSocket a
-> IO (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Connection OscSocket a -> IO a
forall a. Connection OscSocket a -> IO a
withSc3
withSc3AtSeq :: Sc3_Address -> Int -> Connection OscSocket a -> IO [a]
withSc3AtSeq :: forall a.
Sc3_Address -> Node_Id -> Connection OscSocket a -> IO [a]
withSc3AtSeq (OscProtocol
protocol, Address_Pattern
hostname, Node_Id
port) Node_Id
k Connection OscSocket a
f = do
let mk_socket :: Node_Id -> IO OscSocket
mk_socket Node_Id
i = Sc3_Address -> IO OscSocket
openOscSocket (OscProtocol
protocol, Address_Pattern
hostname, Node_Id
port Node_Id -> Node_Id -> Node_Id
forall a. Num a => a -> a -> a
+ Node_Id
i)
(Node_Id -> IO a) -> [Node_Id] -> IO [a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\Node_Id
i -> IO OscSocket -> Connection OscSocket a -> IO a
forall t r. Transport t => IO t -> Connection t r -> IO r
withTransport (Node_Id -> IO OscSocket
mk_socket Node_Id
i) Connection OscSocket a
f) [Node_Id
0 .. Node_Id
k Node_Id -> Node_Id -> Node_Id
forall a. Num a => a -> a -> a
- Node_Id
1]
withSc3AtSeq_ :: Sc3_Address -> Int -> Connection OscSocket a -> IO ()
withSc3AtSeq_ :: forall a. Sc3_Address -> Node_Id -> Connection OscSocket a -> IO ()
withSc3AtSeq_ Sc3_Address
loc Node_Id
k = IO [a] -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO [a] -> IO ())
-> (Connection OscSocket a -> IO [a])
-> Connection OscSocket a
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sc3_Address -> Node_Id -> Connection OscSocket a -> IO [a]
forall a.
Sc3_Address -> Node_Id -> Connection OscSocket a -> IO [a]
withSc3AtSeq Sc3_Address
loc Node_Id
k
stop :: SendOsc m => m ()
stop :: forall (m :: * -> *). SendOsc m => m ()
stop = Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage ([Node_Id] -> Message
Command.g_freeAll [Node_Id
1])
reset :: SendOsc m => m ()
reset :: forall (m :: * -> *). SendOsc m => m ()
reset =
let m :: [Message]
m =
[ Message
Command.clearSched
, [Node_Id] -> Message
Command.n_free [Node_Id
1, Node_Id
2]
, [(Node_Id, AddAction, Node_Id)] -> Message
Command.g_new [(Node_Id
1, AddAction
Enum.AddToHead, Node_Id
0), (Node_Id
2, AddAction
Enum.AddToTail, Node_Id
0)]
]
in BundleOf Message -> m ()
forall (m :: * -> *). SendOsc m => BundleOf Message -> m ()
sendBundle (Double -> [Message] -> BundleOf Message
forall t. Double -> [t] -> BundleOf t
bundle Double
immediately [Message]
m)
type Play_Opt = (Command.Node_Id, Enum.AddAction, Command.Group_Id, [(String, Double)])
play_graphdef_msg :: Play_Opt -> Graphdef.Graphdef -> Message
play_graphdef_msg :: Play_Opt -> Graphdef -> Message
play_graphdef_msg (Node_Id
nid, AddAction
act, Node_Id
gid, [(Address_Pattern, Double)]
param) Graphdef
g =
let nm :: Address_Pattern
nm = Ascii -> Address_Pattern
ascii_to_string (Graphdef -> Ascii
Graphdef.graphdef_name Graphdef
g)
in Address_Pattern
-> Node_Id
-> AddAction
-> Node_Id
-> [(Address_Pattern, Double)]
-> Message
Command.s_new Address_Pattern
nm Node_Id
nid AddAction
act Node_Id
gid [(Address_Pattern, Double)]
param
recv_or_load_graphdef :: Transport m => Graphdef.Graphdef -> m Message
recv_or_load_graphdef :: forall (m :: * -> *). Transport m => Graphdef -> m Message
recv_or_load_graphdef Graphdef
g = do
Address_Pattern
tmp <- IO Address_Pattern -> m Address_Pattern
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Address_Pattern
getTemporaryDirectory
let nm :: Address_Pattern
nm = Ascii -> Address_Pattern
ascii_to_string (Graphdef -> Ascii
Graphdef.graphdef_name Graphdef
g)
fn :: Address_Pattern
fn = Address_Pattern
tmp Address_Pattern -> Address_Pattern -> Address_Pattern
</> Address_Pattern
nm Address_Pattern -> Address_Pattern -> Address_Pattern
<.> Address_Pattern
"scsyndef"
by :: ByteString
by = Graphdef -> ByteString
Graphdef.encode_graphdef Graphdef
g
sz :: Int64
sz = ByteString -> Int64
L.length ByteString
by
if Int64
sz Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
< Int64
forall n. Num n => n
sc3_udp_limit
then Message -> m Message
forall (m :: * -> *). DuplexOsc m => Message -> m Message
async (ByteString -> Message
Command.d_recv_bytes ByteString
by)
else IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Address_Pattern -> Graphdef -> IO ()
Graphdef.graphdefWrite Address_Pattern
fn Graphdef
g) m () -> m Message -> m Message
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Message -> m Message
forall (m :: * -> *). DuplexOsc m => Message -> m Message
async (Address_Pattern -> Message
Command.d_load Address_Pattern
fn)
playGraphdef :: Transport m => Play_Opt -> Graphdef.Graphdef -> m ()
playGraphdef :: forall (m :: * -> *). Transport m => Play_Opt -> Graphdef -> m ()
playGraphdef Play_Opt
opt Graphdef
g = Graphdef -> m Message
forall (m :: * -> *). Transport m => Graphdef -> m Message
recv_or_load_graphdef Graphdef
g m Message -> m () -> m ()
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage (Play_Opt -> Graphdef -> Message
play_graphdef_msg Play_Opt
opt Graphdef
g)
playSynthdef :: Transport m => Play_Opt -> Synthdef.Synthdef -> m ()
playSynthdef :: forall (m :: * -> *). Transport m => Play_Opt -> Synthdef -> m ()
playSynthdef Play_Opt
opt = Play_Opt -> Graphdef -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> Graphdef -> m ()
playGraphdef Play_Opt
opt (Graphdef -> m ()) -> (Synthdef -> Graphdef) -> Synthdef -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Synthdef -> Graphdef
Synthdef.synthdef_to_graphdef
playUgen :: Transport m => Play_Opt -> Ugen.Ugen -> m ()
playUgen :: forall (m :: * -> *). Transport m => Play_Opt -> Ugen -> m ()
playUgen Play_Opt
loc =
Play_Opt -> Synthdef -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> Synthdef -> m ()
playSynthdef Play_Opt
loc
(Synthdef -> m ()) -> (Ugen -> Synthdef) -> Ugen -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Address_Pattern -> Ugen -> Synthdef
Synthdef.synthdef Address_Pattern
"Anonymous"
(Ugen -> Synthdef) -> (Ugen -> Ugen) -> Ugen -> Synthdef
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Double -> Ugen -> Ugen
Composite.wrapOut Maybe Double
forall a. Maybe a
Nothing
sc_latency :: IO Double
sc_latency :: IO Double
sc_latency = (Address_Pattern -> Double) -> IO Address_Pattern -> IO Double
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Address_Pattern -> Double
forall a. Read a => Address_Pattern -> a
read (Address_Pattern -> Address_Pattern -> IO Address_Pattern
System.lookup_env_default Address_Pattern
"ScLatency" Address_Pattern
"0.1")
run_bundle :: Transport m => Double -> Time -> BundleOf Message -> m ()
run_bundle :: forall (m :: * -> *).
Transport m =>
Double -> Double -> BundleOf Message -> m ()
run_bundle Double
latency Double
t0 BundleOf Message
b = do
let t :: Double
t = Double
t0 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ BundleOf Message -> Double
forall t. BundleOf t -> Double
bundleTime BundleOf Message
b
IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Double -> IO ()
forall (m :: * -> *) n. (MonadIO m, RealFrac n) => n -> m ()
pauseThreadUntil (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
latency))
(Message -> m ()) -> [Message] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Double -> Message -> m ()
forall (m :: * -> *). DuplexOsc m => Double -> Message -> m ()
maybe_async_at Double
t) (BundleOf Message -> [Message]
forall t. BundleOf t -> [t]
bundleMessages BundleOf Message
b)
nrt_play :: Transport m => Nrt.Nrt -> m ()
nrt_play :: forall (m :: * -> *). Transport m => Nrt -> m ()
nrt_play Nrt
sc = do
Double
t0 <- IO Double -> m Double
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Double
forall (m :: * -> *). MonadIO m => m Double
time
Double
latency <- IO Double -> m Double
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Double
sc_latency
(BundleOf Message -> m ()) -> [BundleOf Message] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Double -> Double -> BundleOf Message -> m ()
forall (m :: * -> *).
Transport m =>
Double -> Double -> BundleOf Message -> m ()
run_bundle Double
latency Double
t0) (Nrt -> [BundleOf Message]
Nrt.nrt_bundles Nrt
sc)
nrt_play_reorder :: Transport m => Nrt.Nrt -> m ()
nrt_play_reorder :: forall (m :: * -> *). Transport m => Nrt -> m ()
nrt_play_reorder Nrt
s = do
let ([BundleOf Message]
i, [BundleOf Message]
r) = (Double -> Bool) -> Nrt -> ([BundleOf Message], [BundleOf Message])
Nrt.nrt_span (Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
0) Nrt
s
i' :: [Message]
i' = (BundleOf Message -> [Message]) -> [BundleOf Message] -> [Message]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap BundleOf Message -> [Message]
forall t. BundleOf t -> [t]
bundleMessages [BundleOf Message]
i
([Message]
a, [Message]
b) = [Message] -> ([Message], [Message])
Command.partition_async [Message]
i'
(Message -> m Message) -> [Message] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Message -> m Message
forall (m :: * -> *). DuplexOsc m => Message -> m Message
async [Message]
a
Double
t0 <- IO Double -> m Double
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Double
forall (m :: * -> *). MonadIO m => m Double
time
Double
latency <- IO Double -> m Double
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Double
sc_latency
(BundleOf Message -> m ()) -> [BundleOf Message] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Double -> Double -> BundleOf Message -> m ()
forall (m :: * -> *).
Transport m =>
Double -> Double -> BundleOf Message -> m ()
run_bundle Double
latency Double
t0) (Double -> [Message] -> BundleOf Message
forall t. Double -> [t] -> BundleOf t
Bundle Double
0 [Message]
b BundleOf Message -> [BundleOf Message] -> [BundleOf Message]
forall a. a -> [a] -> [a]
: [BundleOf Message]
r)
nrt_audition :: Nrt.Nrt -> IO ()
nrt_audition :: Nrt -> IO ()
nrt_audition = Connection OscSocket () -> IO ()
forall a. Connection OscSocket a -> IO a
withSc3 (Connection OscSocket () -> IO ())
-> (Nrt -> Connection OscSocket ()) -> Nrt -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Nrt -> Connection OscSocket ()
forall (m :: * -> *). Transport m => Nrt -> m ()
nrt_play
class Audible e where
playAt :: Transport m => Play_Opt -> e -> m ()
play :: Transport m => e -> m ()
play = Play_Opt -> e -> m ()
forall e (m :: * -> *).
(Audible e, Transport m) =>
Play_Opt -> e -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> e -> m ()
playAt (-Node_Id
1, AddAction
Enum.AddToHead, Node_Id
1, [])
instance Audible Graphdef.Graphdef where
playAt :: forall (m :: * -> *). Transport m => Play_Opt -> Graphdef -> m ()
playAt = Play_Opt -> Graphdef -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> Graphdef -> m ()
playGraphdef
instance Audible Synthdef.Synthdef where
playAt :: forall (m :: * -> *). Transport m => Play_Opt -> Synthdef -> m ()
playAt = Play_Opt -> Synthdef -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> Synthdef -> m ()
playSynthdef
instance Audible Ugen.Ugen where
playAt :: forall (m :: * -> *). Transport m => Play_Opt -> Ugen -> m ()
playAt = Play_Opt -> Ugen -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> Ugen -> m ()
playUgen
auditionAt :: Audible e => Sc3_Address -> Play_Opt -> e -> IO ()
auditionAt :: forall e. Audible e => Sc3_Address -> Play_Opt -> e -> IO ()
auditionAt Sc3_Address
loc Play_Opt
opt = Sc3_Address -> Connection OscSocket () -> IO ()
forall a. Sc3_Address -> Connection OscSocket a -> IO a
withSc3At Sc3_Address
loc (Connection OscSocket () -> IO ())
-> (e -> Connection OscSocket ()) -> e -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Play_Opt -> e -> Connection OscSocket ()
forall e (m :: * -> *).
(Audible e, Transport m) =>
Play_Opt -> e -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> e -> m ()
playAt Play_Opt
opt
auditionAtSeq :: Audible e => Sc3_Address -> Play_Opt -> Int -> e -> IO ()
auditionAtSeq :: forall e.
Audible e =>
Sc3_Address -> Play_Opt -> Node_Id -> e -> IO ()
auditionAtSeq Sc3_Address
loc Play_Opt
opt Node_Id
k = Sc3_Address -> Node_Id -> Connection OscSocket () -> IO ()
forall a. Sc3_Address -> Node_Id -> Connection OscSocket a -> IO ()
withSc3AtSeq_ Sc3_Address
loc Node_Id
k (Connection OscSocket () -> IO ())
-> (e -> Connection OscSocket ()) -> e -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Play_Opt -> e -> Connection OscSocket ()
forall e (m :: * -> *).
(Audible e, Transport m) =>
Play_Opt -> e -> m ()
forall (m :: * -> *). Transport m => Play_Opt -> e -> m ()
playAt Play_Opt
opt
def_play_opt :: Play_Opt
def_play_opt :: Play_Opt
def_play_opt = (-Node_Id
1, AddAction
Enum.AddToHead, Node_Id
1, [])
auditionOpt :: Audible e => Play_Opt -> e -> IO ()
auditionOpt :: forall e. Audible e => Play_Opt -> e -> IO ()
auditionOpt Play_Opt
o e
e = do
Sc3_Address
addr <- IO Sc3_Address
sc3_env_or_default_address
Sc3_Address -> Play_Opt -> e -> IO ()
forall e. Audible e => Sc3_Address -> Play_Opt -> e -> IO ()
auditionAt Sc3_Address
addr Play_Opt
o e
e
audition :: Audible e => e -> IO ()
audition :: forall e. Audible e => e -> IO ()
audition = Play_Opt -> e -> IO ()
forall e. Audible e => Play_Opt -> e -> IO ()
auditionOpt Play_Opt
def_play_opt
auditionSeq :: Audible e => Int -> e -> IO ()
auditionSeq :: forall e. Audible e => Node_Id -> e -> IO ()
auditionSeq Node_Id
k e
x = do
Sc3_Address
addr <- IO Sc3_Address
sc3_env_or_default_address
Sc3_Address -> Play_Opt -> Node_Id -> e -> IO ()
forall e.
Audible e =>
Sc3_Address -> Play_Opt -> Node_Id -> e -> IO ()
auditionAtSeq Sc3_Address
addr Play_Opt
def_play_opt Node_Id
k e
x
withNotifications :: DuplexOsc m => m a -> m a
withNotifications :: forall (m :: * -> *) a. DuplexOsc m => m a -> m a
withNotifications m a
f = do
Message -> m ()
forall (m :: * -> *). DuplexOsc m => Message -> m ()
async_ (Bool -> Message
Command.notify Bool
True)
a
r <- m a
f
Message -> m ()
forall (m :: * -> *). DuplexOsc m => Message -> m ()
async_ (Bool -> Message
Command.notify Bool
False)
a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
r
b_getn1_data :: DuplexOsc m => Int -> (Int, Int) -> m [Double]
b_getn1_data :: forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> (Node_Id, Node_Id) -> m [Double]
b_getn1_data Node_Id
b (Node_Id, Node_Id)
s = do
let f :: Message -> [Double]
f Message
m = let (Node_Id
_, Node_Id
_, Node_Id
_, [Double]
r) = Message -> (Node_Id, Node_Id, Node_Id, [Double])
Command.unpack_b_setn_err Message
m in [Double]
r
Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage (Node_Id -> (Node_Id, Node_Id) -> Message
Command.b_getn1 Node_Id
b (Node_Id, Node_Id)
s)
(Message -> [Double]) -> m Message -> m [Double]
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Message -> [Double]
f (Address_Pattern -> m Message
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m Message
waitReply Address_Pattern
"/b_setn")
b_getn1_data_segment ::
DuplexOsc m =>
Int ->
Int ->
(Int, Int) ->
m [Double]
b_getn1_data_segment :: forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> Node_Id -> (Node_Id, Node_Id) -> m [Double]
b_getn1_data_segment Node_Id
n Node_Id
b (Node_Id
i, Node_Id
j) = do
let ix :: [(Node_Id, Node_Id)]
ix = Node_Id -> Node_Id -> Node_Id -> [(Node_Id, Node_Id)]
Command.b_indices Node_Id
n Node_Id
j Node_Id
i
[[Double]]
d <- ((Node_Id, Node_Id) -> m [Double])
-> [(Node_Id, Node_Id)] -> m [[Double]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Node_Id -> (Node_Id, Node_Id) -> m [Double]
forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> (Node_Id, Node_Id) -> m [Double]
b_getn1_data Node_Id
b) [(Node_Id, Node_Id)]
ix
[Double] -> m [Double]
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Double]] -> [Double]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Double]]
d)
b_fetch :: DuplexOsc m => Int -> Int -> m [[Double]]
b_fetch :: forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> Node_Id -> m [[Double]]
b_fetch Node_Id
n Node_Id
b = do
let f :: Message -> f [[Double]]
f Message
m =
let (Node_Id
_, Node_Id
nf, Node_Id
nc, Double
_) = Message -> (Node_Id, Node_Id, Node_Id, Double)
Command.unpack_b_info_err Message
m
ix :: (Node_Id, Node_Id)
ix = (Node_Id
0, Node_Id
nf Node_Id -> Node_Id -> Node_Id
forall a. Num a => a -> a -> a
* Node_Id
nc)
deinterleave :: [a] -> [[a]]
deinterleave = [[a]] -> [[a]]
forall a. [[a]] -> [[a]]
transpose ([[a]] -> [[a]]) -> ([a] -> [[a]]) -> [a] -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Node_Id -> [a] -> [[a]]
forall e. Node_Id -> [e] -> [[e]]
Split.chunksOf Node_Id
nc
in ([Double] -> [[Double]]) -> f [Double] -> f [[Double]]
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Double] -> [[Double]]
forall {a}. [a] -> [[a]]
deinterleave (Node_Id -> Node_Id -> (Node_Id, Node_Id) -> f [Double]
forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> Node_Id -> (Node_Id, Node_Id) -> m [Double]
b_getn1_data_segment Node_Id
n Node_Id
b (Node_Id, Node_Id)
ix)
Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage (Node_Id -> Message
Command.b_query1 Node_Id
b)
Address_Pattern -> m Message
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m Message
waitReply Address_Pattern
"/b_info" m Message -> (Message -> m [[Double]]) -> m [[Double]]
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Message -> m [[Double]]
forall {f :: * -> *}. DuplexOsc f => Message -> f [[Double]]
f
b_fetch1 :: DuplexOsc m => Int -> Int -> m [Double]
b_fetch1 :: forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> Node_Id -> m [Double]
b_fetch1 Node_Id
n Node_Id
b = ([[Double]] -> [Double]) -> m [[Double]] -> m [Double]
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Address_Pattern -> [[Double]] -> [Double]
forall a. Partial => Address_Pattern -> [a] -> a
Safe.headNote Address_Pattern
"b_fetch1: no data") (Node_Id -> Node_Id -> m [[Double]]
forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> Node_Id -> m [[Double]]
b_fetch Node_Id
n Node_Id
b)
b_fetch_hdr :: Transport m => Int -> Int -> m ((Int, Int, Int, Double), [[Double]])
b_fetch_hdr :: forall (m :: * -> *).
Transport m =>
Node_Id
-> Node_Id -> m ((Node_Id, Node_Id, Node_Id, Double), [[Double]])
b_fetch_hdr Node_Id
k Node_Id
b = do
(Node_Id, Node_Id, Node_Id, Double)
q <- Node_Id -> m (Node_Id, Node_Id, Node_Id, Double)
forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> m (Node_Id, Node_Id, Node_Id, Double)
b_query1_unpack Node_Id
b
[[Double]]
d <- Node_Id -> Node_Id -> m [[Double]]
forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> Node_Id -> m [[Double]]
b_fetch Node_Id
k Node_Id
b
((Node_Id, Node_Id, Node_Id, Double), [[Double]])
-> m ((Node_Id, Node_Id, Node_Id, Double), [[Double]])
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Node_Id, Node_Id, Node_Id, Double)
q, [[Double]]
d)
b_query1_unpack_generic :: (DuplexOsc m, Num n, Fractional r) => Int -> m (n, n, n, r)
b_query1_unpack_generic :: forall (m :: * -> *) n r.
(DuplexOsc m, Num n, Fractional r) =>
Node_Id -> m (n, n, n, r)
b_query1_unpack_generic Node_Id
n = do
Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage (Node_Id -> Message
Command.b_query1 Node_Id
n)
Message
q <- Address_Pattern -> m Message
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m Message
waitReply Address_Pattern
"/b_info"
(n, n, n, r) -> m (n, n, n, r)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message -> (n, n, n, r)
forall i f. (Num i, Fractional f) => Message -> (i, i, i, f)
Generic.unpack_b_info_err Message
q)
b_query1_unpack :: DuplexOsc m => Command.Buffer_Id -> m (Int, Int, Int, Double)
b_query1_unpack :: forall (m :: * -> *).
DuplexOsc m =>
Node_Id -> m (Node_Id, Node_Id, Node_Id, Double)
b_query1_unpack = Node_Id -> m (Node_Id, Node_Id, Node_Id, Double)
forall (m :: * -> *) n r.
(DuplexOsc m, Num n, Fractional r) =>
Node_Id -> m (n, n, n, r)
b_query1_unpack_generic
c_getn1_data :: (DuplexOsc m, Floating t) => (Int, Int) -> m [t]
c_getn1_data :: forall (m :: * -> *) t.
(DuplexOsc m, Floating t) =>
(Node_Id, Node_Id) -> m [t]
c_getn1_data (Node_Id, Node_Id)
s = do
let f :: [Datum] -> [b]
f [Datum]
d = case [Datum]
d of
Int32 Int32
_ : Int32 Int32
_ : [Datum]
x -> (Datum -> Maybe b) -> [Datum] -> [b]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Datum -> Maybe b
forall n. Floating n => Datum -> Maybe n
datum_floating [Datum]
x
[Datum]
_ -> Address_Pattern -> [b]
forall a. Partial => Address_Pattern -> a
error Address_Pattern
"c_getn1_data"
Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage ((Node_Id, Node_Id) -> Message
Command.c_getn1 (Node_Id, Node_Id)
s)
([Datum] -> [t]) -> m [Datum] -> m [t]
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Datum] -> [t]
forall {b}. Floating b => [Datum] -> [b]
f (Address_Pattern -> m [Datum]
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m [Datum]
waitDatum Address_Pattern
"/c_setn")
n_query1_unpack_f :: DuplexOsc m => (Message -> t) -> Command.Node_Id -> m t
n_query1_unpack_f :: forall (m :: * -> *) t.
DuplexOsc m =>
(Message -> t) -> Node_Id -> m t
n_query1_unpack_f Message -> t
f Node_Id
n = do
Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage ([Node_Id] -> Message
Command.n_query [Node_Id
n])
Message
r <- Address_Pattern -> m Message
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m Message
waitReply Address_Pattern
"/n_info"
t -> m t
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Message -> t
f Message
r)
n_query1_unpack :: DuplexOsc m => Command.Node_Id -> m (Maybe (Int, Int, Int, Int, Int, Maybe (Int, Int)))
n_query1_unpack :: forall (m :: * -> *).
DuplexOsc m =>
Node_Id
-> m (Maybe
(Node_Id, Node_Id, Node_Id, Node_Id, Node_Id,
Maybe (Node_Id, Node_Id)))
n_query1_unpack = (Message
-> Maybe
(Node_Id, Node_Id, Node_Id, Node_Id, Node_Id,
Maybe (Node_Id, Node_Id)))
-> Node_Id
-> m (Maybe
(Node_Id, Node_Id, Node_Id, Node_Id, Node_Id,
Maybe (Node_Id, Node_Id)))
forall (m :: * -> *) t.
DuplexOsc m =>
(Message -> t) -> Node_Id -> m t
n_query1_unpack_f Message
-> Maybe
(Node_Id, Node_Id, Node_Id, Node_Id, Node_Id,
Maybe (Node_Id, Node_Id))
Command.unpack_n_info
n_query1_unpack_plain :: DuplexOsc m => Command.Node_Id -> m [Int]
n_query1_unpack_plain :: forall (m :: * -> *). DuplexOsc m => Node_Id -> m [Node_Id]
n_query1_unpack_plain = (Message -> [Node_Id]) -> Node_Id -> m [Node_Id]
forall (m :: * -> *) t.
DuplexOsc m =>
(Message -> t) -> Node_Id -> m t
n_query1_unpack_f Message -> [Node_Id]
Command.unpack_n_info_plain
g_queryTree1_unpack :: DuplexOsc m => Command.Group_Id -> m Status.Query_Node
g_queryTree1_unpack :: forall (m :: * -> *). DuplexOsc m => Node_Id -> m Query_Node
g_queryTree1_unpack Node_Id
n = do
Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage ([(Node_Id, Bool)] -> Message
Command.g_queryTree [(Node_Id
n, Bool
True)])
Message
r <- Address_Pattern -> m Message
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m Message
waitReply Address_Pattern
"/g_queryTree.reply"
Query_Node -> m Query_Node
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Datum] -> Query_Node
Status.queryTree (Message -> [Datum]
messageDatum Message
r))
serverStatus :: DuplexOsc m => m [String]
serverStatus :: forall (m :: * -> *). DuplexOsc m => m [Address_Pattern]
serverStatus = ([Datum] -> [Address_Pattern]) -> m [Datum] -> m [Address_Pattern]
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Datum] -> [Address_Pattern]
Status.statusFormat m [Datum]
forall (m :: * -> *). DuplexOsc m => m [Datum]
serverStatusData
server_status_concise :: DuplexOsc m => m String
server_status_concise :: forall (m :: * -> *). DuplexOsc m => m Address_Pattern
server_status_concise = ([Datum] -> Address_Pattern) -> m [Datum] -> m Address_Pattern
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Datum] -> Address_Pattern
Status.status_format_concise m [Datum]
forall (m :: * -> *). DuplexOsc m => m [Datum]
serverStatusData
serverSampleRateNominal :: DuplexOsc m => m Double
serverSampleRateNominal :: forall (m :: * -> *). DuplexOsc m => m Double
serverSampleRateNominal = ([Datum] -> Double) -> m [Datum] -> m Double
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Node_Id -> [Datum] -> Double
forall n. Floating n => Node_Id -> [Datum] -> n
Status.extractStatusField Node_Id
7) m [Datum]
forall (m :: * -> *). DuplexOsc m => m [Datum]
serverStatusData
serverSampleRateActual :: DuplexOsc m => m Double
serverSampleRateActual :: forall (m :: * -> *). DuplexOsc m => m Double
serverSampleRateActual = ([Datum] -> Double) -> m [Datum] -> m Double
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Node_Id -> [Datum] -> Double
forall n. Floating n => Node_Id -> [Datum] -> n
Status.extractStatusField Node_Id
8) m [Datum]
forall (m :: * -> *). DuplexOsc m => m [Datum]
serverStatusData
serverStatusData :: DuplexOsc m => m [Datum]
serverStatusData :: forall (m :: * -> *). DuplexOsc m => m [Datum]
serverStatusData = do
Message -> m ()
forall (m :: * -> *). SendOsc m => Message -> m ()
sendMessage Message
Command.status
Address_Pattern -> m [Datum]
forall (m :: * -> *). RecvOsc m => Address_Pattern -> m [Datum]
waitDatum Address_Pattern
"/status.reply"
serverTree :: DuplexOsc m => m [String]
serverTree :: forall (m :: * -> *). DuplexOsc m => m [Address_Pattern]
serverTree = do
Query_Node
qt <- Node_Id -> m Query_Node
forall (m :: * -> *). DuplexOsc m => Node_Id -> m Query_Node
g_queryTree1_unpack Node_Id
0
let tr :: Tree Query_Node
tr = Query_Node -> Tree Query_Node
Status.queryTree_rt Query_Node
qt
[Address_Pattern] -> m [Address_Pattern]
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return [Address_Pattern
"***** SuperCollider Server Tree *****", Tree Address_Pattern -> Address_Pattern
Tree.drawTree ((Query_Node -> Address_Pattern)
-> Tree Query_Node -> Tree Address_Pattern
forall a b. (a -> b) -> Tree a -> Tree b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Query_Node -> Address_Pattern
Status.query_node_pp Tree Query_Node
tr)]