]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/Translator/Filter.hs
Removed most warnings and solved non-rotating tile problem.
[tmp/julm/arpeggigon.git] / src / RMCA / Translator / Filter.hs
1 -- Contains function for scheduling and filtering events given the
2 -- correct informations.
3
4 module RMCA.Translator.Filter where
5
6 import Data.Bifunctor as BF
7 import Data.List (sortBy)
8 import Data.Ord
9 import RMCA.Translator.Message
10
11 -- Takes a list of time stamped "things", a sample rate and a buffer
12 -- size. The function argument is a function that needs to tell which
13 -- arguments are kept in the case where two would come into
14 -- contact. On the left are the events that can be thrown into the
15 -- buffer, on the right are the events that will need to wait. Both
16 -- list are sorted.
17 --
18 -- /!\ The frame number is relative. A preprocessing operation
19 -- removing all events too soon to be happening and shifting them is
20 -- necessary.
21 schedule :: Frames
22 -> [(Frames, a)]
23 -> ([(Frames,a)], [(Frames,a)])
24 schedule size = BF.first scatterEvents
25 . break ((>= size) . fst) . sortBy (comparing fst)
26
27 {- Rendered useless
28 -- The function choose between the event in case two are in conflict.
29 --
30 -- /!\ That functional argument is a bit unsatisfying, it would be
31 -- probably better if we'd try to push events to the next frame if
32 -- they conflict and only remove them if it's impossible to do
33 -- otherwise.
34 nubDuplicate :: (Eq a) => ([a] -> a) -> [(Frames, a)] -> [(Frames, a)]
35 nubDuplicate f = map (BF.second f) . scatterEvents
36 . map (\l@((n,_):_) -> (n,map snd l)) . group
37 -}
38 -- When to events are at the same frame, shift them so that they are
39 -- all separated by one frame. Then take every list and make sure that
40 -- the first frame of the next list is at least one frame after the
41 -- last frame of that list.
42 scatterEvents :: [(Frames, a)] -> [(Frames, a)]
43 scatterEvents (x@(n,_):(m,b):xs) = x:scatterEvents ((m',b):xs)
44 where m' = m + max 0 (1 + n - m)
45 scatterEvents [x] = [x]
46 scatterEvents _ = []