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
True, the class AKCallbackInstrument does not have a property midiIn, although the documentation does show it being used that way. Instead of using AKCallbackInstrument, use AKMIDICallbackInstrument. That class has midiIn, and seems to work fine.
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)
}
}