)
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)