Safe Haskell | None |
---|---|
Language | Haskell2010 |
Interface to RtMidi
Synopsis
- data InputDevice
- data OutputDevice
- class IsDevice d where
- getDeviceType :: d -> DeviceType
- data DeviceType
- data Api
- newtype Error = Error String
- ready :: (MonadIO m, IsDevice d) => d -> m Bool
- compiledApis :: MonadIO m => m [Api]
- openPort :: (MonadIO m, IsDevice d) => d -> Int -> String -> m ()
- openVirtualPort :: (MonadIO m, IsDevice d) => d -> String -> m ()
- closePort :: (MonadIO m, IsDevice d) => d -> m ()
- portCount :: (MonadIO m, IsDevice d) => d -> m Int
- portName :: (MonadIO m, IsDevice d) => d -> Int -> m (Maybe String)
- listPorts :: (MonadIO m, IsDevice d) => d -> m [(Int, String)]
- findPort :: (MonadIO m, IsDevice d) => d -> (String -> Bool) -> m (Maybe Int)
- defaultInput :: MonadIO m => m InputDevice
- createInput :: MonadIO m => Api -> String -> Int -> m InputDevice
- setCallback :: MonadUnliftIO m => InputDevice -> (Double -> [Word8] -> m ()) -> m ()
- setForeignCallback :: MonadIO m => InputDevice -> FunPtr (CDouble -> Ptr CUChar -> CInt -> Ptr () -> IO ()) -> Ptr () -> m ()
- cancelCallback :: MonadIO m => InputDevice -> m ()
- ignoreTypes :: MonadIO m => InputDevice -> Bool -> Bool -> Bool -> m ()
- getMessage :: MonadIO m => InputDevice -> m (Double, [Word8])
- getMessageSized :: MonadIO m => InputDevice -> Int -> m (Double, [Word8])
- defaultOutput :: MonadIO m => m OutputDevice
- createOutput :: MonadIO m => Api -> String -> m OutputDevice
- sendMessage :: MonadIO m => OutputDevice -> [Word8] -> m ()
- currentApi :: MonadIO m => IsDevice d => d -> m Api
Documentation
data InputDevice Source #
A handle to a device to be used for input
Instances
Eq InputDevice Source # | |
Defined in Sound.RtMidi (==) :: InputDevice -> InputDevice -> Bool # (/=) :: InputDevice -> InputDevice -> Bool # | |
Show InputDevice Source # | |
Defined in Sound.RtMidi showsPrec :: Int -> InputDevice -> ShowS # show :: InputDevice -> String # showList :: [InputDevice] -> ShowS # | |
IsDevice InputDevice Source # | |
Defined in Sound.RtMidi toDevice :: InputDevice -> Device |
data OutputDevice Source #
A handle to a device to be used for input
Instances
Eq OutputDevice Source # | |
Defined in Sound.RtMidi (==) :: OutputDevice -> OutputDevice -> Bool # (/=) :: OutputDevice -> OutputDevice -> Bool # | |
Show OutputDevice Source # | |
Defined in Sound.RtMidi showsPrec :: Int -> OutputDevice -> ShowS # show :: OutputDevice -> String # showList :: [OutputDevice] -> ShowS # | |
IsDevice OutputDevice Source # | |
Defined in Sound.RtMidi toDevice :: OutputDevice -> Device |
class IsDevice d where Source #
Generalizes InputDevice
and OutputDevice
for use in common functions
toDevice, getDeviceType
getDeviceType :: d -> DeviceType Source #
Instances
IsDevice OutputDevice Source # | |
Defined in Sound.RtMidi toDevice :: OutputDevice -> Device | |
IsDevice InputDevice Source # | |
Defined in Sound.RtMidi toDevice :: InputDevice -> Device |
data DeviceType Source #
Allows us to discriminate in/out functions in generic contexts
Instances
Eq DeviceType Source # | |
Defined in Sound.RtMidi (==) :: DeviceType -> DeviceType -> Bool # (/=) :: DeviceType -> DeviceType -> Bool # | |
Show DeviceType Source # | |
Defined in Sound.RtMidi showsPrec :: Int -> DeviceType -> ShowS # show :: DeviceType -> String # showList :: [DeviceType] -> ShowS # |
Enum of RtMidi-supported APIs
An internal RtMidi error
Instances
Eq Error Source # | |
Show Error Source # | |
Exception Error Source # | |
Defined in Sound.RtMidi toException :: Error -> SomeException # fromException :: SomeException -> Maybe Error # displayException :: Error -> String # |
:: (MonadIO m, IsDevice d) | |
=> d | |
-> Int | port number |
-> String | name for the application port that is used |
-> m () |
Open a MIDI connection
openVirtualPort :: (MonadIO m, IsDevice d) => d -> String -> m () Source #
This function creates a virtual MIDI output port to which other software applications can connect.
This type of functionality is currently only supported by the Macintosh OS X, Linux ALSA and JACK APIs (the function does nothing with the other APIs).
closePort :: (MonadIO m, IsDevice d) => d -> m () Source #
Close an open MIDI connection (if one exists).
portCount :: (MonadIO m, IsDevice d) => d -> m Int Source #
Return the number of MIDI ports available to the Device
.
portName :: (MonadIO m, IsDevice d) => d -> Int -> m (Maybe String) Source #
Return a string identifier for the specified MIDI port number.
Nothing
is returned if an invalid port specifier is provided.
listPorts :: (MonadIO m, IsDevice d) => d -> m [(Int, String)] Source #
Convenience function to list ports.
Note that the underlying library does not offer an "atomic" interface for this so results may be inconsistent if you connect/disconnect ports during this call.
findPort :: (MonadIO m, IsDevice d) => d -> (String -> Bool) -> m (Maybe Int) Source #
Convenience function to lookup the first port satisfying the predicate.
You may want to find an exact name:
findPort d (== name)
Or you may want to match part of a name:
findPort d (isInfixOf name)
Note that if you are performing many lookups, it's better to use listPorts
and
do the lookups yourself (see the caveats there too).
defaultInput :: MonadIO m => m InputDevice Source #
Default constructor for a Device
to use for input.
:: MonadIO m | |
=> Api | API to use |
-> String | client name |
-> Int | size of the MIDI input queue |
-> m InputDevice |
Create a new Device
to use for input.
:: MonadUnliftIO m | |
=> InputDevice | |
-> (Double -> [Word8] -> m ()) | Function that takes a timestamp and a MIDI message as arguments |
-> m () |
Set a callback function to be invoked for incoming MIDI messages.
The callback function will be called whenever an incoming MIDI message is received. While not absolutely necessary, it is best to set the callback function before opening a MIDI port to avoid leaving some messages in the queue.
:: MonadIO m | |
=> InputDevice | |
-> FunPtr (CDouble -> Ptr CUChar -> CInt -> Ptr () -> IO ()) | |
-> Ptr () | Pointer to context that will be passed into the callback |
-> m () |
Set a foreign callback function to be invoked for incoming MIDI messages.
This variant allows you to set the callback to a C function pointer so we're not forced to enter a Haskell wrapper every invocation.
cancelCallback :: MonadIO m => InputDevice -> m () Source #
Cancel use of the current callback function (if one exists).
Subsequent incoming MIDI messages will be written to the queue and can be retrieved with the getMessage
function.
:: MonadIO m | |
=> InputDevice | |
-> Bool | SysEx messages |
-> Bool | Time messages |
-> Bool | Sense messages |
-> m () |
Specify whether certain MIDI message types should be queued or ignored during input.
By default, MIDI timing and active sensing messages are ignored during message input because of their
relative high data rates. MIDI sysex messages are ignored by default as well.
Variable values of true
imply that the respective message type will be ignored.
getMessage :: MonadIO m => InputDevice -> m (Double, [Word8]) Source #
Return data bytes for the next available MIDI message in the input queue and the event delta-time in seconds.
This function returns immediately whether a new message is available or not.
A valid message is indicated by whether the list contains any elements.
Note that large sysex messages will be silently dropped! Use getMessageSized
or use a callback to get these safely.
getMessageSized :: MonadIO m => InputDevice -> Int -> m (Double, [Word8]) Source #
Variant of getMessage
that allows you to set message buffer size (typically for large sysex messages).
defaultOutput :: MonadIO m => m OutputDevice Source #
Default constructor for a Device
to use for output.
:: MonadIO m | |
=> Api | API to use |
-> String | client name |
-> m OutputDevice |
Create a new Device
to use for output.
sendMessage :: MonadIO m => OutputDevice -> [Word8] -> m () Source #
Immediately send a single message out an open MIDI output port.