I want to read a midi file and display things when note events are triggered. I found this stackoverflow question, where the second answer suggests to use AudioKit : How Do
typewriter found the solution to my problem. Here is the code which works now, printing the midi number of the note each time it is played (but I didn't add sound yet) :
// dont write the .mid extension in filename :
let sequencer = AKSequencer(filename:"coucou")
let callbackInstr = AKMIDICallbackInstrument()
callbackInstr.callback = myCallBack
sequencer.setGlobalMIDIOutput(callbackInstr.midiIn)
sequencer.play()
func myCallBack(a:UInt8, b:MIDINoteNumber, c:MIDIVelocity) -> () {
if (a == 144) { // if noteOn
print(b)
}
}