Monday, 30 May 2011

Network MIDI on iOS - Part 1

This is an app I wrote to try out some ideas for networked MIDI on iPhone and iPad. It connects to a host computer running OS X Tiger or later (see the documentation for Apple's Audio MIDI Setup application), or any compatible RTP MIDI host such as rtpMIDI for Windows.

I will discuss the implementation details in further blog posts, as it introduces some useful concepts such as:
  • Composing outgoing MIDI data in response to user input
  • Processing incoming MIDI data in real time (with semaphores and lock free buffers)
  • Finding network services with Bonjour
For now, here's the source code.
Updated project for iOS 5.1 - 6 using ARC:

XCode 4.51 Project (MediaFire download)

Updated project for iOS 7 (should work back to iOS 5.1):

Please note you need to run this on a device rather than the simulator.

(Now seems to work OK on the iOS 7 simulator at least).


See Part 2 and Part 3.


  1. can i ask what your licensing policies are? i'd like to use this in my app. not the interface, just the back-end stuff.

  2. Hi Drew, please consider any code posted here as in the public domain unless otherwise stated, so feel free to use it. If you'd like to acknowledge where you got it then by all means, but there's no obligation. If you're using it in a commercial app now you may also need to consider hardware USB MIDI interfaces connected via the Camera Connection Kit, as this option didn't exist when I wrote the original code. Luckily this is much easier than the network version!

  3. network midi stuff seems to be working. i'm new to ios, so i'm using your app as an example to learn how to use the settings/tableview as well. i copied your code over to my app, changed it for arc and auto synthesis of properties, and it does run. however, when i try to select a midi connection or midi channel, the interface does nothing (doesn't switch to the simple selection view). it does run the code inside SimpleSelectionViewController's howInNavigationController method, because if i put a NSLog in there, it does show up. but nothing changes at all on my interface. aside from the code itself, is there something else you needed to do to get this working? i went over the .xib files for my code and yours, and they seem to match (looks to be default). i must be missing some property that's changed elsewhere.

  4. Hi Drew, does your calling view actually have a non-nil navigation controller? That would probably do it. You could create a method to just present the selection view modally in that case, or create a navigation controller and present that. By the way, I updated the project to use ARC etc. - you might want to grab the updated code, as I noticed a word-alignment problem with the buffers in the writeMIDIPacket: methods when compiling with Clang/LLVM that didn't happen with GCC.

  5. i ripped out everything, updated the files, and re-implemented your work. everything seems fine. my app is structured a bit different, and i was trying to use this from my main delegate, which isn't a view controller. after putting this in my view controller, all is fine so i think you were right about the problem. thanks again, the example has been quite a help to me and my learning of obj-c. i can't wait to pick apart your arp/sequencing code in a future project.

  6. Cool, glad you got it going. I've uploaded an updated version of the arpeggiator as well if you want to give that a try, it still needs some work to make it slightly more readable (the UI stuff is mixed up with the MIDI stuff at the moment, and it uses atomic FIFO queues for inter-thread communication for no particularly good reason) but it should be an improvement on the last version.

  7. Great article! I had this up and running some time ago but when I came back to it recently, found it isn't working on iOS7. Keyboard disappeared and connections are blank... Any idea what happened?

  8. Hi, give the following a try:
    This fixes the issue with the keyboard not being visible (it's just the different button appearance in iOS 7 - this version should work in iOS 5 onwards). As far as the connections being blank, is your computer definitely sharing a session? If you open the Audio MIDI Setup application, open the MIDI window, double click network and then add a session (setting "Who may connect to me?" to "Anyone") then you should start seeing your device messages showing up in the latency display.

  9. This project is a great start for what I'm trying to accomplish! I'm lost trying to figure out how to work with multiple devices at the same time given that MIDINetworkSession is a singleton with one source and one destination. In your project I've selected multiple devices, but I can't seem to get them to all respond together. Any pointers in the right direction would be greatly appreciated.

  10. Thank you very much for sharing your code. Its a really helpful to get started!