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)
Gene De Lisa
  • 3,628
  • 1
  • 21
  • 36
  • Don't know if this helps, but here is a similar 32/64-bit issue with MIDI: http://stackoverflow.com/questions/27169807/swift-unsafemutablepointerunmanagedcfstring-allocation-and-print. – Martin R Dec 30 '14 at 17:35
  • 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. – Gene De Lisa Dec 30 '14 at 20:49
  • 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. – Gene De Lisa Mar 04 '15 at 12:09
  • Thanks for the update! – As far as I know, there is still no way to call C callback functions from Swift code. – Martin R Mar 04 '15 at 12:12

0 Answers0