Why not real midi data?

Asked by Tobias Wahlström


I really like the idea behind ttymidi and need it for my project - very nice work!

I'm about to make a box (powered by an arduino) with a set of knobs used to send midi data to pure data. Since I don't got a midi -> usb converter I also want to forward midi data from my digital piano to the pc using the arduino. I have already written the code for the arduino to handle all this and inject my own midi things into the midi data from the piano (with nice handling on running status messages from the piano).

When I just was about to use ttymidi to make alsa aware of the midi data i read that ttymidi not support real midi data. When using midi data from a real midi device it feels silly to convert those into these "almost real" midi messages.

What is the reason for not using the real midi protocol?
Is there some other similar software to handle real midi data?

If I don't find anything that works out of the box I guess I will make a patch for ttymidi to handle real midi data...


Question information

English Edit question
ttyMIDI Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thiago Teixeira (tvst) said :

Maybe I should clarify this "almost real" MIDI thing I wrote about on the ttyMIDI website... Most of the confusion here comes from the fact that there are 2 connections involved in ttyMIDI:

[your custom hardware] --> [ttyMIDI] --> [ALSA apps]

Connection 1: From your custom hardware to the computer running ttyMIDI (using USB or other serial port).
Connection 2: From ttyMIDI to ALSA applications.

First things first. The 2nd connection IS REAL MIDI. This connection is generally the one that really matters.

The 1st connection is "almost real" MIDI, but this is generally not a problem: The reason why most people use ttyMIDI is to control ALSA applications using some custom hardware that they built themselves. Since you build the hardware yourself, you can make it speak to ttyMIDI through any protocol -- it doesn't matter -- so long as Connection 2 is still real MIDI.

Now, instead of reinventing the wheel and inventing my own protocol for Connection 1, I decided to use MIDI for that connection too. The problem is that I wanted to keep ttyMIDI as simple as possible, so I changed exactly one thing from the MIDI spec: I made EVERY command be composed of 3 bytes, which simplifies the decoding process. (For all I could make out, some commands in the MIDI spec can be composed of 2 bytes. In ttyMIDI, I force these to have a 3rd byte that is just set to 0).

I also ended up adding an extra non-MIDI command to the ttyMIDI protocol which allows you to send text messages to print in your computer terminal, mainly for your own debugging.

But none of this should REALLY matter most of the time, because you have absolute control of the hardware you are building. So long as you follow my spec, everything will work as it should. That is:
1) your hardware talks to ttyMIDI using "almost MIDI"
2) ttyMIDI talks to ALSA apps using MIDI


Now, the only time (that I can think of) where it is important for Connection 1 to use real MIDI is when you want create some custom hardware that will work as a bridge between existing MIDI devices and ALSA apps, like this:

[existing MIDI device] --> [your custom hardware] --> [ttyMIDI] --> [ALSA apps]

In this case, if ttyMIDI spoke actual MIDI (in Connection 1) then your custom hardware could just forward the MIDI messages directly to ttyMIDI. But since it doesn't, all you have to do is translate a few MIDI messages to ttyMIDI.

But this is a bit of a roundabout way of doing USB-MIDI conversion. In my view, you should skip ttyMIDI altogether and just use a commercial off-the-shelf USB-MIDI converter. Or, if you really want to build your own, you are better off using the USB-MIDI driver which is already in the Linux kernel. I believe that driver is called snd-usb-audio. The USB-MIDI specification can be found here: http://www.usb.org/developers/devclass_docs/midi10.pdf . You'll see it's not very simple... which is why ttyMIDI was written in the first place :)

Revision history for this message
Tobias Wahlström (tobias-tanke) said :

Thanks for the explanation of why you choose this solution.

The reason I want real midi in "connection 1" (as you call it) is the following is that this would fit my problem.

My problem is that I want to make a custom hardware *but* it will also connect to "real" midi hardware (since I don't have a midi <-> usb converter and don't want to spend the money if I can make one without spending any money).

You suggested that I could convert this real midi data into "almost midi data" - well that should work!

But to me it feels more natural (and simple) to use the real protocol all the way. I actually got it working yesterday! I also had problems receiving midi data from the serial port on my laptop (its an acer aspire one). I got the application cutecom to communicate properly with my arduino board - so I used the code for setting up the serial device from cutecom and got it all working.

I guess there is no license issue (as long as I provide my code to the public). You use GPL and cutecom GPLv2.

Would you like this within your project or should I publish it somewhere else? As an alternative command, or prehaps by adding pluggable prototocols for "connection 1"? What do you think?

Revision history for this message
Thiago Teixeira (tvst) said :

That's an interesting idea, about adding pluggable protocols. So what you're saying is that you implemented true MIDI for connection 1? Or did you make your own protocol?

Either way, why don't you email me the code and I'll think of the best way of incorporating it.

Revision history for this message
Thiago Teixeira (tvst) said :

Also, did you check this out? http://itp.nyu.edu/physcomp/Labs/MIDIOutput
It seems similar to what you've been trying to do...

Revision history for this message
Jari Suominen (jari-tasankokaiku) said :

Hi, I just wrote to say that nowadays the current version of ttymidi indeed is using real MIDI data. System exclusive messages are not currently forwarded to ALSA MIDI, but all other messages type are. You also can use running status if you will. So you can send normal MIDI to ttyMIDI through the serial port of your serial device and everything should work fine.

Can you help with this problem?

Provide an answer of your own, or ask Tobias Wahlström for more information if necessary.

To post a message you must log in.