{- |
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.AudioQuantize
    ( 

-- * Exported types
    AudioQuantize(..)                       ,
    noAudioQuantize                         ,


 -- * Methods
-- ** free #method:free#
    AudioQuantizeFreeMethodInfo             ,
    audioQuantizeFree                       ,


-- ** reset #method:reset#
    AudioQuantizeResetMethodInfo            ,
    audioQuantizeReset                      ,


-- ** samples #method:samples#
    AudioQuantizeSamplesMethodInfo          ,
    audioQuantizeSamples                    ,




    ) 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 AudioQuantize = AudioQuantize (ManagedPtr AudioQuantize)
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr AudioQuantize where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing

noAudioQuantize :: Maybe AudioQuantize
noAudioQuantize = Nothing


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

-- method AudioQuantize::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "quant", argType = TInterface (Name {namespace = "GstAudio", name = "AudioQuantize"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioQuantize", 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_quantize_free" gst_audio_quantize_free :: 
    Ptr AudioQuantize ->                    -- quant : TInterface (Name {namespace = "GstAudio", name = "AudioQuantize"})
    IO ()

{- |
Free a 'GI.GstAudio.Structs.AudioQuantize.AudioQuantize'.
-}
audioQuantizeFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    AudioQuantize
    {- ^ /@quant@/: a 'GI.GstAudio.Structs.AudioQuantize.AudioQuantize' -}
    -> m ()
audioQuantizeFree quant = liftIO $ do
    quant' <- unsafeManagedPtrGetPtr quant
    gst_audio_quantize_free quant'
    touchManagedPtr quant
    return ()

data AudioQuantizeFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo AudioQuantizeFreeMethodInfo AudioQuantize signature where
    overloadedMethod _ = audioQuantizeFree

-- method AudioQuantize::reset
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "quant", argType = TInterface (Name {namespace = "GstAudio", name = "AudioQuantize"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioQuantize", 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_quantize_reset" gst_audio_quantize_reset :: 
    Ptr AudioQuantize ->                    -- quant : TInterface (Name {namespace = "GstAudio", name = "AudioQuantize"})
    IO ()

{- |
Reset /@quant@/ to the state is was when created, clearing any
history it might have.
-}
audioQuantizeReset ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    AudioQuantize
    {- ^ /@quant@/: a 'GI.GstAudio.Structs.AudioQuantize.AudioQuantize' -}
    -> m ()
audioQuantizeReset quant = liftIO $ do
    quant' <- unsafeManagedPtrGetPtr quant
    gst_audio_quantize_reset quant'
    touchManagedPtr quant
    return ()

data AudioQuantizeResetMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo AudioQuantizeResetMethodInfo AudioQuantize signature where
    overloadedMethod _ = audioQuantizeReset

-- method AudioQuantize::samples
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "quant", argType = TInterface (Name {namespace = "GstAudio", name = "AudioQuantize"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstAudioQuantize", 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 TUInt, 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_quantize_samples" gst_audio_quantize_samples :: 
    Ptr AudioQuantize ->                    -- quant : TInterface (Name {namespace = "GstAudio", name = "AudioQuantize"})
    Ptr () ->                               -- in : TBasicType TPtr
    Ptr () ->                               -- out : TBasicType TPtr
    Word32 ->                               -- samples : TBasicType TUInt
    IO ()

{- |
Perform quantization on /@samples@/ in /@in@/ and write the result to /@out@/.

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.

/@in@/ and /@out@/ may point to the same memory location, in which case samples will be
modified in-place.
-}
audioQuantizeSamples ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    AudioQuantize
    {- ^ /@quant@/: a 'GI.GstAudio.Structs.AudioQuantize.AudioQuantize' -}
    -> Ptr ()
    {- ^ /@in@/: input samples -}
    -> Ptr ()
    {- ^ /@out@/: output samples -}
    -> Word32
    {- ^ /@samples@/: number of samples -}
    -> m ()
audioQuantizeSamples quant in_ out samples = liftIO $ do
    quant' <- unsafeManagedPtrGetPtr quant
    gst_audio_quantize_samples quant' in_ out samples
    touchManagedPtr quant
    return ()

data AudioQuantizeSamplesMethodInfo
instance (signature ~ (Ptr () -> Ptr () -> Word32 -> m ()), MonadIO m) => O.MethodInfo AudioQuantizeSamplesMethodInfo AudioQuantize signature where
    overloadedMethod _ = audioQuantizeSamples

type family ResolveAudioQuantizeMethod (t :: Symbol) (o :: *) :: * where
    ResolveAudioQuantizeMethod "free" o = AudioQuantizeFreeMethodInfo
    ResolveAudioQuantizeMethod "reset" o = AudioQuantizeResetMethodInfo
    ResolveAudioQuantizeMethod "samples" o = AudioQuantizeSamplesMethodInfo
    ResolveAudioQuantizeMethod l o = O.MethodResolutionFailed l o

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

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