)
where
import Bindings.EsounD
+import Control.Exception.Peel
import Control.Monad.IO.Class
+import Control.Monad.IO.Peel
import Control.Monad.Trans.Region
import Control.Monad.Trans.Region.OnExit
import Control.Monad.Unicode
import Data.Bits
import Data.StorableVector.Lazy as L
-import Foreign.C.String
import Network
import Prelude.Unicode
import Sound.EsounD.Streams
openPlayer ∷ ∀fr ch s pr.
( Frame fr
, Channels ch
- , MonadIO pr
+ , MonadPeelIO pr
)
- ⇒ Int -- ^ sample rate for the stream.
- → HostName -- ^ host to connect to.
- → Maybe String -- ^ name used to identify this stream to
- -- ESD (if any).
+ ⇒ Int -- ^ sample rate for the stream.
+ → Maybe HostName -- ^ host to connect to.
+ → Maybe String -- ^ name used to identify this stream to
+ -- ESD (if any).
→ RegionT s pr (Player fr ch (RegionT s pr))
openPlayer rate host name
- = do h ← liftIO openSocket
+ = block $
+ do h ← liftIO openSocket
ch ← onExit $ sanitizeIOError $ closeSocket h
return Player {
plRate = rate
}
where
fmt :: C'esd_format_t
- fmt = frameFmt ((⊥) ∷ fr) .&.
- channelFmt ((⊥) ∷ ch) .&.
- c'ESD_STREAM .&.
+ fmt = frameFmt ((⊥) ∷ fr) .|.
+ channelFmt ((⊥) ∷ ch) .|.
+ c'ESD_STREAM .|.
c'ESD_PLAY
openSocket :: IO Handle
- openSocket = withCString host $ \hostPtr →
+ openSocket = withCStrOrNull host $ \hostPtr →
withCStrOrNull name $ \namePtr →
c'esd_play_stream
fmt
(fromIntegral rate)
hostPtr
namePtr
- ≫= wrapSocket "esd_play_stream() returned an error"
+ ≫= wrapSocket
+ ( "esd_play_stream("
+ ⧺ show fmt
+ ⧺ ", "
+ ⧺ show rate
+ ⧺ ", "
+ ⧺ show host
+ ⧺ ", "
+ ⧺ show name
+ ⧺ ") returned an error"
+ )