module Sound.SC3.UGen.UId where
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class as M
import Control.Monad.Trans.Reader
import Data.Unique
import Sound.OSC.Transport.FD as T
class (Functor m,Applicative m,M.MonadIO m) => UId m where
generateUId :: m Int
generateUId = fmap hashUnique (M.liftIO newUnique)
instance UId IO where
generateUId = liftM hashUnique newUnique
instance (T.Transport t,Functor io,Applicative io,MonadIO io) =>
UId (ReaderT t io) where
generateUId = ReaderT (M.liftIO . const generateUId)
type Fn1 a b = a -> b
type Fn2 a b c = a -> b -> c
type Fn3 a b c d = a -> b -> c -> d
type Fn4 a b c d e = a -> b -> c -> d -> e
liftUId :: UId m => (Int -> Fn1 a b) -> Fn1 a (m b)
liftUId f a = do
n <- generateUId
return (f n a)
liftUId2 :: UId m => (Int -> Fn2 a b c) -> Fn2 a b (m c)
liftUId2 f a b = do
n <- generateUId
return (f n a b)
liftUId3 :: UId m => (Int -> Fn3 a b c d) -> Fn3 a b c (m d)
liftUId3 f a b c = do
n <- generateUId
return (f n a b c)
liftUId4 :: UId m => (Int -> Fn4 a b c d e) -> Fn4 a b c d (m e)
liftUId4 f a b c d = do
n <- generateUId
return (f n a b c d)