From alsa-devel-owner@alsa.jcu.cz  Thu Jul 30 10:23:44 1998
Received: from entry.jcu.cz (perex@entry.jcu.cz [160.217.1.111])
	by marvin.jcu.cz (8.8.8/8.8.8) with SMTP id KAA18743;
	Thu, 30 Jul 1998 10:22:30 +0200
Date: Thu, 30 Jul 1998 10:22:30 +0200 (MET DST)
From: Jaroslav Kysela <perex@jcu.cz>
To: Frank van de Pol <F.K.W.van.de.Pol@inter.nl.net>
cc: alsa-devel@alsa.jcu.cz
Subject: Re: kernel MIDI interface
In-Reply-To: <199807291914.VAA13281@obelix.fvdpol.inter.nl.net>
Message-ID: <Pine.LNX.3.96.980730101945.5215B-100000@entry.jcu.cz>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

On Wed, 29 Jul 1998, Frank van de Pol wrote:

> I wrote:
> > 
> > I've been experimenting with the MIDI interface for kernel modules from the
> > alsa-driver-0.2.0-pre2 driver. 
> > 
> > Playback works great. I get nice tight timing with the ALSA sequencer. Recording
> > works ok for MIDI note on/off and program changes.
> > 
> > With control changes and pitchbend messages I receive an odd sequence.
> > Instead of the expected 3 byte message I get 2 messages of 2 bytes. Instead
> > of eg. a "bf,6c,xx" message I get a "bf,6c" and a "bf,xx" message. 
> 
> Some additional info:
> 
> The synth I used for generating the MIDI data is a Novation BassStation
> (analogue monophonic synth). I've snapped a part of the MIDI stream produced
> by my synth into a file, and made a 'od -t x1 ' dump of it. As can be seen I
> played 2 notes, played with a controller, and ended with playing 2 notes.
> 
> 0000000 9f 1f 7b 9f 1f 00 9f 1f 72 9f 1f 00 bf 6c 51 6c
> 0000020 4f 6c 4c 6c 49 6c 47 6c 44 6c 42 6c 3f 6c 3c 6c
> 0000040 39 6c 36 6c 32 6c 2f 6c 2c 6c 27 6c 23 6c 20 6c
> 0000060 1c 6c 19 6c 16 6c 14 6c 17 6c 1d 6c 23 6c 29 6c
> 0000100 2e 6c 32 6c 36 6c 3b 6c 3f 6c 40 9f 1d 7f 9f 1d
> 0000120 00
> 0000121
> 
> Weird thing is that no running state is used for the note events, but the
> controller data is using running state. Should not matter, it still complies
> to the MIDI spec. I think this running state confuses the ALSA MIDI input
> routines. Here's the (dmesg) output from the test program included with the
> 'pre2' driver for a similar action:
> 
> 
> snd: rx command 'GF1': 9f:1d:72:	(note on)
> snd: rx command 'GF1': 9f:1d:00:	(note off)
> snd: rx command 'GF1': 9f:1d:72:
> snd: rx command 'GF1': 9f:1d:00:
> snd: rx command 'GF1': bf:6c:18:	(1st controller event, went ok)
> snd: rx command 'GF1': bf:6c:		(ALSA confused by running status???)
> snd: rx command 'GF1': bf:19:		( part 2 of the confused message)

OK. Here is fix for this bug:

--- ../../alsa-driver1/kernel/midi.c	Thu Jul  9 23:00:04 1998
+++ midi.c	Thu Jul 30 10:18:49 1998
@@ -117,7 +117,7 @@
   if ( rmidi -> input.u.p.cused == 1 ) { 	/* init byte? */
     if ( b & 0x80 ) {				/* MIDI status byte */
       if ( ( b & 0xf0 ) == 0xf0 ) {		/* common message */
-        tmp = len_tab_c[ b >> 4 ];
+        tmp = len_tab_c[ b & 0x0f ];
         switch ( tmp ) {
           case 254:				/* wait for next data */
             snd_spin_unlock( rmidi, input, &flags );
@@ -158,8 +158,8 @@
           rmidi -> input.u.p.command( rmidi, rmidi -> input.u.p.cmd_private_data, rmidi -> input.u.p.cbuffer, rmidi -> input.u.p.cused );
         rmidi -> input.u.p.cused = rmidi -> input.u.p.cleft = 0;
         snd_spin_unlock( rmidi, input, &flags );
-        return 0;
       }
+      return 0;
     }
   }
   /* ok.. look if we wait for next data */


					Jaroslav

-----
Jaroslav Kysela <perex@jcu.cz>
Academic Computer Centre, University of South Bohemia
Branisovska 31, C. Budejovice, CZ-370 05 Czech Republic


