{-# LINE 1 "src/Sound/ALSA/Sequencer/Marshal/Port.hsc" #-}
--------------------------------------------------------------------------------
{-# LINE 2 "src/Sound/ALSA/Sequencer/Marshal/Port.hsc" #-}
-- |
-- Module    : Sound.ALSA.Sequencer.Marshal
-- Copyright : (c) Henning Thielemann, 2010
--             (c) Iavor S. Diatchki, 2007
-- License   : BSD3
--
-- Maintainer: Henning Thielemann
-- Stability : provisional
--
-- PRIVATE MODULE.
--
-- Here we have the various types used by the library,
-- and how they are imported\/exported to C.
--
-- NOTE: In the translations bellow we make the following assumptions
-- about the sizes of C types.
-- CChar  = 8 bits
-- CShort = 16 bit
-- CInt   = 32 bits
--------------------------------------------------------------------------------

module Sound.ALSA.Sequencer.Marshal.Port where


{-# LINE 26 "src/Sound/ALSA/Sequencer/Marshal/Port.hsc" #-}
import qualified Sound.ALSA.Sequencer.Utility as U
import Foreign.C.Types (CInt, CUInt, )
import Foreign.Storable (Storable, )
import Data.Bits ((.|.), )
import Data.Word (Word8, )



-- The type of client ports.
newtype T = Cons Word8 deriving (Eq, Ord, Storable)

instance Show T where
   showsPrec prec (Cons x) =
      U.showsRecord prec "Port" [U.showsField x]


exp :: T -> CInt
exp (Cons p) = fromIntegral p

imp :: CInt -> T
imp p = Cons (fromIntegral p)


-- | Port capabilities.
newtype Cap = Cap { unCap :: CUInt } deriving (Eq,Ord)

-- | Port types.
newtype Type = Type { unType :: CUInt } deriving (Eq,Ord)

systemTimer     :: T
systemTimer     = Cons 0
systemAnnounce  :: T
systemAnnounce  = Cons 1
unknown         :: T
unknown         = Cons 253

{-# LINE 60 "src/Sound/ALSA/Sequencer/Marshal/Port.hsc" #-}

capRead       :: Cap
capRead       = Cap 1
capWrite      :: Cap
capWrite      = Cap 2
capSyncRead   :: Cap
capSyncRead   = Cap 4
capSyncWrite  :: Cap
capSyncWrite  = Cap 8
capDuplex     :: Cap
capDuplex     = Cap 16
capSubsRead   :: Cap
capSubsRead   = Cap 32
capSubsWrite  :: Cap
capSubsWrite  = Cap 64
capNoExport   :: Cap
capNoExport   = Cap 128

{-# LINE 71 "src/Sound/ALSA/Sequencer/Marshal/Port.hsc" #-}

caps :: [Cap] -> Cap
caps cs = Cap (foldl (.|.) 0 (map unCap cs))

typeSpecific      :: Type
typeSpecific      = Type 1
typeMidiGeneric   :: Type
typeMidiGeneric   = Type 2
typeMidiGM        :: Type
typeMidiGM        = Type 4
typeMidiGS        :: Type
typeMidiGS        = Type 8
typeMidiXG        :: Type
typeMidiXG        = Type 16
typeMidiMT32      :: Type
typeMidiMT32      = Type 32
typeMidiGM2       :: Type
typeMidiGM2       = Type 64
typeSynth         :: Type
typeSynth         = Type 1024
typeDirectSample  :: Type
typeDirectSample  = Type 2048
typeSample        :: Type
typeSample        = Type 4096
typeHardware      :: Type
typeHardware      = Type 65536
typeSoftware      :: Type
typeSoftware      = Type 131072
typeSynthesizer   :: Type
typeSynthesizer   = Type 262144
typePort          :: Type
typePort          = Type 524288
typeApplication   :: Type
typeApplication   = Type 1048576

{-# LINE 94 "src/Sound/ALSA/Sequencer/Marshal/Port.hsc" #-}

types :: [Type] -> Type
types cs = Type (foldl (.|.) 0 (map unType cs))