]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - Reactogon/MIDI.hs
First version of arpeggiated.
[tmp/julm/arpeggigon.git] / Reactogon / MIDI.hs
1 module MIDI ( SampleRate
2 , Pitch
3 , toPitch
4 , fromPitch
5 , Velocity
6 , Voice ( fromVoice
7 , toVoice
8 )
9 , Note(..)
10 , ControllerIdx
11 , ControllerValue
12 , Control
13 ) where
14
15 import Sound.MIDI.Message.Channel.Voice ( fromPitch
16 , toPitch
17 )
18 import qualified Sound.MIDI.Message.Channel.Voice as Voice
19
20 type SampleRate = Int
21
22 type Pitch = Voice.Pitch
23 type Velocity = Voice.Velocity
24
25 class Voice a where
26 fromVoice :: Voice.T -> Maybe a
27 toVoice :: a -> Voice.T
28
29 data Note = NoteOn Pitch Velocity
30 | NoteOff Pitch Velocity
31 deriving(Show)
32
33 instance Voice Note where
34 fromVoice (Voice.NoteOn p v) = Just $ NoteOn p v
35 fromVoice (Voice.NoteOff p v) = Just $ NoteOff p v
36 fromVoice _ = Nothing
37 toVoice (NoteOn p v) = Voice.NoteOn p v
38 toVoice (NoteOff p v) = Voice.NoteOff p v
39
40 type ControllerIdx = Voice.Controller
41 type ControllerValue = Int
42
43 data Control = Control ControllerIdx ControllerValue
44
45 instance Voice Control where
46 fromVoice (Voice.Control i v) = Just $ Control i v
47 fromVoice _ = Nothing
48 toVoice (Control i v) = Voice.Control i v