Haskell Jack client with absolute time

I just modified the Sound.JACK package so that the MIDI event loops
are passed an additional parameter which represents jacks frame time
at the start of the processing cycle.

Now a simple MIDI monitor that prints its input and forwards all events to output
looks like that:

{-# options -O2 #-}
module Main where

import qualified Sound.JACK as Jack
import Sound.JACK.Midi

main ∷ IO ()
main = Jack.mainMidi foo

foo ∷ NFrames →  (NFrames, Event) →  IO (NFrames, Event)
foo cycleStart (t, e) = do
    putStrLn $ "Time: " ⊕ (show $ cycleStart + t) ⊕ " " ⊕ (show e)
    return (t, e)

and its output (two notes and pressing a program button on my keyboard):

$ dist/build/midimon/midimon | grep -v ActiveSensing
started midimon...
Time: 302239993 MIDIEvent (Channel {fromChannel = 0}) (NoteOn (Pitch {fromPitch = 60}) (Velocity {fromVelocity = 52}))
Time: 302256544 MIDIEvent (Channel {fromChannel = 0}) (NoteOff (Pitch {fromPitch = 60}) (Velocity {fromVelocity = 64}))
Time: 302284765 MIDIEvent (Channel {fromChannel = 0}) (NoteOn (Pitch {fromPitch = 62}) (Velocity {fromVelocity = 58}))
Time: 302303650 MIDIEvent (Channel {fromChannel = 0}) (NoteOff (Pitch {fromPitch = 62}) (Velocity {fromVelocity = 64}))
Time: 302394999 MIDIEvent (Channel {fromChannel = 0}) (Control BankSelectMSB 0)
Time: 302395028 MIDIEvent (Channel {fromChannel = 0}) (Control BankSelectLSB 112)
Time: 302395055 MIDIEvent (Channel {fromChannel = 0}) (ProgramChange (Program {fromProgram = 1}))
Time: 302395097 MIDIEvent (Channel {fromChannel = 0}) (Control MainVolumeMSB 79)
Time: 302395125 MIDIEvent (Channel {fromChannel = 0}) (Control Controller4A 50)
Warning: Did not understand Event: MidiEvent @ 52	: [240,67,16,76,8,0,118,21,247]
Warning: Did not understand Event: MidiEvent @ 51	: [240,67,16,76,8,0,114,84,247]
Warning: Did not understand Event: MidiEvent @ 51	: [240,67,16,76,8,0,119,52,247]
Warning: Did not understand Event: MidiEvent @ 49	: [240,67,16,76,8,0,115,72,247]
Time: 302395676 MIDIEvent (Channel {fromChannel = 0}) (Control ChorusDepth 0)
Warning: Did not understand Event: MidiEvent @ 27	: [240,67,16,76,3,2,11,30,247]
Warning: Did not understand Event: MidiEvent @ 27	: [240,67,16,76,8,0,34,50,247]
quitting...
jack_client_thread zombified - exiting from JACK

We see that the output is nicely parsed (except for the sysex events, which I dont care about right now)

Advertisements

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: