AKMIDICallbackInstrument implementation issue

℡╲_俬逩灬. 提交于 2019-12-14 01:01:04

问题


Updating to the latest version of AudioKit left me changing several AKCallbackInstrument instances over to the new AKMIDICallbackInstrument class which now incorporates the former as legacy behavior. When doing so however, I ran into this weird error. Maybe a Swift nuance I am missing?

let callback = AKMIDICallbackInstrument() { status, note, velocity in
    if status == .noteOn {  //errors out
       // do something
    }
}

Comparing status to .noteOn errors out with: "Expression type 'Bool' is ambiguous without more context.". Makes sense, because AKMIDICallbackInstrument is not returning an AKMIDIStatus in status anymore, but a straight MIDIByte (UInt8). Using direct MIDI command numerics works.

let callback = AKMIDICallbackInstrument() { status, note, velocity in
    if status == 0x90 {
       // do something
    }
}

So we have a problem and a potential solution. I'm just not sure that this is the way to go and AKMIDICallbackInstrument didn't hit the docs yet.


回答1:


For the time being, you can convert the MIDIByte to AKMIDIStatus like this:

let status = AKMIDIStatus(rawValue: Int(statusByte >> 4))

On the develop branch, there is a new initializer for AKMIDIStatus that directly takes MIDIByte as a parameter to make this a little easier.



来源:https://stackoverflow.com/questions/53363525/akmidicallbackinstrument-implementation-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!