From alsa-devel-owner@alsa.jcu.cz  Sat Feb 20 11:26:57 1999
Received: from smaux.kusm.kyoto-u.ac.jp (smaux.kusm.kyoto-u.ac.jp [130.54.53.12])
	by marvin.jcu.cz (8.9.1a/8.9.1) with SMTP id LAA01511
	for <alsa-devel@jcu.cz>; Sat, 20 Feb 1999 11:26:51 +0100
Received: (qmail 17000 invoked from network); 20 Feb 1999 19:26:49 +0900
Received: from smdoc2.kusm.kyoto-u.ac.jp (130.54.53.38)
  by smaux.kusm.kyoto-u.ac.jp with SMTP; 20 Feb 1999 19:26:49 +0900
Received: (qmail 11221 invoked by uid 2161); 20 Feb 1999 10:26:46 -0000
Message-ID: <19990220192645.A11204@smdoc2.kusm.kyoto-u.ac.jp>
Date: Sat, 20 Feb 1999 19:26:45 +0900
From: Yamahata Isaku <yamahata@kusm.kyoto-u.ac.jp>
To: alsa-devel@jcu.cz
Subject: sending active sencing when closing sequencer port
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=FCuugMFkClbJLl1L
Content-Transfer-Encoding: 7bit
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list


--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello.
On the behavier of ALSA sequencer client of raw midi device when unused.
(static int midisynth_unuse(void *private_data) @ kernel/seq/seq_midi.c).

Suppose that we created an ALSA sequencer client and are sending midi event
to a sequencer client of a raw midi device.
When our sequencer client exits, eventually ALSA driver call midisynth_unuse
for destination client and the destinaiton client will close the associated
raw midi device.
But if the sequencer client exited abnomally, a midi device which is
connected to the midi port of the raw midi device would countinue to
pronouce forever.

This problem can be solved by sending active sencing midi event (0xFE)
before closing raw midi device. Patch is attached.

But there is a question.
Is it an appropreate behavior?

---
Isaku Yamahata
yamahata@kusm.kyoto-u.ac.jp
CQG00274@nifty.ne.jp
http://www.kusm.kyoto-u.ac.jp/%7Eyamahata/
  
--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="seq_midi.diff"

Index: seq_midi.c
===================================================================
RCS file: /home/alsa/cvsroot/alsa-driver/kernel/seq/seq_midi.c,v
retrieving revision 1.4
diff -u -r1.4 seq_midi.c
--- seq_midi.c	1999/02/12 10:56:28	1.4
+++ seq_midi.c	1999/02/20 10:15:51
@@ -627,9 +627,12 @@
 {
 	int err;
 	seq_midisynth_t *msynth = (seq_midisynth_t *)private_data;
+	unsigned char buf = 0xfe;/*active sensing midi event*/
 
 	if (!msynth->output_rmidi)
 		return -EINVAL;
+	/*sending single active sensing message to shut the device up*/
+	snd_midi_transmit (uart_client->rmidi, &buf, 1);
 	snd_midi_flush_output(msynth->output_rmidi);
 	msynth->output_rmidi = NULL;
 	err = snd_midi_close(msynth->card->number, msynth->device, SND_RAWMIDI_LFLG_OUTPUT);

--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="uart16550_seq.diff"

Index: uart16550_seq.c
===================================================================
RCS file: /home/alsa/cvsroot/alsa-driver/lowlevel/generic/uart16550_seq.c,v
retrieving revision 1.3
diff -u -r1.3 uart16550_seq.c
--- uart16550_seq.c	1999/02/16 20:24:08	1.3
+++ uart16550_seq.c	1999/02/20 10:16:51
@@ -116,6 +116,7 @@
 
 	uart16550_port->client = uart16550_client;
 	uart16550_port->port = uart_port;
+	uart16550_port->running_status = 0;
 
 	return uart16550_port;
 }
@@ -478,6 +479,10 @@
 		buffer[1] = uart_port + 1;
 		dump_midi(uart_client->rmidi, buffer, 2);
 		uart_client->current_port = uart_port;
+
+		//reset running status
+		uart_client->port_a->running_status = 0;
+		uart_client->port_b->running_status = 0;
 	}
 }
 
@@ -774,11 +779,17 @@
 		if ((uart_client->port_status & UART16550_PORT_A_OPENED) == 0)
 			return -EINVAL;
 		uart_client->port_status &= ~UART16550_PORT_A_OPENED;
+		if (uart_client->port_a != NULL) {
+		        uart_client->port_a->running_status = 0;
+		}
 		break;
 	case UART16550_PORT_B:
 		if ((uart_client->port_status & UART16550_PORT_B_OPENED) == 0)
 			return -EINVAL;
 		uart_client->port_status &= ~UART16550_PORT_B_OPENED;
+		if (uart_client->port_b != NULL) {
+		        uart_client->port_b->running_status = 0;
+		}
 		break;
 	default:
 		return -ENODEV;
@@ -786,9 +797,18 @@
 	}
 
 	if (uart_client->port_status == UART16550_PORT_NOT_OPENED) {
-		int err = snd_midi_close(uart_client->card->number,
-					 uart_client->device,
-					 SND_RAWMIDI_LFLG_OUTPUT);
+	        unsigned char buf = 0xfe;
+		//sending single active sensing message to shut up
+		int err = snd_midi_transmit (uart_client->rmidi, &buf, 1);
+		if (err != 1)
+		        snd_printd ("snd_seq_uart16550_do_unuse sending active sensing is failed.\n");
+	        uart_client->current_port = UART16550_PORT_UNKNOWN;
+		err = snd_midi_flush_output(uart_client->rmidi);
+		if (err != 0)
+		        snd_printd ("snd_seq_uart16550_do_unuse flushing raw midi device failed.\n");
+		err = snd_midi_close(uart_client->card->number,
+				     uart_client->device,
+				     SND_RAWMIDI_LFLG_OUTPUT);
 		snd_printd("snd_seq_uart16550_do_unuse really closed\n");
 		MOD_DEC_USE_COUNT;
 		return err;	//if err < 0, there is nothing to be done.

--FCuugMFkClbJLl1L--

