MIDI on linux should always be this easy!


#include <stdio.h>
typedef unsigned char u8;

u8 state = 0;
u8 vel = 0;
u8 note = 0;

void read_midi(u8 c)
    if( c & 0x80 )
        state = c >> 4;
    switch( state )
        case 0x8:
        case 0x9:
            note = c;
            state = 0x91;
        case 0x91:
            vel = c;
            state = 0;
            printf("%x %x\n",note,vel);
        case 0xA:
        case 0xB:
        case 0xC:
        case 0xD:

int main(int args, char **argv)
    FILE *midi_in;
    u8 c;
    midi_in = fopen("/dev/midi", "r");
    while( 1 != 2 )
        c = fgetc(midi_in);

    return 0;

That’s how easy it should be to write a MIDI inspection program. And it is, if you’re running linux with the OSS drivers installed. I can’t speak for my other installations that run the 2.6.x kernel, but this Alix box running voyager doesn’t seem to have any trouble exporting a /dev/midi character device to the filesystem, enabling programmers easy access at the data generated by my Keystation, which is hooked up via USB.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: