]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - src/RMCA/Translator/Note.hs
Removed useless dependencies in .cabal.
[tmp/julm/arpeggigon.git] / src / RMCA / Translator / Note.hs
1 {-# LANGUAGE Arrows #-}
2
3 module RMCA.Translator.Note where
4
5 import Data.Ratio
6 import FRP.Yampa
7 import RMCA.Global.Clock
8 import RMCA.Semantics
9 import RMCA.Translator.Message
10
11 messageToNote :: Message -> Note
12 messageToNote (NoteOn _ p s) = Note { notePch = p
13 , noteStr = s
14 , noteDur = 1 % 4
15 , noteOrn = noOrn
16 }
17 messageToNote m = error $ "In messageToNote: the message "
18 ++ show m ++ " is not a note message"
19
20 -- noteToMessage gives a pair of two time-stamped messages. The one on
21 -- the left is a note message, the other a note off.
22 noteToMessages :: LTempo
23 -> SampleRate
24 -> Int -- Channel number
25 -> (Frames,Note) -- Note to convert
26 -> [(Frames,Message)]
27 noteToMessages layTempo sr chan =
28 proc (t,n@Note { noteDur = d }) -> do
29 nm <- noteOnToMessage chan -< n
30 let dt :: Double
31 dt = fromRational (d * toRational (tempoToQNoteIvl layTempo))
32 dn :: Int
33 dn = floor $ dt * fromIntegral sr
34 returnA -< [(t,nm),(t + dn,switchOnOff nm)]
35
36 noteOnToMessage :: Int -> Note -> Message
37 noteOnToMessage c Note { notePch = p
38 , noteStr = s
39 } = NoteOn (makeChannel c) p s