5 Replies
      Latest reply on Apr 22, 2019 5:27 PM by KMT
      Smashbrose Level 1 Level 1 (0 points)

        Hi!  I am trying to develop an application that uses Core MIDI to instantiate a connection to my Macbook via Audio MIDI Setup.  I have created a client within my application and that shows up under the directory in Audio MIDI Setup on my macbook.  Now I am stuck trying to figure out how to send MIDI from my app to my computer.  I have tried MIDISend, and using CreateOutputPort.  Both are successful in the sense that I don't get zeros when printing to the console, but nothing changes in the DAW when I set the controller and number values to the exact numbers I created in my app.


        I have a feeling that I am missing a network connection within my app somehow so that it recognizes my computer as a source, but I have not yet found an effective method to do this.


        Any information as to how I get midi to send from my app to my DAW on my computer would be greatly appreciated!


        I am trying to make this for my final project in one of my coding classes.




        • Re: Connecting iOS to MacOS via Audio MIDI Setup & Sending MIDI
          KMT Level 9 Level 9 (15,805 points)

               >have a feeling that I am missing a network connection


          Did your process include adding your iOS device via Audio MIDI Setup?


          Try this if not...

          1. Attach your iOS device via Lightning cable (direct, not thru a hub, drive, etc.)
          2. Run Audio MIDI Setup (/Applications/Utilities), then use the menu Window > Show iOS Device Browser

          Audio Devices. Select/enable your iOS device on the left.

          1. Open Preferences → Audio, then choose the IOS device as an audio input device


          Also see: https://support.apple.com/guide/audio-midi-setup/set-up-midi-devices-ams875bae1e0/mac

            • Re: Connecting iOS to MacOS via Audio MIDI Setup & Sending MIDI
              Smashbrose Level 1 Level 1 (0 points)

              Hey KMT, thanks for the quick reply.  When I connect my device via lightning, there is no option within Audio MIDI Setup that prompts a window for iOS Device Browser, I only have (1) Show Audio Devices, (2) Hide MIDI Studio, and (3) Show Network Device Broswer.  In my iOS swift application on XCode I have been able to initiate a client on my iPad using Core MIDI, have been able to hit connect on my macbook to my recognized iPad, but am stuck from there trying to figure out how to send MIDI between the devices.  I think I have to somehow recognize my computer as a source and send that data through that as a reference point but am stuck trying to figure that out.

              I have tried following the Apple Developer Core MIDI page for MIDI Send but am stuck with that since It does not seem like any MIDI is getting from my iPad to my computer.


              Below is some of the code I have been writing to try and figure out a connection, it is a little messy from everything I have been trying, but any help would be great!


              This is a class I created that I've been trying to use to send MIDI to my computer.


              import Foundation

              import CoreMIDI


              var midi1 = MidiOutClass()


              class MidiOutClass{


                  var midiClient = MIDIClientRef()

                  var midiSource = MIDIEndpointRef()

                 // var midiFound = MIDIObjectType(rawValue: <#Int32#>)

                  var outputPort = MIDIPortRef()

                  var endPoint = MIDIObjectRef()

                  var ent = MIDIEntityRef()


                  func openClient(){

                      MIDIClientCreate("Gregs iPad" as CFString, nil, nil, &midiClient)  // this sets up the iPad in the Directory of Audio MIDI Setup

                      //MIDISourceCreate(midiClient, "MIDI Source" as CFString, &midiSource)



                      MIDIOutputPortCreate(midiClient, "Output" as CFString, &outputPort)

                     // let midiSource = MIDIGetSource(1)


                     // MIDIEndpointGetEntity(midiSource, &ent)






                     // print(endPoint)

                      print("midi out opened") // should do this if successful



              //    func createPort(){

              //        var result = MIDIOutputPortCreate(midiClient, "Output" as CFString, &outputPort)

              //        print(result)

              //        result = MIDIObjectFindByUniqueID(MIDIUniqueID.init(), &endPoint, &midiSourceType!)

              //    }




                  func midiSend(status: Int, controlID: Int, value: Int){


                      var packet = UnsafeMutablePointer<MIDIPacket>.allocate(capacity: 1)

                      let packetList = UnsafeMutablePointer<MIDIPacketList>.allocate(capacity: 1)

                      let midiDataToSend:[UInt8] = [UInt8(status), UInt8(controlID), UInt8(value)];

                      packet = MIDIPacketListInit(packetList);

                      packet = MIDIPacketListAdd(packetList, 1024, packet, 0, 3, midiDataToSend);


                      MIDISend(outputPort, midiSource, packetList)

                      print("MIDI Send")


              //    MIDIReceived(midiSource, packetList)

                //      MIDISend(<#T##port: MIDIPortRef##MIDIPortRef#>, <#T##dest: MIDIEndpointRef##MIDIEndpointRef#>, <#T##pktlist: UnsafePointer<MIDIPacketList>##UnsafePointer<MIDIPacketList>#>)


                      // MIDIDeviceGetEntity(<#T##device: MIDIDeviceRef##MIDIDeviceRef#>, <#T##entityIndex0: Int##Int#>)


                 //     packet.deallocate()

                  //    packetList.deallocate()





              Thank you again for the help,


              - Greg