module Sound.Honk.Internal
(
BeepFd(..)
, beepOpen
, beepDo
, beepClose
, withBeepFd
) where
import Control.Applicative
import Control.Exception (bracket)
import Foreign.C (throwErrnoIfMinus1, throwErrnoIfMinus1_)
import Foreign.C.Types
import Prelude
newtype BeepFd = BeepFd CInt
beepOpen :: IO BeepFd
beepOpen = BeepFd <$> throwErrnoIfMinus1 "beepOpen" c_beepOpen
beepDo :: BeepFd
-> Rational
-> 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 ()