packages feed

alsa-seq-0.5: src/Sound/ALSA/Sequencer/Marshal/Address.hsc

module Sound.ALSA.Sequencer.Marshal.Address where

#include <alsa/asoundlib.h>

import qualified Sound.ALSA.Sequencer.Marshal.Client as Client
import qualified Sound.ALSA.Sequencer.Marshal.Port as Port

import qualified Sound.ALSA.Sequencer.Utility as U

import Foreign.C.Types (CInt, )
import Foreign.Storable
          (Storable, sizeOf, alignment, peek, poke, pokeByteOff, peekByteOff, )


data T = Cons
   { client :: !Client.T
   , port   :: !Port.T
   } deriving (Eq, Ord)

instance Show T where
   showsPrec prec (Cons c p) =
      U.showsRecord prec "Address" [U.showsField c, U.showsField p]


exp :: T -> (CInt,CInt)
exp a = (Client.exp (client a), Port.exp (port a))


instance Storable T where
  sizeOf _    = #size snd_seq_real_time_t
  alignment _ = 4 -- XXX
  peek p      = do cl <- #{peek snd_seq_addr_t, client} p
                   po <- #{peek snd_seq_addr_t, port} p
                   return Cons { client = cl, port = po }
  poke p v    = #{poke snd_seq_addr_t, client} p (client v)
             >> #{poke snd_seq_addr_t, port}   p (port v)


-- | The address of all subscribed ports.
subscribers :: T
subscribers =
   Cons {
      client = Client.subscribers,
      port   = Port.unknown
   }