module SFML.Audio.Sound
(
createSound
, copySound
, destroy
, play
, pause
, stop
, setSoundBuffer
, getSoundBuffer
, setLoop
, getLoop
, getStatus
, setPitch
, setVolume
, setPosition
, setRelativeToListener
, setMinDistance
, setAttenuation
, setPlayingOffset
, getPitch
, getVolume
, getPosition
, isRelativeToListener
, getMinDistance
, getAttenuation
, getPlayingOffset
)
where
import SFML.Audio.SFSound
import SFML.Audio.SoundStatus
import SFML.Audio.Types
import SFML.SFResource
import SFML.System.Time
import SFML.System.Vector3
import Control.Monad ((>=>))
import Foreign.C.Types
import Foreign.Ptr (Ptr)
import Foreign.Storable (peek)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Marshal.Utils (with)
createSound :: IO Sound
createSound = sfSound_create
foreign import ccall unsafe "sfSound_create"
sfSound_create :: IO Sound
copySound :: Sound -> IO Sound
copySound = sfSound_copy
foreign import ccall unsafe "sfSound_copy"
sfSound_copy :: Sound -> IO Sound
instance SFResource Sound where
destroy = sfSound_destroy
foreign import ccall unsafe "sfSound_destroy"
sfSound_destroy :: Sound -> IO ()
setSoundBuffer :: Sound -> SoundBuffer -> IO ()
setSoundBuffer = sfSound_setBuffer
foreign import ccall unsafe "sfSound_setBuffer"
sfSound_setBuffer :: Sound -> SoundBuffer -> IO ()
getSoundBuffer :: Sound -> IO SoundBuffer
getSoundBuffer = sfSound_getBuffer
foreign import ccall unsafe "sfSound_getBuffer"
sfSound_getBuffer :: Sound -> IO SoundBuffer
instance SFSound Sound where
play = sfSound_play
pause = sfSound_pause
stop = sfSound_stop
getAttenuation = sfSound_getAttenuation >=> return . realToFrac
getLoop = sfSound_getLoop >=> return . toEnum . fromIntegral
getMinDistance = sfSound_getMinDistance >=> return . realToFrac
getPitch = sfSound_getPitch >=> return . realToFrac
getPlayingOffset sound = alloca $ \ptr -> sfSound_getPlayingOffset_helper sound ptr >> peek ptr
getPosition sound = alloca $ \ptr -> sfSound_getPosition_helper sound ptr >> peek ptr
getStatus = sfSound_getStatus >=> return . toEnum . fromIntegral
getVolume = sfSound_getVolume >=> return . realToFrac
isRelativeToListener = sfSound_isRelativeToListener >=> return . toEnum . fromIntegral
setAttenuation m a = sfSound_setAttenuation m (realToFrac a)
setLoop sound val = sfSound_setLoop sound (fromIntegral . fromEnum $ val)
setMinDistance m d = sfSound_setMinDistance m (realToFrac d)
setPitch m p = sfSound_setPitch m (realToFrac p)
setPlayingOffset = sfSound_setPlayingOffset
setPosition sound pos = with pos $ sfSound_setPosition_helper sound
setRelativeToListener sound val = sfSound_setRelativeToListener sound (fromIntegral . fromEnum $ val)
setVolume m v = sfSound_setVolume m (realToFrac v)
foreign import ccall unsafe "sfSound_play"
sfSound_play :: Sound -> IO ()
foreign import ccall unsafe "sfSound_pause"
sfSound_pause :: Sound -> IO ()
foreign import ccall unsafe "sfSound_stop"
sfSound_stop :: Sound -> IO ()
foreign import ccall unsafe "sfSound_getAttenuation"
sfSound_getAttenuation :: Sound -> IO CFloat
foreign import ccall unsafe "sfSound_getLoop"
sfSound_getLoop :: Sound -> IO CInt
foreign import ccall unsafe "sfSound_getMinDistance"
sfSound_getMinDistance :: Sound -> IO CFloat
foreign import ccall unsafe "sfSound_getPitch"
sfSound_getPitch :: Sound -> IO CFloat
foreign import ccall unsafe "sfSound_getPlayingOffset_helper"
sfSound_getPlayingOffset_helper :: Sound -> Ptr Time -> IO ()
foreign import ccall unsafe "sfSound_getPosition_helper"
sfSound_getPosition_helper :: Sound -> Ptr Vec3f -> IO ()
foreign import ccall unsafe "sfSound_getStatus"
sfSound_getStatus :: Sound -> IO CInt
foreign import ccall unsafe "sfSound_getVolume"
sfSound_getVolume :: Sound -> IO CFloat
foreign import ccall unsafe "sfSound_isRelativeToListener"
sfSound_isRelativeToListener :: Sound -> IO CInt
foreign import ccall unsafe "sfSound_setAttenuation"
sfSound_setAttenuation :: Sound -> CFloat -> IO ()
foreign import ccall unsafe "sfSound_setLoop"
sfSound_setLoop :: Sound -> CInt -> IO ()
foreign import ccall unsafe "sfSound_setMinDistance"
sfSound_setMinDistance :: Sound -> CFloat -> IO ()
foreign import ccall unsafe "sfSound_setPitch"
sfSound_setPitch :: Sound -> CFloat -> IO ()
foreign import ccall unsafe "sfSound_setPlayingOffset"
sfSound_setPlayingOffset :: Sound -> Time -> IO ()
foreign import ccall unsafe "sfSound_setPosition_helper"
sfSound_setPosition_helper :: Sound -> Ptr Vec3f -> IO ()
foreign import ccall unsafe "sfSound_setRelativeToListener"
sfSound_setRelativeToListener :: Sound -> CInt -> IO ()
foreign import ccall unsafe "sfSound_setVolume"
sfSound_setVolume :: Sound -> CFloat -> IO ()