1 {-# LANGUAGE Arrows #-}
3 module RMCA.Translator.Translator ( readMessages
7 import qualified Data.Bifunctor as BF
9 import RMCA.Auxiliary.Curry
11 import RMCA.Translator.Message
12 import RMCA.Translator.Note
13 import RMCA.Translator.SortMessage
15 -- Uses function defined in SortMessage. This is a pure function and
16 -- it might not need to be a signal function.
17 readMessages' :: [(Frames,RawMessage)]
18 -> ([(Frames,Note)], [(Frames,Message)], [(Frames,RawMessage)])
19 readMessages' = proc r -> do
20 (mes, raw) <- sortRawMessages -< r
21 (notes, ctrl) <- BF.first convertMessages <<< sortNotes -< mes
22 returnA -< (notes, ctrl, raw)
24 readMessages :: SF [(Frames, RawMessage)]
25 ([(Frames,Note)], [(Frames,Message)], [(Frames,RawMessage)])
26 readMessages = arr readMessages'
28 gatherMessages' :: LTempo
31 -> ([(Frames,Note)],[(Frames,Message)],[(Frames,RawMessage)])
32 -> [(Frames, RawMessage)]
33 gatherMessages' layTempo sr chan = proc (notes, ctrl, raw) -> do
34 notes' <- concat <<< map (noteToMessages layTempo sr chan) -< notes
35 rawNotes <- map (BF.second toRawMessage) -< notes'
36 rawCtrl <- map (BF.second toRawMessage) -< ctrl
37 returnA -< rawNotes ++ rawCtrl ++ raw
40 ( LTempo, SampleRate, Int
41 , ([(Frames,Note)],[(Frames,Message)],[(Frames,RawMessage)]))
42 [(Frames, RawMessage)]
43 gatherMessages = arr $ uncurry4 gatherMessages'