How to connect AKSequencer to a AKCallbackInstrument?
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)
}
}
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.