Skip to content

Instantly share code, notes, and snippets.

@evanrinehart
Last active September 2, 2019 19:03
Show Gist options
  • Save evanrinehart/615c4105a33b63848fd21d3027852d79 to your computer and use it in GitHub Desktop.
Save evanrinehart/615c4105a33b63848fd21d3027852d79 to your computer and use it in GitHub Desktop.
import qualified Sound.JACK.MIDI as MIDI
import Sound.JACK (NFrames(NFrames), )
import qualified Sound.MIDI.Message as Msg
import qualified Sound.MIDI.Message.Channel as Ch
import Data.IORef
startMidiListener :: IO ()
startMidiListener = do
counter <- newIORef 0
MIDI.main (makeMidiEventHandler counter)
makeMidiEventHandler :: IORef Int -> NFrames -> (NFrames, Msg.T) -> IO (NFrames, Msg.T)
makeMidiEventHandler counter (NFrames cycleStart) (tf@(NFrames t), e) = do
putStrLn message
modifyIORef counter (+ 1)
incr <- readIORef counter
putStrLn (show incr)
return (tf, e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment