Subject: Re: midi stuff
To: Gavan Fantom <gavan@coolfactor.org>
From: Andrew Kilpatrick <andrew@andrewkilpatrick.org>
List: tech-kern
Date: 04/15/2001 17:12:03
Hi Gavin,

On Sun, Apr 15, 2001 at 11:13:10AM +0100, Gavan Fantom wrote:
> On Fri, 13 Apr 2001, Andrew Kilpatrick wrote:
> 
> > I started working on MIDI code the other day, and I found that
> > the MIDI driver doesn't work very well. The state machine doesn't
> > handle all the possible states for MIDI messages, and quickly
> > gets into an endless loop, eventually overrunning its buffer and
> > causing a panic.
> 
> Erk. What is your MIDI application here? Which messages does it choke on?
> 

I'm working MIDI and audio software for NetBSD. The midi input function 
seems to choke when I send a lot of aftertouch commands. 

> Having looked at the code there are a number of serious improvements that
> could be made (see a thread about /dev/music in the archives), but I don't
> remember thinking of anything that it couldn't recover from.
> 
> Are you using the raw MIDI device, or the sequencer?
> 

I'm currently using the raw device.

> > Anyway, I started designing a new state machine that handles the
> > incoming messages properly, but am running into some trouble because
> > the data coming into this module is often wrong. I'm pretty sure my
> > MIDI interface isn't broken. It's currently a cheesy AWE32 with the
> > game port MIDI port, because my USB interface isn't supported. I'm
> > not sure what is at fault.
> 
> Could you post some sample data and say what it's doing wrong?

In midi.c the midi_in() function uses a variable called sc->in_pos
which it uses to keep track of which byte of a message it's on. It's 
writing into a buffer that is only 3 bytes long, but when I use 
aftertouch (which happens almost all the time when I play on my keyboard)
the in_pos never resets, and just keeps counting up and up, eventually 
crashing the system.

I thought I may have found the problem, but was being confused because
I didn't fully understand some of the things that my keyboard was 
sending. I was mistaking some of the messages for errors, when in fact
they were valid MIDI data.

I'm going to work on this some more and see if it can work. People don't
seem to use may comments in kernel code which makes it pretty overwhelming
for a newcomer.

Andrew