Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AKMIDICallbackInstrument implementation issue

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.

like image 970
caxix Avatar asked Nov 08 '22 00:11

caxix


1 Answers

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.

like image 113
c_booth Avatar answered Nov 11 '22 10:11

c_booth