]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - RCMA/Translator/Note.hs
Basic translation from high level notes to low levels implemented.
[tmp/julm/arpeggigon.git] / RCMA / Translator / Note.hs
1 {-# LANGUAGE Arrows #-}
2
3 module RCMA.Translator.Note where
4
5 import Data.Ratio
6 import FRP.Yampa
7 import RCMA.Global.Clock
8 import RCMA.Layer.Layer
9 import RCMA.Semantics
10 import RCMA.Translator.Message
11
12 messageToNote :: Message -> Note
13 messageToNote (NoteOn _ p s) = Note { notePch = p
14 , noteStr = s
15 , noteDur = 1 % 4
16 , noteOrn = noOrn
17 }
18
19 -- noteToMessage gives a pair of two time-stamped messages. The one on
20 -- the left is a note message, the other a note off.
21 --
22 -- For now this is only a tuple but a list will probably be necessary
23 -- for ornaments, etc..
24 noteToMessages :: Tempo -> Layer -> Int -> (Time,Note)
25 -> ((Time,Message),(Time,Message))
26 noteToMessages tempo l@(Layer { relTempo = rt }) chan =
27 proc m@(t,n@Note { notePch = p
28 , noteStr = s
29 , noteDur = d
30 }) -> do
31 nm <- noteOnToMessage chan -< n
32 let tl = floor (rt * fromIntegral tempo)
33 dt = fromRational (d * (toRational $ tempoToDTime tl))
34 returnA -< ((t,nm),(dt,switchOnOff nm))
35
36 noteOnToMessage :: Int -> Note -> Message
37 noteOnToMessage c (Note { notePch = p
38 , noteStr = s
39 }) = NoteOn (makeChannel c) p s
40
41 convertControl :: Message -> Controller
42 convertControl _ = Lol