]> gitweb @ CieloNegro.org - EsounD.git/blobdiff - Sound/EsounD/Player.hs
openPlayer should accept Nothing for the hostname
[EsounD.git] / Sound / EsounD / Player.hs
index cfb4e31edb9b9f3f70d5c1dcf04f071860b90426..7f7eb223a88ddb2c593c7dfd695b58a2076c7f9d 100644 (file)
@@ -19,7 +19,6 @@ 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
@@ -57,10 +56,10 @@ openPlayer ∷ ∀fr ch s pr.
                , Channels ch
                , MonadIO 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
@@ -72,17 +71,27 @@ openPlayer rate host name
                     }
     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"
+                               )