1 {-# LANGUAGE Arrows #-}
3 module RCMA.Layer.Layer where
6 import Data.ReactiveValue
8 import RCMA.Global.Clock
11 -- Data representing the state of a layer. It is updated continuously.
12 data Layer = Layer { relTempo :: Double
13 , relPitch :: RelPitch
14 , strength :: Strength
15 , beatsPerBar :: BeatsPerBar
16 , beatCounter :: BeatNo
19 layerTempo :: SF (Tempo, Layer) LTempo
20 layerTempo = proc (t, Layer { relTempo = r }) -> do
21 returnA -< floor $ r * fromIntegral t
23 -- The layer is modified after the beat as been
24 layerMetronome :: SF (Tempo, Layer) (Event (BeatNo, Layer))
25 layerMetronome = proc (t, l@Layer { beatCounter = b , beatsPerBar = bpb}) -> do
26 eb <- metronome <<< layerTempo -< (t, l)
27 returnA -< eb `tag` let nb = nextBeatNo b bpb in (nb, l { beatCounter = nb })
29 layerRV :: CBMVar Layer -> ReactiveFieldReadWrite IO Layer
30 layerRV mvar = ReactiveFieldReadWrite setter getter notifier
31 where setter :: Layer -> IO ()
32 setter = writeCBMVar mvar
35 getter = readCBMVar mvar
37 notifier :: IO () -> IO ()
38 notifier = installCallbackCBMVar mvar
40 getDefaultLayerRV :: IO (ReactiveFieldReadWrite IO Layer)
41 getDefaultLayerRV = layerRV <$> newCBMVar dl
42 where dl = Layer { relTempo = 1