NOTEMIDI - Linux Serial Port MIDI Interface

Author: Michael Minn <nycminn@earthlink.net>

v, 23 September 2000


NOTEMIDI is a Linux interface for MIDI input and output via the RS-232 serial port on notebook (laptop) computers. NOTEMIDI can be used with the MIDIator MS-124W interface, Roland Sound Canvas sound modules or Yamaha MU-x series sound modules.

1. Introduction

2. Hardware Setup

  • 2.1 Roland Sound Canvas or Yamaha XG Sound Module
  • 2.2 MIDIator MS-124W
  • 3. NOTEMIDI Software Installation

    4. Implementation Details

  • 4.1 The NOTEMIDI Kernel Module
  • 4.2 MS-124 Protocol
  • 4.3 Roland & Yamaha Protocol
  • 4.4 MIDI Input
  • 4.5 OSS & ALSA
  • 5. Alternative Software


    1. Introduction

    The options for getting MIDI output from a Linux laptop are still relatively limited as of this writing. Laptop computers do not have PCI slots for connecting sound cards and some internal sound chips (such as the ESS Maestro 2E) do not yet have Linux MIDI driver software. USB MIDI products are available for Windows, but Linux drivers do not yet exist and manufacturers are loathe to release specs so the open source community can develop drivers.

    However, the obsolete RS-232 serial port that is still incorporated into most laptops can be used for MIDI output and input. Although an unmodified PC RS-232 cannot operate at the MIDI speed of 31.2Kbaud, there are two simple hardware options for MIDI with an external sound module via the serial port:

  • If you have a Roland Sound Canvas (SC-88, SC-8850, etc.) or a Yamaha MU series sound module (MU80, MU100, etc.), there is a serial port interface built in to the module that can be connected to the serial port with a 8-pin DIN to 9-pin D-SUB serial cable (described later). Since only the superuser can directly access the serial port, the NOTEMIDI device driver provides direct access to the serial port.
     

  • MIDI input and output ports are available via the MIDIator Systems MS-124W interface which connects to the RS-232 port. Since this box costs around $200 with cables and shipping, this is a rather pricey option, but if you want multiple ports this is the way to go.

  • The NOTEMIDI device driver (kernel module) was conceived with notebook computers in mind, since even the most rudimentary desktop soundcards provide MIDI output in some form. However, the NOTEMIDI device driver can be used with any Linux computer that has an 9-pin RS-232 serial port.

    NOTEMIDI is available here as a source tarball.

    The NOTEMIDI device driver is not OSS or ALSA compatible. It simply provides a device file for raw MIDI input/output (without timing information). The NOTEMIDI tarball includes a command line MIDI player (NOTEPLAY), MIDI recorder (NOTERECORD) and echo utility (NOTEECHO).

    NOTEMIDI was written on and for Red Hat Linux 6.2. I cannot guarantee it's operation under any other kernel version or distribution. I would appreciate notification of any bugs, problems or successes using NOTEMIDI.

    I am deeply indebted to John Stone for pointing me in the right direction in this project. He has written MIDID, another method (with a daemon and message queues) of accessing the MS-124W. Use of this software is described later in this document.


    2. Hardware Setup

    2.1 Roland Sound Canvas or Yamaha XG Sound Module

    If you have a Roland Sound Canvas or Yamaha XG Sound Module you can connect them directly to the RS-232 serial port via a cable that connects a 8-pin MINI DIN (aka Macintosh serial cable) to 9-Pin D-SUB (RS-232). I haven't seen a commercially available cable but I believe you can connect a Macintosh serial cable with a 25-pin RS-232 via a NULL modem connector to a 25-pin to 9-pin convertor. You CAN NOT use a Mac modem cable with gender convertors to RS-232...the pins are wired backwards.

    If you have a soldering iron and a Radio Shack handy, I would just get a Mac serial cable, cut the end off, get a 9-pin female plug from Radio Shack and connect the wires like this.

    DIN pin 1 = D-SUB pin 8 (CTS)
    DIN pin 2 = D-SUB pin 7 (RTS)
    DIN pin 3 = D-SUB pin 2 (RxD)
    DIN pin 4 & 8 = D-SUB pin 5 (GROUND)
    DIN pin 5 = D-SUB pin 3 (TxD)

    The pin numbers for the DIN (Mac) plug should be barely visible in small raised letters under good light.

    Once you've bought or created your cable, connect the sound module to the PC. On a Roland sound module, set the MIDI select switch on the back panel to PC, (not Mac, MIDI, or USB). On a Yamaha sound module, set MIDI input to PC-2 (38,400 baud) NOT PC-1 (Mac). After changing the sound module switch to/from MIDI/PC, you may need to restart the sound module (turn off and turn on again).

    If you're in the market for a sound module (tone generator), I highly recommend the Roland SC-8850, sold in the United States by Edirol. It's a bit expensive ($900) but worth it...although the string sounds aren't great.

    If you visit the Edirol site, you might also e-mail them with a request that they write Linux drivers for their UA-100 USB sound interface. It's a wonderfully clean 20-bit A/D, D/A with built-in effects and MIDI in/out. In an e-mail in July, 2000, a rep indicated that they were not ruling out the creation of Linux drivers but were not planning on writing them anytime soon. Perhaps a little expression of market interest will nudge them in our direction.

    2.2 MIDIator MS-124W

    If you're using something other than a Roland or Yamaha sound module (or some other module that has a serial input port) you can use the MIDIator MS-124W. The MIDIator MS-124W is available from Midiator Systems.

    Note that this is NOT the plain MS-124 (a lower end and cheaper product) or the MS-124T (which is slower, has no MIDI input, and has no addressable MIDI output). The baud rates are different and therefore will not work with the NOTEMIDI driver...although you might be able to hack my code and get it to work.

    This box costs around $200 with cables and shipping. On my Toshiba 2555DVD the module was successfully parasitically powered, so I didn't need the power adapter...you may want to get it just in case. You should also get the connecting cable just to make sure you get a cable with the right pin assignments.

    The MODE switches on the MS-124W should be set to "M" and "B" (multiple burst mode).


    3. NOTEMIDI Software Installation

    Download the source tarball and gunzip/tar it:

    	$ gunzip notemidi-0.2000.09.22.tar.gz
    $ tar -xvf notemidi-0.2000.09-22.tar

    This will create a NOTEMIDI directory. Compile and install:

    	$ make install
    

    If the compilation and installation succeeds, you will have a loaded notemidi.o module. You can verify this with:

    	$ cat /proc/modules
    
    You will have four new devices for sending/receiving MIDI:
    	/dev/notemidi - direct access to the serial port for Roland and Yamaha connections;
    			will not work with the MS-124W
    	
    	/dev/ms124w - output to all four MS-124W ports simultaneously
    	/dev/ms124w0 - output to MS-124W port #1
    	/dev/ms124w1 - output to MS-124W port #2
    	/dev/ms124w2 - output to MS-124W port #3
    	/dev/ms124w3 - output to MS-124W port #4
    

    You should now be able to play MIDI files with NOTEPLAY. A sample MIDI file of Saint Saens Aquarium from Carnival of the Animals has been included for demonstration purposes. If you are using a MS-124W, type:

    	$ noteplay aquarium.mid
    

    If you are using a Roland Sound Canvas or Yamaha sound module, type:

    	$ noteplay -d /dev/notemidi aquarium.mid
    

    You should now have MIDI output!

    notemidi.o will give unresolved symbols message on boot. This doesn't seem to be a problem and I assume it's caused since the serial port device handling isn't loaded when /etc/rc.c/rc.local is executed at boot time.


    4. Implementation Details

    NOTEMIDI is extremely simple. If all you want to do is play simple MIDI files, the instructions given above should be sufficient. However, the following information is provided for those who want or need to know more about this software.

    For those more curious about the serial port, the Serial Port HOWTO is an excellent source for more information.

    There are a number of sites on the web offering other options for MIDI output. However, most of them involve building hardware and that led me to the MS-124W.

    4.1 The NOTEMIDI Kernel Module

    The NOTEMIDI module simply relays MIDI data to the Linux Serial Port device /dev/ttyS0. While this may not be the safest way to deal with the serial port, controlling the serial port is relatively complex and since the code for supporting the serial port is already part of the kernel, I see no reason to reinvent the wheel.

    NOTEMIDI performs the following functions:

  • NOTEMIDI permits any user to send or receive data from the serial port. Serial port device /dev/ttyS0 can only be directly accessed by the superuser.
     
  • NOTEMIDI restricts port access to one user at a time to prevent overlapping and interleaved MIDI bytes from multiple sources.
     
  • NOTEMIDI handles converting raw MIDI data to the simple MS-124W protocol (described below) through the /dev/ms124w device files.
     
  • /dev/notemidi performs no manipulation of serial data and relays it directly to/from the serial port.
     
  • NOTEMIDI is loaded at boot time so MIDI access is available instantly when the user logs in.
  • 4.2 MS-124 Protocol

    MIDIator, unlike many hardware vendors, has been extremely helpful in providing information on their products and programming information for the MS-124W is available both as a flyer that comes with the device and online from Midiator Systems.

    There are three different modes of operation, selected by the two panel switches on the unit. NOTEMIDI uses the simplest (and the one that requires no complex interrupt handling: MULTIPORT BURST MODE. Each MIDI output byte requires sending two bytes: a BURST BYTE specifying which of the four output ports to use, and a data byte. Although this effectively halves the potential transfer rate, to 19K baud, it avoids the complex handshaking techniques needed for the other two modes.

    The BURST BYTE has the format:

    pppp1000

    where each bit of pppp represents one of the four output ports. /dev/ms124w sends 1111100, therefore routing each data byte to all four ports simultaneously. /dev/ms124w1, /dev/ms124w2, /dev/ms124w3, /dev/ms124w4 send burst bytes 10001000, 01001000, 00101000, and 00011000, respectively. Programmers could easily implement this themselves in their own software by accessing the serial port device file /dev/ttyS0 or the "plain" NOTEMIDI port /dev/notemidi directly.

    Since the serial port operates at 38.4 Baud (versus MIDI rate of 31.25) there would be no parallel advantage to operating out of multiple ports to avoid MIDI choke. Therefore, I have not permitted multiple devices to be opened simultaneously. Of course, you could implement this yourself by sending data to /dev/notemidi and handling sending the burst byte yourself.

    4.3 Roland & Yamaha Protocol

    There is no protocol conversion for the Roland & Yamaha serial interfaces. MIDI data (without delta time information, of course) is simply sent directly to the serial port. NOTEMIDI provides /dev/notemidi for direct access, since a program would have to be run as superuser to directly access the Linux serial port device /dev/ttyS0.

    For modules with multiple parts, such as the SC-8850, Roland implements the undefined MIDI code F5 as a two-byte MIDI command for part selection. F5 should be sent, followed by a byte that selects the part: F500 for no selection, F501 for part 1, F502 for part 2, etc. All subsequent MIDI data will be played by the selected part.

    4.4 MIDI Input

    The MS-124W provides one MIDI input port and the Roland and Yamaha modules provide routing of MIDI data from their MIDI IN ports when set to receive data from their serial interfaces (consult the user's manual for your hardware). This data is available by reading any of the NOTEMIDI ports. However, no timing information is provided, so a simple cat /dev/notemidi >> file.mid will not create a usable MIDI file.

    It would be possible to read MIDI input directly from /dev/ttyS0. However, again, you have to be superuser to access this device file.

    NOTERECORD is a simple utility for recording from MIDI input to a MIDI file. It builds delta time information based on a tempo of 120 beats per second. If you want more control over MIDI input and timing, you'll have to implement it yourself.

    NOTERECORD echos MIDI input back to the device so you can hear it. NOTEECHO is a simple utility that simply echos the data but doesn't record it to a file.

    I believe the Serial driver has a 64 byte FIFO circular cache. Therefore, any MIDI data received while a port is not actively being read that exceeds this cache will be discarded by the Linux serial driver.

    I have only made rudimentary testing of MIDI input. I have had no problems with the MS-124W input, but input sporadically locked when inputting via my Roland SC-8850 module. Since I primarily sequence from notation, MIDI input is not significant to me and I would welcome any suggestions about how to improve MIDI input.

    4.5 OSS & ALSA

    I considered trying to make these modules ALSA compliant, but I didn't want to deal with all the added complexity and bureaucracy for something as simple as this. Also, serial port interfaces are definitely a thing of the past and not the future, so I didn't see any reason to waste my time on providing support for something that may not be around much longer.

    I also tried to build an interface for the Opcode MIDI Translator, but the spec I got from a hacker was for a different model and I had no success since the parallel port protocol is apparently rather complicated. Also, I believe that the company is phasing out this product and, regardless, the wave of the future is USB, not parallel port.


    5. Alternative Software

    John Stone has written MIDID, another method (with a daemon and message queues) of accessing the MS-124W. It seems a bit complex for my tastes, but if you're not having any success with NOTEMIDI, or you're trying to get MIDI out of another UNIX platform, you may want to investigate this further.

    He has provided instructions for installation. I have not tried the most recent version, but I am including my experiences with a previous version in case you need further guidance.

    Download the software into your home directory from:

    	http://jedi.ks.uiuc.edu/~johns/projects/midid/
    

    Gunzip and un-tar creates a "midid" directory. Make creates the executables quickly and flawlessly.

    	gunzip midid.tar.gz
    	tar -xfv midid.tar
    	cd midid
    	make
    

    Create a text file with a single line. This maps the Midiator interface to the serial port (i.e. /dev/ttyS0 or COM1). I named it "/home/michael/.midid"

    	"Midiator-MS-124W"   "/dev/ttyS0"
    

    Kick off the midi daemon with the config file you just created.

    	cd daemon
    	./midid /home/michael/.midid
    

    You can then play midi files with midiplay:

    	seq/midiplay [your_file].mid
    

    The version of midiplay I got from an outdated site had problems with tempos and type 0 files (which is what I use exclusively). John has stated that the current version of MIDID has fixed these problems.