    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.UI.SDL.Mixer.Channels
    -- Copyright   :  (c) David Himmelstrup 2005
    -- License     :  BSD-like
    --
    -- Maintainer  :  lemmih@gmail.com
    -- Stability   :  provisional
    -- Portability :  portable
    --
    -----------------------------------------------------------------------------
    module Graphics.UI.SDL.Mixer.Channels
        ( allocateChannels
        , volume
        , tryPlayChannel
        , playChannel
        , tryFadeInChannel
        , fadeInChannel
        , tryFadeInChannelTimed
        , fadeInChannelTimed
        , pause
        , resume
        , haltChannel
        , expireChannel
        , fadeOutChannel
        , isChannelPlaying
        , numChannelsPlaying
        , isChannelPaused
        , numChannelsPaused
        , fadingChannel
        , getChunk
        ) where

    import Foreign(Ptr, newForeignPtr_, toBool, withForeignPtr)

    import Graphics.UI.SDL.Mixer.Types(Fading, Channel, Chunk, ChunkStruct)
    import Graphics.UI.SDL.General(unwrapInt)

    -- int Mix_AllocateChannels(int numchans)
    foreign import ccall unsafe "Mix_AllocateChannels" allocateChannels :: Int -> IO Int

    -- int Mix_Volume(int channel, int volume)
    foreign import ccall unsafe "Mix_Volume" volume :: Int -> Int -> IO Int

    tryPlayChannel :: Channel -> Chunk -> Int -> IO Int
    tryPlayChannel :: Channel -> Chunk -> Channel -> IO Channel
    tryPlayChannel channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops
        = Channel -> Chunk -> Channel -> Channel -> IO Channel
    tryPlayChannelTimed Channel
    channel Chunk
    chunk Channel
    loops (-1)

    playChannel :: Channel -> Chunk -> Int -> IO Int
    playChannel :: Channel -> Chunk -> Channel -> IO Channel
    playChannel channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops
        = Channel -> Chunk -> Channel -> Channel -> IO Channel
    playChannelTimed Channel
    channel Chunk
    chunk Channel
    loops (-1)

    -- int Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks)
    foreign import ccall unsafe "Mix_PlayChannelTimed" mixPlayChannelTimed
        :: Int -> Ptr ChunkStruct -> Int -> Int -> IO Int
    tryPlayChannelTimed :: Channel -> Chunk -> Int -> Int -> IO Int
    tryPlayChannelTimed :: Channel -> Chunk -> Channel -> Channel -> IO Channel
    tryPlayChannelTimed channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops ticks :: Channel
    ticks
        = Chunk -> (Ptr ChunkStruct -> IO Channel) -> IO Channel
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr Chunk
    chunk ((Ptr ChunkStruct -> IO Channel) -> IO Channel)
    -> (Ptr ChunkStruct -> IO Channel) -> IO Channel
    forall a b. (a -> b) -> a -> b
    $ \chunkPtr :: Ptr ChunkStruct
    chunkPtr ->
          Channel -> Ptr ChunkStruct -> Channel -> Channel -> IO Channel
    mixPlayChannelTimed Channel
    channel Ptr ChunkStruct
    chunkPtr Channel
    loops Channel
    ticks

    playChannelTimed :: Channel -> Chunk -> Int -> Int -> IO Int
    playChannelTimed :: Channel -> Chunk -> Channel -> Channel -> IO Channel
    playChannelTimed channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops ticks :: Channel
    ticks
        = (Channel -> Bool) -> String -> IO Channel -> IO Channel
    unwrapInt (Channel -> Channel -> Bool
    forall a. Eq a => a -> a -> Bool
    /=(-1)) "Mix_PlayChannelTimed"
                    (Channel -> Chunk -> Channel -> Channel -> IO Channel
    tryPlayChannelTimed Channel
    channel Chunk
    chunk Channel
    loops Channel
    ticks)

    tryFadeInChannel :: Channel -> Chunk -> Int -> Int -> IO Int
    tryFadeInChannel :: Channel -> Chunk -> Channel -> Channel -> IO Channel
    tryFadeInChannel channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops ms :: Channel
    ms
        = Channel -> Chunk -> Channel -> Channel -> Channel -> IO Channel
    tryFadeInChannelTimed Channel
    channel Chunk
    chunk Channel
    loops Channel
    ms (-1)

    fadeInChannel :: Channel -> Chunk -> Int -> Int -> IO Int
    fadeInChannel :: Channel -> Chunk -> Channel -> Channel -> IO Channel
    fadeInChannel channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops ms :: Channel
    ms
        = Channel -> Chunk -> Channel -> Channel -> Channel -> IO Channel
    fadeInChannelTimed Channel
    channel Chunk
    chunk Channel
    loops Channel
    ms (-1)

    -- int Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks)
    foreign import ccall unsafe "Mix_FadeInChannelTimed" mixFadeInChannelTimed
        :: Int -> Ptr ChunkStruct -> Int -> Int -> Int -> IO Int
    tryFadeInChannelTimed :: Channel -> Chunk -> Int -> Int -> Int -> IO Int
    tryFadeInChannelTimed :: Channel -> Chunk -> Channel -> Channel -> Channel -> IO Channel
    tryFadeInChannelTimed channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops ms :: Channel
    ms ticks :: Channel
    ticks
        = Chunk -> (Ptr ChunkStruct -> IO Channel) -> IO Channel
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr Chunk
    chunk ((Ptr ChunkStruct -> IO Channel) -> IO Channel)
    -> (Ptr ChunkStruct -> IO Channel) -> IO Channel
    forall a b. (a -> b) -> a -> b
    $ \chunkPtr :: Ptr ChunkStruct
    chunkPtr ->
          Channel
    -> Ptr ChunkStruct -> Channel -> Channel -> Channel -> IO Channel
    mixFadeInChannelTimed Channel
    channel Ptr ChunkStruct
    chunkPtr Channel
    loops Channel
    ms Channel
    ticks

    fadeInChannelTimed :: Channel -> Chunk -> Int -> Int -> Int -> IO Int
    fadeInChannelTimed :: Channel -> Chunk -> Channel -> Channel -> Channel -> IO Channel
    fadeInChannelTimed channel :: Channel
    channel chunk :: Chunk
    chunk loops :: Channel
    loops ms :: Channel
    ms ticks :: Channel
    ticks
        = (Channel -> Bool) -> String -> IO Channel -> IO Channel
    unwrapInt (Channel -> Channel -> Bool
    forall a. Eq a => a -> a -> Bool
    /=(-1)) "Mix_FadeInChannelTimed"
                    (Channel -> Chunk -> Channel -> Channel -> Channel -> IO Channel
    tryFadeInChannelTimed Channel
    channel Chunk
    chunk Channel
    loops Channel
    ms Channel
    ticks)

    -- void Mix_Pause(int channel)
    foreign import ccall unsafe "Mix_Pause" pause :: Channel -> IO ()

    -- void Mix_Resume(int channel)
    foreign import ccall unsafe "Mix_Resume" resume :: Channel -> IO ()

    -- int Mix_HaltChannel(int channel)
    foreign import ccall unsafe "Mix_HaltChannel" mixHaltChannel :: Int -> IO Int
    haltChannel :: Channel -> IO ()
    haltChannel :: Channel -> IO ()
    haltChannel channel :: Channel
    channel = Channel -> IO Channel
    mixHaltChannel Channel
    channel IO Channel -> IO () -> IO ()
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> () -> IO ()
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()

    -- int Mix_ExpireChannel(int channel, int ticks)
    foreign import ccall unsafe "Mix_ExpireChannel" expireChannel :: Channel -> Int -> IO Int

    -- int Mix_FadeOutChannel(int channel, int ms)
    foreign import ccall unsafe "Mix_FadeOutChannel" fadeOutChannel :: Channel -> Int -> IO Int

    -- int Mix_Playing(int channel)
    foreign import ccall unsafe "Mix_Playing" mixPlaying :: Int -> IO Int

    isChannelPlaying :: Channel -> IO Bool
    isChannelPlaying :: Channel -> IO Bool
    isChannelPlaying = (Channel -> Bool) -> IO Channel -> IO Bool
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Channel -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (IO Channel -> IO Bool)
    -> (Channel -> IO Channel) -> Channel -> IO Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Channel -> IO Channel
    mixPlaying

    numChannelsPlaying :: IO Int
    numChannelsPlaying :: IO Channel
    numChannelsPlaying = Channel -> IO Channel
    mixPlaying (-1)

    -- int Mix_Paused(int channel)
    foreign import ccall unsafe "Mix_Paused" mixPaused :: Int -> IO Int

    isChannelPaused :: Channel -> IO Bool
    isChannelPaused :: Channel -> IO Bool
    isChannelPaused = (Channel -> Bool) -> IO Channel -> IO Bool
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Channel -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (IO Channel -> IO Bool)
    -> (Channel -> IO Channel) -> Channel -> IO Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Channel -> IO Channel
    mixPaused

    numChannelsPaused :: IO Int
    numChannelsPaused :: IO Channel
    numChannelsPaused = Channel -> IO Channel
    mixPaused (-1)

    -- Mix_Fading Mix_FadingChannel(int which)
    foreign import ccall unsafe "Mix_FadingChannel" mixFadingChannel :: Int -> IO Int
    fadingChannel :: Channel -> IO Fading
    fadingChannel :: Channel -> IO Fading
    fadingChannel = (Channel -> Fading) -> IO Channel -> IO Fading
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Channel -> Fading
    forall a. Enum a => Channel -> a
    toEnum (IO Channel -> IO Fading)
    -> (Channel -> IO Channel) -> Channel -> IO Fading
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Channel -> IO Channel
    mixFadingChannel

    -- Mix_Chunk *Mix_GetChunk(int channel)
    foreign import ccall unsafe "Mix_GetChunk" mixGetChunk :: Int -> IO (Ptr ChunkStruct)
    getChunk :: Channel -> IO Chunk
    getChunk :: Channel -> IO Chunk
    getChunk ch :: Channel
    ch = Ptr ChunkStruct -> IO Chunk
    forall a. Ptr a -> IO (ForeignPtr a)
    newForeignPtr_ (Ptr ChunkStruct -> IO Chunk) -> IO (Ptr ChunkStruct) -> IO Chunk
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Channel -> IO (Ptr ChunkStruct)
    mixGetChunk Channel
    ch