module Sound.ALSA.Sequencer.Marshal.Port where
import qualified Sound.ALSA.Sequencer.Utility as U
import qualified Foreign.C.Types as C
import qualified Data.Word as Word
import Foreign.Storable (Storable, )
import Data.Ix (Ix, range, index, inRange, rangeSize, )
import Data.Maybe (fromMaybe, )
import qualified Data.Ix.Enum as IxEnum
import qualified Data.EnumSet as EnumSet
newtype T =
Cons Word.Word8
deriving (Eq, Ord, Storable)
instance Show T where
showsPrec prec (Cons x) =
U.showsRecord prec "Port" [U.showsField x]
exp :: T -> C.CInt
exp (Cons p) = fromIntegral p
imp :: C.CInt -> T
imp p = Cons (fromIntegral p)
data CapabilityFlag =
CapOther Int
| CapRead
| CapWrite
| CapSyncRead
| CapSyncWrite
| CapDuplex
| CapSubsRead
| CapSubsWrite
| CapNoExport
deriving (Eq, Ord, Show)
data TypeFlag =
TypeOther Int
| TypeSpecific
| TypeMIDIGeneric
| TypeMIDIGM
| TypeMIDIGS
| TypeMIDIXG
| TypeMIDIMT32
| TypeMIDIGM2
| TypeSynth
| TypeDirectSample
| TypeSample
| TypeHardware
| TypeSoftware
| TypeSynthesizer
| TypePort
| TypeApplication
deriving (Eq, Ord, Show)
capFlagSet :: CapabilityFlag -> Cap
capFlagSet cap =
case cap of
CapOther n -> EnumSet.singletonByPosition n
CapRead -> capRead
CapWrite -> capWrite
CapSyncRead -> capSyncRead
CapSyncWrite -> capSyncWrite
CapDuplex -> capDuplex
CapSubsRead -> capSubsRead
CapSubsWrite -> capSubsWrite
CapNoExport -> capNoExport
instance Enum CapabilityFlag where
fromEnum cap =
case cap of
CapOther n -> n
_ -> EnumSet.mostSignificantPosition (capFlagSet cap)
toEnum n =
fromMaybe (CapOther n) $
lookup (EnumSet.singletonByPosition n) $
map (\cap -> (capFlagSet cap, cap)) $
CapRead :
CapWrite :
CapSyncRead :
CapSyncWrite :
CapDuplex :
CapSubsRead :
CapSubsWrite :
CapNoExport :
[]
instance Ix CapabilityFlag where
range = IxEnum.range
index = IxEnum.index
inRange = IxEnum.inRange
rangeSize = IxEnum.rangeSize
typeFlagSet :: TypeFlag -> Type
typeFlagSet typ =
case typ of
TypeOther n -> EnumSet.singletonByPosition n
TypeSpecific -> typeSpecific
TypeMIDIGeneric -> typeMidiGeneric
TypeMIDIGM -> typeMidiGM
TypeMIDIGS -> typeMidiGS
TypeMIDIXG -> typeMidiXG
TypeMIDIMT32 -> typeMidiMT32
TypeMIDIGM2 -> typeMidiGM2
TypeSynth -> typeSynth
TypeDirectSample -> typeDirectSample
TypeSample -> typeSample
TypeHardware -> typeHardware
TypeSoftware -> typeSoftware
TypeSynthesizer -> typeSynthesizer
TypePort -> typePort
TypeApplication -> typeApplication
instance Enum TypeFlag where
fromEnum typ =
case typ of
TypeOther n -> n
_ -> EnumSet.mostSignificantPosition (typeFlagSet typ)
toEnum n =
fromMaybe (TypeOther n) $
lookup (EnumSet.singletonByPosition n) $
map (\typ -> (typeFlagSet typ, typ)) $
TypeSpecific :
TypeMIDIGeneric :
TypeMIDIGM :
TypeMIDIGS :
TypeMIDIXG :
TypeMIDIMT32 :
TypeMIDIGM2 :
TypeSynth :
TypeDirectSample :
TypeSample :
TypeHardware :
TypeSoftware :
TypeSynthesizer :
TypePort :
TypeApplication :
[]
instance Ix TypeFlag where
range = IxEnum.range
index = IxEnum.index
inRange = IxEnum.inRange
rangeSize = IxEnum.rangeSize
type Cap = EnumSet.T C.CUInt CapabilityFlag
type Type = EnumSet.T C.CUInt TypeFlag
systemTimer :: T
systemTimer = Cons 0
systemAnnounce :: T
systemAnnounce = Cons 1
unknown :: T
unknown = Cons 253
capRead :: Cap
capRead = EnumSet.Cons 1
capWrite :: Cap
capWrite = EnumSet.Cons 2
capSyncRead :: Cap
capSyncRead = EnumSet.Cons 4
capSyncWrite :: Cap
capSyncWrite = EnumSet.Cons 8
capDuplex :: Cap
capDuplex = EnumSet.Cons 16
capSubsRead :: Cap
capSubsRead = EnumSet.Cons 32
capSubsWrite :: Cap
capSubsWrite = EnumSet.Cons 64
capNoExport :: Cap
capNoExport = EnumSet.Cons 128
caps :: [Cap] -> Cap
caps = EnumSet.unions
typeSpecific :: Type
typeSpecific = EnumSet.Cons 1
typeMidiGeneric :: Type
typeMidiGeneric = EnumSet.Cons 2
typeMidiGM :: Type
typeMidiGM = EnumSet.Cons 4
typeMidiGS :: Type
typeMidiGS = EnumSet.Cons 8
typeMidiXG :: Type
typeMidiXG = EnumSet.Cons 16
typeMidiMT32 :: Type
typeMidiMT32 = EnumSet.Cons 32
typeMidiGM2 :: Type
typeMidiGM2 = EnumSet.Cons 64
typeSynth :: Type
typeSynth = EnumSet.Cons 1024
typeDirectSample :: Type
typeDirectSample = EnumSet.Cons 2048
typeSample :: Type
typeSample = EnumSet.Cons 4096
typeHardware :: Type
typeHardware = EnumSet.Cons 65536
typeSoftware :: Type
typeSoftware = EnumSet.Cons 131072
typeSynthesizer :: Type
typeSynthesizer = EnumSet.Cons 262144
typePort :: Type
typePort = EnumSet.Cons 524288
typeApplication :: Type
typeApplication = EnumSet.Cons 1048576
types :: [Type] -> Type
types = EnumSet.unions