Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ALSA: seq: Improve UMP SysEx packing
Date: Wed, 26 Jun 2024 18:52:27 +0200	[thread overview]
Message-ID: <8734ozir3o.wl-tiwai@suse.de> (raw)
In-Reply-To: <20240626161017.9479-1-tiwai@suse.de>

On Wed, 26 Jun 2024 18:10:15 +0200,
Takashi Iwai wrote:
> 
> The initial implementation of 7bit SysEx message conversion to UMP did
> a trick to deal with the first SysEx start byte (0xf7).  The converter
> trims it and sends the first packet with the content of 5 bytes.
> Although this is valid and should work, it's not ideal and a bit
> confusing as if something goes wrong.
> 
> This patch improves the handling to try filling always 6 bytes in the
> package.
> 
> Fixes: e9e02819a98a ("ALSA: seq: Automatic conversion of UMP events")
> Signed-off-by: Takashi Iwai <tiwai@suse.de>

Scratch this one.  It won't work properly when the sysex message is
split.  Will rework on it.


Takashi

> ---
>  sound/core/seq/seq_ump_convert.c | 48 +++++++++++++++++++-------------
>  1 file changed, 28 insertions(+), 20 deletions(-)
> 
> diff --git a/sound/core/seq/seq_ump_convert.c b/sound/core/seq/seq_ump_convert.c
> index e90b27a135e6..952e64c499dd 100644
> --- a/sound/core/seq/seq_ump_convert.c
> +++ b/sound/core/seq/seq_ump_convert.c
> @@ -1192,7 +1192,7 @@ static int cvt_sysex_to_ump(struct snd_seq_client *dest,
>  {
>  	struct snd_seq_ump_event ev_cvt;
>  	unsigned char status;
> -	u8 buf[6], *xbuf;
> +	u8 buf[6];
>  	int offset = 0;
>  	int len, err;
>  
> @@ -1200,36 +1200,44 @@ static int cvt_sysex_to_ump(struct snd_seq_client *dest,
>  		return 0;
>  
>  	setup_ump_event(&ev_cvt, event);
> +	len = 0;
> +	status = UMP_SYSEX_STATUS_START;
>  	for (;;) {
> -		len = snd_seq_expand_var_event_at(event, sizeof(buf), buf, offset);
> -		if (len <= 0)
> +		err = snd_seq_expand_var_event_at(event, sizeof(buf) - len,
> +						  buf + len, offset);
> +		if (err < 0)
> +			break;
> +		len += err;
> +		if (!len)
>  			break;
>  		if (WARN_ON(len > 6))
>  			break;
> -		offset += len;
> -		xbuf = buf;
> -		if (*xbuf == UMP_MIDI1_MSG_SYSEX_START) {
> -			status = UMP_SYSEX_STATUS_START;
> -			xbuf++;
> +		offset += err;
> +		if (status == UMP_SYSEX_STATUS_START &&
> +		    buf[0] == UMP_MIDI1_MSG_SYSEX_START) {
>  			len--;
> -			if (len > 0 && xbuf[len - 1] == UMP_MIDI1_MSG_SYSEX_END) {
> -				status = UMP_SYSEX_STATUS_SINGLE;
> -				len--;
> -			}
> -		} else {
> -			if (xbuf[len - 1] == UMP_MIDI1_MSG_SYSEX_END) {
> -				status = UMP_SYSEX_STATUS_END;
> -				len--;
> -			} else {
> -				status = UMP_SYSEX_STATUS_CONTINUE;
> -			}
> +			memmove(buf, buf + 1, len);
> +			continue; /* fill one more byte */
>  		}
> -		fill_sysex7_ump(dest_port, ev_cvt.ump, status, xbuf, len);
> +		if (buf[len - 1] == UMP_MIDI1_MSG_SYSEX_END) {
> +			len--;
> +			if (status == UMP_SYSEX_STATUS_START)
> +				status = UMP_SYSEX_STATUS_SINGLE;
> +			else
> +				status = UMP_SYSEX_STATUS_END;
> +		}
> +		fill_sysex7_ump(dest_port, ev_cvt.ump, status, buf, len);
>  		err = __snd_seq_deliver_single_event(dest, dest_port,
>  						     (struct snd_seq_event *)&ev_cvt,
>  						     atomic, hop);
>  		if (err < 0)
>  			return err;
> +
> +		if (status == UMP_SYSEX_STATUS_START)
> +			status = UMP_SYSEX_STATUS_CONTINUE;
> +		else if (status != UMP_SYSEX_STATUS_CONTINUE)
> +			break;
> +		len = 0; /* reset filling */
>  	}
>  	return 0;
>  }
> -- 
> 2.43.0
> 

      reply	other threads:[~2024-06-26 16:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-26 16:10 [PATCH] ALSA: seq: Improve UMP SysEx packing Takashi Iwai
2024-06-26 16:52 ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8734ozir3o.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=linux-sound@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox