From 951367c7c17ddbc417a998fe9a19d6434f63f386 Mon Sep 17 00:00:00 2001 From: PHO Date: Sat, 6 Nov 2010 15:05:45 +0900 Subject: [PATCH] Sound.EsounD.Internals --- EsounD.cabal | 3 +++ Sound/EsounD.hs | 22 +++------------------- Sound/EsounD/Internals.hs | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 Sound/EsounD/Internals.hs diff --git a/EsounD.cabal b/EsounD.cabal index bdee7b5..cb7e8e1 100644 --- a/EsounD.cabal +++ b/EsounD.cabal @@ -35,6 +35,9 @@ Library Exposed-Modules: Sound.EsounD + Other-Modules: + Sound.EsounD.Internals + Extensions: EmptyDataDecls KindSignatures diff --git a/Sound/EsounD.hs b/Sound/EsounD.hs index 16e85a5..82bd72a 100644 --- a/Sound/EsounD.hs +++ b/Sound/EsounD.hs @@ -13,20 +13,17 @@ module Sound.EsounD import Bindings.EsounD import Control.Monad.IO.Class -import Control.Monad.Trans.Region as R +import Control.Monad.Trans.Region import Control.Monad.Trans.Region.OnExit import Control.Monad.Unicode import Data.Bits import Data.Int import Foreign.C.String -import Foreign.C.Types -import Foreign.Ptr import Network import Prelude.Unicode +import Sound.EsounD.Internals import System.IO import System.IO.SaferFileHandles.Unsafe -import System.Posix.IO -import System.Posix.Types class Frame fr where frameFmt ∷ fr → C'esd_format_t @@ -61,7 +58,7 @@ data Player fr ch (r ∷ * → *) } instance Dup (Player fr ch) where - dup pl = do ch' ← R.dup (plCloseH pl) + dup pl = do ch' ← dup (plCloseH pl) return pl { plCloseH = ch' } -- | Open an ESD handle for playing a stream. @@ -99,16 +96,3 @@ openPlayer rate host name hostPtr namePtr ≫= wrapSocket "esd_play_stream() returned an error" - -wrapSocket :: String -> CInt → IO Handle -wrapSocket e (-1) = fail e -wrapSocket _ fd = fdToHandle (Fd fd) - -closeSocket :: Handle → IO () -closeSocket h = do (Fd fd) ← handleToFd h - _ ← c'esd_close (fromIntegral fd) - return () - -withCStrOrNull :: Maybe String → (CString → IO a) → IO a -withCStrOrNull Nothing f = f nullPtr -withCStrOrNull (Just s) f = withCString s f diff --git a/Sound/EsounD/Internals.hs b/Sound/EsounD/Internals.hs new file mode 100644 index 0000000..987dd1e --- /dev/null +++ b/Sound/EsounD/Internals.hs @@ -0,0 +1,27 @@ +module Sound.EsounD.Internals + ( wrapSocket + , closeSocket + , withCStrOrNull + ) + where + +import Bindings.EsounD +import Foreign.C.String +import Foreign.C.Types +import Foreign.Ptr +import System.IO +import System.Posix.IO +import System.Posix.Types + +wrapSocket :: String -> CInt → IO Handle +wrapSocket e (-1) = fail e +wrapSocket _ fd = fdToHandle (Fd fd) + +closeSocket :: Handle → IO () +closeSocket h = do (Fd fd) ← handleToFd h + _ ← c'esd_close (fromIntegral fd) + return () + +withCStrOrNull :: Maybe String → (CString → IO a) → IO a +withCStrOrNull Nothing f = f nullPtr +withCStrOrNull (Just s) f = withCString s f -- 2.40.0