diff options
author | Andrew Cady <d@jerkface.net> | 2015-12-03 05:35:10 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2015-12-03 05:35:10 -0500 |
commit | 3618430364b04d4283a8e01590cae5476255fc30 (patch) | |
tree | abe8bb46c75b4f188d783f7c892861c781060975 /AlsaSeq.hs | |
parent | 6b1f45968645c12a31a750e7c1e428ca44ab4172 (diff) |
store midi event history in a simple list
Diffstat (limited to 'AlsaSeq.hs')
-rw-r--r-- | AlsaSeq.hs | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -1,7 +1,7 @@ | |||
1 | {-# LANGUAGE NondecreasingIndentation #-} | 1 | {-# LANGUAGE NondecreasingIndentation #-} |
2 | module AlsaSeq (withAlsaInit, parseAlsaEvents, forwardNoteEvent, | 2 | module AlsaSeq (withAlsaInit, parseAlsaEvents, parseAlsaEvents', forwardNoteEvent, |
3 | cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch, | 3 | cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch, |
4 | unPitch, unChannel, MidiHook) where | 4 | unPitch, unChannel, MidiHook, MidiPitchSet) where |
5 | import qualified Sound.ALSA.Exception as AlsaExc | 5 | import qualified Sound.ALSA.Exception as AlsaExc |
6 | import qualified Sound.ALSA.Sequencer.Address as Addr | 6 | import qualified Sound.ALSA.Sequencer.Address as Addr |
7 | import qualified Sound.ALSA.Sequencer as SndSeq | 7 | import qualified Sound.ALSA.Sequencer as SndSeq |
@@ -143,6 +143,9 @@ inputPendingLoop h b = do | |||
143 | (AlsaExc.Cons location _ code) -> AlsaExc.throw location code | 143 | (AlsaExc.Cons location _ code) -> AlsaExc.throw location code |
144 | (Right result) -> return result | 144 | (Right result) -> return result |
145 | 145 | ||
146 | type MidiPitchSet = Set.Set (Event.Channel, Event.Pitch) | ||
147 | parseAlsaEvents :: SndSeq.AllowInput mode => | ||
148 | SndSeq.T mode -> Set.Set (Event.Channel, Event.Pitch) -> (Event.T -> IO a) -> IO MidiPitchSet | ||
146 | parseAlsaEvents h keysDown immediate = loop keysDown | 149 | parseAlsaEvents h keysDown immediate = loop keysDown |
147 | where | 150 | where |
148 | loop keysDown = do | 151 | loop keysDown = do |
@@ -162,6 +165,25 @@ parseAlsaEvents h keysDown immediate = loop keysDown | |||
162 | loop (Set.delete (Event.noteChannel n, Event.noteNote n) keysDown) | 165 | loop (Set.delete (Event.noteChannel n, Event.noteNote n) keysDown) |
163 | _ -> loop keysDown | 166 | _ -> loop keysDown |
164 | 167 | ||
168 | parseAlsaEvents' h keysDown immediate = loop [] keysDown | ||
169 | where | ||
170 | loop events keysDown = do | ||
171 | pending <- inputPendingLoop h True | ||
172 | if (pending == 0) then | ||
173 | return (events, keysDown) | ||
174 | else do | ||
175 | ev <- Event.input h | ||
176 | immediate ev | ||
177 | case Event.body ev of | ||
178 | Event.NoteEv Event.NoteOn n -> | ||
179 | if (Event.unVelocity (Event.noteVelocity n) == 0) then | ||
180 | loop (ev:events) (Set.delete (Event.noteChannel n, Event.noteNote n) keysDown) | ||
181 | else | ||
182 | loop (ev:events) (Set.insert (Event.noteChannel n, Event.noteNote n) keysDown) | ||
183 | Event.NoteEv Event.NoteOff n -> | ||
184 | loop (ev:events) (Set.delete (Event.noteChannel n, Event.noteNote n) keysDown) | ||
185 | _ -> loop (ev:events) keysDown | ||
186 | |||
165 | type MidiHook = Event.T -> IO () | 187 | type MidiHook = Event.T -> IO () |
166 | 188 | ||
167 | forwardNoteEvent :: SndSeq.AllowOutput mode => SndSeq.T mode -> Queue.T -> Addr.T -> MidiHook | 189 | forwardNoteEvent :: SndSeq.AllowOutput mode => SndSeq.T mode -> Queue.T -> Addr.T -> MidiHook |