1 {-# LANGUAGE Arrows, FlexibleContexts #-}
3 module RMCA.Layer.Board ( boardSF
6 import Control.Concurrent
7 import Control.Concurrent.MVar
9 import Data.ReactiveValue
13 import RMCA.Auxiliary.Curry
14 import RMCA.Global.Clock
15 import RMCA.Layer.Layer
20 -- The state of the board is described by the list of the playheads
21 -- and the different actions onto the board.
22 boardAction :: [PlayHead]
23 -> SF ((Board, Layer), Event BeatNo) (Event ([PlayHead], [Note]))
24 boardAction ph = proc ((board, Layer { relPitch = rp
28 arr $ fmap (uncurry5 advanceHeads)
29 -< ebno `tag` (board, fromEvent ebno, rp, s, ph)
30 --returnA -< traceShow e e
32 boardSF :: SF (Board, Layer, Tempo) (Event [Note])
33 boardSF = proc (board, l, t) -> do
34 ebno <- layerMetronome -< (t, l)
35 iph <- startHeads -< board
36 boardSF' iph -< (board, l, ebno)
37 where boardSF' :: [PlayHead] -> SF (Board, Layer, Event BeatNo) (Event [Note])
38 boardSF' ph = switch (swap ^<< splitE ^<< boardAction ph)
42 -- We need the list of initial playheads
43 boardSF :: [PlayHead] -> SF (Board, Layer, Tempo) (Event [Note])
44 boardSF iph = proc (board, l@Layer { relPitch = rp
47 ebno <- layerMetronome -< (t,l)
48 boardSF' iph -< ((board, l), ebno)
50 boardSF' :: [PlayHead] -> SF ((Board, Layer), Event BeatNo) (Event [Note])
51 boardSF' ph = dSwitch (boardAction ph >>> arr splitE >>> arr swap)
52 (\nph -> second notYet >>> boardSF' nph)
57 -> ReactiveFieldReadWrite IO Tempo
58 -> ReactiveFieldReadWrite IO Layer
59 -> ReactiveFieldReadWrite IO [Note]
61 boardSetup board tempoRV layerRV outBoardRV = do
62 layer <- reactiveValueRead layerRV
63 tempo <- reactiveValueRead tempoRV
64 (inBoard, outBoard) <- yampaReactiveDual (layer, tempo) (boardSF board)
65 let inRV = pairRW layerRV tempoRV
69 reactiveValueOnCanRead outBoard
70 (reactiveValueRead outBoard >>= reactiveValueWrite outBoardRV . event [] id)
71 putStrLn "Board started."