1 {-# LANGUAGE Arrows #-}
3 module RMCA.Translator.Note where
7 import RMCA.Global.Clock
9 import RMCA.Translator.Message
11 messageToNote :: Message -> Note
12 messageToNote (NoteOn _ p s) = Note { notePch = p
17 messageToNote m = error $ "In messageToNote: the message "
18 ++ show m ++ " is not a note message"
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
24 -> Int -- Channel number
25 -> (Frames,Note) -- Note to convert
27 noteToMessages layTempo sr chan =
28 proc (t,n@Note { noteDur = d }) -> do
29 nm <- noteOnToMessage chan -< n
30 let dt = fromRational (d * toRational (tempoToQNoteIvl layTempo))
31 dn = floor $ dt * fromIntegral sr
32 returnA -< [(t,nm),(t + dn,switchOnOff nm)]
34 noteOnToMessage :: Int -> Note -> Message
35 noteOnToMessage c Note { notePch = p
37 } = NoteOn (makeChannel c) p s