summaryrefslogtreecommitdiff
path: root/AlsaSeq.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2015-12-03 05:35:10 -0500
committerAndrew Cady <d@jerkface.net>2015-12-03 05:35:10 -0500
commit3618430364b04d4283a8e01590cae5476255fc30 (patch)
treeabe8bb46c75b4f188d783f7c892861c781060975 /AlsaSeq.hs
parent6b1f45968645c12a31a750e7c1e428ca44ab4172 (diff)
store midi event history in a simple list
Diffstat (limited to 'AlsaSeq.hs')
-rw-r--r--AlsaSeq.hs26
1 files changed, 24 insertions, 2 deletions
diff --git a/AlsaSeq.hs b/AlsaSeq.hs
index 1c53b18..e8321af 100644
--- a/AlsaSeq.hs
+++ b/AlsaSeq.hs
@@ -1,7 +1,7 @@
1{-# LANGUAGE NondecreasingIndentation #-} 1{-# LANGUAGE NondecreasingIndentation #-}
2module AlsaSeq (withAlsaInit, parseAlsaEvents, forwardNoteEvent, 2module AlsaSeq (withAlsaInit, parseAlsaEvents, parseAlsaEvents', forwardNoteEvent,
3cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch, 3cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch,
4unPitch, unChannel, MidiHook) where 4unPitch, unChannel, MidiHook, MidiPitchSet) where
5import qualified Sound.ALSA.Exception as AlsaExc 5import qualified Sound.ALSA.Exception as AlsaExc
6import qualified Sound.ALSA.Sequencer.Address as Addr 6import qualified Sound.ALSA.Sequencer.Address as Addr
7import qualified Sound.ALSA.Sequencer as SndSeq 7import 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
146type MidiPitchSet = Set.Set (Event.Channel, Event.Pitch)
147parseAlsaEvents :: SndSeq.AllowInput mode =>
148 SndSeq.T mode -> Set.Set (Event.Channel, Event.Pitch) -> (Event.T -> IO a) -> IO MidiPitchSet
146parseAlsaEvents h keysDown immediate = loop keysDown 149parseAlsaEvents 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
168parseAlsaEvents' 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
165type MidiHook = Event.T -> IO () 187type MidiHook = Event.T -> IO ()
166 188
167forwardNoteEvent :: SndSeq.AllowOutput mode => SndSeq.T mode -> Queue.T -> Addr.T -> MidiHook 189forwardNoteEvent :: SndSeq.AllowOutput mode => SndSeq.T mode -> Queue.T -> Addr.T -> MidiHook