{-# LINE 1 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Sound.ALSA.Sequencer.Subscribe.Query
( T
, Type(..)
, malloc
, copy
, clone
, getClient
, getPort
, getRoot
, getType
, getIndex
, getNumSubs
, getAddr
, getQueue
, getExclusive
, getTimeUpdate
, getTimeReal
, setClient
, setPort
, setType
, setIndex
, query
, queryAll
) where
import qualified Sound.ALSA.Sequencer.Marshal.Sequencer as Seq
import qualified Sound.ALSA.Sequencer.Marshal.Address as Addr
import qualified Sound.ALSA.Sequencer.Marshal.Client as Client
import qualified Sound.ALSA.Sequencer.Marshal.Port as Port
import qualified Sound.ALSA.Sequencer.Marshal.Queue as Queue
import qualified Sound.ALSA.Sequencer.Area as Area
import qualified Sound.ALSA.Sequencer.Utility as U
import qualified Sound.ALSA.Exception as Exc
import qualified Foreign.C.Types as C
import Foreign.Ptr (Ptr, )
import Data.Word (Word, )
import Data.Maybe.HT (toMaybe, )
data T_
newtype T = Cons (Area.ForeignPtr T_)
with :: T -> (Area.Ptr T_ -> IO a) -> IO a
with (Cons p) f = Area.withForeignPtr p f
malloc :: IO T
malloc = Area.alloca $ \p ->
do Exc.checkResult_ "Sequencer.query_subscribe" =<< malloc_ p
fmap Cons (Area.newForeignPtr free =<< Area.peek p)
setPort :: T -> T -> IO ()
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_malloc"
malloc_ :: Area.Ptr (Area.Ptr T_) -> IO C.CInt
foreign import ccall unsafe "alsa/asoundlib.h &snd_seq_query_subscribe_free"
free :: Area.FunPtr (Area.Ptr T_ -> IO ())
copy
:: T
-> T
-> IO ()
copy to from =
with to $ \p1 ->
with from $ \p2 ->
copy_ p1 p2
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_copy"
copy_ :: Area.Ptr T_ -> Area.Ptr T_ -> IO ()
clone :: T -> IO T
clone :: T -> IO T
clone T
from =
do T
to <- IO T
malloc
copy to from
forall (m :: * -> *) a. Monad m => a -> m a
return T
to
instance Area.C T where
malloc = malloc
copy = copy
clone = clone
{-# LINE 64 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getClient :: T -> IO Client.T
getClient i =
fmap Client.imp $ with i getClient_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_client"
getClient_ :: Area.Ptr T_ -> IO C.CInt
setClient :: T -> Client.T -> IO ()
setClient i c =
with i (flip setClient_ (Client.exp c))
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_set_client"
setClient_ :: Area.Ptr T_ -> C.CInt -> IO ()
{-# LINE 67 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getPort :: T -> IO Port.T
getPort i =
fmap Port.imp $ with i getPort_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_port"
getPort_ :: Area.Ptr T_ -> IO C.CInt
setPort :: T -> Port.T -> IO ()
setPort i c =
with i (flip setPort_ (Port.exp c))
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_set_port"
setPort_ :: Area.Ptr T_ -> C.CInt -> IO ()
{-# LINE 69 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getType :: T -> IO Type
getType i =
fmap impType $ with i getType_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_type"
getType_ :: Area.Ptr T_ -> IO C.CInt
setType :: T -> Type -> IO ()
setType i c =
with i (flip setType_ (expType c))
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_set_type"
setType_ :: Area.Ptr T_ -> C.CInt -> IO ()
{-# LINE 71 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getIndex :: T -> IO Word
getIndex i =
fmap fromIntegral $ with i getIndex_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_index"
getIndex_ :: Area.Ptr T_ -> IO C.CInt
setIndex :: T -> Word -> IO ()
setIndex i c =
with i (flip setIndex_ (fromIntegral c))
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_set_index"
setIndex_ :: Area.Ptr T_ -> C.CInt -> IO ()
{-# LINE 73 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getNumSubs :: T -> IO Word
getNumSubs i =
fmap fromIntegral $ with i getNumSubs_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_num_subs"
getNumSubs_ :: Area.Ptr T_ -> IO C.CInt
{-# LINE 76 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getQueue :: T -> IO Queue.T
getQueue i =
fmap Queue.imp $ with i getQueue_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_queue"
getQueue_ :: Area.Ptr T_ -> IO C.CInt
{-# LINE 77 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getExclusive :: T -> IO Bool
getExclusive i =
fmap (0 /=) $ with i getExclusive_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_exclusive"
getExclusive_ :: Area.Ptr T_ -> IO C.CInt
{-# LINE 78 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getTimeUpdate :: T -> IO Bool
getTimeUpdate i =
fmap (0 /=) $ with i getTimeUpdate_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_time_update"
getTimeUpdate_ :: Area.Ptr T_ -> IO C.CInt
{-# LINE 79 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getTimeReal :: T -> IO Bool
getTimeReal i =
fmap (0 /=) $ with i getTimeReal_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_time_real"
getTimeReal_ :: Area.Ptr T_ -> IO C.CInt
{-# LINE 80 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getRoot :: T -> IO Addr.T
getRoot i =
Area.peek =<< with i getRoot_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_root"
getRoot_ :: Area.Ptr T_ -> IO (Area.Ptr Addr.T)
{-# LINE 84 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
setRoot :: T -> Addr.T -> IO ()
setRoot i c =
with i (\iptr -> Area.with c (setRoot_ iptr))
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_set_root"
setRoot_ :: Area.Ptr T_ -> (Area.Ptr Addr.T) -> IO ()
{-# LINE 86 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
getAddr :: T -> IO Addr.T
getAddr i =
Area.peek =<< with i getAddr_
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_subscribe_get_addr"
getAddr_ :: Area.Ptr T_ -> IO (Area.Ptr Addr.T)
{-# LINE 88 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
queryPort :: Seq.T mode -> T -> IO Bool
queryPort (Seq.Cons h) q =
U.checkResultQuery "Subscribe.queryPort" =<< with q (queryPort_ h)
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_query_port_subscribers"
queryPort_ :: Ptr Seq.Core -> Ptr T_ -> IO C.CInt
query :: Seq.T mode -> Addr.T -> Type -> Word -> IO (Maybe T)
query ss root t i = do
q <- malloc
setRoot q root
setType q t
setIndex q i
r <- queryPort ss q
return $ toMaybe r q
queryAll :: Seq.T mode -> Addr.T -> Type -> IO [T]
queryAll :: forall mode. T mode -> T -> Type -> IO [T]
queryAll T mode
ss T
root Type
t = Word -> IO [T]
queryRest Word
0 where
queryRest :: Word -> IO [T]
queryRest Word
i = forall mode. T mode -> T -> Type -> Word -> IO (Maybe T)
query T mode
ss T
root Type
t Word
i forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return []) (\T
q -> (T
qforall a. a -> [a] -> [a]
:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Word -> IO [T]
queryRest (forall a. Enum a => a -> a
succ Word
i))
data Type =
Read
| Write
deriving (Int -> Type -> ShowS
[Type] -> ShowS
Type -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Type] -> ShowS
$cshowList :: [Type] -> ShowS
show :: Type -> String
$cshow :: Type -> String
showsPrec :: Int -> Type -> ShowS
$cshowsPrec :: Int -> Type -> ShowS
Show, Type -> Type -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Type -> Type -> Bool
$c/= :: Type -> Type -> Bool
== :: Type -> Type -> Bool
$c== :: Type -> Type -> Bool
Eq, Eq Type
Type -> Type -> Bool
Type -> Type -> Ordering
Type -> Type -> Type
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Type -> Type -> Type
$cmin :: Type -> Type -> Type
max :: Type -> Type -> Type
$cmax :: Type -> Type -> Type
>= :: Type -> Type -> Bool
$c>= :: Type -> Type -> Bool
> :: Type -> Type -> Bool
$c> :: Type -> Type -> Bool
<= :: Type -> Type -> Bool
$c<= :: Type -> Type -> Bool
< :: Type -> Type -> Bool
$c< :: Type -> Type -> Bool
compare :: Type -> Type -> Ordering
$ccompare :: Type -> Type -> Ordering
Ord, Int -> Type
Type -> Int
Type -> [Type]
Type -> Type
Type -> Type -> [Type]
Type -> Type -> Type -> [Type]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Type -> Type -> Type -> [Type]
$cenumFromThenTo :: Type -> Type -> Type -> [Type]
enumFromTo :: Type -> Type -> [Type]
$cenumFromTo :: Type -> Type -> [Type]
enumFromThen :: Type -> Type -> [Type]
$cenumFromThen :: Type -> Type -> [Type]
enumFrom :: Type -> [Type]
$cenumFrom :: Type -> [Type]
fromEnum :: Type -> Int
$cfromEnum :: Type -> Int
toEnum :: Int -> Type
$ctoEnum :: Int -> Type
pred :: Type -> Type
$cpred :: Type -> Type
succ :: Type -> Type
$csucc :: Type -> Type
Enum)
expType :: Type -> C.CInt
expType :: Type -> CInt
expType Type
t = case Type
t of
Type
Read -> CInt
0
{-# LINE 123 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
Write -> 1
{-# LINE 124 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
impType :: C.CInt -> Type
impType :: CInt -> Type
impType CInt
t = case CInt
t of
CInt
0 -> Type
Read
{-# LINE 128 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
1 -> Write
{-# LINE 129 "src/Sound/ALSA/Sequencer/Subscribe/Query.hsc" #-}
_ -> error ("QuerySubscribe.impType: unknown subscription type (" ++ show t ++ ")")