]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/Translator/Filter.hs
Volume modification.
[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 -- When to events are at the same frame, shift them so that they are
28 -- all separated by one frame. Then take every list and make sure that
29 -- the first frame of the next list is at least one frame after the
30 -- last frame of that list.
31 scatterEvents :: [(Frames, a)] -> [(Frames, a)]
32 scatterEvents (x@(n,_):(m,b):xs) = x:scatterEvents ((m',b):xs)
33 where m' = m + max 0 (1 + n - m)
34 scatterEvents [x] = [x]
35 scatterEvents _ = []