1 module MIDI ( EventQueue
19 import qualified Sound.MIDI.Message as Message
21 import Sound.MIDI.Message.Channel.Voice ( fromPitch
26 import qualified Sound.MIDI.Message.Channel as Channel
27 import qualified Sound.MIDI.Message.Channel.Voice as Voice
31 type EventQueue = Map Time Message
35 type RawMessage = Message.T
39 fromMessage :: RawMessage -> Maybe a
40 toMessage :: a -> RawMessage
43 type MidiVoice = Voice.T
45 type Channel = Channel.Channel
46 type Pitch = Voice.Pitch
47 type Velocity = Voice.Velocity
50 class (Message a) => Voice a where
51 fromVoice :: MidiVoice -> Maybe a
52 toVoice :: a -> MidiVoice
55 type ControllerIdx = Voice.Controller
56 type ControllerValue = Int
58 data Message = NoteOn Channel Pitch Velocity
59 | NoteOff Channel Pitch Velocity
60 | Control Channel ControllerIdx ControllerValue
63 fromRawMessage :: RawMessage -> Maybe Message
64 fromRawMessage (Message.Channel (Channel.Cons c
65 (Channel.Voice (Voice.NoteOn p v)))) = Just $ NoteOn c p v
66 fromRawMessage (Message.Channel (Channel.Cons c
67 (Channel.Voice (Voice.NoteOff p v)))) = Just $ NoteOff c p v
68 fromRawMessage _ = Nothing
70 toRawMessage :: Message -> RawMessage
71 toRawMessage (NoteOn c p v) = (Message.Channel $ Channel.Cons c
72 (Channel.Voice $ Voice.NoteOn p v))
73 toRawMessage (NoteOff c p v) = (Message.Channel $ Channel.Cons c
74 (Channel.Voice $ Voice.NoteOff p v))
77 instance Message Note where
78 fromMessage (Message.Channel (Channel.Cons c
79 (Channel.Voice (Voice.NoteOn p v)))) = Just $ NoteOn c p v
80 fromMessage (Message.Channel (Channel.Cons c
81 (Channel.Voice (Voice.NoteOff p v)))) = Just $ NoteOff c p v
82 fromMessage _ = Nothing
83 toMessage (NoteOn c p v) = (Message.Channel $ Channel.Cons c
84 (Channel.Voice $ Voice.NoteOn p v))
85 toMessage (NoteOff c p v) = (Message.Channel $ Channel.Cons c
86 (Channel.Voice $ Voice.NoteOff p v))
88 instance Voice Note where
89 fromVoice (Voice.NoteOn p v) = Just $ NoteOn p v
90 fromVoice (Voice.NoteOff p v) = Just $ NoteOff p v
92 toVoice (NoteOn p v) = Voice.NoteOn p v
93 toVoice (NoteOff p v) = Voice.NoteOff p v
98 data Control = Control ControllerIdx ControllerValue
101 instance Voice Control where
102 fromVoice (Voice.Control i v) = Just $ Control i v
103 fromVoice _ = Nothing
104 toVoice (Control i v) = Voice.Control i v