{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE 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)
import qualified Data.ByteString.UTF8 as UTF8
import Data.Int
class (Monad m , MonadIO m) => VividAction (m :: * -> *) where
callOSC :: OSC -> m ()
callOSC = callBS . 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 message = do
now <- getTime
syncId <- newSyncId
callBS $ encodeOSCBundle $
OSCBundle now [Right message, Right $ SCCmd.sync syncId]
waitForSync syncId
oscWSync :: VividAction m => (SyncId -> m ()) -> m ()
oscWSync actionFromId = do
syncId <- newSyncId
actionFromId syncId
waitForSync syncId