]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - Reactogon/Translator/SortMessage.hs
Sorting might need a bit of reactivity. Leaving it there for now.
[tmp/julm/arpeggigon.git] / Reactogon / Translator / SortMessage.hs
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.
5
6 module Reactogon.Translator.SortMessage where
7
8 import qualified Data.Bifunctor as BF
9 import Data.Maybe
10 import Reactogon.Semantics
11 import Reactogon.Translator.Message
12
13 -- TEMPORARY
14 data Control
15 --
16
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
24
25 sortNotes :: [Message] -> ([Note], [Control])
26 sortNotes = sortNotes' ([],[])
27 where sortNotes' r [] = r
28 sortNotes' (n, c) (x:xs)
29 | isNoteOn x = sortNotes' (x:n, c) xs
30 | isNoteOff x = sortNotes' (n,c) xs
31 | isControl x = sortNotes' (n,x:c) xs
32 | otherwise = sortNotes' (n,c) xs
33
34 sortMessages :: [RawMessage] -> ([Note], [Control], [RawMessage])
35 sortMessages = (\((a,b),c) -> (a,b,c)) . BF.first sortNotes . sortRawMessages
36
37 gatherMessages :: ([Note], [Control], [RawMessage]) -> [Message]
38 gatherMessages ([], [], []) = []
39 gatherMessages _ = undefined