packages feed

gi-gst-0.1.6.13: GI/Gst/Structs/TimedValue.hs


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

Structure for saving a timestamp and a value.
-}

module GI.Gst.Structs.TimedValue
    ( 

-- * Exported types
    TimedValue(..)                          ,
    newZeroTimedValue                       ,
    noTimedValue                            ,


 -- * Properties
-- ** Timestamp
    timedValueReadTimestamp                 ,


-- ** Value
    timedValueReadValue                     ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Gst.Types
import GI.Gst.Callbacks

newtype TimedValue = TimedValue (ForeignPtr TimedValue)
-- | Construct a `TimedValue` struct initialized to zero.
newZeroTimedValue :: MonadIO m => m TimedValue
newZeroTimedValue = liftIO $ callocBytes 16 >>= wrapPtr TimedValue

noTimedValue :: Maybe TimedValue
noTimedValue = Nothing

timedValueReadTimestamp :: TimedValue -> IO Word64
timedValueReadTimestamp s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Word64
    return val

timedValueReadValue :: TimedValue -> IO Double
timedValueReadValue s = withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO CDouble
    let val' = realToFrac val
    return val'

type family ResolveTimedValueMethod (t :: Symbol) (o :: *) :: * where
    ResolveTimedValueMethod l o = MethodResolutionFailed l o

instance (info ~ ResolveTimedValueMethod t TimedValue, MethodInfo info TimedValue p) => IsLabelProxy t (TimedValue -> p) where
    fromLabelProxy _ = overloadedMethod (MethodProxy :: MethodProxy info)

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