MIDIClientCreate does not work for 32 bit processors in Swift
Asked Answered
W

0

1

I am able to create a midiclient via MIDIClientCreate when the scheme is a 64 bit processor (iPhone 5 and later). It does not work for 32 bit processors e.g. iPhone 4s.

    #if !arch(arm64) || !arch(x86_64)
    var status = OSStatus(noErr)
    var s:CFString = "MyClient"
    var client : Unmanaged<MIDIClient>?
    status = MIDIClientCreate(s,
            MIDINotifyProc( COpaquePointer( [ MyMIDINotifyProc ] ) ),
            nil,
            &client)
    if status == OSStatus(noErr) {
       if let c = client {
            var val = c.takeRetainedValue()

Blammo. Bad access exception on takeRetainedValue. As you see, the status is OK, and I'm unwrapping the optional.

Do you have any suggestions?

In case you're wondering, for 64 bit processors, it's a lot simpler because you can just initialize the client var. Look at MIDIServices.h and you'll see that MIDICLient is defined differently for different processors.

 var client = MIDIClientRef()
 status = MIDIClientCreate(s,
    MIDINotifyProc( COpaquePointer( [ MyMIDINotifyProc ] ) ),
    nil,
    &client)
Whippletree answered 30/12, 2014 at 16:24 Comment(4)
Don't know if this helps, but here is a similar 32/64-bit issue with MIDI: #27170307.Dav
Thanks for the response, Martin. The weird thing is that what works there doesn't work in this case. The MIDIClientCreate() call simply does not create the client nor does it set the status to error.Whippletree
FWIW, In the current Swift 1.2 beta, this nonsense is gone. You can now create a MIDI client. But there is still the callback problem.Whippletree
Thanks for the update! – As far as I know, there is still no way to call C callback functions from Swift code.Dav

© 2022 - 2024 — McMap. All rights reserved.