1 -- The idea is that the stream of data coming from the MIDI input port
2 -- will be sorted in three categories: note on events, controller
3 -- events and other events. The latter will be transmitted as is
4 -- through the whole systems.
6 module Reactogon.Translator.SortMessage where
8 import qualified Data.Bifunctor as BF
10 import Reactogon.Semantics
11 import Reactogon.Translator.Message
17 sortRawMessages :: [RawMessage] -> ([Message], [RawMessage])
18 sortRawMessages = sortRawMessages' ([],[])
19 where sortRawMessages' r [] = r
20 sortRawMessages' (m, rm) (x:xs)
21 | isNothing nm = sortRawMessages' (m, x:rm) xs
22 | otherwise = sortRawMessages' ((fromJust nm) :m, rm) xs
23 where nm = fromRawMessage x
25 sortNotes :: [Message] -> ([Note], [Control])
28 sortMessages :: [RawMessage] -> ([Note], [Control], [RawMessage])
29 sortMessages = (\((a,b),c) -> (a,b,c)) . BF.first sortNotes . sortRawMessages
31 gatherMessages :: ([Note], [Control], [RawMessage]) -> [Message]
32 gatherMessages ([], [], []) = []
33 gatherMessages _ = undefined