summaryrefslogtreecommitdiff
path: root/midi-dump.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2014-01-15 02:59:47 -0500
committerAndrew Cady <d@jerkface.net>2014-01-15 02:59:47 -0500
commitfaea360761df201d74a6b7bd4baa0a37cab1335f (patch)
treeef5a6a2683ceed5243d2952faed704a9b015d656 /midi-dump.hs
parentfb1f73e37b37d4ee2966554efc0e47aed0fcb5c9 (diff)
use nonblocking IO; poll (and spin the CPU)
once this is integrated into the mail loop, there will be a delay to avoid the CPU spin.
Diffstat (limited to 'midi-dump.hs')
-rw-r--r--midi-dump.hs23
1 files changed, 14 insertions, 9 deletions
diff --git a/midi-dump.hs b/midi-dump.hs
index d0bde4e..436644c 100644
--- a/midi-dump.hs
+++ b/midi-dump.hs
@@ -27,10 +27,10 @@ prettyNote (Event.Note noteChannel noteNote noteVelocity noteOffVelocity noteDur
27 let pitch = Event.unPitch noteNote 27 let pitch = Event.unPitch noteNote
28 vlcty = Event.unVelocity noteVelocity 28 vlcty = Event.unVelocity noteVelocity
29 in 29 in
30 printf "%d (%d)" pitch vlcty 30 printf "%d(%d)" pitch vlcty
31 31
32alsaInit k = do 32alsaInit k = do
33 SndSeq.withDefault SndSeq.Block $ \h -> do 33 SndSeq.withDefault SndSeq.Nonblock $ \h -> do
34 Client.setName (h :: SndSeq.T SndSeq.DuplexMode) "Haskell-Beat" 34 Client.setName (h :: SndSeq.T SndSeq.DuplexMode) "Haskell-Beat"
35 Port.withSimple h "inout" 35 Port.withSimple h "inout"
36 (Port.caps [Port.capRead, Port.capSubsRead, Port.capWrite, Port.capSubsWrite]) 36 (Port.caps [Port.capRead, Port.capSubsRead, Port.capWrite, Port.capSubsWrite])
@@ -49,6 +49,8 @@ alsaInit k = do
49 let publicAddr = Addr.Cons c public 49 let publicAddr = Addr.Cons c public
50 privateAddr = Addr.Cons c private 50 privateAddr = Addr.Cons c private
51 51
52 Queue.control h q Event.QueueStart Nothing
53
52 k h public private q publicAddr privateAddr 54 k h public private q publicAddr privateAddr
53 55
54main :: IO () 56main :: IO ()
@@ -69,13 +71,16 @@ main = (do
69 Exit.exitFailure 71 Exit.exitFailure
70 72
71 let wait keysDown = do 73 let wait keysDown = do
72 ev <- Event.input h 74 pending <- Event.inputPending h True
73 case Event.body ev of 75 if (pending > 0)
74 Event.NoteEv Event.NoteOn n -> return (Event.NoteOn, n, Set.insert (Event.noteNote n) keysDown) 76 then do
75 Event.NoteEv Event.NoteOff n -> return (Event.NoteOff, n, Set.delete (Event.noteNote n) keysDown) 77 ev <- Event.input h
76 _ -> wait keysDown 78 case Event.body ev of
77 79 Event.NoteEv Event.NoteOn n -> return (Event.NoteOn, n, Set.insert (Event.noteNote n) keysDown)
78 Queue.control h q Event.QueueStart Nothing 80 Event.NoteEv Event.NoteOff n -> return (Event.NoteOff, n, Set.delete (Event.noteNote n) keysDown)
81 _ -> wait keysDown
82 else
83 wait keysDown
79 84
80 let mkEv e = 85 let mkEv e =
81 (Event.simple publicAddr e) { 86 (Event.simple publicAddr e) {