{-# LANGUAGE
KindSignatures
, Rank2Types
#-}
{-# LANGUAGE NoIncoherentInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE NoUndecidableInstances #-}
module Vivid.Actions.Class (
VividAction(..)
, callOSCAndSync
, oscWSync
) where
import Vivid.SC.Server.Types (BufferId, NodeId, SyncId(..))
import qualified Vivid.SC.Server.Commands as SCCmd
import Vivid.OSC
import Vivid.SynthDef.Types (SynthDef)
import Control.Monad.IO.Class (MonadIO)
import Data.ByteString (ByteString)
class (Monad m , MonadIO m) => VividAction (m :: * -> *) where
callOSC :: OSC -> m ()
callOSC = ByteString -> m ()
forall (m :: * -> *). VividAction m => ByteString -> m ()
callBS (ByteString -> m ()) -> (OSC -> ByteString) -> OSC -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OSC -> ByteString
encodeOSC
callBS :: ByteString -> m ()
sync :: m ()
waitForSync :: SyncId -> m ()
wait :: Real n => n -> m ()
getTime :: m Timestamp
newBufferId :: m BufferId
newNodeId :: m NodeId
newSyncId :: m SyncId
fork :: m () -> m ()
defineSD :: SynthDef a -> m ()
callOSCAndSync :: VividAction m => OSC -> m ()
callOSCAndSync :: OSC -> m ()
callOSCAndSync OSC
message = do
Timestamp
now <- m Timestamp
forall (m :: * -> *). VividAction m => m Timestamp
getTime
SyncId
syncId <- m SyncId
forall (m :: * -> *). VividAction m => m SyncId
newSyncId
ByteString -> m ()
forall (m :: * -> *). VividAction m => ByteString -> m ()
callBS (ByteString -> m ()) -> ByteString -> m ()
forall a b. (a -> b) -> a -> b
$ OSCBundle -> ByteString
encodeOSCBundle (OSCBundle -> ByteString) -> OSCBundle -> ByteString
forall a b. (a -> b) -> a -> b
$
Timestamp -> [Either ByteString OSC] -> OSCBundle
OSCBundle Timestamp
now [OSC -> Either ByteString OSC
forall a b. b -> Either a b
Right OSC
message, OSC -> Either ByteString OSC
forall a b. b -> Either a b
Right (OSC -> Either ByteString OSC) -> OSC -> Either ByteString OSC
forall a b. (a -> b) -> a -> b
$ SyncId -> OSC
SCCmd.sync SyncId
syncId]
SyncId -> m ()
forall (m :: * -> *). VividAction m => SyncId -> m ()
waitForSync SyncId
syncId
oscWSync :: VividAction m => (SyncId -> m ()) -> m ()
oscWSync :: (SyncId -> m ()) -> m ()
oscWSync SyncId -> m ()
actionFromId = do
SyncId
syncId <- m SyncId
forall (m :: * -> *). VividAction m => m SyncId
newSyncId
SyncId -> m ()
actionFromId SyncId
syncId
SyncId -> m ()
forall (m :: * -> *). VividAction m => SyncId -> m ()
waitForSync SyncId
syncId