{-# LANGUAGE ForeignFunctionInterface #-}
module Sound.ALSA.Sequencer.Event (
output,
outputBuffer,
outputDirect,
outputPending,
extractOutput,
removeOutput,
drainOutput,
dropOutput,
dropOutputBuffer,
syncOutputQueue,
input,
inputPending,
dropInput,
dropInputBuffer,
Event.T(..), simple, forSourcePort, forConnection,
Event.Data(..),
Event.Type,
NoteEv(..), Note(..), simpleNote,
CtrlEv(..), Ctrl(..),
CustomEv(..), Custom(..), customZero,
ExtEv(..),
QueueEv(..),
AddrEv(..),
ConnEv(..),
EmptyEv(..),
Tag(..),
Tempo(..),
Parameter(..),
Value(..),
Channel(..),
Pitch(..),
Velocity(..), normalVelocity, offVelocity,
Duration(..),
) where
import Sound.ALSA.Sequencer.Marshal.Event as Event
import qualified Sound.ALSA.Sequencer.Address as Addr
import qualified Sound.ALSA.Sequencer.Port as Port
import qualified Sound.ALSA.Sequencer.Client as Client
import qualified Sound.ALSA.Sequencer.Connect as Connect
import qualified Sound.ALSA.Sequencer.Queue as Queue
import qualified Sound.ALSA.Sequencer.Marshal.Sequencer as Seq
import qualified Sound.ALSA.Sequencer.Marshal.Time as Time
import qualified Sound.ALSA.Exception as Exc
import qualified Foreign.C.Types as C
import Foreign.Ptr (Ptr, nullPtr, )
import Foreign.Marshal.Alloc (alloca, )
import Foreign.Storable (peek, )
import Data.Word (Word, )
syncOutputQueue :: Seq.T mode -> IO ()
syncOutputQueue :: forall mode. T mode -> IO ()
syncOutputQueue (Seq.Cons Ptr Core
h) =
forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"syncOutputQueue" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> IO CInt
snd_seq_sync_output_queue Ptr Core
h
foreign import ccall safe "alsa/asoundlib.h snd_seq_sync_output_queue"
snd_seq_sync_output_queue :: Ptr Seq.Core -> IO C.CInt
input :: Seq.AllowInput mode => Seq.T mode -> IO Event.T
input :: forall mode. AllowInput mode => T mode -> IO T
input (Seq.Cons Ptr Core
h) = forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr T)
p ->
do forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"input" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> Ptr (Ptr T) -> IO CInt
snd_seq_event_input Ptr Core
h Ptr (Ptr T)
p
forall a. Storable a => Ptr a -> IO a
peek forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr T)
p
foreign import ccall safe "alsa/asoundlib.h snd_seq_event_input"
snd_seq_event_input :: Ptr Seq.Core -> Ptr (Ptr Event.T) -> IO C.CInt
checkResult :: String -> C.CInt -> IO Word
checkResult :: String -> CInt -> IO Word
checkResult String
loc CInt
n =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ forall a. Integral a => String -> a -> IO a
Exc.checkResult String
loc CInt
n
inputPending
:: Seq.AllowInput mode
=> Seq.T mode
-> Bool
-> IO Word
inputPending :: forall mode. AllowInput mode => T mode -> Bool -> IO Word
inputPending (Seq.Cons Ptr Core
h) Bool
fill =
String -> CInt -> IO Word
checkResult String
"inputPending" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> CInt -> IO CInt
snd_seq_event_input_pending Ptr Core
h (if Bool
fill then CInt
1 else CInt
0)
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_event_input_pending"
snd_seq_event_input_pending :: Ptr Seq.Core -> C.CInt -> IO C.CInt
output :: Seq.AllowOutput mode
=> Seq.T mode
-> Event.T
-> IO Word
output :: forall mode. AllowOutput mode => T mode -> T -> IO Word
output (Seq.Cons Ptr Core
h) T
e =
forall a. T -> (Ptr T -> IO a) -> IO a
Event.with T
e forall a b. (a -> b) -> a -> b
$ \Ptr T
p -> String -> CInt -> IO Word
checkResult String
"output" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> Ptr T -> IO CInt
snd_seq_event_output Ptr Core
h Ptr T
p
foreign import ccall safe "alsa/asoundlib.h snd_seq_event_output"
snd_seq_event_output :: Ptr Seq.Core -> Ptr Event.T -> IO C.CInt
outputBuffer :: Seq.AllowOutput mode
=> Seq.T mode
-> Event.T
-> IO Word
outputBuffer :: forall mode. AllowOutput mode => T mode -> T -> IO Word
outputBuffer (Seq.Cons Ptr Core
h) T
e =
forall a. T -> (Ptr T -> IO a) -> IO a
Event.with T
e forall a b. (a -> b) -> a -> b
$ \Ptr T
p -> String -> CInt -> IO Word
checkResult String
"outputBuffer" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> Ptr T -> IO CInt
snd_seq_event_output_buffer Ptr Core
h Ptr T
p
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_event_output_buffer"
snd_seq_event_output_buffer :: Ptr Seq.Core -> Ptr Event.T -> IO C.CInt
outputDirect
:: Seq.AllowOutput mode
=> Seq.T mode
-> Event.T
-> IO Word
outputDirect :: forall mode. AllowOutput mode => T mode -> T -> IO Word
outputDirect (Seq.Cons Ptr Core
h) T
e =
forall a. T -> (Ptr T -> IO a) -> IO a
Event.with T
e forall a b. (a -> b) -> a -> b
$ \Ptr T
p -> String -> CInt -> IO Word
checkResult String
"outputDirect" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> Ptr T -> IO CInt
snd_seq_event_output_direct Ptr Core
h Ptr T
p
foreign import ccall safe "alsa/asoundlib.h snd_seq_event_output_direct"
snd_seq_event_output_direct :: Ptr Seq.Core -> Ptr Event.T -> IO C.CInt
outputPending
:: Seq.AllowOutput mode
=> Seq.T mode
-> IO Word
outputPending :: forall mode. AllowOutput mode => T mode -> IO Word
outputPending (Seq.Cons Ptr Core
h) =
forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Ptr Core -> IO CInt
snd_seq_event_output_pending Ptr Core
h
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_event_output_pending"
snd_seq_event_output_pending :: Ptr Seq.Core -> IO C.CInt
extractOutput
:: Seq.AllowOutput mode
=> Seq.T mode
-> IO Event.T
(Seq.Cons Ptr Core
h) =
forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr T)
p -> do forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"extractOutput" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> Ptr (Ptr T) -> IO CInt
snd_seq_extract_output Ptr Core
h Ptr (Ptr T)
p
forall a. Storable a => Ptr a -> IO a
peek forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. Storable a => Ptr a -> IO a
peek Ptr (Ptr T)
p
removeOutput :: Seq.AllowOutput mode
=> Seq.T mode -> IO ()
removeOutput :: forall mode. AllowOutput mode => T mode -> IO ()
removeOutput (Seq.Cons Ptr Core
h) = forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"removeOutput" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> Ptr (Ptr T) -> IO CInt
snd_seq_extract_output Ptr Core
h forall a. Ptr a
nullPtr
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_extract_output"
:: Ptr Seq.Core -> Ptr (Ptr Event.T) -> IO C.CInt
drainOutput
:: Seq.AllowOutput mode
=> Seq.T mode
-> IO Word
drainOutput :: forall mode. AllowOutput mode => T mode -> IO Word
drainOutput (Seq.Cons Ptr Core
h) = String -> CInt -> IO Word
checkResult String
"drainOutput" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> IO CInt
snd_seq_drain_output Ptr Core
h
foreign import ccall safe "alsa/asoundlib.h snd_seq_drain_output"
snd_seq_drain_output :: Ptr Seq.Core -> IO C.CInt
dropOutput
:: Seq.AllowOutput mode
=> Seq.T mode -> IO ()
dropOutput :: forall mode. AllowOutput mode => T mode -> IO ()
dropOutput (Seq.Cons Ptr Core
h) = forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"dropOutput" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> IO CInt
snd_seq_drop_output Ptr Core
h
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_drop_output"
snd_seq_drop_output :: Ptr Seq.Core -> IO C.CInt
dropOutputBuffer
:: Seq.AllowOutput mode
=> Seq.T mode -> IO ()
dropOutputBuffer :: forall mode. AllowOutput mode => T mode -> IO ()
dropOutputBuffer (Seq.Cons Ptr Core
h) = forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"dropOutputBuffer" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> IO CInt
snd_seq_drop_output_buffer Ptr Core
h
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_drop_output_buffer"
snd_seq_drop_output_buffer :: Ptr Seq.Core -> IO C.CInt
dropInput
:: Seq.AllowInput mode
=> Seq.T mode -> IO ()
dropInput :: forall mode. AllowInput mode => T mode -> IO ()
dropInput (Seq.Cons Ptr Core
h) = forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"dropInput" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> IO CInt
snd_seq_drop_input Ptr Core
h
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_drop_input"
snd_seq_drop_input :: Ptr Seq.Core -> IO C.CInt
dropInputBuffer
:: Seq.AllowInput mode
=> Seq.T mode -> IO ()
dropInputBuffer :: forall mode. AllowInput mode => T mode -> IO ()
dropInputBuffer (Seq.Cons Ptr Core
h) = forall a. Integral a => String -> a -> IO ()
Exc.checkResult_ String
"dropInputBuffer" forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr Core -> IO CInt
snd_seq_drop_input_buffer Ptr Core
h
foreign import ccall unsafe "alsa/asoundlib.h snd_seq_drop_input_buffer"
snd_seq_drop_input_buffer :: Ptr Seq.Core -> IO C.CInt
simpleNote :: Channel -> Pitch -> Velocity -> Event.Note
simpleNote :: Channel -> Pitch -> Velocity -> Note
simpleNote Channel
c Pitch
n Velocity
v =
Event.Note {
noteChannel :: Channel
Event.noteChannel = Channel
c,
noteNote :: Pitch
Event.noteNote = Pitch
n,
noteVelocity :: Velocity
Event.noteVelocity = Velocity
v,
noteOffVelocity :: Velocity
Event.noteOffVelocity = Velocity
offVelocity,
noteDuration :: Duration
Event.noteDuration = Word32 -> Duration
Duration Word32
0
}
normalVelocity, offVelocity :: Velocity
normalVelocity :: Velocity
normalVelocity = Word8 -> Velocity
Velocity Word8
64
offVelocity :: Velocity
offVelocity = Word8 -> Velocity
Velocity Word8
0
simple :: Addr.T -> Event.Data -> Event.T
simple :: T -> Data -> T
simple T
src Data
bdy = Cons
{ highPriority :: Bool
Event.highPriority = Bool
False
, tag :: Tag
Event.tag = Word8 -> Tag
Tag Word8
0
, queue :: T
Event.queue = T
Queue.direct
, time :: T
Event.time = Stamp -> T
Time.consAbs forall a b. (a -> b) -> a -> b
$ Word32 -> Stamp
Time.Tick Word32
0
, source :: T
Event.source = T
src
, dest :: T
Event.dest = T
Addr.subscribers
, body :: Data
Event.body = Data
bdy
}
forSourcePort :: Port.T -> Event.Data -> Event.T
forSourcePort :: T -> Data -> T
forSourcePort T
port =
T -> Data -> T
simple (T -> T -> T
Addr.Cons T
Client.unknown T
port)
forConnection :: Connect.T -> Event.Data -> Event.T
forConnection :: T -> Data -> T
forConnection (Connect.Cons T
src T
dst) Data
bdy =
(T -> Data -> T
simple T
src Data
bdy) { dest :: T
Event.dest = T
dst }
customZero :: Event.Custom
customZero :: Custom
customZero = Word32 -> Word32 -> Word32 -> Custom
Event.Custom Word32
0 Word32
0 Word32
0