{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.GstAudio.Structs.AudioChannelMixer
    ( 

-- * Exported types
    AudioChannelMixer(..)                   ,
    noAudioChannelMixer                     ,


 -- * Methods
-- ** free #method:free#
    AudioChannelMixerFreeMethodInfo         ,
    audioChannelMixerFree                   ,


-- ** isPassthrough #method:isPassthrough#
    AudioChannelMixerIsPassthroughMethodInfo,
    audioChannelMixerIsPassthrough          ,


-- ** samples #method:samples#
    AudioChannelMixerSamplesMethodInfo      ,
    audioChannelMixerSamples                ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP


newtype AudioChannelMixer = AudioChannelMixer (ManagedPtr AudioChannelMixer)
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr AudioChannelMixer where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing

noAudioChannelMixer :: Maybe AudioChannelMixer
noAudioChannelMixer = Nothing


instance O.HasAttributeList AudioChannelMixer
type instance O.AttributeList AudioChannelMixer = AudioChannelMixerAttributeList
type AudioChannelMixerAttributeList = ('[ ] :: [(Symbol, *)])

-- method AudioChannelMixer::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mix", argType = TInterface (Name {namespace = "GstAudio", name = "AudioChannelMixer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioChannelMixer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_mixer_free" gst_audio_channel_mixer_free :: 
    Ptr AudioChannelMixer ->                -- mix : TInterface (Name {namespace = "GstAudio", name = "AudioChannelMixer"})
    IO ()

{- |
Free memory allocated by /@mix@/.
-}
audioChannelMixerFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    AudioChannelMixer
    {- ^ /@mix@/: a 'GI.GstAudio.Structs.AudioChannelMixer.AudioChannelMixer' -}
    -> m ()
audioChannelMixerFree mix = liftIO $ do
    mix' <- unsafeManagedPtrGetPtr mix
    gst_audio_channel_mixer_free mix'
    touchManagedPtr mix
    return ()

data AudioChannelMixerFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo AudioChannelMixerFreeMethodInfo AudioChannelMixer signature where
    overloadedMethod _ = audioChannelMixerFree

-- method AudioChannelMixer::is_passthrough
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mix", argType = TInterface (Name {namespace = "GstAudio", name = "AudioChannelMixer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioChannelMixer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_mixer_is_passthrough" gst_audio_channel_mixer_is_passthrough :: 
    Ptr AudioChannelMixer ->                -- mix : TInterface (Name {namespace = "GstAudio", name = "AudioChannelMixer"})
    IO CInt

{- |
Check if /@mix@/ is in passthrough.
-}
audioChannelMixerIsPassthrough ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    AudioChannelMixer
    {- ^ /@mix@/: a 'GI.GstAudio.Structs.AudioChannelMixer.AudioChannelMixer' -}
    -> m Bool
    {- ^ __Returns:__ 'True' is /@mix@/ is passthrough. -}
audioChannelMixerIsPassthrough mix = liftIO $ do
    mix' <- unsafeManagedPtrGetPtr mix
    result <- gst_audio_channel_mixer_is_passthrough mix'
    let result' = (/= 0) result
    touchManagedPtr mix
    return result'

data AudioChannelMixerIsPassthroughMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo AudioChannelMixerIsPassthroughMethodInfo AudioChannelMixer signature where
    overloadedMethod _ = audioChannelMixerIsPassthrough

-- method AudioChannelMixer::samples
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "mix", argType = TInterface (Name {namespace = "GstAudio", name = "AudioChannelMixer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioChannelMixer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "in", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "input samples", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "out", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "output samples", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "samples", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of samples", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_mixer_samples" gst_audio_channel_mixer_samples :: 
    Ptr AudioChannelMixer ->                -- mix : TInterface (Name {namespace = "GstAudio", name = "AudioChannelMixer"})
    Ptr () ->                               -- in : TBasicType TPtr
    Ptr () ->                               -- out : TBasicType TPtr
    Int32 ->                                -- samples : TBasicType TInt
    IO ()

{- |
In case the samples are interleaved, /@in@/ and /@out@/ must point to an
array with a single element pointing to a block of interleaved samples.

If non-interleaved samples are used, /@in@/ and /@out@/ must point to an
array with pointers to memory blocks, one for each channel.

Perform channel mixing on /@inData@/ and write the result to /@outData@/.
/@inData@/ and /@outData@/ need to be in /@format@/ and /@layout@/.
-}
audioChannelMixerSamples ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    AudioChannelMixer
    {- ^ /@mix@/: a 'GI.GstAudio.Structs.AudioChannelMixer.AudioChannelMixer' -}
    -> Ptr ()
    {- ^ /@in@/: input samples -}
    -> Ptr ()
    {- ^ /@out@/: output samples -}
    -> Int32
    {- ^ /@samples@/: number of samples -}
    -> m ()
audioChannelMixerSamples mix in_ out samples = liftIO $ do
    mix' <- unsafeManagedPtrGetPtr mix
    gst_audio_channel_mixer_samples mix' in_ out samples
    touchManagedPtr mix
    return ()

data AudioChannelMixerSamplesMethodInfo
instance (signature ~ (Ptr () -> Ptr () -> Int32 -> m ()), MonadIO m) => O.MethodInfo AudioChannelMixerSamplesMethodInfo AudioChannelMixer signature where
    overloadedMethod _ = audioChannelMixerSamples

type family ResolveAudioChannelMixerMethod (t :: Symbol) (o :: *) :: * where
    ResolveAudioChannelMixerMethod "free" o = AudioChannelMixerFreeMethodInfo
    ResolveAudioChannelMixerMethod "isPassthrough" o = AudioChannelMixerIsPassthroughMethodInfo
    ResolveAudioChannelMixerMethod "samples" o = AudioChannelMixerSamplesMethodInfo
    ResolveAudioChannelMixerMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveAudioChannelMixerMethod t AudioChannelMixer, O.MethodInfo info AudioChannelMixer p) => O.IsLabelProxy t (AudioChannelMixer -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveAudioChannelMixerMethod t AudioChannelMixer, O.MethodInfo info AudioChannelMixer p) => O.IsLabel t (AudioChannelMixer -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif