MIDI is actually just serial data at 31,250bps in 8N1 format that is transmitted over a 5-pin DIN cable. This means you can receive MIDI data from your musical instrument using a serial port, or an FTDI cable.
Receiving MIDI data over the FTDI cable doesn’t magically turn your USB serial device into a MIDI device – you need to be running a software bridge or a driver that pretends to be a virtual MIDI device emitting these messages. For this purpose, I shall use the Serial MIDI Converter from SpikenzieLabs.
I’m using Mac OS X 10.6.6 and the latest Java update, so I didn’t need any extra JAR files.
Wiring It Up
The circuit is relatively simple – you need the DIN socket, an opto-isolator, 2 resistors, and optionally a diode. In my case, parts came from a scrap bin, so I used a 330 ohm resistor instead of a 220 ohm for Rb and a 1K for Rd instead of 280 ohms. For the opto-isolator, element14 had some non-RoHS CNY17-2 on sale, so I just used that.
Note that the RXD output is only meant for interfacing with a TTL circuit like an FTDI chip/cable or MAX232 transceiver, not the RS232 serial port directly.
You can find the same circuit diagram (with different values & parts) in the official MIDI Electrical Specification Diagram.
Setting Custom Baud Rates on a Mac
It turns out that setting a non-standard baud rate on a POSIX system was, erm, non-standard. Linux has its own way of setting it, and so does the Mac OS. 31,250bps was definitely non-standard, and it caused Serial MIDI Converter to stop working without any error messages. You can however find the exception and stack trace in your logs using the Console utility.
The Serial MIDI converter relies on the RXTX Java library for serial I/O. I read through the source code and found out that there was no support for setting custom baud rates on the Mac, which caused it to throw an exception (which in turn wasn’t handled by the converter). If I’m not wrong, there is already code to handle setting custom baud rates in Windows and Linux.
Since Mac OS X 10.3, custom baud rates can be set by sending the IOSSIOSPEED ioctl to the device. So I decided to implement support for it (not sure if that’s the right place to post the patch though) in the RXTX Java library. I’m offering pre-compiled JAR and .jnilib files for download below.
Apparently the custom baud rate problem was just one of the road blocks.
The Serial MIDI converter was not made to be robust because it expects to receive Note On messages only, and it parses incoming data in three byte pieces. Sending single-byte messages may just cause it to lose its mind. My piano sends “realtime” MIDI messages, which causes the converter to repeat these unrecognized messages to the virtual MIDI device. I had to hack in some if statements to ignore those.
After fixing that, I found an even bigger problem – my piano sends Note On, but it doesn’t send Note Off messages, so the target device (my Mac) won’t know when the key is released. This cannot really be remedied, so I gave up. Had I checked the MIDI implementation chart earlier I would have found this out.
When you’re troubleshooting, I highly recommend using the Console utility to check for exceptions and the handy MIDI Monitor application from snoize. If you configured everything correctly, you should see Note On messages appear in the MIDI Monitor.
To get the converter working on Snow Leopard, you need the .jnilib that is compiled for x86_64. Furthermore, if you need to connect to a MIDI device, your baud rate needs to be set at 31,250bps, something that is currently unsupported by any build of the RXTX library. For that reason, I’m offering pre-compiled and matching JAR and .jnilib.
You will need to replace these files inside the Serial MIDI Converter application, by right-clicking its icon, then choose Show Package Contents. Navigate to Contents > Resources > Java and you should find these files. Just copy the files you download here into the directory, replacing the old copies.
The version of this RXTX library is 2.2pre2, which works fine for the MIDI Serial Converter.
Thanks for the article Darell. This reads like you are quite literate in this MIDI area and it’s wonderful that you share this knowledge.
I am despondent with the future of my Yamaha P80 & Roland SC88 Pro. May I ask the following please:
Is the any OSX 10.6 drivers etc that you know of that will help me use my USB port to connect with the 8pin mini din connector on the midi instruments listed above? I am assuming that your solution is for direction connection via the 5pin Din MIDI. I looking for a solution throught the RS232 connection on the instruments.
I have build an usb – 8 pin din lead using an FDI chip set; but , my limited experimentation in Apple’s audio midi setup has not allowed me to marry the virtual USB/RS232 port to any device in the studio set.
I’ve only be at this for a couple of days and will no doubt crack this at some stage – I just looking for a “leg up”.
Hi Greg, it seems you’re on the right track. The software that bridges the virtual RS232 port to a virtual MIDI device used here is called the Serial MIDI Converter. However as I’ve mentioned, it was never designed for this purpose, and I definitely don’t recommend it. I haven’t been able to find something better (or maybe I just haven’t looked hard enough). This seems to be the missing piece in your setup.
If you’re using MIDI in a proper studio setup, I highly recommend you get a USB to MIDI converter, which is more robust and reliable. You would then need to make a 8pin to 5pin cable for the converter, as I believe the 5pin DIN is the standard now.
[…] in the spec. (Otherwise they would have caught this, no?) After some furious Google searching I found that someone had solved this. Apparently this is a limitation in the RXTX Java Serial library, and by adding the fix from the […]
Did this ever get merged, or even looked at? I ran into the same problem. These RxTx guys have a mailing list, maybe you should nudge them in the right direction?
I don’t know actually. It looks like it’s unmaintained and there hasn’t been a release in a while. It also looks like nobody’s clearing bugs on the bug tracker too.
I’ll try to see if I can reach them on the mailing list.
Thanks man it’s working…
Do you mind if I quote a few of your articles as long as I provide credit and sources back to your site?
My blog is in the very same area of interest as yours and
my visitors would certainly benefit from some of the information you present here.
Please let me know if this alright with you.
Excellent, I was worried because SM converter wasn’t working on my Mac book with Yosemite 10.10.2. After replacing the two files it runs like a charm!
CNY17: EQUIVALENT PHOTOCOUPLEUR 4N36? TNKS
I think a general purpose optocoupler, like the 4N36, would work fine.