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

\<refsect2>\<para>
This interface is implemented by elements which can perform some color
balance operation on video frames they process. For example, modifying
the brightness, contrast, hue or saturation.
\<\/para>\<para>
Example elements are \'xvimagesink\' and \'colorbalance\'
\<\/para>
\<\/refsect2>
-}

module GI.GstVideo.Interfaces.ColorBalance
    ( 

-- * Exported types
    ColorBalance(..)                        ,
    noColorBalance                          ,
    IsColorBalance                          ,


 -- * Methods
-- ** getBalanceType #method:getBalanceType#
    ColorBalanceGetBalanceTypeMethodInfo    ,
    colorBalanceGetBalanceType              ,


-- ** getValue #method:getValue#
    ColorBalanceGetValueMethodInfo          ,
    colorBalanceGetValue                    ,


-- ** listChannels #method:listChannels#
    ColorBalanceListChannelsMethodInfo      ,
    colorBalanceListChannels                ,


-- ** setValue #method:setValue#
    ColorBalanceSetValueMethodInfo          ,
    colorBalanceSetValue                    ,


-- ** valueChanged #method:valueChanged#
    ColorBalanceValueChangedMethodInfo      ,
    colorBalanceValueChanged                ,




 -- * Signals
-- ** valueChanged #signal:valueChanged#
    C_ColorBalanceValueChangedCallback      ,
    ColorBalanceValueChangedCallback        ,
    ColorBalanceValueChangedSignalInfo      ,
    afterColorBalanceValueChanged           ,
    genClosure_ColorBalanceValueChanged     ,
    mk_ColorBalanceValueChangedCallback     ,
    noColorBalanceValueChangedCallback      ,
    onColorBalanceValueChanged              ,
    wrap_ColorBalanceValueChangedCallback   ,




    ) 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

import {-# SOURCE #-} qualified GI.GstVideo.Enums as GstVideo.Enums
import {-# SOURCE #-} qualified GI.GstVideo.Objects.ColorBalanceChannel as GstVideo.ColorBalanceChannel

-- interface ColorBalance 
newtype ColorBalance = ColorBalance (ManagedPtr ColorBalance)
noColorBalance :: Maybe ColorBalance
noColorBalance = Nothing

type family ResolveColorBalanceMethod (t :: Symbol) (o :: *) :: * where
    ResolveColorBalanceMethod "listChannels" o = ColorBalanceListChannelsMethodInfo
    ResolveColorBalanceMethod "valueChanged" o = ColorBalanceValueChangedMethodInfo
    ResolveColorBalanceMethod "getBalanceType" o = ColorBalanceGetBalanceTypeMethodInfo
    ResolveColorBalanceMethod "getValue" o = ColorBalanceGetValueMethodInfo
    ResolveColorBalanceMethod "setValue" o = ColorBalanceSetValueMethodInfo
    ResolveColorBalanceMethod l o = O.MethodResolutionFailed l o

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

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

-- signal ColorBalance::value-changed
type ColorBalanceValueChangedCallback =
    GstVideo.ColorBalanceChannel.ColorBalanceChannel ->
    Int32 ->
    IO ()

noColorBalanceValueChangedCallback :: Maybe ColorBalanceValueChangedCallback
noColorBalanceValueChangedCallback = Nothing

type C_ColorBalanceValueChangedCallback =
    Ptr () ->                               -- object
    Ptr GstVideo.ColorBalanceChannel.ColorBalanceChannel ->
    Int32 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_ColorBalanceValueChangedCallback :: C_ColorBalanceValueChangedCallback -> IO (FunPtr C_ColorBalanceValueChangedCallback)

genClosure_ColorBalanceValueChanged :: ColorBalanceValueChangedCallback -> IO Closure
genClosure_ColorBalanceValueChanged cb = do
    let cb' = wrap_ColorBalanceValueChangedCallback cb
    mk_ColorBalanceValueChangedCallback cb' >>= newCClosure


wrap_ColorBalanceValueChangedCallback ::
    ColorBalanceValueChangedCallback ->
    Ptr () ->
    Ptr GstVideo.ColorBalanceChannel.ColorBalanceChannel ->
    Int32 ->
    Ptr () ->
    IO ()
wrap_ColorBalanceValueChangedCallback _cb _ channel value _ = do
    channel' <- (newObject GstVideo.ColorBalanceChannel.ColorBalanceChannel) channel
    _cb  channel' value


onColorBalanceValueChanged :: (GObject a, MonadIO m) => a -> ColorBalanceValueChangedCallback -> m SignalHandlerId
onColorBalanceValueChanged obj cb = liftIO $ connectColorBalanceValueChanged obj cb SignalConnectBefore
afterColorBalanceValueChanged :: (GObject a, MonadIO m) => a -> ColorBalanceValueChangedCallback -> m SignalHandlerId
afterColorBalanceValueChanged obj cb = connectColorBalanceValueChanged obj cb SignalConnectAfter

connectColorBalanceValueChanged :: (GObject a, MonadIO m) =>
                                   a -> ColorBalanceValueChangedCallback -> SignalConnectMode -> m SignalHandlerId
connectColorBalanceValueChanged obj cb after = liftIO $ do
    let cb' = wrap_ColorBalanceValueChangedCallback cb
    cb'' <- mk_ColorBalanceValueChangedCallback cb'
    connectSignalFunPtr obj "value-changed" cb'' after

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

data ColorBalanceValueChangedSignalInfo
instance SignalInfo ColorBalanceValueChangedSignalInfo where
    type HaskellCallbackType ColorBalanceValueChangedSignalInfo = ColorBalanceValueChangedCallback
    connectSignal _ = connectColorBalanceValueChanged

type instance O.SignalList ColorBalance = ColorBalanceSignalList
type ColorBalanceSignalList = ('[ '("valueChanged", ColorBalanceValueChangedSignalInfo)] :: [(Symbol, *)])

class ManagedPtrNewtype a => IsColorBalance a
instance IsColorBalance ColorBalance
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr ColorBalance where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing


-- method ColorBalance::get_balance_type
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "balance", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalance"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The #GstColorBalance implementation", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GstVideo", name = "ColorBalanceType"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_color_balance_get_balance_type" gst_color_balance_get_balance_type :: 
    Ptr ColorBalance ->                     -- balance : TInterface (Name {namespace = "GstVideo", name = "ColorBalance"})
    IO CUInt

{- |
Get the 'GI.GstVideo.Enums.ColorBalanceType' of this implementation.
-}
colorBalanceGetBalanceType ::
    (B.CallStack.HasCallStack, MonadIO m, IsColorBalance a) =>
    a
    {- ^ /@balance@/: The 'GI.GstVideo.Interfaces.ColorBalance.ColorBalance' implementation -}
    -> m GstVideo.Enums.ColorBalanceType
    {- ^ __Returns:__ A the 'GI.GstVideo.Enums.ColorBalanceType'. -}
colorBalanceGetBalanceType balance = liftIO $ do
    balance' <- unsafeManagedPtrCastPtr balance
    result <- gst_color_balance_get_balance_type balance'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr balance
    return result'

data ColorBalanceGetBalanceTypeMethodInfo
instance (signature ~ (m GstVideo.Enums.ColorBalanceType), MonadIO m, IsColorBalance a) => O.MethodInfo ColorBalanceGetBalanceTypeMethodInfo a signature where
    overloadedMethod _ = colorBalanceGetBalanceType

-- method ColorBalance::get_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "balance", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalance"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GstColorBalance instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channel", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalanceChannel"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GstColorBalanceChannel instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "gst_color_balance_get_value" gst_color_balance_get_value :: 
    Ptr ColorBalance ->                     -- balance : TInterface (Name {namespace = "GstVideo", name = "ColorBalance"})
    Ptr GstVideo.ColorBalanceChannel.ColorBalanceChannel -> -- channel : TInterface (Name {namespace = "GstVideo", name = "ColorBalanceChannel"})
    IO Int32

{- |
Retrieve the current value of the indicated channel, between min_value
and max_value.

See Also: The 'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel'.@/min_value/@ and
        'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel'.@/max_value/@ members of the
        'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel' object.
-}
colorBalanceGetValue ::
    (B.CallStack.HasCallStack, MonadIO m, IsColorBalance a, GstVideo.ColorBalanceChannel.IsColorBalanceChannel b) =>
    a
    {- ^ /@balance@/: A 'GI.GstVideo.Interfaces.ColorBalance.ColorBalance' instance -}
    -> b
    {- ^ /@channel@/: A 'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel' instance -}
    -> m Int32
    {- ^ __Returns:__ The current value of the channel. -}
colorBalanceGetValue balance channel = liftIO $ do
    balance' <- unsafeManagedPtrCastPtr balance
    channel' <- unsafeManagedPtrCastPtr channel
    result <- gst_color_balance_get_value balance' channel'
    touchManagedPtr balance
    touchManagedPtr channel
    return result

data ColorBalanceGetValueMethodInfo
instance (signature ~ (b -> m Int32), MonadIO m, IsColorBalance a, GstVideo.ColorBalanceChannel.IsColorBalanceChannel b) => O.MethodInfo ColorBalanceGetValueMethodInfo a signature where
    overloadedMethod _ = colorBalanceGetValue

-- method ColorBalance::list_channels
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "balance", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalance"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GstColorBalance instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TGList (TInterface (Name {namespace = "GstVideo", name = "ColorBalanceChannel"})))
-- throws : False
-- Skip return : False

foreign import ccall "gst_color_balance_list_channels" gst_color_balance_list_channels :: 
    Ptr ColorBalance ->                     -- balance : TInterface (Name {namespace = "GstVideo", name = "ColorBalance"})
    IO (Ptr (GList (Ptr GstVideo.ColorBalanceChannel.ColorBalanceChannel)))

{- |
Retrieve a list of the available channels.
-}
colorBalanceListChannels ::
    (B.CallStack.HasCallStack, MonadIO m, IsColorBalance a) =>
    a
    {- ^ /@balance@/: A 'GI.GstVideo.Interfaces.ColorBalance.ColorBalance' instance -}
    -> m [GstVideo.ColorBalanceChannel.ColorBalanceChannel]
    {- ^ __Returns:__ A
         GList containing pointers to 'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel'
         objects. The list is owned by the 'GI.GstVideo.Interfaces.ColorBalance.ColorBalance'
         instance and must not be freed. -}
colorBalanceListChannels balance = liftIO $ do
    balance' <- unsafeManagedPtrCastPtr balance
    result <- gst_color_balance_list_channels balance'
    result' <- unpackGList result
    result'' <- mapM (newObject GstVideo.ColorBalanceChannel.ColorBalanceChannel) result'
    touchManagedPtr balance
    return result''

data ColorBalanceListChannelsMethodInfo
instance (signature ~ (m [GstVideo.ColorBalanceChannel.ColorBalanceChannel]), MonadIO m, IsColorBalance a) => O.MethodInfo ColorBalanceListChannelsMethodInfo a signature where
    overloadedMethod _ = colorBalanceListChannels

-- method ColorBalance::set_value
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "balance", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalance"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GstColorBalance instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channel", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalanceChannel"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GstColorBalanceChannel instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The new value for the channel.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_color_balance_set_value" gst_color_balance_set_value :: 
    Ptr ColorBalance ->                     -- balance : TInterface (Name {namespace = "GstVideo", name = "ColorBalance"})
    Ptr GstVideo.ColorBalanceChannel.ColorBalanceChannel -> -- channel : TInterface (Name {namespace = "GstVideo", name = "ColorBalanceChannel"})
    Int32 ->                                -- value : TBasicType TInt
    IO ()

{- |
Sets the current value of the channel to the passed value, which must
be between min_value and max_value.

See Also: The 'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel'.@/min_value/@ and
        'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel'.@/max_value/@ members of the
        'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel' object.
-}
colorBalanceSetValue ::
    (B.CallStack.HasCallStack, MonadIO m, IsColorBalance a, GstVideo.ColorBalanceChannel.IsColorBalanceChannel b) =>
    a
    {- ^ /@balance@/: A 'GI.GstVideo.Interfaces.ColorBalance.ColorBalance' instance -}
    -> b
    {- ^ /@channel@/: A 'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel' instance -}
    -> Int32
    {- ^ /@value@/: The new value for the channel. -}
    -> m ()
colorBalanceSetValue balance channel value = liftIO $ do
    balance' <- unsafeManagedPtrCastPtr balance
    channel' <- unsafeManagedPtrCastPtr channel
    gst_color_balance_set_value balance' channel' value
    touchManagedPtr balance
    touchManagedPtr channel
    return ()

data ColorBalanceSetValueMethodInfo
instance (signature ~ (b -> Int32 -> m ()), MonadIO m, IsColorBalance a, GstVideo.ColorBalanceChannel.IsColorBalanceChannel b) => O.MethodInfo ColorBalanceSetValueMethodInfo a signature where
    overloadedMethod _ = colorBalanceSetValue

-- method ColorBalance::value_changed
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "balance", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalance"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GstColorBalance instance", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channel", argType = TInterface (Name {namespace = "GstVideo", name = "ColorBalanceChannel"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GstColorBalanceChannel whose value has changed", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "value", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The new value of the channel", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gst_color_balance_value_changed" gst_color_balance_value_changed :: 
    Ptr ColorBalance ->                     -- balance : TInterface (Name {namespace = "GstVideo", name = "ColorBalance"})
    Ptr GstVideo.ColorBalanceChannel.ColorBalanceChannel -> -- channel : TInterface (Name {namespace = "GstVideo", name = "ColorBalanceChannel"})
    Int32 ->                                -- value : TBasicType TInt
    IO ()

{- |
A helper function called by implementations of the GstColorBalance
interface. It fires the 'GI.GstVideo.Interfaces.ColorBalance.ColorBalance'::@/value-changed/@ signal on the
instance, and the 'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel'::@/value-changed/@ signal on the
channel object.
-}
colorBalanceValueChanged ::
    (B.CallStack.HasCallStack, MonadIO m, IsColorBalance a, GstVideo.ColorBalanceChannel.IsColorBalanceChannel b) =>
    a
    {- ^ /@balance@/: A 'GI.GstVideo.Interfaces.ColorBalance.ColorBalance' instance -}
    -> b
    {- ^ /@channel@/: A 'GI.GstVideo.Objects.ColorBalanceChannel.ColorBalanceChannel' whose value has changed -}
    -> Int32
    {- ^ /@value@/: The new value of the channel -}
    -> m ()
colorBalanceValueChanged balance channel value = liftIO $ do
    balance' <- unsafeManagedPtrCastPtr balance
    channel' <- unsafeManagedPtrCastPtr channel
    gst_color_balance_value_changed balance' channel' value
    touchManagedPtr balance
    touchManagedPtr channel
    return ()

data ColorBalanceValueChangedMethodInfo
instance (signature ~ (b -> Int32 -> m ()), MonadIO m, IsColorBalance a, GstVideo.ColorBalanceChannel.IsColorBalanceChannel b) => O.MethodInfo ColorBalanceValueChangedMethodInfo a signature where
    overloadedMethod _ = colorBalanceValueChanged