Jon
Jon

Reputation: 11

How do I compose the CoreMidi MIDISendSysex Request in Swift 3?

I'm receiving the error.

Cannot convert value of type '() -> ()' to type 'MIDICompletionProc' (aka '@convention(c) (UnsafeMutablePointer) -> ()') in coercion.

Everything else looks OK but for the life of me I can't seem to compose the CompletionProc function call.

    var mySysExSendRequest : MIDISysexSendRequest
    let myCompProc = sysexCompletionProc (a separate static function)

    mySysExSendRequest = MIDISysexSendRequest(destination: Dest,
                                                  data: dataptr,
                                                  bytesToSend: 16,
                                                  complete: complete,
                                                  reserved: res,
                                                  completionProc: sysexCompletionProc as MIDICompletionProc,
                                                  completionRefCon: nil)

    MIDISendSysex(&mySysExSendRequest)

Upvotes: 1

Views: 445

Answers (1)

Alnitak
Alnitak

Reputation: 339786

You're currently supplying a function that takes no arguments, i.e. () -> Void.

Your completion proc must have this signature:

(UnsafeMutablePointer<MIDISysexSendRequest>) -> Void

Also note that since the proc has to be compatible with @convention(c) semantics it cannot be a class method or a closure.

It may be possible to work around that restriction by passing a pointer to self in the completionRefCon field and then casting that back (using "unsafe" methods) within the callback.

Upvotes: 1

Related Questions