Synopsis: Type-safe bindings to EsounD (ESD; Enlightened Sound Daemon)
Description:
Type-safe bindings to EsounD: <http://www.tux.org/~ricdude/EsounD.html>
-Version: 0.1
+Version: 0.2
License: PublicDomain
License-File: COPYING
Author: PHO <pho at cielonegro dot org>
Maintainer: PHO <pho at cielonegro dot org>
Stability: experimental
Homepage: http://cielonegro.org/EsounD.html
+Bug-Reports: http://static.cielonegro.org/ditz/EsounD/
Category: Sound
Tested-With: GHC == 7.0.1
Cabal-Version: >= 1.6
base == 4.*,
base-unicode-symbols == 0.2.*,
bindings-EsounD == 0.1.*,
- monad-peel == 0.1.*,
+ monad-control == 0.2.*,
network == 2.3.*,
- regions == 0.8.*,
- safer-file-handles == 0.9.*,
+ regions == 0.9.*,
+ safer-file-handles == 0.10.*,
storablevector == 0.2.*,
transformers == 0.2.*,
unix == 2.4.*
)
where
import Bindings.EsounD
-import Control.Exception.Peel
+import Control.Exception.Control
import Control.Monad.IO.Class
-import Control.Monad.IO.Peel
+import Control.Monad.IO.Control
import Control.Monad.Trans.Region
import Control.Monad.Trans.Region.OnExit
import Control.Monad.Unicode
return co { coCloseH = ch' }
-- | Open an ESD handle for controlling ESD.
-openController ∷ MonadPeelIO pr
+openController ∷ MonadControlIO pr
⇒ Maybe HostName -- ^ host to connect to.
→ RegionT s pr (Controller (RegionT s pr))
openController host
- = block $
+ = mask_ $
do s ← liftIO openSocket
- ch ← onExit $ sanitizeIOError $ closeSocket' s
+ ch ← onExit $ closeSocket' s
return Controller {
coSocket = s
, coCloseH = ch
→ cr ()
lock co
= liftIO $
- sanitizeIOError $
c'esd_lock (fdToCInt $ coSocket co)
≫= failOnError "esd_lock(fd) returned an error" (≤ 0)
≫ return ()
→ cr ()
unlock co
= liftIO $
- sanitizeIOError $
c'esd_unlock (fdToCInt $ coSocket co)
≫= failOnError "esd_unlock(fd) returned an error" (≤ 0)
≫ return ()
→ cr ()
standby co
= liftIO $
- sanitizeIOError $
c'esd_standby (fdToCInt $ coSocket co)
≫= failOnError "esd_standby(fd) returned an error" (≤ 0)
≫ return ()
→ cr ()
resume co
= liftIO $
- sanitizeIOError $
c'esd_resume (fdToCInt $ coSocket co)
≫= failOnError "esd_resume(fd) returned an error" (≤ 0)
≫ return ()
class (Frame fr, Channels ch) ⇒ SampleSource fr ch dvec where
-- | Cache a sample in the server.
- cacheSample ∷ (MonadPeelIO pr)
+ cacheSample ∷ (MonadControlIO pr)
⇒ Controller (RegionT s pr)
→ Maybe String -- ^ name used to identify this sample to
→ Int -- ^ sample rate
instance Frame fr ⇒ SampleSource fr Mono (L.Vector fr) where
cacheSample co name rate v
- = block $
+ = mask_ $
do sa ← createSample
co
name
instance Frame fr ⇒ SampleSource fr Stereo (L.Vector fr, L.Vector fr) where
cacheSample co name rate (l, r)
- = block $
+ = mask_ $
do sa ← createSample
co
name
createSample ∷ ∀fr ch s pr.
( Frame fr
, Channels ch
- , MonadPeelIO pr
+ , MonadControlIO pr
)
⇒ Controller (RegionT s pr)
→ Maybe String
→ Int
→ RegionT s pr (Sample (RegionT s pr))
createSample co name rate _ _ len
- = block $
+ = mask_ $
do sid ← liftIO newCache
- ch ← onExit $ sanitizeIOError $ deleteCache sid
+ ch ← onExit $ deleteCache sid
return Sample {
saID = sid
, saCtrl = co
→ cr ()
playSample sa
= liftIO $
- sanitizeIOError $
c'esd_sample_play (fdToCInt $ coSocket $ saCtrl sa) (saID sa)
≫= failOnError ( printf "esd_sample_play(%s, %s) returned an error"
(show $ coSocket $ saCtrl sa)
→ cr ()
loopSample sa
= liftIO $
- sanitizeIOError $
c'esd_sample_loop (fdToCInt $ coSocket $ saCtrl sa) (saID sa)
≫= failOnError ( printf "esd_sample_loop(%s, %s) returned an error"
(show $ coSocket $ saCtrl sa)
→ cr ()
stopSample sa
= liftIO $
- sanitizeIOError $
c'esd_sample_stop (fdToCInt $ coSocket $ saCtrl sa) (saID sa)
≫= failOnError ( printf "esd_sample_stop(%s, %s) returned an error"
(show $ coSocket $ saCtrl sa)
→ cr ()
killSample sa
= liftIO $
- sanitizeIOError $
c'esd_sample_kill (fdToCInt $ coSocket $ saCtrl sa) (saID sa)
≫= failOnError ( printf "esd_sample_kill(%s, %s) returned an error"
(show $ coSocket $ saCtrl sa)
→ cr ServerInfo
getServerInfo co
= liftIO $
- sanitizeIOError $
bracket retrieve dispose extractServerInfo
where
retrieve ∷ IO (Ptr C'esd_server_info)
→ cr AllInfo
getAllInfo co
= liftIO $
- sanitizeIOError $
bracket retrieve dispose extractAllInfo
where
retrieve ∷ IO (Ptr C'esd_info)
→ cr ()
setStreamPan co sid l r
= liftIO $
- sanitizeIOError $
c'esd_set_stream_pan (fdToCInt $ coSocket co)
(fromIntegral sid)
(floor $ l ⋅ c'ESD_VOLUME_BASE)
→ cr ()
setDefaultSamplePan co sid l r
= liftIO $
- sanitizeIOError $
c'esd_set_default_sample_pan (fdToCInt $ coSocket co)
(fromIntegral sid)
(floor $ l ⋅ c'ESD_VOLUME_BASE)
→ cr ServerState
getServerState co
= liftIO $
- sanitizeIOError $
fmap extractServerState $
c'esd_get_standby_mode (fdToCInt $ coSocket co)
≫= failOnError "esd_get_standby_mode(fd) returned an error" (≡ c'ESM_ERROR)
)
where
import Bindings.EsounD
-import Control.Exception.Peel
+import Control.Exception.Control
import Control.Monad.IO.Class
-import Control.Monad.IO.Peel
+import Control.Monad.IO.Control
import Control.Monad.Trans.Region
import Control.Monad.Trans.Region.OnExit
import Control.Monad.Unicode
openFilter ∷ ∀fr ch s pr.
( Frame fr
, Channels ch
- , MonadPeelIO pr
+ , MonadControlIO pr
)
⇒ Int -- ^ sample rate for the stream.
→ Maybe HostName -- ^ host to connect to.
-- ESD (if any).
→ RegionT s pr (Filter fr ch (RegionT s pr))
openFilter rate host name
- = block $
+ = mask_ $
do h ← liftIO openSocket
ch ← onExit $ sanitizeIOError $ closeSocket h
return Filter {
)
where
import Bindings.EsounD
-import Control.Exception.Peel
+import Control.Exception.Control
import Control.Monad.IO.Class
-import Control.Monad.IO.Peel
+import Control.Monad.IO.Control
import Control.Monad.Trans.Region
import Control.Monad.Trans.Region.OnExit
import Control.Monad.Unicode
openMonitor ∷ ∀fr ch s pr.
( Frame fr
, Channels ch
- , MonadPeelIO pr
+ , MonadControlIO pr
)
⇒ Int -- ^ sample rate for the stream.
→ Maybe HostName -- ^ host to connect to.
-- to ESD (if any).
→ RegionT s pr (Monitor fr ch (RegionT s pr))
openMonitor rate host name
- = block $
+ = mask_ $
do h ← liftIO openSocket
ch ← onExit $ sanitizeIOError $ closeSocket h
return Monitor {
fmt ∷ C'esd_format_t
fmt = frameFmt ((⊥) ∷ fr) .|.
channelFmt ((⊥) ∷ ch) .|.
- c'ESD_STREAM .|.
+ c'ESD_STREAM .|.
c'ESD_MONITOR
openSocket ∷ IO Handle
)
where
import Bindings.EsounD
-import Control.Exception.Peel
+import Control.Exception.Control
import Control.Monad.IO.Class
-import Control.Monad.IO.Peel
+import Control.Monad.IO.Control
import Control.Monad.Trans.Region
import Control.Monad.Trans.Region.OnExit
import Control.Monad.Unicode
openPlayer ∷ ∀fr ch s pr.
( Frame fr
, Channels ch
- , MonadPeelIO pr
+ , MonadControlIO pr
)
⇒ Int -- ^ sample rate for the stream.
→ Maybe HostName -- ^ host to connect to.
-- ESD (if any).
→ RegionT s pr (Player fr ch (RegionT s pr))
openPlayer rate host name
- = block $
+ = mask_ $
do h ← liftIO openSocket
ch ← onExit $ sanitizeIOError $ closeSocket h
return Player {
)
where
import Bindings.EsounD
-import Control.Exception.Peel
+import Control.Exception.Control
import Control.Monad.IO.Class
-import Control.Monad.IO.Peel
+import Control.Monad.IO.Control
import Control.Monad.Trans.Region
import Control.Monad.Trans.Region.OnExit
import Control.Monad.Unicode
openRecorder ∷ ∀fr ch s pr.
( Frame fr
, Channels ch
- , MonadPeelIO pr
+ , MonadControlIO pr
)
⇒ Int -- ^ sample rate for the stream.
→ Maybe HostName -- ^ host to connect to.
-- to ESD (if any).
→ RegionT s pr (Recorder fr ch (RegionT s pr))
openRecorder rate host name
- = block $
+ = mask_ $
do h ← liftIO openSocket
ch ← onExit $ sanitizeIOError $ closeSocket h
return Recorder {
fmt ∷ C'esd_format_t
fmt = frameFmt ((⊥) ∷ fr) .|.
channelFmt ((⊥) ∷ ch) .|.
- c'ESD_STREAM .|.
+ c'ESD_STREAM .|.
c'ESD_RECORD
openSocket ∷ IO Handle