0

Using AKSequencer for midi and a Control track. I'm aware AKMIDIStatus has undergone some changes in recent revisions. My exploration leads me to believe this simple 'note on' 'note off' callback should work:

        func playThroughCallback(_ statusByte: UInt8,
                             _ noteNumber: MIDINoteNumber,
                             _ velocity: MIDIVelocity) {
        //print("MIDI Sequence Event \(status)")
        guard let status = AKMIDIStatus(byte: statusByte) else { return }

        switch status {
        case .noteOn: midi?.sendNoteOnMessage(noteNumber: noteNumber, velocity: velocity)
        case .noteOff: midi?.sendNoteOffMessage(noteNumber: noteNumber, velocity: velocity)
        default: return

        }
}

But the enum cases seem to have vanished.

Edit: Reverting to 4.5.5 enabled me to use the solution here: AKMIDICallbackInstrument Implementation Issue

Darewe
  • 43
  • 4

1 Answers1

2

Try creating an AKMIDIStatus using the incoming byte, then reading the AKMIDIStatusType

let callbackReceiver = AKMIDICallbackInstrument(midiInputName: "myCoolInput", 
    callback: { status, noteNumber, velocity in
        let statusType = AKMIDIStatus(byte: status)?.type //can be noteOn, noteOff, etc
        if(statusType == AKMIDIStatusType.noteOn){
            print("Note on.")
        }
})

myTrack.setMIDIOutput(callbackReceiver.midiIn)

Just tested as working in AudioKit 4.6.1

Typewriter
  • 1,216
  • 1
  • 11
  • 18
  • Thanks for this, using `AKMIDIStatus(byte: statusByte)?.type` works as expected. Under my nose as ever... – Darewe Feb 24 '19 at 12:40