1 {-# LANGUAGE Arrows #-}
3 module Reactimation where
8 import qualified Data.Map as M
10 import Control.Concurrent.MVar
11 import Sound.JACK ( NFrames(NFrames)
18 mainReact :: MVar EventQueue
22 mainReact inRef outRef clientRef =
23 reactimate (initialize inRef) (sensing clientRef inRef) (actuation outRef) $
29 initialize :: MVar EventQueue -> IO EventQueue
30 initialize inRef = takeMVar inRef
32 sensing :: MVar ClientState
35 -> IO (DTime, Maybe EventQueue)
36 sensing clientRef inRef _ = do
38 client <- readMVar clientRef
39 input <- takeMVar inRef
40 let (NFrames buff) = buffSize client
41 dt = (fromIntegral $ rate client)/(fromIntegral buff)
43 return (dt, Just input)
45 actuation :: MVar EventQueue
49 actuation outRef _ output = do
51 out <- takeMVar outRef
52 putMVar outRef $ M.union output out
53 print "Done actuating."
56 mainSF :: SF EventQueue EventQueue