#if __GLASGOW_HASKELL__ < 701
# define interruptible safe
#else
#endif
module Sound.Honk.Internal
(
BeepFd(..)
, beepOpen
, beepDo
, beepClose
, withBeepFd
) where
import Control.Applicative ( (<$>) )
import Control.Exception.Base ( bracket )
import Foreign.C ( throwErrnoIfMinus1, throwErrnoIfMinus1_ )
import Foreign.C.Types
newtype BeepFd = BeepFd CInt
beepOpen :: IO BeepFd
beepOpen = BeepFd <$> throwErrnoIfMinus1 "beepOpen" c_beepOpen
beepDo :: BeepFd
-> Double
-> Double
-> IO ()
beepDo (BeepFd fd) dur freq =
throwErrnoIfMinus1_ "beepDo" $
c_beepDo fd (realToFrac freq) (realToFrac dur)
beepClose :: BeepFd -> IO ()
beepClose (BeepFd fd) = c_beepClose fd
withBeepFd :: (BeepFd -> IO a) -> IO a
withBeepFd = bracket beepOpen beepClose
foreign import ccall "honk.h beep_open"
c_beepOpen :: IO CInt
foreign import ccall interruptible "honk.h beep_do"
c_beepDo :: CInt -> CDouble -> CDouble -> IO CInt
foreign import ccall "honk.h beep_close"
c_beepClose :: CInt -> IO ()