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.Controller
12 import RMCA.Translator.Message
13 import RMCA.Translator.Note
14 import RMCA.Translator.SortMessage
16 -- Uses function defined in SortMessage. This is a pure function and
17 -- it might not need to be a signal function.
18 readMessages' :: [(Frames,RawMessage)]
19 -> ([(Frames,Note)], [(Frames,Controller)], [(Frames,RawMessage)])
20 readMessages' = proc r -> do
21 (mes, raw) <- sortRawMessages -< r
22 (notes, ctrl) <- convertMessages <<< sortNotes -< mes
23 returnA -< (notes, ctrl, raw)
25 readMessages :: SF [(Frames, RawMessage)]
26 ([(Frames,Note)], [(Frames,Controller)], [(Frames,RawMessage)])
27 readMessages = arr readMessages'
29 gatherMessages' :: LTempo
32 -> ([(Frames,Note)],[(Frames,Controller)],[(Frames,RawMessage)])
33 -> [(Frames, RawMessage)]
34 gatherMessages' layTempo sr chan = proc (notes, ctrl, raw) -> do
35 notes' <- concat <<< map (noteToMessages layTempo sr chan) -< notes
36 ctrl' <- map (BF.second controllerToMessages) -< ctrl
37 rawNotes <- map (BF.second toRawMessage) -< notes'
38 rawCtrl <- map (BF.second toRawMessage) -< ctrl'
39 returnA -< rawNotes ++ rawCtrl ++ raw
42 ( LTempo, SampleRate, Int
43 , ([(Frames,Note)],[(Frames,Controller)],[(Frames,RawMessage)]))
44 [(Frames, RawMessage)]
45 gatherMessages = arr $ uncurry4 gatherMessages'