packages feed

alure-0.1: source/Sound/UI/ALURE/Marshal.hs

module Sound.UI.ALURE.Marshal
  (
    fromContextAttributes,

    marshalBuffer,
    unmarshalBuffer,
    marshalBool,
    unmarshalBool,
  ) where

import Sound.UI.ALURE.Internal
import Sound.OpenAL.ALC.Context
import Sound.OpenAL.AL.Buffer
import qualified Sound.OpenAL.AL.BufferInternal as AL


{- 
  Note:
  The following module converts between types in haskell OpenAL types and
  C OpenAL types. Since the haskell OpenAL package uses internal modules
  for this, we have our own hack here.
-}

marshalBuffer :: Maybe Buffer -> CALUInt
marshalBuffer = 
    fromIntegral . AL.marshalBuffer

unmarshalBuffer :: CALUInt -> Maybe Buffer 
unmarshalBuffer = 
    AL.unmarshalBuffer . fromIntegral



alc_FREQUENCY :: CALCInt
alc_FREQUENCY         = 0x1007

alc_REFRESH :: CALCInt
alc_REFRESH           = 0x1008

alc_SYNC :: CALCInt
alc_SYNC              = 0x1009

alc_MONO_SOURCES :: CALCInt
alc_MONO_SOURCES      = 0x1010

alc_STEREO_SOURCES :: CALCInt
alc_STEREO_SOURCES    = 0x1011

marshalContextAttribute :: ContextAttribute -> (CALCInt, CALCInt)
marshalContextAttribute a = case a of
   Frequency f -> (alc_FREQUENCY, round f)
   Refresh r -> (alc_REFRESH, round r)
   Sync s -> (alc_SYNC, marshalALCboolean s)
   MonoSources m -> (alc_MONO_SOURCES, fromIntegral m)
   StereoSources s -> (alc_STEREO_SOURCES, fromIntegral s)
   where
      marshalALCboolean = fromIntegral . fromEnum

fromAttribs :: [ContextAttribute] -> [CALCInt]
fromAttribs attrs =
    let pairToList (key, value) = [key, value]
    in  concatMap (pairToList . marshalContextAttribute) attrs



fromContextAttributes :: [ContextAttribute] -> [CALCInt]
fromContextAttributes = fromAttribs


marshalBool :: Bool -> CALBoolean
marshalBool = 
    toEnum . fromEnum

unmarshalBool :: CALBoolean -> Bool
unmarshalBool = 
    toEnum . fromEnum