简体   繁体   中英

How do you use AKMIDIStatus in a AKMIDICallbackInstrument callback with AudioKit 4.6.1

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM