1 {-# LANGUAGE Arrows #-}
3 module RCMA.Translator.Translator where
5 import qualified Data.Bifunctor as BF
7 import RCMA.Auxiliary.Curry
8 import RCMA.Layer.Layer
10 import RCMA.Translator.Clock
11 import RCMA.Translator.Controller
12 import RCMA.Translator.Message
13 import RCMA.Translator.Note
14 import RCMA.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 gatherMessages :: LTempo
28 -> ([(Frames,Note)],[(Frames,Controller)],[(Frames,RawMessage)])
29 -> [(Frames, RawMessage)]
30 gatherMessages layTempo sr chan = proc (notes, ctrl, raw) -> do
31 notes' <- concat <<< map (noteToMessages layTempo sr chan) -< notes
32 ctrl' <- map (BF.second controllerToMessages) -< ctrl
33 rawNotes <- map (BF.second toRawMessage) -< notes'
34 rawCtrl <- map (BF.second toRawMessage) -< ctrl'
35 returnA -< rawNotes ++ rawCtrl ++ raw