From patchwork Sat May 20 07:00:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 681D5C77B7F for ; Sat, 20 May 2023 07:03:31 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 952813E7; Sat, 20 May 2023 09:02:39 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 952813E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566209; bh=yvQbYHMdYYD58E7u6Rw+COilYfr6yB5XntHX5xoAz+E=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=tdOWJ7CeS+ZKa83AKMejxeC6PtGWcpQF3V4SCbWhNYE/vm6IpoDWlYAFzQ6UWZH8y zOFjVPrEys+vRwaRA++7p260Usu9+1u8ZUmKIJirH+XSgzIriqocJGcNPj0O4Igwet 5iWt5zccfv2TeBQVNAQj58IjK5dWkL+/ian4W+Us= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 87044F80552; Sat, 20 May 2023 09:02:38 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 13779F80272; Sat, 20 May 2023 09:02:38 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 798E2F80551; Sat, 20 May 2023 09:00:36 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 24C9AF80087 for ; Sat, 20 May 2023 09:00:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 24C9AF80087 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ODfRP6Nq; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=GAHtawJY Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 85CB122039; Sat, 20 May 2023 07:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lv8lzvPi2AwYV+W+LyidROa3ulPVQZs2GlpTau91ivU=; b=ODfRP6NqB13bO7i+g8T6PdN2nymQyVgsnKgNihFYg5CqeQtulIJWTUZ1JYFOjmEe519Te5 Y3qXrToxXwIts7tv2LopMdyaR9wk/TgXJafechvk/YTuUnUIseeC2AWDsrBkmPRChWt+pG OEUHhtrjQyDr2IiRD1yCbQNekBTD+3U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lv8lzvPi2AwYV+W+LyidROa3ulPVQZs2GlpTau91ivU=; b=GAHtawJY2kcUAwKHgCKwgvW21Y7ZeJxlXg84LMIHGTWE5G3cVIDfhS/4qP3NF/dQgBtT+O 073OpJoLrJDskSDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6BD97139F5; Sat, 20 May 2023 07:00:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cMiFGQlwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:25 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 1/8] uapi: Update rawmidi API to 2.0.3 Date: Sat, 20 May 2023 09:00:14 +0200 Message-Id: <20230520070021.1301-2-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: DBXD57IBXU76TT7PE264ZYN5YQMM7OQR X-Message-ID-Hash: DBXD57IBXU76TT7PE264ZYN5YQMM7OQR X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Copied from the kernel uapi header for rawmidi API. A few new structs and constants for UMP are defined in addition to a few new ioctls. Signed-off-by: Takashi Iwai --- include/sound/uapi/asound.h | 58 ++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/include/sound/uapi/asound.h b/include/sound/uapi/asound.h index 62a0364fc3cd..a09089814c7b 100644 --- a/include/sound/uapi/asound.h +++ b/include/sound/uapi/asound.h @@ -706,7 +706,7 @@ enum { * Raw MIDI section - /dev/snd/midi?? */ -#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 2) +#define SNDRV_RAWMIDI_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 3) enum { SNDRV_RAWMIDI_STREAM_OUTPUT = 0, @@ -717,6 +717,7 @@ enum { #define SNDRV_RAWMIDI_INFO_OUTPUT 0x00000001 #define SNDRV_RAWMIDI_INFO_INPUT 0x00000002 #define SNDRV_RAWMIDI_INFO_DUPLEX 0x00000004 +#define SNDRV_RAWMIDI_INFO_UMP 0x00000008 struct snd_rawmidi_info { unsigned int device; /* RO/WR (control): device number */ @@ -775,6 +776,57 @@ struct snd_rawmidi_status { unsigned char reserved[16]; /* reserved for future use */ }; +/* UMP EP Protocol / JRTS capability bits */ +#define SNDRV_UMP_EP_INFO_PROTO_MIDI_MASK 0x0300 +#define SNDRV_UMP_EP_INFO_PROTO_MIDI1 0x0100 /* MIDI 1.0 */ +#define SNDRV_UMP_EP_INFO_PROTO_MIDI2 0x0200 /* MIDI 2.0 */ +#define SNDRV_UMP_EP_INFO_PROTO_JRTS_MASK 0x0003 +#define SNDRV_UMP_EP_INFO_PROTO_JRTS_TX 0x0001 /* JRTS Transmit */ +#define SNDRV_UMP_EP_INFO_PROTO_JRTS_RX 0x0002 /* JRTS Receive */ + +/* UMP Endpoint information */ +struct snd_ump_endpoint_info { + int card; /* card number */ + int device; /* device number */ + unsigned int flags; /* additional info */ + unsigned int protocol_caps; /* protocol capabilities */ + unsigned int protocol; /* current protocol */ + unsigned int num_blocks; /* # of function blocks */ + unsigned short version; /* UMP major/minor version */ + unsigned short padding[7]; + unsigned char name[128]; /* endpoint name string */ + unsigned char product_id[128]; /* unique product id string */ + unsigned char reserved[32]; +} __packed; + +/* UMP direction */ +#define SNDRV_UMP_DIR_INPUT 0x01 +#define SNDRV_UMP_DIR_OUTPUT 0x02 +#define SNDRV_UMP_DIR_BIDIRECTION 0x03 + +/* UMP block info flags */ +#define SNDRV_UMP_BLOCK_IS_MIDI1 (1U << 0) /* MIDI 1.0 port w/o restrict */ +#define SNDRV_UMP_BLOCK_IS_LOWSPEED (1U << 1) /* 31.25Kbps B/W MIDI1 port */ + +/* UMP groups and blocks */ +#define SNDRV_UMP_MAX_GROUPS 16 +#define SNDRV_UMP_MAX_BLOCKS 32 + +/* UMP Block information */ +struct snd_ump_block_info { + int card; /* card number */ + int device; /* device number */ + unsigned char block_id; /* block ID (R/W) */ + unsigned char direction; /* UMP direction */ + unsigned char active; /* Activeness */ + unsigned char first_group; /* first group ID */ + unsigned char num_groups; /* number of groups */ + unsigned char padding[3]; + unsigned int flags; /* various info flags */ + unsigned char name[128]; /* block name string */ + unsigned char reserved[32]; +} __packed; + #define SNDRV_RAWMIDI_IOCTL_PVERSION _IOR('W', 0x00, int) #define SNDRV_RAWMIDI_IOCTL_INFO _IOR('W', 0x01, struct snd_rawmidi_info) #define SNDRV_RAWMIDI_IOCTL_USER_PVERSION _IOW('W', 0x02, int) @@ -782,6 +834,9 @@ struct snd_rawmidi_status { #define SNDRV_RAWMIDI_IOCTL_STATUS _IOWR('W', 0x20, struct snd_rawmidi_status) #define SNDRV_RAWMIDI_IOCTL_DROP _IOW('W', 0x30, int) #define SNDRV_RAWMIDI_IOCTL_DRAIN _IOW('W', 0x31, int) +/* Additional ioctls for UMP rawmidi devices */ +#define SNDRV_UMP_IOCTL_ENDPOINT_INFO _IOR('W', 0x40, struct snd_ump_endpoint_info) +#define SNDRV_UMP_IOCTL_BLOCK_INFO _IOR('W', 0x41, struct snd_ump_block_info) /* * Timer section - /dev/snd/timer @@ -1114,6 +1169,7 @@ struct snd_ctl_tlv { #define SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE _IOWR('U', 0x40, int) #define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info) #define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int) +#define SNDRV_CTL_IOCTL_UMP_NEXT_DEVICE _IOWR('U', 0x43, int) #define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int) #define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int) From patchwork Sat May 20 07:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9F0CC77B7F for ; Sat, 20 May 2023 07:04:31 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id BEDEC741; Sat, 20 May 2023 09:03:39 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz BEDEC741 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566269; bh=7g5lgg8K6ULr4rCfFJMUM9g1W70gZv1L9Jtq0z+f3xA=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=k9dMiiaxvTyTzD81fMFhamGRzcQ2ni7IsLMnCOln/mceAJyiNciabaxCVi2WSKabg Bp1+E8girlqZSZBshnWlVlpy7MNbIprpUFfXyNItivoPrX6gH+P3gKuzo6hzadUKwH MMED9FtiT6+WmW7rXHLeb7kLYg8ULQTeB7FG030E= Received: by alsa1.perex.cz (Postfix, from userid 50401) id A406AF80544; Sat, 20 May 2023 09:02:39 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 6154BF802E8; Sat, 20 May 2023 09:02:38 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B9112F80549; Sat, 20 May 2023 09:00:40 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3E5AEF8025A for ; Sat, 20 May 2023 09:00:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3E5AEF8025A Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vUIpOhkx; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=XGeiQVvq Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AEA511FD6C; Sat, 20 May 2023 07:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1GqwfBOie39jVzprd95QeelYmlNjzR/oK6v665L/0rc=; b=vUIpOhkxGWV6O7mdocsZJRzaYywGwPSMjwpAb+B50Hjv6nnealdEVOeVXgG8SePJmH55uE wzzC73dESrsCcxdfBeetiIlFokSZMC51RzZtoXP45wTUTrkla+Ywk/pRIbV0TIMu1gZp3s 4RSKrHPrYlGwQibsQTTxN0MEZ9jHl0Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1GqwfBOie39jVzprd95QeelYmlNjzR/oK6v665L/0rc=; b=XGeiQVvqg+lo4Cvkwd68SMuCSviTo+WyK0b7n09d3PVdf+qdOfbCBbXpBanquMZAHGQSRC FtxHXOZ5h+FjLiDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8A09E134F5; Sat, 20 May 2023 07:00:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CPLGIAlwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:25 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 2/8] rawmidi: Add UMP ioctl support Date: Sat, 20 May 2023 09:00:15 +0200 Message-Id: <20230520070021.1301-3-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: UXCKXHWFUM4IY5LEZRA47NWV33RO6IGC X-Message-ID-Hash: UXCKXHWFUM4IY5LEZRA47NWV33RO6IGC X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Just implement internal callbacks for two new ioctls for UMP (ump_endpoint_info and ump_block_info). No public API functions are added yet here. Signed-off-by: Takashi Iwai --- src/rawmidi/rawmidi.c | 19 +++++++++++++++++++ src/rawmidi/rawmidi_hw.c | 26 +++++++++++++++++++++++++- src/rawmidi/rawmidi_local.h | 5 +++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c index 570e06755456..8dca9312c6d9 100644 --- a/src/rawmidi/rawmidi.c +++ b/src/rawmidi/rawmidi.c @@ -1120,3 +1120,22 @@ ssize_t snd_rawmidi_tread(snd_rawmidi_t *rawmidi, struct timespec *tstamp, void return -ENOTSUP; return (rawmidi->ops->tread)(rawmidi, tstamp, buffer, size); } + +#ifndef DOXYGEN +/* + * internal API functions for obtaining UMP info from rawmidi instance + */ +int _snd_rawmidi_ump_endpoint_info(snd_rawmidi_t *rmidi, void *info) +{ + if (!rmidi->ops->ump_endpoint_info) + return -ENXIO; + return rmidi->ops->ump_endpoint_info(rmidi, info); +} + +int _snd_rawmidi_ump_block_info(snd_rawmidi_t *rmidi, void *info) +{ + if (!rmidi->ops->ump_block_info) + return -ENXIO; + return rmidi->ops->ump_block_info(rmidi, info); +} +#endif /* DOXYGEN */ diff --git a/src/rawmidi/rawmidi_hw.c b/src/rawmidi/rawmidi_hw.c index e5bb3ee3b31c..69e5e02f1d6a 100644 --- a/src/rawmidi/rawmidi_hw.c +++ b/src/rawmidi/rawmidi_hw.c @@ -272,6 +272,28 @@ static ssize_t snd_rawmidi_hw_tread(snd_rawmidi_t *rmidi, struct timespec *tstam return ret + result; } +static int snd_rawmidi_hw_ump_endpoint_info(snd_rawmidi_t *rmidi, void *buf) +{ + snd_rawmidi_hw_t *hw = rmidi->private_data; + + if (rmidi->version < SNDRV_PROTOCOL_VERSION(2, 0, 3)) + return -ENXIO; + if (ioctl(hw->fd, SNDRV_UMP_IOCTL_ENDPOINT_INFO, buf) < 0) + return -errno; + return 0; +} + +static int snd_rawmidi_hw_ump_block_info(snd_rawmidi_t *rmidi, void *buf) +{ + snd_rawmidi_hw_t *hw = rmidi->private_data; + + if (rmidi->version < SNDRV_PROTOCOL_VERSION(2, 0, 3)) + return -ENXIO; + if (ioctl(hw->fd, SNDRV_UMP_IOCTL_BLOCK_INFO, buf) < 0) + return -errno; + return 0; +} + static const snd_rawmidi_ops_t snd_rawmidi_hw_ops = { .close = snd_rawmidi_hw_close, .nonblock = snd_rawmidi_hw_nonblock, @@ -282,7 +304,9 @@ static const snd_rawmidi_ops_t snd_rawmidi_hw_ops = { .drain = snd_rawmidi_hw_drain, .write = snd_rawmidi_hw_write, .read = snd_rawmidi_hw_read, - .tread = snd_rawmidi_hw_tread + .tread = snd_rawmidi_hw_tread, + .ump_endpoint_info = snd_rawmidi_hw_ump_endpoint_info, + .ump_block_info = snd_rawmidi_hw_ump_block_info, }; diff --git a/src/rawmidi/rawmidi_local.h b/src/rawmidi/rawmidi_local.h index 4a88e7e4a5ba..7025542f6774 100644 --- a/src/rawmidi/rawmidi_local.h +++ b/src/rawmidi/rawmidi_local.h @@ -35,6 +35,8 @@ typedef struct { ssize_t (*write)(snd_rawmidi_t *rawmidi, const void *buffer, size_t size); ssize_t (*read)(snd_rawmidi_t *rawmidi, void *buffer, size_t size); ssize_t (*tread)(snd_rawmidi_t *rawmidi, struct timespec *tstamp, void *buffer, size_t size); + int (*ump_endpoint_info)(snd_rawmidi_t *rmidi, void *buf); + int (*ump_block_info)(snd_rawmidi_t *rmidi, void *buf); } snd_rawmidi_ops_t; struct _snd_rawmidi { @@ -62,3 +64,6 @@ int snd_rawmidi_virtual_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp, int merge, int mode); #define snd_rawmidi_conf_generic_id(id) _snd_conf_generic_id(id) + +int _snd_rawmidi_ump_endpoint_info(snd_rawmidi_t *rmidi, void *info); +int _snd_rawmidi_ump_block_info(snd_rawmidi_t *rmidi, void *info); From patchwork Sat May 20 07:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41B5CC77B7A for ; Sat, 20 May 2023 07:04:47 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id EA9AE83A; Sat, 20 May 2023 09:03:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz EA9AE83A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566285; bh=Tz6803L9pIC3IxU30R6mXDfsK1qqjOe1uUr/Lbp146o=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=vrR+pNqBqFylHJ4FRpAvce1zFGvrI7TdQw701GvCiUlepQsJe0MNqWPIiOjuJqu7S 5+uFAeEVxsCSwQEvL7OfN5rA1nL3s7sv6WBasAZVswJY4l9vx+glxCX3RhljYc8AoZ FMo1Zo11RhDytEL8AlvYP66bZflj19Eqc0YyLnvg= Received: by alsa1.perex.cz (Postfix, from userid 50401) id A16EDF8057B; Sat, 20 May 2023 09:02:40 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 2C19FF8057C; Sat, 20 May 2023 09:02:40 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5922CF8053D; Sat, 20 May 2023 09:00:52 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 56F42F80272 for ; Sat, 20 May 2023 09:00:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 56F42F80272 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=EMHSPg2E; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=iRhM67L8 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DA25C1FE3F; Sat, 20 May 2023 07:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J9HgxvfeavMjqkHgkUNMfnskdHOXkbIZcGQDNUUCbTU=; b=EMHSPg2EveoGCHJIvOyT2ObSDTmgGeIkshKyRcAN9KNIfQecYhvkjgakNSy5xiLqYdlyp2 zr4QjR4H9BJcAzfItR7Fx3ds0NXzWmP7oQNrlqcg8Dte4D6Alebc4wcEV3vyFoZWSkZ92/ Ouo/YNlsEhpb14WyKXzWFCL4aJqZkrM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J9HgxvfeavMjqkHgkUNMfnskdHOXkbIZcGQDNUUCbTU=; b=iRhM67L84N1vLXDvYEN0WDHxRUpmIGTyUers2GLldhnjq9JCYQwiAUPs/KD5Ce+ROZMiZi B6qH2BZ5h6pf/QDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B3EB9134F5; Sat, 20 May 2023 07:00:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4HoVKwlwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:25 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 3/8] ump: Add initial support Date: Sat, 20 May 2023 09:00:16 +0200 Message-Id: <20230520070021.1301-4-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: WFMDBPJ3J7DOSUF5FBFM6QLOE4KMSZ6Y X-Message-ID-Hash: WFMDBPJ3J7DOSUF5FBFM6QLOE4KMSZ6Y X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This patch adds the initial support for UMP rawmidi access. It's merely the wrapper for the standard rawmidi to access to the UMP rawmidi device. Signed-off-by: Takashi Iwai --- configure.ac | 1 + include/Makefile.am | 2 +- include/rawmidi.h | 3 + include/ump.h | 119 +++++++ src/Versions.in | 6 + src/rawmidi/Makefile.am | 5 +- src/rawmidi/rawmidi_hw.c | 10 +- src/rawmidi/rawmidi_local.h | 2 + src/rawmidi/ump.c | 616 ++++++++++++++++++++++++++++++++++++ src/rawmidi/ump_local.h | 9 + 10 files changed, 769 insertions(+), 4 deletions(-) create mode 100644 include/ump.h create mode 100644 src/rawmidi/ump.c create mode 100644 src/rawmidi/ump_local.h diff --git a/configure.ac b/configure.ac index b6266651b9d6..0588eec34f81 100644 --- a/configure.ac +++ b/configure.ac @@ -795,6 +795,7 @@ cat >> include/asoundlib.h <" >> include/asoundlib.h test "$build_rawmidi" = "yes" && echo "#include " >> include/asoundlib.h +test "$build_rawmidi" = "yes" && echo "#include " >> include/asoundlib.h test "$build_pcm" = "yes" && echo "#include " >> include/asoundlib.h test "$build_hwdep" = "yes" && echo "#include " >> include/asoundlib.h echo "#include " >> include/asoundlib.h diff --git a/include/Makefile.am b/include/Makefile.am index 9909fb73c7d6..b7f67b250810 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -34,7 +34,7 @@ endif endif if BUILD_RAWMIDI -alsainclude_HEADERS += rawmidi.h +alsainclude_HEADERS += rawmidi.h ump.h endif if BUILD_HWDEP diff --git a/include/rawmidi.h b/include/rawmidi.h index 716810536a2e..2630d1e67572 100644 --- a/include/rawmidi.h +++ b/include/rawmidi.h @@ -93,6 +93,9 @@ typedef enum _snd_rawmidi_read_mode { SND_RAWMIDI_READ_TSTAMP = 1, } snd_rawmidi_read_mode_t; +/** rawmidi info bit flags */ +#define SND_RAWMIDI_INFO_UMP 0x00000008 /* rawmidi is UMP */ + int snd_rawmidi_open(snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi, const char *name, int mode); int snd_rawmidi_open_lconf(snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi, diff --git a/include/ump.h b/include/ump.h new file mode 100644 index 000000000000..c79b2335aeff --- /dev/null +++ b/include/ump.h @@ -0,0 +1,119 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/** + * \file include/ump.h + * \brief API library for ALSA rawmidi/UMP interface + * + * API library for ALSA rawmidi/UMP interface + */ + +#ifndef __ALSA_UMP_H +#define __ALSA_UMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** UMP (Endpoint) RawMIDI device */ +typedef struct _snd_ump snd_ump_t; +/** UMP Endpoint information container */ +typedef struct snd_ump_endpoint_info snd_ump_endpoint_info_t; +/** UMP Block information container */ +typedef struct snd_ump_block_info snd_ump_block_info_t; + +int snd_ump_open(snd_ump_t **inputp, snd_ump_t **outputp, const char *name, int mode); +int snd_ump_close(snd_ump_t *ump); +snd_rawmidi_t *snd_ump_rawmidi(snd_ump_t *ump); +const char *snd_ump_name(snd_ump_t *ump); +int snd_ump_poll_descriptors_count(snd_ump_t *ump); +int snd_ump_poll_descriptors(snd_ump_t *ump, struct pollfd *pfds, unsigned int space); +int snd_ump_poll_descriptors_revents(snd_ump_t *ump, struct pollfd *pfds, unsigned int nfds, unsigned short *revents); +int snd_ump_nonblock(snd_ump_t *ump, int nonblock); +int snd_ump_rawmidi_info(snd_ump_t *ump, snd_rawmidi_info_t *info); +int snd_ump_rawmidi_params(snd_ump_t *ump, snd_rawmidi_params_t *params); +int snd_ump_rawmidi_params_current(snd_ump_t *ump, snd_rawmidi_params_t *params); +int snd_ump_rawmidi_status(snd_ump_t *ump, snd_rawmidi_status_t *status); +int snd_ump_drop(snd_ump_t *ump); +int snd_ump_drain(snd_ump_t *ump); +ssize_t snd_ump_write(snd_ump_t *ump, const void *buffer, size_t size); +ssize_t snd_ump_read(snd_ump_t *ump, void *buffer, size_t size); +ssize_t snd_ump_tread(snd_ump_t *ump, struct timespec *tstamp, void *buffer, size_t size); + +/** Max number of UMP Groups */ +#define SND_UMP_MAX_GROUPS 16 +/** Max number of UMP Blocks */ +#define SND_UMP_MAX_BLOCKS 32 + +/** UMP direction */ +enum _snd_ump_direction { + /** Input only */ + SND_UMP_DIR_INPUT = 0x01, + /** Output only */ + SND_UMP_DIR_OUTPUT = 0x02, + /** Bidirectional */ + SND_UMP_DIR_BIDIRECTION = 0x03, +}; + +/** Bitmask for UMP EP MIDI protocols */ +#define SND_UMP_EP_INFO_PROTO_MIDI_MASK 0x0300 +/** Bit flag for MIDI 1.0 protocol */ +#define SND_UMP_EP_INFO_PROTO_MIDI1 0x0100 +/** Bit flag for MIDI 2.0 protocol */ +#define SND_UMP_EP_INFO_PROTO_MIDI2 0x0200 +/** Bitmask for UMP Jitter-reduction timestamp */ +#define SND_UMP_EP_INFO_PROTO_JRTS_MASK 0x0003 +/** Bit flag for JRTS in Transmit */ +#define SND_UMP_EP_INFO_PROTO_JRTS_TX 0x0001 +/** Bit flag for JRTS in Receive */ +#define SND_UMP_EP_INFO_PROTO_JRTS_RX 0x0002 + +size_t snd_ump_endpoint_info_sizeof(void); +/** \hideinitializer + * \brief allocate an invalid #snd_ump_endpoint_info_t using standard alloca + * \param ptr returned pointer + */ +#define snd_ump_endpoint_info_alloca(ptr) __snd_alloca(ptr, snd_ump_endpoint_info) +int snd_ump_endpoint_info_malloc(snd_ump_endpoint_info_t **info); +void snd_ump_endpoint_info_free(snd_ump_endpoint_info_t *info); +void snd_ump_endpoint_info_copy(snd_ump_endpoint_info_t *dst, const snd_ump_endpoint_info_t *src); +int snd_ump_endpoint_info_get_card(const snd_ump_endpoint_info_t *info); +int snd_ump_endpoint_info_get_device(const snd_ump_endpoint_info_t *info); +unsigned int snd_ump_endpoint_info_get_flags(const snd_ump_endpoint_info_t *info); +unsigned int snd_ump_endpoint_info_get_protocol_caps(const snd_ump_endpoint_info_t *info); +unsigned int snd_ump_endpoint_info_get_protocol(const snd_ump_endpoint_info_t *info); +unsigned int snd_ump_endpoint_info_get_num_blocks(const snd_ump_endpoint_info_t *info); +unsigned int snd_ump_endpoint_info_get_version(const snd_ump_endpoint_info_t *info); +const char *snd_ump_endpoint_info_get_name(const snd_ump_endpoint_info_t *info); +const char *snd_ump_endpoint_info_get_product_id(const snd_ump_endpoint_info_t *info); +int snd_ump_endpoint_info(snd_ump_t *ump, snd_ump_endpoint_info_t *info); + +/** Bit flag for MIDI 1.0 port w/o restrict in UMP Block info flags */ +#define SND_UMP_BLOCK_IS_MIDI1 (1U << 0) +/** Bit flag for 31.25Kbps B/W MIDI1 port in UMP Block info flags */ +#define SND_UMP_BLOCK_IS_LOWSPEED (1U << 1) + +size_t snd_ump_block_info_sizeof(void); +/** \hideinitializer + * \brief allocate an invalid #snd_ump_block_info_t using standard alloca + * \param ptr returned pointer + */ +#define snd_ump_block_info_alloca(ptr) __snd_alloca(ptr, snd_ump_block_info) +int snd_ump_block_info_malloc(snd_ump_block_info_t **info); +void snd_ump_block_info_free(snd_ump_block_info_t *info); +void snd_ump_block_info_copy(snd_ump_block_info_t *dst, const snd_ump_block_info_t *src); +int snd_ump_block_info_get_card(const snd_ump_block_info_t *info); +int snd_ump_block_info_get_device(const snd_ump_block_info_t *info); +unsigned int snd_ump_block_info_get_block_id(const snd_ump_block_info_t *info); +void snd_ump_block_info_set_block_id(snd_ump_block_info_t *info, unsigned int id); +unsigned int snd_ump_block_info_get_active(const snd_ump_block_info_t *info); +unsigned int snd_ump_block_info_get_flags(const snd_ump_block_info_t *info); +unsigned int snd_ump_block_info_get_direction(const snd_ump_block_info_t *info); +unsigned int snd_ump_block_info_get_first_group(const snd_ump_block_info_t *info); +unsigned int snd_ump_block_info_get_num_groups(const snd_ump_block_info_t *info); +const char *snd_ump_block_info_get_name(const snd_ump_block_info_t *info); +int snd_ump_block_info(snd_ump_t *ump, snd_ump_block_info_t *info); + +#ifdef __cplusplus +} +#endif + +#endif /* __ALSA_UMP_H */ diff --git a/src/Versions.in b/src/Versions.in index ed7376811d62..3315fa2840e0 100644 --- a/src/Versions.in +++ b/src/Versions.in @@ -148,3 +148,9 @@ ALSA_1.2.9 { @SYMBOL_PREFIX@snd_pcm_hw_params_set_drain_silence; @SYMBOL_PREFIX@snd_pcm_hw_params_get_drain_silence; } ALSA_1.2.6; + +ALSA_1.2.10 { + global: + + @SYMBOL_PREFIX@snd_ump_*; +} ALSA_1.2.9; diff --git a/src/rawmidi/Makefile.am b/src/rawmidi/Makefile.am index 41858a1fb07e..269186597335 100644 --- a/src/rawmidi/Makefile.am +++ b/src/rawmidi/Makefile.am @@ -1,10 +1,11 @@ EXTRA_LTLIBRARIES=librawmidi.la -librawmidi_la_SOURCES = rawmidi.c rawmidi_hw.c rawmidi_symbols.c +librawmidi_la_SOURCES = rawmidi.c rawmidi_hw.c rawmidi_symbols.c \ + ump.c if BUILD_SEQ librawmidi_la_SOURCES += rawmidi_virt.c endif -noinst_HEADERS = rawmidi_local.h +noinst_HEADERS = rawmidi_local.h ump_local.h all: librawmidi.la diff --git a/src/rawmidi/rawmidi_hw.c b/src/rawmidi/rawmidi_hw.c index 69e5e02f1d6a..3119db9d7490 100644 --- a/src/rawmidi/rawmidi_hw.c +++ b/src/rawmidi/rawmidi_hw.c @@ -35,6 +35,7 @@ const char *_snd_module_rawmidi_hw = ""; #endif #define SNDRV_FILE_RAWMIDI ALSA_DEVICE_DIRECTORY "midiC%iD%i" +#define SNDRV_FILE_UMP_RAWMIDI ALSA_DEVICE_DIRECTORY "umpC%iD%i" #define SNDRV_RAWMIDI_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 0) #ifndef DOC_HIDDEN @@ -321,8 +322,12 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp, snd_rawmidi_t *rmidi; snd_rawmidi_hw_t *hw = NULL; snd_rawmidi_info_t info; + int is_ump; int fmode; + is_ump = !!(mode & _SND_RAWMIDI_OPEN_UMP); + mode &= ~_SND_RAWMIDI_OPEN_UMP; + if (inputp) *inputp = NULL; if (outputp) @@ -332,7 +337,10 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp, if ((ret = snd_ctl_hw_open(&ctl, NULL, card, 0)) < 0) return ret; - sprintf(filename, SNDRV_FILE_RAWMIDI, card, device); + if (is_ump) + sprintf(filename, SNDRV_FILE_UMP_RAWMIDI, card, device); + else + sprintf(filename, SNDRV_FILE_RAWMIDI, card, device); __again: if (attempt++ > 3) { diff --git a/src/rawmidi/rawmidi_local.h b/src/rawmidi/rawmidi_local.h index 7025542f6774..19dbf72584fa 100644 --- a/src/rawmidi/rawmidi_local.h +++ b/src/rawmidi/rawmidi_local.h @@ -67,3 +67,5 @@ int snd_rawmidi_virtual_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp, int _snd_rawmidi_ump_endpoint_info(snd_rawmidi_t *rmidi, void *info); int _snd_rawmidi_ump_block_info(snd_rawmidi_t *rmidi, void *info); + +#define _SND_RAWMIDI_OPEN_UMP (1U << 16) /* internal open mode bit */ diff --git a/src/rawmidi/ump.c b/src/rawmidi/ump.c new file mode 100644 index 000000000000..5da79459f618 --- /dev/null +++ b/src/rawmidi/ump.c @@ -0,0 +1,616 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/** + * \file rawmidi/ump.c + * \brief Universal MIDI Protocol (UMP) Interface + */ + +#include +#include +#include +#include "local.h" +#include "rawmidi_local.h" +#include "ump_local.h" + +static int get_rawmidi_flags(snd_ump_t *ump) +{ + snd_rawmidi_info_t info; + int err; + + err = snd_rawmidi_info(ump->rawmidi, &info); + if (err < 0) + return err; + if (!(info.flags & SNDRV_RAWMIDI_INFO_UMP)) + return -EINVAL; + ump->flags = info.flags; + return 0; +} + +/** + * \brief Opens a new connection to the UMP interface. + * \param inputp Returned input handle (NULL if not wanted) + * \param outputp Returned output handle (NULL if not wanted) + * \param name ASCII identifier of the UMP handle + * \param mode Open mode + * \return 0 on success otherwise a negative error code + * + * Opens a new connection to the UMP interface specified with + * an ASCII identifier and mode. + */ +int snd_ump_open(snd_ump_t **inputp, snd_ump_t **outputp, const char *name, + int mode) +{ + snd_ump_t *input = NULL, *output = NULL; + int err; + + if (inputp) + *inputp = NULL; + if (outputp) + *outputp = NULL; + if (!inputp && !outputp) + return -EINVAL; + + err = -ENOMEM; + if (inputp) { + input = calloc(1, sizeof(*input)); + if (!input) + goto error; + input->is_input = 1; + } + if (outputp) { + output = calloc(1, sizeof(*output)); + if (!output) + goto error; + } + + err = snd_rawmidi_open(input ? &input->rawmidi : NULL, + output ? &output->rawmidi : NULL, + name, mode | _SND_RAWMIDI_OPEN_UMP); + if (err < 0) + goto error; + + if (input) { + err = get_rawmidi_flags(input); + if (err < 0) + goto error; + } + if (output) { + err = get_rawmidi_flags(output); + if (err < 0) + goto error; + } + + if (inputp) + *inputp = input; + if (outputp) + *outputp = output; + + return 0; + + error: + if (input) { + if (input->rawmidi) + snd_rawmidi_close(input->rawmidi); + free(input); + } + if (output) { + if (output->rawmidi) + snd_rawmidi_close(output->rawmidi); + free(output); + } + return err; +} + +/** + * \brief close UMP handle + * \param ump UMP handle + * \return 0 on success otherwise a negative error code + * + * Closes the specified UMP handle and frees all associated + * resources. + */ +int snd_ump_close(snd_ump_t *ump) +{ + int err; + + err = snd_rawmidi_close(ump->rawmidi); + free(ump); + return err; +} + +/** + * \brief get RawMidi instance associated with the UMP handle + * \param ump UMP handle + * \return the associated RawMidi handle + * + * Returns the associated RawMidi instance with the given UMP handle + */ +snd_rawmidi_t *snd_ump_rawmidi(snd_ump_t *ump) +{ + return ump->rawmidi; +} + +/** + * \brief get identifier of UMP handle + * \param ump UMP handle + * \return ascii identifier of UMP handle + * + * Returns the ASCII identifier of given UMP handle. It's the same + * identifier specified in snd_ump_open(). + */ +const char *snd_ump_name(snd_ump_t *ump) +{ + return snd_rawmidi_name(ump->rawmidi); +} + +/** + * \brief get count of poll descriptors for UMP handle + * \param ump UMP handle + * \return count of poll descriptors + */ +int snd_ump_poll_descriptors_count(snd_ump_t *ump) +{ + return snd_rawmidi_poll_descriptors_count(ump->rawmidi); +} + +/** + * \brief get poll descriptors + * \param ump UMP handle + * \param pfds array of poll descriptors + * \param space space in the poll descriptor array + * \return count of filled descriptors + */ +int snd_ump_poll_descriptors(snd_ump_t *ump, struct pollfd *pfds, + unsigned int space) +{ + return snd_rawmidi_poll_descriptors(ump->rawmidi, pfds, space); +} + +/** + * \brief get returned events from poll descriptors + * \param ump UMP handle + * \param pfds array of poll descriptors + * \param nfds count of poll descriptors + * \param revents returned events + * \return zero if success, otherwise a negative error code + */ +int snd_ump_poll_descriptors_revents(snd_ump_t *ump, struct pollfd *pfds, + unsigned int nfds, unsigned short *revents) +{ + return snd_rawmidi_poll_descriptors_revents(ump->rawmidi, pfds, nfds, + revents); +} + +/** + * \brief set nonblock mode + * \param ump UMP handle + * \param nonblock 0 = block, 1 = nonblock mode + * \return 0 on success otherwise a negative error code + * + * The nonblock mode cannot be used when the stream is in + * #SND_RAWMIDI_APPEND state. + */ +int snd_ump_nonblock(snd_ump_t *ump, int nonblock) +{ + return snd_rawmidi_nonblock(ump->rawmidi, nonblock); +} + +/** + * \brief get information about associated RawMidi handle + * \param ump UMP handle + * \param info pointer to a snd_rawmidi_info_t structure to be filled + * \return 0 on success otherwise a negative error code + */ +int snd_ump_rawmidi_info(snd_ump_t *ump, snd_rawmidi_info_t *info) +{ + return snd_rawmidi_info(ump->rawmidi, info); +} + +/** + * \brief set parameters about associated RawMidi stream + * \param ump UMP handle + * \param params pointer to a snd_rawmidi_params_t structure to be filled + * \return 0 on success otherwise a negative error code + */ +int snd_ump_rawmidi_params(snd_ump_t *ump, snd_rawmidi_params_t *params) +{ + return snd_rawmidi_params(ump->rawmidi, params); +} + +/** + * \brief get current parameters about associated RawMidi stream + * \param ump UMP handle + * \param params pointer to a snd_rawmidi_params_t structure to be filled + * \return 0 on success otherwise a negative error code + */ +int snd_ump_rawmidi_params_current(snd_ump_t *ump, snd_rawmidi_params_t *params) +{ + return snd_rawmidi_params_current(ump->rawmidi, params); +} + +/** + * \brief get status of associated RawMidi stream + * \param ump UMP handle + * \param status pointer to a snd_rawmidi_status_t structure to be filled + * \return 0 on success otherwise a negative error code + */ +int snd_ump_rawmidi_status(snd_ump_t *ump, snd_rawmidi_status_t *status) +{ + return snd_rawmidi_status(ump->rawmidi, status); +} + +/** + * \brief drop all packets in the rawmidi I/O ring buffer immediately + * \param ump UMP handle + * \return 0 on success otherwise a negative error code + */ +int snd_ump_drop(snd_ump_t *ump) +{ + return snd_rawmidi_drop(ump->rawmidi); +} + +/** + * \brief drain all packets in the UMP I/O ring buffer + * \param ump UMP handle + * \return 0 on success otherwise a negative error code + * + * Waits until all MIDI packets are not drained (sent) to the + * hardware device. + */ +int snd_ump_drain(snd_ump_t *ump) +{ + return snd_rawmidi_drain(ump->rawmidi); +} + +/** + * \brief write UMP packets to UMP stream + * \param ump UMP handle + * \param buffer buffer containing UMP packets + * \param size output buffer size in bytes + */ +ssize_t snd_ump_write(snd_ump_t *ump, const void *buffer, size_t size) +{ + if (ump->is_input) + return -EINVAL; + return snd_rawmidi_write(ump->rawmidi, buffer, size); +} + +/** + * \brief read UMP packets from UMP stream + * \param ump UMP handle + * \param buffer buffer to store the input MIDI bytes + * \param size input buffer size in bytes + * \retval count of UMP packet in bytes otherwise a negative error code + */ +ssize_t snd_ump_read(snd_ump_t *ump, void *buffer, size_t size) +{ + if (!ump->is_input) + return -EINVAL; + return snd_rawmidi_read(ump->rawmidi, buffer, size); +} + +/** + * \brief read UMP packets from UMP stream with timestamp + * \param ump UMP handle + * \param[out] tstamp timestamp for the returned UMP packets + * \param buffer buffer to store the input UMP packets + * \param size input buffer size in bytes + * \retval count of UMP packet in bytes otherwise a negative error code + */ +ssize_t snd_ump_tread(snd_ump_t *ump, struct timespec *tstamp, void *buffer, + size_t size) +{ + if (!ump->is_input) + return -EINVAL; + return snd_rawmidi_tread(ump->rawmidi, tstamp, buffer, size); +} + +/** + * \brief get size of the snd_ump_endpoint_info_t structure in bytes + * \return size of the snd_ump_endpoint_info_t structure in bytes + */ +size_t snd_ump_endpoint_info_sizeof(void) +{ + return sizeof(snd_ump_endpoint_info_t); +} + +/** + * \brief allocate the snd_ump_endpoint_info_t structure + * \param ptr returned pointer + * \return 0 on success otherwise a negative error code if fails + * + * Allocates a new snd_rawmidi_status_t structure using the standard + * malloc C library function. + */ +int snd_ump_endpoint_info_malloc(snd_ump_endpoint_info_t **info) +{ + *info = calloc(1, sizeof(snd_ump_endpoint_info_t)); + if (!*info) + return -ENOMEM; + return 0; +} + +/** + * \brief frees the snd_ump_endpoint_info_t structure + * \param status pointer to the snd_ump_endpoint_info_t structure to free + * + * Frees the given snd_ump_endpoint_info_t structure using the standard + * free C library function. + */ +void snd_ump_endpoint_info_free(snd_ump_endpoint_info_t *info) +{ + free(info); +} + +/** + * \brief copy one snd_ump_endpoint_info_t structure to another + * \param dst destination snd_ump_endpoint_info_t structure + * \param src source snd_ump_endpoint_info_t structure + */ +void snd_ump_endpoint_info_copy(snd_ump_endpoint_info_t *dst, + const snd_ump_endpoint_info_t *src) +{ + *dst = *src; +} + +/** + * \brief get card number of UMP endpoint + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return the card number of the given UMP endpoint + */ +int snd_ump_endpoint_info_get_card(const snd_ump_endpoint_info_t *info) +{ + return info->card; +} + +/** + * \brief get device number of UMP endpoint + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return the device number of the given UMP endpoint + */ +int snd_ump_endpoint_info_get_device(const snd_ump_endpoint_info_t *info) +{ + return info->device; +} + +/** + * \brief get UMP endpoint info flags + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return UMP endpoint flag bits + */ +unsigned int snd_ump_endpoint_info_get_flags(const snd_ump_endpoint_info_t *info) +{ + return info->flags; +} + +/** + * \brief get UMP endpoint protocol capability bits + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return UMP endpoint protocol capability bits + */ +unsigned int snd_ump_endpoint_info_get_protocol_caps(const snd_ump_endpoint_info_t *info) +{ + return info->protocol_caps; +} + +/** + * \brief get the current UMP endpoint protocol + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return UMP endpoint protocol bits + */ +unsigned int snd_ump_endpoint_info_get_protocol(const snd_ump_endpoint_info_t *info) +{ + return info->protocol; +} + +/** + * \brief get the number of UMP blocks belonging to the endpoint + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return number of UMP blocks + */ +unsigned int snd_ump_endpoint_info_get_num_blocks(const snd_ump_endpoint_info_t *info) +{ + return info->num_blocks; +} + +/** + * \brief get UMP version number + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return UMP version number + */ +unsigned int snd_ump_endpoint_info_get_version(const snd_ump_endpoint_info_t *info) +{ + return info->version; +} + +/** + * \brief get UMP endpoint name string + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return UMP endpoint name string + */ +const char *snd_ump_endpoint_info_get_name(const snd_ump_endpoint_info_t *info) +{ + return (const char *)info->name; +} + +/** + * \brief get UMP endpoint product ID string + * \param info pointer to a snd_ump_endpoint_info_t structure + * \return UMP endpoint product ID string + */ +const char *snd_ump_endpoint_info_get_product_id(const snd_ump_endpoint_info_t *info) +{ + return (const char *)info->product_id; +} + +/** + * \brief get endpoint information about UMP handle + * \param ump UMP handle + * \param info pointer to a snd_ump_endpoint_info_t structure to be filled + * \return 0 on success otherwise a negative error code + */ +int snd_ump_endpoint_info(snd_ump_t *ump, snd_ump_endpoint_info_t *info) +{ + return _snd_rawmidi_ump_endpoint_info(ump->rawmidi, info); +} + +/** + * \brief get size of the snd_ump_block_info_t structure in bytes + * \return size of the snd_ump_block_info_t structure in bytes + */ +size_t snd_ump_block_info_sizeof(void) +{ + return sizeof(snd_ump_block_info_t); +} + +/** + * \brief allocate the snd_ump_block_info_t structure + * \param ptr returned pointer + * \return 0 on success otherwise a negative error code if fails + * + * Allocates a new snd_ump_block_info_t structure using the standard + * malloc C library function. + */ +int snd_ump_block_info_malloc(snd_ump_block_info_t **info) +{ + *info = calloc(1, sizeof(snd_ump_block_info_t)); + if (!*info) + return -ENOMEM; + return 0; +} + +/** + * \brief frees the snd_ump_block_info_t structure + * \param status pointer to the snd_ump_block_info_t structure to free + * + * Frees the given snd_ump_block_info_t structure using the standard + * free C library function. + */ +void snd_ump_block_info_free(snd_ump_block_info_t *info) +{ + free(info); +} + +/** + * \brief copy one snd_ump_block_info_t structure to another + * \param dst destination snd_ump_block_info_t structure + * \param src source snd_ump_block_info_t structure + */ +void snd_ump_block_info_copy(snd_ump_block_info_t *dst, + const snd_ump_block_info_t *src) +{ + *dst = *src; +} + +/** + * \brief get card number of UMP block + * \param info pointer to a snd_ump_block_info_t structure + * \return the card number of the given UMP block + */ +int snd_ump_block_info_get_card(const snd_ump_block_info_t *info) +{ + return info->card; +} + +/** + * \brief get device number of UMP block + * \param info pointer to a snd_ump_block_info_t structure + * \return the device number of the given UMP block + */ +int snd_ump_block_info_get_device(const snd_ump_block_info_t *info) +{ + return info->device; +} + +/** + * \brief get UMP block ID + * \param info pointer to a snd_ump_block_info_t structure + * \return ID number of the given UMP block + */ +unsigned int snd_ump_block_info_get_block_id(const snd_ump_block_info_t *info) +{ + return info->block_id; +} + +/** + * \brief set UMP block ID for query + * \param info pointer to a snd_ump_block_info_t structure + * \param id the ID number for query + */ +void snd_ump_block_info_set_block_id(snd_ump_block_info_t *info, + unsigned int id) +{ + info->block_id = id; +} + +/** + * \brief get UMP block activeness + * \param info pointer to a snd_ump_block_info_t structure + * \return 1 if the block is active or 0 if inactive + */ +unsigned int snd_ump_block_info_get_active(const snd_ump_block_info_t *info) +{ + return info->active; +} + +/** + * \brief get UMP block information flags + * \param info pointer to a snd_ump_block_info_t structure + * \return info flag bits for the given UMP block + */ +unsigned int snd_ump_block_info_get_flags(const snd_ump_block_info_t *info) +{ + return info->flags; +} + +/** + * \brief get UMP block direction + * \param info pointer to a snd_ump_block_info_t structure + * \return direction of UMP block (input,output,bidirectional) + */ +unsigned int snd_ump_block_info_get_direction(const snd_ump_block_info_t *info) +{ + return info->direction; +} + +/** + * \brief get first UMP group ID belonging to the block + * \param info pointer to a snd_ump_block_info_t structure + * \return the first UMP group ID belonging to the block + */ +unsigned int snd_ump_block_info_get_first_group(const snd_ump_block_info_t *info) +{ + return info->first_group; +} + +/** + * \brief get number of UMP groups belonging to the block + * \param info pointer to a snd_ump_block_info_t structure + * \return the number of UMP groups belonging to the block + */ +unsigned int snd_ump_block_info_get_num_groups(const snd_ump_block_info_t *info) +{ + return info->num_groups; +} + +/** + * \brief get the name string of UMP block + * \param info pointer to a snd_ump_block_info_t structure + * \return the name string of UMP block + */ +const char *snd_ump_block_info_get_name(const snd_ump_block_info_t *info) +{ + return (const char *)info->name; +} + +/** + * \brief get UMP block information + * \param info pointer to a snd_ump_block_info_t structure + * \return 0 on success otherwise a negative error code + * + * The caller should fill the block ID to query at first via + * snd_ump_block_info_set_block_id(). + */ +int snd_ump_block_info(snd_ump_t *ump, snd_ump_block_info_t *info) +{ + return _snd_rawmidi_ump_block_info(ump->rawmidi, info); +} diff --git a/src/rawmidi/ump_local.h b/src/rawmidi/ump_local.h new file mode 100644 index 000000000000..424051ae688b --- /dev/null +++ b/src/rawmidi/ump_local.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#include "rawmidi.h" +#include "ump.h" + +struct _snd_ump { + snd_rawmidi_t *rawmidi; + unsigned int flags; + int is_input; +}; From patchwork Sat May 20 07:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249118 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C26CEC7EE26 for ; Sat, 20 May 2023 07:05:17 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5F76D851; Sat, 20 May 2023 09:04:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5F76D851 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566315; bh=9QmkTRE6gtISnt+z8pNc/G09S2gqpS6MAtPefT01M+0=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=XgIHSlNXCgSFpDPWUWd7zZ+agsEYcrfAUv+LN850JlpWV0KQvwJrMLsNDgQqo7P4m okDnPIW3mhC8qR6Z16aHMmccEPJX0vvZdtGdcoZIzzYu1OybvPFtF2j24ZMMc+3vPO 7++M6p764FqLq0uk17ZJLvzkP3k1du00dZS9DKok= Received: by alsa1.perex.cz (Postfix, from userid 50401) id B9FBAF805A0; Sat, 20 May 2023 09:02:41 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 485D0F805AF; Sat, 20 May 2023 09:02:41 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 737ACF80272; Sat, 20 May 2023 09:00:58 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 992F8F8016A for ; Sat, 20 May 2023 09:00:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 992F8F8016A Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=a9lVjX1f; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=o2ZZxq9r Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0537022086; Sat, 20 May 2023 07:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XbLHN/hGfs8euysdNdAuTizGVRDNJPjxWcylqxjm6bc=; b=a9lVjX1fey/VQTTyMZMm6fFeCdodvxlkYY6RYWfHsNN6ozOb5qjyQi1vwl0iv0IwMcWbOf Syc+TLiNHmIfgFc8ayfDJAjBDqjAZstMcn/i8jGrHGTFW4ruUuCNgTwP6DkCoevydtOaSt Ry3Y82OLge5NW8yLNpQcP81lOWefTDA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XbLHN/hGfs8euysdNdAuTizGVRDNJPjxWcylqxjm6bc=; b=o2ZZxq9rwl6q8H1gzu2NKERxtMrP3zUvaS4ioD2kw8Eb3tekz1TIZ+ku3VLmFrW2QgwBd9 g3Ewd3MQae+VK+BA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DCE0A139F5; Sat, 20 May 2023 07:00:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sOobNQlwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:25 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 4/8] control: Add UMP device query support Date: Sat, 20 May 2023 09:00:17 +0200 Message-Id: <20230520070021.1301-5-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: WC3VO4DZUS5TTLFILAOFJSHAJZHDEO6I X-Message-ID-Hash: WC3VO4DZUS5TTLFILAOFJSHAJZHDEO6I X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add a function to query the next available UMP device via control interface, just like the existing one for rawmidi. As the UMP rawmidi is compatible with the standard rawmidi, no extra helper for the rawmidi_info is present. Ditto for the preferred subdevice, too. Signed-off-by: Takashi Iwai --- include/control.h | 1 + src/control/control.c | 14 ++++++++++++++ src/control/control_hw.c | 9 +++++++++ src/control/control_local.h | 1 + 4 files changed, 25 insertions(+) diff --git a/include/control.h b/include/control.h index d0c40d2fa32b..a2439d78057a 100644 --- a/include/control.h +++ b/include/control.h @@ -417,6 +417,7 @@ int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev); int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device); int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info); int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev); +int snd_ctl_ump_next_device(snd_ctl_t *ctl, int *device); #endif int snd_ctl_set_power_state(snd_ctl_t *ctl, unsigned int state); int snd_ctl_get_power_state(snd_ctl_t *ctl, unsigned int *state); diff --git a/src/control/control.c b/src/control/control.c index c4ca74ec5497..615a66906414 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -1267,6 +1267,20 @@ int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev) return ctl->ops->rawmidi_prefer_subdevice(ctl, subdev); } +/** + * \brief Get next UMP device number + * \param ctl CTL handle + * \param device current device on entry and next device on return + * \return 0 on success otherwise a negative error code + */ +int snd_ctl_ump_next_device(snd_ctl_t *ctl, int *device) +{ + assert(ctl && device); + if (ctl->ops->ump_next_device) + return ctl->ops->ump_next_device(ctl, device); + return -ENXIO; +} + /** * \brief Set Power State to given SND_CTL_POWER_* value and do the power management * \param ctl CTL handle diff --git a/src/control/control_hw.c b/src/control/control_hw.c index 02636910c809..ffb6f17325a7 100644 --- a/src/control/control_hw.c +++ b/src/control/control_hw.c @@ -325,6 +325,14 @@ static int snd_ctl_hw_rawmidi_prefer_subdevice(snd_ctl_t *handle, int subdev) return 0; } +static int snd_ctl_hw_ump_next_device(snd_ctl_t *handle, int *device) +{ + snd_ctl_hw_t *hw = handle->private_data; + if (ioctl(hw->fd, SNDRV_CTL_IOCTL_UMP_NEXT_DEVICE, device) < 0) + return -errno; + return 0; +} + static int snd_ctl_hw_set_power_state(snd_ctl_t *handle, unsigned int state) { snd_ctl_hw_t *hw = handle->private_data; @@ -379,6 +387,7 @@ static const snd_ctl_ops_t snd_ctl_hw_ops = { .rawmidi_next_device = snd_ctl_hw_rawmidi_next_device, .rawmidi_info = snd_ctl_hw_rawmidi_info, .rawmidi_prefer_subdevice = snd_ctl_hw_rawmidi_prefer_subdevice, + .ump_next_device = snd_ctl_hw_ump_next_device, .set_power_state = snd_ctl_hw_set_power_state, .get_power_state = snd_ctl_hw_get_power_state, .read = snd_ctl_hw_read, diff --git a/src/control/control_local.h b/src/control/control_local.h index b84dc4291c29..aa05bac84913 100644 --- a/src/control/control_local.h +++ b/src/control/control_local.h @@ -47,6 +47,7 @@ typedef struct _snd_ctl_ops { int (*rawmidi_next_device)(snd_ctl_t *handle, int *device); int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info); int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev); + int (*ump_next_device)(snd_ctl_t *handle, int *device); int (*set_power_state)(snd_ctl_t *handle, unsigned int state); int (*get_power_state)(snd_ctl_t *handle, unsigned int *state); int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event); From patchwork Sat May 20 07:00:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B30EDC77B7A for ; Sat, 20 May 2023 07:05:59 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B4672822; Sat, 20 May 2023 09:05:07 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B4672822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566357; bh=uANbKS0cuNFi6Ridjvluzy9ZnziGY0DT9AVZUDCdmiw=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=Ckbf+jmmgYk5WvtdkkdmyyJpi4qG1ndpvg/3o14ip3jiFhOIW6A71zoyTm7B5btQe SH/XUCuZFIni8T+dW3Sxs7JnaX4eeYBZwg47QdlTwoPklgqtr83MJ8j5X2qtZrfvsL 7Y8Ed3k0q8E7iScJjyd/gOKgxxMz02I+DwEE5LEA= Received: by alsa1.perex.cz (Postfix, from userid 50401) id C3629F805CB; Sat, 20 May 2023 09:02:42 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 41EA0F805C7; Sat, 20 May 2023 09:02:42 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 915C3F8025A; Sat, 20 May 2023 09:01:42 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9A049F80431 for ; Sat, 20 May 2023 09:00:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9A049F80431 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=JeKNDg4P; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=zKigNbuw Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2A3E62208A; Sat, 20 May 2023 07:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VrPzMUjBfqcPwLhcgySDW5elVfhKHW1tLSG40ja7Ffk=; b=JeKNDg4PcU+AO778GerqxtRt4RwKxHnHtaLegRlf8Mp+PvE22l75tlwHT3+Z6/fDIEs8vM NTCGt8woelXhXOL/VJGaq9ufMlX261cGZHxibmCmqqMeSeetD4qNbbnWFjBhyPXvjM6GY5 WZkmZHAqo/LyIrTzaXB5lYpWT1Fw4/Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VrPzMUjBfqcPwLhcgySDW5elVfhKHW1tLSG40ja7Ffk=; b=zKigNbuwAestw+3lkBxK5euy/TTGO/evIiroRexafSZ1FOeopgDOgyPHyzt4bH+XkslCqO 2LAt2tjlnDVOHJBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0A48F134F5; Sat, 20 May 2023 07:00:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sJmlAQpwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:26 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 5/8] ump: Add helpers to parse / set UMP packet data Date: Sat, 20 May 2023 09:00:18 +0200 Message-Id: <20230520070021.1301-6-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: PBYWL3XS4AEEUCSWUCOXLOVUXXXTUH3O X-Message-ID-Hash: PBYWL3XS4AEEUCSWUCOXLOVUXXXTUH3O X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This patch defines the structs / unions that can be used for encoding and decoding UMP packets, as well as inline helper functions. Signed-off-by: Takashi Iwai --- include/Makefile.am | 2 +- include/local.h | 2 + include/ump_msg.h | 571 ++++++++++++++++++++++++++++++++++++++++ src/rawmidi/ump_local.h | 1 + 4 files changed, 575 insertions(+), 1 deletion(-) create mode 100644 include/ump_msg.h diff --git a/include/Makefile.am b/include/Makefile.am index b7f67b250810..16d68b511297 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -34,7 +34,7 @@ endif endif if BUILD_RAWMIDI -alsainclude_HEADERS += rawmidi.h ump.h +alsainclude_HEADERS += rawmidi.h ump.h ump_msg.h endif if BUILD_HWDEP diff --git a/include/local.h b/include/local.h index 151e3fd4d39b..51042d764f65 100644 --- a/include/local.h +++ b/include/local.h @@ -69,9 +69,11 @@ #if __BYTE_ORDER == __LITTLE_ENDIAN #define SND_LITTLE_ENDIAN #define SNDRV_LITTLE_ENDIAN +#define SNDRV_LITTLE_ENDIAN_BITFIELD #elif __BYTE_ORDER == __BIG_ENDIAN #define SND_BIG_ENDIAN #define SNDRV_BIG_ENDIAN +#define SNDRV_BIG_ENDIAN_BITFIELD #else #error "Unsupported endian..." #endif diff --git a/include/ump_msg.h b/include/ump_msg.h new file mode 100644 index 000000000000..1b7f70667054 --- /dev/null +++ b/include/ump_msg.h @@ -0,0 +1,571 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/** + * \file include/ump_msg.h + * \brief API library for ALSA rawmidi/UMP interface + * + * API library for ALSA rawmidi/UMP interface + */ + +#ifndef __ALSA_UMP_MSG_H +#define __ALSA_UMP_MSG_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** general UMP packet header in 32bit word */ +typedef struct _snd_ump_msg_hdr { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t byte1; /**< First data byte */ + uint8_t byte2; /**< Second data byte */ +#else + uint8_t byte2; /**< Second data byte */ + uint8_t byte1; /**< First data byte */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_hdr_t; + +/** MIDI 1.0 Note Off / Note On (32bit) */ +typedef struct _snd_ump_msg_midi1_note { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t note; /**< Note (7bit) */ + uint8_t velocity; /**< Velocity (7bit) */ +#else + uint8_t velocity; /**< Velocity (7bit) */ + uint8_t note; /**< Note (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_midi1_note_t; + +/** MIDI 1.0 Poly Pressure (32bit) */ +typedef struct _snd_ump_msg_midi1_paf { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t note; /** Note (7bit) */ + uint8_t data; /** Pressure (7bit) */ +#else + uint8_t data; /** Pressure (7bit) */ + uint8_t note; /** Note (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_midi1_paf_t; + +/** MIDI 1.0 Control Change (32bit) */ +typedef struct _snd_ump_msg_midi1_cc { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t index; /** Control index (7bit) */ + uint8_t data; /** Control data (7bit) */ +#else + uint8_t data; /** Control data (7bit) */ + uint8_t index; /** Control index (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_midi1_cc_t; + +/** MIDI 1.0 Program Change (32bit) */ +typedef struct _snd_ump_msg_midi1_program { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t program; /**< Program number (7bit) */ + uint8_t reserved; /**< Unused */ +#else + uint8_t reserved; /**< Unused */ + uint8_t program; /**< Program number (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_midi1_program_t; + +/** MIDI 1.0 Channel Pressure (32bit) */ +typedef struct _snd_ump_msg_midi1_caf { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t data; /**< Pressure (7bit) */ + uint8_t reserved; /**< Unused */ +#else + uint8_t reserved; /**< Unused */ + uint8_t data; /**< Pressure (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_midi1_caf_t; + +/** MIDI 1.0 Pitch Bend (32bit) */ +typedef struct _snd_ump_msg_midi1_pitchbend { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t data_lsb; /**< LSB of pitchbend (7bit) */ + uint8_t data_msb; /**< MSB of pitchbend (7bit) */ +#else + uint8_t data_msb; /**< MSB of pitchbend (7bit) */ + uint8_t data_lsb; /**< LSB of pitchbend (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_midi1_pitchbend_t; + +/** System Common and Real Time messages (32bit); no channel field */ +typedef struct snd_ump_msg_system { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status; /**< Status */ + uint8_t parm1; /**< First parameter */ + uint8_t parm2; /**< Second parameter */ +#else + uint8_t parm1; /**< First parameter */ + uint8_t parm2; /**< Second parameter */ + uint8_t status; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ +#endif +} __attribute((packed)) snd_ump_msg_system_t; + +/** MIDI 1.0 UMP CVM (32bit) */ +typedef union _snd_ump_msg_midi1 { + snd_ump_msg_midi1_note_t note_on; + snd_ump_msg_midi1_note_t note_off; + snd_ump_msg_midi1_paf_t poly_pressure; + snd_ump_msg_midi1_cc_t control_change; + snd_ump_msg_midi1_program_t program_change; + snd_ump_msg_midi1_caf_t channel_pressure; + snd_ump_msg_midi1_pitchbend_t pitchbend; + snd_ump_msg_system_t system; + snd_ump_msg_hdr_t hdr; + uint32_t raw; +} snd_ump_msg_midi1_t; + +/** MIDI 2.0 Note-on/off attribute type */ +enum { + SND_UMP_MIDI2_NOTE_ATTR_NO_DATA = 0x00, /**< No attribute data */ + SND_UMP_MIDI2_NOTE_ATTR_MANUFACTURER = 0x01, /**< Manufacturer specific */ + SND_UMP_MIDI2_NOTE_ATTR_PROFILE = 0x02, /**< Profile specific */ + SND_UMP_MIDI2_NOTE_ATTR_PITCH79 = 0x03, /**< Pitch 7.9 */ +}; + +/* MIDI 2.0 Note Off / Note On (64bit) */ +typedef struct _snd_ump_msg_midi2_note { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t note; /**< Note (7bit) */ + uint8_t attr_type; /**< Attribute type */ + + uint16_t velocity; /**< Velocity (16bit) */ + uint16_t attr_data; /**< Attribute data (16bit) */ +#else + uint8_t attr_type; /**< Attribute type */ + uint8_t note; /**< Note (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint16_t attr_data; /**< Attribute data (16bit) */ + uint16_t velocity; /**< Velocity (16bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_note_t; + +/** MIDI 2.0 Poly Pressure (64bit) */ +typedef struct _snd_ump_msg_midi2_paf { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t note; /**< Note (7bit) */ + uint8_t reserved; /**< Unused */ + + uint32_t data; /**< Pressure (32bit) */ +#else + uint8_t reserved; /**< Unused */ + uint8_t note; /**< Note (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t data; /**< Pressure (32bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_paf_t; + +/** MIDI 2.0 Per-Note Controller (64bit) */ +typedef struct _snd_ump_msg_midi2_per_note_cc { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t note; /**< Note (7bit) */ + uint8_t index; /**< Control index (8bit) */ + + uint32_t data; /**< Data (32bit) */ +#else + uint8_t index; /**< Control index (8bit) */ + uint8_t note; /**< Note (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t data; /**< Data (32bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_per_note_cc_t; + +/** MIDI 2.0 per-note management flag bits */ +enum { + SND_UMP_MIDI2_PNMGMT_RESET_CONTROLLERS = 0x01, /**< Reset (set) per-note controllers */ + SND_UMP_MIDI2_PNMGMT_DETACH_CONTROLLERS = 0x02, /**< Detach per-note controllers */ +}; + +/** MIDI 2.0 Per-Note Management (64bit) */ +typedef struct _snd_ump_msg_midi2_per_note_mgmt { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t note; /**< Note (7bit) */ + uint8_t flags; /**< Option flags (8bit) */ + + uint32_t reserved; /**< Unused */ +#else + uint8_t flags; /**< Option flags (8bit) */ + uint8_t note; /**< Note (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t reserved; /**< Unused */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_per_note_mgmt_t; + +/** MIDI 2.0 Control Change (64bit) */ +typedef struct _snd_ump_msg_midi2_cc { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t index; /**< Control index (7bit) */ + uint8_t reserved; /**< Unused */ + + uint32_t data; /**< Control data (32bit) */ +#else + uint8_t reserved; /**< Unused */ + uint8_t index; /**< Control index (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t data; /**< Control data (32bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_cc_t; + +/** MIDI 2.0 Registered Controller (RPN) / Assignable Controller (NRPN) (64bit) */ +typedef struct _snd_ump_msg_midi2_rpn { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t bank; /**< Bank number (7bit) */ + uint8_t index; /**< Control index (7bit) */ + + uint32_t data; /**< Data (32bit) */ +#else + uint8_t index; /**< Control index (7bit) */ + uint8_t bank; /**< Bank number (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t data; /**< Data (32bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_rpn_t; + +/** MIDI 2.0 Program Change (64bit) */ +typedef struct _snd_ump_msg_midi2_program { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint16_t reserved:15; /**< Unused */ + uint16_t bank_valid:1; /**< Option flag: bank valid */ + + uint8_t program; /**< Program number (7bit) */ + uint8_t reserved2; /**< Unused */ + uint8_t bank_msb; /**< MSB of bank (8bit) */ + uint8_t bank_lsb; /**< LSB of bank (7bit) */ +#else + uint16_t bank_valid:1; /**< Option flag: bank valid */ + uint16_t reserved:15; /**< Unused */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint8_t bank_lsb; /**< LSB of bank (7bit) */ + uint8_t bank_msb; /**< MSB of bank (8bit) */ + uint8_t reserved2; /**< Unused */ + uint8_t program; /**< Program number (7bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_program_t; + +/** MIDI 2.0 Channel Pressure (64bit) */ +typedef struct _snd_ump_msg_midi2_caf { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint16_t reserved; /**< Unused */ + + uint32_t data; /** Data (32bit) */ +#else + uint16_t reserved; /**< Unused */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t data; /** Data (32bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_caf_t; + +/* MIDI 2.0 Pitch Bend (64bit) */ +typedef struct _snd_ump_msg_midi2_pitchbend { +#ifdef SNDRV_BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint16_t reserved; /**< Unused */ + + uint32_t data; /** Data (32bit) */ +#else + uint16_t reserved; /**< Unused */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t data; /** Data (32bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_pitchbend_t; + +/* MIDI 2.0 Per-Note Pitch Bend (64bit) */ +typedef struct _snd_ump_msg_midi2_per_note_pitchbend { +#ifdef __BIG_ENDIAN_BITFIELD + uint8_t type:4; /**< UMP packet type */ + uint8_t group:4; /**< UMP Group */ + uint8_t status:4; /**< Status */ + uint8_t channel:4; /**< Channel */ + uint8_t note; /**< Note (7bit) */ + uint8_t reserved; /**< Unused */ + + uint32_t data; /**< Data (32bit) */ +#else + /* 0 */ + uint8_t reserved; /**< Unused */ + uint8_t note; /**< Note (7bit) */ + uint8_t channel:4; /**< Channel */ + uint8_t status:4; /**< Status */ + uint8_t group:4; /**< UMP Group */ + uint8_t type:4; /**< UMP packet type */ + + uint32_t data; /**< Data (32bit) */ +#endif +} __attribute((packed)) snd_ump_msg_midi2_per_note_pitchbend_t; + +/** MIDI2 UMP packet (64bit little-endian) */ +typedef union _snd_ump_msg_midi2 { + snd_ump_msg_midi2_note_t note_on; + snd_ump_msg_midi2_note_t note_off; + snd_ump_msg_midi2_paf_t poly_pressure; + snd_ump_msg_midi2_per_note_cc_t per_note_acc; + snd_ump_msg_midi2_per_note_cc_t per_note_rcc; + snd_ump_msg_midi2_per_note_mgmt_t per_note_mgmt; + snd_ump_msg_midi2_cc_t control_change; + snd_ump_msg_midi2_rpn_t rpn; + snd_ump_msg_midi2_rpn_t nrpn; + snd_ump_msg_midi2_rpn_t relative_rpn; + snd_ump_msg_midi2_rpn_t relative_nrpn; + snd_ump_msg_midi2_program_t program_change; + snd_ump_msg_midi2_caf_t channel_pressure; + snd_ump_msg_midi2_pitchbend_t pitchbend; + snd_ump_msg_midi2_per_note_pitchbend_t per_note_pitchbend; + snd_ump_msg_hdr_t hdr; + uint32_t raw[2]; +} snd_ump_msg_midi2_t; + +/** + * UMP message type + */ +enum { + SND_UMP_MSG_TYPE_SYSTEM = 0x01, /* System messages */ + SND_UMP_MSG_TYPE_MIDI1_CHANNEL_VOICE = 0x02, /* MIDI 1.0 messages */ + SND_UMP_MSG_TYPE_DATA = 0x03, /* 7bit SysEx messages */ + SND_UMP_MSG_TYPE_MIDI2_CHANNEL_VOICE = 0x04, /* MIDI 2.0 messages */ + SND_UMP_MSG_TYPE_EXTENDED_DATA = 0x05, /* 8bit data message */ +}; + +/** + * UMP MIDI 1.0 / 2.0 message status code (4bit) + */ +enum { + SND_UMP_MSG_PER_NOTE_RCC = 0x0, + SND_UMP_MSG_PER_NOTE_ACC = 0x1, + SND_UMP_MSG_RPN = 0x2, + SND_UMP_MSG_NRPN = 0x3, + SND_UMP_MSG_RELATIVE_RPN = 0x4, + SND_UMP_MSG_RELATIVE_NRPN = 0x5, + SND_UMP_MSG_PER_NOTE_PITCHBEND = 0x6, + SND_UMP_MSG_NOTE_OFF = 0x8, + SND_UMP_MSG_NOTE_ON = 0x9, + SND_UMP_MSG_POLY_PRESSURE = 0xa, + SND_UMP_MSG_CONTROL_CHANGE = 0xb, + SND_UMP_MSG_PROGRAM_CHANGE = 0xc, + SND_UMP_MSG_CHANNEL_PRESSURE = 0xd, + SND_UMP_MSG_PITCHBEND = 0xe, + SND_UMP_MSG_PER_NOTE_MGMT = 0xf, +}; + +/** + * MIDI System / Realtime message status code (8bit) + */ +enum { + SND_UMP_MSG_REALTIME = 0xf0, /* mask */ + SND_UMP_MSG_SYSEX_START = 0xf0, + SND_UMP_MSG_MIDI_TIME_CODE = 0xf1, + SND_UMP_MSG_SONG_POSITION = 0xf2, + SND_UMP_MSG_SONG_SELECT = 0xf3, + SND_UMP_MSG_TUNE_REQUEST = 0xf6, + SND_UMP_MSG_SYSEX_END = 0xf7, + SND_UMP_MSG_TIMING_CLOCK = 0xf8, + SND_UMP_MSG_START = 0xfa, + SND_UMP_MSG_CONTINUE = 0xfb, + SND_UMP_MSG_STOP = 0xfc, + SND_UMP_MSG_ACTIVE_SENSING = 0xfe, + SND_UMP_MSG_RESET = 0xff, +}; + +/** + * \brief get UMP status (4bit) from 32bit UMP message header + */ +static inline uint8_t snd_ump_msg_hdr_status(uint32_t ump) +{ + return (ump >> 20) & 0x0f; +} + +/** + * \brief get UMP channel (4bit) from 32bit UMP message header + */ +static inline uint8_t snd_ump_msg_hdr_channel(uint32_t ump) +{ + return (ump >> 16) & 0x0f; +} + +/** + * \brief get UMP message type (4bit) from 32bit UMP message header + */ +static inline uint8_t snd_ump_msg_hdr_type(uint32_t ump) +{ + return (ump >> 28); +} + +/** + * \brief get UMP group (4bit) from 32bit UMP message header + */ +static inline uint8_t snd_ump_msg_hdr_group(uint32_t ump) +{ + return (ump >> 24) & 0x0f; +} + +/** + * \brief get UMP status from UMP packet pointer + */ +static inline uint8_t snd_ump_msg_status(const uint32_t *ump) +{ + return snd_ump_msg_hdr_status(*ump); +} + +/** + * \brief get UMP channel from UMP packet pointer + */ +static inline uint8_t snd_ump_msg_channel(const uint32_t *ump) +{ + return snd_ump_msg_hdr_channel(*ump); +} + +/** + * \brief get UMP message type from UMP packet pointer + */ +static inline uint8_t snd_ump_msg_type(const uint32_t *ump) +{ + return snd_ump_msg_hdr_type(*ump); +} + +/** + * \brief get UMP group from UMP packet pointer + */ +static inline uint8_t snd_ump_msg_group(const uint32_t *ump) +{ + return snd_ump_msg_hdr_group(*ump); +} + +#ifdef __cplusplus +} +#endif + +#endif /* __ALSA_UMP_MSG_H */ diff --git a/src/rawmidi/ump_local.h b/src/rawmidi/ump_local.h index 424051ae688b..53ce9a66dfcf 100644 --- a/src/rawmidi/ump_local.h +++ b/src/rawmidi/ump_local.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include "rawmidi.h" #include "ump.h" +#include "ump_msg.h" struct _snd_ump { snd_rawmidi_t *rawmidi; From patchwork Sat May 20 07:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F6E9C77B7A for ; Sat, 20 May 2023 07:04:23 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 4A849820; Sat, 20 May 2023 09:03:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4A849820 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566260; bh=I8gpMvWlH3OKVLXmeJtrV/2sgDBCwMYDQ1hKpWCuAbc=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=suGPkowWpZ9KoxQAosP/JPVX5tY3h/O8GUufb8d16HO/AnL+nrc1UQhD6f61JsMEN 4teWoJwJGJoo/WwaBbUS+7/m2+gQMcBq+XMcEjUaiox0QXthSd4swJgMBxvv5ws9aW btYJB7WCm/gexE0yFFs89rW8jsaTzUZ5+qNNcnOo= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7E2C7F80568; Sat, 20 May 2023 09:02:39 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 0EC17F80567; Sat, 20 May 2023 09:02:39 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A7A31F80548; Sat, 20 May 2023 09:00:50 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9A98FF8053D for ; Sat, 20 May 2023 09:00:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9A98FF8053D Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=qdRrpym4; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=GMvjEz7S Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 49585220C9; Sat, 20 May 2023 07:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sTt0DxRtIddr9JNNnFKqgFbm1+90y+GMnDDHmAmodPY=; b=qdRrpym4W6YYd2YDrxAb+qK31iNnlRJVdtkPczbbgo//dutJZJFWdLpSs3/Jb9AwgUoitn HQCNrNKIogpXIYAhBb/ANUsyKM1LztOGi+BOHc1CkdD6A16/9pnaJUrTRtE5mt9fsfToTW AkSYGZIqsfThMnM1jh8UMcJBYbqU1bY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sTt0DxRtIddr9JNNnFKqgFbm1+90y+GMnDDHmAmodPY=; b=GMvjEz7SW9Ru/2N+zN+Jaefyn1guTikZsVlzR9/6VOgmRZRaJYN5yGET+EjmeTzA6eT+vx 170oiUBOzhniicDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2D7AC139F5; Sat, 20 May 2023 07:00:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CAROCgpwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:26 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 6/8] ump: Add helpers for handling SysEx data Date: Sat, 20 May 2023 09:00:19 +0200 Message-Id: <20230520070021.1301-7-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: BKCXWJXK5ATM7OGQ7PEIAIYABXFXJZBI X-Message-ID-Hash: BKCXWJXK5ATM7OGQ7PEIAIYABXFXJZBI X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Yet a few more helpers for handling SysEx data with UMP packets. Signed-off-by: Takashi Iwai --- include/ump_msg.h | 27 +++++++++++++++ src/rawmidi/ump.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/include/ump_msg.h b/include/ump_msg.h index 1b7f70667054..4ccce546f8d5 100644 --- a/include/ump_msg.h +++ b/include/ump_msg.h @@ -500,6 +500,14 @@ enum { SND_UMP_MSG_RESET = 0xff, }; +/** MIDI 2.0 SysEx / Data Status; same values for both 7-bit and 8-bit SysEx */ +enum { + SND_UMP_SYSEX_STATUS_SINGLE = 0, + SND_UMP_SYSEX_STATUS_START = 1, + SND_UMP_SYSEX_STATUS_CONTINUE = 2, + SND_UMP_SYSEX_STATUS_END = 3, +}; + /** * \brief get UMP status (4bit) from 32bit UMP message header */ @@ -564,6 +572,25 @@ static inline uint8_t snd_ump_msg_group(const uint32_t *ump) return snd_ump_msg_hdr_group(*ump); } +/** + * \brief get UMP sysex message status + */ +static inline uint8_t snd_ump_sysex_msg_status(const uint32_t *ump) +{ + return (*ump >> 20) & 0xf; +} + +/** + * \brief get UMP sysex message length + */ +static inline uint8_t snd_ump_sysex_msg_length(const uint32_t *ump) +{ + return (*ump >> 16) & 0xf; +} + +int snd_ump_msg_sysex_expand(const uint32_t *ump, uint8_t *buf, size_t maxlen, + size_t *filled); + #ifdef __cplusplus } #endif diff --git a/src/rawmidi/ump.c b/src/rawmidi/ump.c index 5da79459f618..2482884f2661 100644 --- a/src/rawmidi/ump.c +++ b/src/rawmidi/ump.c @@ -614,3 +614,89 @@ int snd_ump_block_info(snd_ump_t *ump, snd_ump_block_info_t *info) { return _snd_rawmidi_ump_block_info(ump->rawmidi, info); } + +/* + * UMP sysex helpers + */ +static int expand_sysex_data(const uint32_t *data, uint8_t *buf, + size_t maxlen, unsigned char bytes, int offset) +{ + int size = 0; + + for (; bytes; bytes--, size++) { + if (!maxlen) + break; + buf[size] = (*data >> offset) & 0x7f; + if (!offset) { + offset = 24; + data++; + } else { + offset -= 8; + } + } + + return size; +} + +static int expand_sysex7(const uint32_t *ump, uint8_t *buf, size_t maxlen, + size_t *filled) +{ + unsigned char status; + unsigned char bytes; + + *filled = 0; + if (!maxlen) + return 0; + + status = snd_ump_sysex_msg_status(ump); + bytes = snd_ump_sysex_msg_length(ump); + if (bytes > 6) + return 0; // invalid - skip + + *filled = expand_sysex_data(ump, buf, maxlen, bytes, 8); + return (status == SND_UMP_SYSEX_STATUS_SINGLE || + status == SND_UMP_SYSEX_STATUS_END); +} + +static int expand_sysex8(const uint32_t *ump, uint8_t *buf, size_t maxlen, + size_t *filled) +{ + unsigned char status; + unsigned char bytes; + + *filled = 0; + if (!maxlen) + return 0; + + status = snd_ump_sysex_msg_status(ump); + if (status > SND_UMP_SYSEX_STATUS_END) + return 0; // unsupported, skip + bytes = snd_ump_sysex_msg_length(ump); + if (!bytes || bytes > 14) + return 0; // skip + + *filled = expand_sysex_data(ump, buf, maxlen, bytes - 1, 0); + return (status == SND_UMP_SYSEX_STATUS_SINGLE || + status == SND_UMP_SYSEX_STATUS_END); +} + +/** + * \brief fill sysex byte from a UMP packet + * \param ump UMP packet pointer + * \param buf buffer point to fill sysex bytes + * \param maxlen max buffer size in bytes + * \param filled the size of filled sysex bytes on the buffer + * \return 1 if the sysex finished, otherwise 0 + */ +int snd_ump_msg_sysex_expand(const uint32_t *ump, uint8_t *buf, size_t maxlen, + size_t *filled) +{ + switch (snd_ump_msg_type(ump)) { + case SND_UMP_MSG_TYPE_DATA: + return expand_sysex7(ump, buf, maxlen, filled); + case SND_UMP_MSG_TYPE_EXTENDED_DATA: + return expand_sysex8(ump, buf, maxlen, filled); + default: + return -EINVAL; + } +} From patchwork Sat May 20 07:00:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44878C77B7A for ; Sat, 20 May 2023 07:05:36 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 7518A827; Sat, 20 May 2023 09:04:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7518A827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566333; bh=j3WON3LL9QE3iR0hHv5oygEjLhIxYqqCN93BjwyjpjI=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=XSUS1KZVzCwQSsCFi2E3RK9TJ2QFLswr+EnI36CXGYi1Xp7McbIo0P6c/6oCiD1KG FsPJfnYtvqc5HXJldI+spfmxg/GQCrFU+7PpzsPs7cJKue3CexYz1T5KwGn5vFrI9Q jNnJSalP46z/kxqfZrwD/217NW91SpSQe3RKahtY= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2D7C7F805C3; Sat, 20 May 2023 09:02:42 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id D2E07F805AF; Sat, 20 May 2023 09:02:41 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id AAFFDF8025A; Sat, 20 May 2023 09:01:37 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 989E4F802E8 for ; Sat, 20 May 2023 09:00:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 989E4F802E8 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sczDET0f; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=gFQuC1Rg Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 675B11FE41; Sat, 20 May 2023 07:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J/punAocWtibjwVL1vtC1KZoF82Z+LthzSAiuwKq6hM=; b=sczDET0fk22h7y4IbxM8ATdvRn/SIkU8iU7vAaMZFdzbWYC7jaMdimT5oyL/Pj1IT8HCpc LFhNtFltmz5/s4oAHrxCwb89Rcf5AzKhd0B4Dmbb/8czWoWGozxmCFhO1RrkLCH3xebaKP 6u7dXig2sxU8PPbnZr5dU9kxT6r4FRc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J/punAocWtibjwVL1vtC1KZoF82Z+LthzSAiuwKq6hM=; b=gFQuC1RgrQPd6MxqgpJRGAxH8SjqVIGZo+xwiFN0HFpTgNkEAx0k/OxQMd4kysn0g8uZFH MaKGJPKfBC49HcDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4C638134F5; Sat, 20 May 2023 07:00:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WE3fEQpwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:26 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 7/8] uapi: Update asequencer.h definitions for 1.0.3 Date: Sat, 20 May 2023 09:00:20 +0200 Message-Id: <20230520070021.1301-8-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: XBDNQTVTTEQLSVJM2QBOAS3R2QE4RDRN X-Message-ID-Hash: XBDNQTVTTEQLSVJM2QBOAS3R2QE4RDRN X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Updated from kernel for supporting UMP on sequencer API. Signed-off-by: Takashi Iwai --- include/sound/uapi/asequencer.h | 91 +++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 21 deletions(-) diff --git a/include/sound/uapi/asequencer.h b/include/sound/uapi/asequencer.h index 2d600320e2ae..3653a3f33778 100644 --- a/include/sound/uapi/asequencer.h +++ b/include/sound/uapi/asequencer.h @@ -26,7 +26,7 @@ #include /** version of the sequencer */ -#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 2) +#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 3) /** * definition of sequencer event types @@ -190,6 +190,7 @@ struct snd_seq_connect { #define SNDRV_SEQ_PRIORITY_HIGH (1<<4) /* event should be processed before others */ #define SNDRV_SEQ_PRIORITY_MASK (1<<4) +#define SNDRV_SEQ_EVENT_UMP (1<<5) /* event holds a UMP packet */ /* note event */ struct snd_seq_ev_note { @@ -268,6 +269,19 @@ struct snd_seq_ev_quote { struct snd_seq_event *event; /* quoted event */ } __attribute__((packed)); +union snd_seq_event_data { /* event data... */ + struct snd_seq_ev_note note; + struct snd_seq_ev_ctrl control; + struct snd_seq_ev_raw8 raw8; + struct snd_seq_ev_raw32 raw32; + struct snd_seq_ev_ext ext; + struct snd_seq_ev_queue_control queue; + union snd_seq_timestamp time; + struct snd_seq_addr addr; + struct snd_seq_connect connect; + struct snd_seq_result result; + struct snd_seq_ev_quote quote; +}; /* sequencer event */ struct snd_seq_event { @@ -278,25 +292,27 @@ struct snd_seq_event { unsigned char queue; /* schedule queue */ union snd_seq_timestamp time; /* schedule time */ - struct snd_seq_addr source; /* source address */ struct snd_seq_addr dest; /* destination address */ - union { /* event data... */ - struct snd_seq_ev_note note; - struct snd_seq_ev_ctrl control; - struct snd_seq_ev_raw8 raw8; - struct snd_seq_ev_raw32 raw32; - struct snd_seq_ev_ext ext; - struct snd_seq_ev_queue_control queue; - union snd_seq_timestamp time; - struct snd_seq_addr addr; - struct snd_seq_connect connect; - struct snd_seq_result result; - struct snd_seq_ev_quote quote; - } data; + union snd_seq_event_data data; }; + /* (compatible) event for UMP-capable clients */ +struct snd_seq_ump_event { + snd_seq_event_type_t type; /* event type */ + unsigned char flags; /* event flags */ + char tag; + unsigned char queue; /* schedule queue */ + union snd_seq_timestamp time; /* schedule time */ + struct snd_seq_addr source; /* source address */ + struct snd_seq_addr dest; /* destination address */ + + union { + union snd_seq_event_data data; + unsigned int ump[4]; + }; +}; /* * bounce event - stored as variable size data @@ -344,10 +360,11 @@ typedef int __bitwise snd_seq_client_type_t; #define KERNEL_CLIENT ((snd_seq_client_type_t) 2) /* event filter flags */ -#define SNDRV_SEQ_FILTER_BROADCAST (1<<0) /* accept broadcast messages */ -#define SNDRV_SEQ_FILTER_MULTICAST (1<<1) /* accept multicast messages */ -#define SNDRV_SEQ_FILTER_BOUNCE (1<<2) /* accept bounce event in error */ -#define SNDRV_SEQ_FILTER_USE_EVENT (1<<31) /* use event filter */ +#define SNDRV_SEQ_FILTER_BROADCAST (1U<<0) /* accept broadcast messages */ +#define SNDRV_SEQ_FILTER_MULTICAST (1U<<1) /* accept multicast messages */ +#define SNDRV_SEQ_FILTER_BOUNCE (1U<<2) /* accept bounce event in error */ +#define SNDRV_SEQ_FILTER_NO_CONVERT (1U<<30) /* don't convert UMP events */ +#define SNDRV_SEQ_FILTER_USE_EVENT (1U<<31) /* use event filter */ struct snd_seq_client_info { int client; /* client number to inquire */ @@ -360,9 +377,15 @@ struct snd_seq_client_info { int event_lost; /* number of lost events */ int card; /* RO: card number[kernel] */ int pid; /* RO: pid[user] */ - char reserved[56]; /* for future use */ + unsigned int midi_version; /* MIDI version */ + unsigned int group_filter; /* UMP group filter bitmap */ + char reserved[48]; /* for future use */ }; +/* MIDI version numbers in client info */ +#define SNDRV_SEQ_CLIENT_LEGACY_MIDI 0 /* Legacy client */ +#define SNDRV_SEQ_CLIENT_UMP_MIDI_1_0 1 /* UMP MIDI 1.0 */ +#define SNDRV_SEQ_CLIENT_UMP_MIDI_2_0 2 /* UMP MIDI 2.0 */ /* client pool size */ struct snd_seq_client_pool { @@ -422,6 +445,8 @@ struct snd_seq_remove_events { #define SNDRV_SEQ_PORT_CAP_SUBS_READ (1<<5) /* allow read subscription */ #define SNDRV_SEQ_PORT_CAP_SUBS_WRITE (1<<6) /* allow write subscription */ #define SNDRV_SEQ_PORT_CAP_NO_EXPORT (1<<7) /* routing not allowed */ +#define SNDRV_SEQ_PORT_CAP_INACTIVE (1<<8) /* inactive port */ +#define SNDRV_SEQ_PORT_CAP_UMP_ENDPOINT (1<<9) /* MIDI 2.0 UMP Endpoint port */ /* port type */ #define SNDRV_SEQ_PORT_TYPE_SPECIFIC (1<<0) /* hardware specific */ @@ -431,6 +456,7 @@ struct snd_seq_remove_events { #define SNDRV_SEQ_PORT_TYPE_MIDI_XG (1<<4) /* XG compatible device */ #define SNDRV_SEQ_PORT_TYPE_MIDI_MT32 (1<<5) /* MT-32 compatible device */ #define SNDRV_SEQ_PORT_TYPE_MIDI_GM2 (1<<6) /* General MIDI 2 compatible device */ +#define SNDRV_SEQ_PORT_TYPE_MIDI_UMP (1<<7) /* UMP */ /* other standards...*/ #define SNDRV_SEQ_PORT_TYPE_SYNTH (1<<10) /* Synth device (no MIDI compatible - direct wavetable) */ @@ -448,6 +474,12 @@ struct snd_seq_remove_events { #define SNDRV_SEQ_PORT_FLG_TIMESTAMP (1<<1) #define SNDRV_SEQ_PORT_FLG_TIME_REAL (1<<2) +/* port direction */ +#define SNDRV_SEQ_PORT_DIR_UNKNOWN 0 +#define SNDRV_SEQ_PORT_DIR_INPUT 1 +#define SNDRV_SEQ_PORT_DIR_OUTPUT 2 +#define SNDRV_SEQ_PORT_DIR_BIDIRECTION 3 + struct snd_seq_port_info { struct snd_seq_addr addr; /* client/port numbers */ char name[64]; /* port name */ @@ -464,7 +496,9 @@ struct snd_seq_port_info { void *kernel; /* reserved for kernel use (must be NULL) */ unsigned int flags; /* misc. conditioning */ unsigned char time_queue; /* queue # for timestamping */ - char reserved[59]; /* for future use */ + unsigned char direction; /* port usage direction (r/w/bidir) */ + unsigned char ump_group; /* 0 = UMP EP (no conversion), 1-16 = UMP group number */ + char reserved[57]; /* for future use */ }; @@ -568,6 +602,18 @@ struct snd_seq_query_subs { char reserved[64]; /* for future use */ }; +/* + * UMP-specific information + */ +/* type of UMP info query */ +#define SNDRV_SEQ_CLIENT_UMP_INFO_ENDPOINT 0 +#define SNDRV_SEQ_CLIENT_UMP_INFO_BLOCK 1 + +struct snd_seq_client_ump_info { + int client; /* client number to inquire/set */ + int type; /* type to inquire/set */ + unsigned char info[512]; /* info (either UMP ep or block info) */ +} __packed; /* * IOCTL commands @@ -577,9 +623,12 @@ struct snd_seq_query_subs { #define SNDRV_SEQ_IOCTL_CLIENT_ID _IOR ('S', 0x01, int) #define SNDRV_SEQ_IOCTL_SYSTEM_INFO _IOWR('S', 0x02, struct snd_seq_system_info) #define SNDRV_SEQ_IOCTL_RUNNING_MODE _IOWR('S', 0x03, struct snd_seq_running_info) +#define SNDRV_SEQ_IOCTL_USER_PVERSION _IOW('S', 0x04, int) #define SNDRV_SEQ_IOCTL_GET_CLIENT_INFO _IOWR('S', 0x10, struct snd_seq_client_info) #define SNDRV_SEQ_IOCTL_SET_CLIENT_INFO _IOW ('S', 0x11, struct snd_seq_client_info) +#define SNDRV_SEQ_IOCTL_GET_CLIENT_UMP_INFO _IOWR('S', 0x12, struct snd_seq_client_ump_info) +#define SNDRV_SEQ_IOCTL_SET_CLIENT_UMP_INFO _IOWR('S', 0x13, struct snd_seq_client_ump_info) #define SNDRV_SEQ_IOCTL_CREATE_PORT _IOWR('S', 0x20, struct snd_seq_port_info) #define SNDRV_SEQ_IOCTL_DELETE_PORT _IOW ('S', 0x21, struct snd_seq_port_info) From patchwork Sat May 20 07:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13249121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B38FC77B7F for ; Sat, 20 May 2023 07:06:06 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 02DCF741; Sat, 20 May 2023 09:05:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 02DCF741 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684566364; bh=c8H5CQpE+WMrFxh3uXlk3bLpjR+YeKDIFU6QTRcxSzU=; h=From:To:Subject:Date:In-Reply-To:References:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From; b=qh94rp1Sgx0E/UzYtRwUhdmyv9SuHcLhxwpFSTe3kd76ZyJt8vHG40O6DLudMiet4 EYcB4QAiv1Hn+R0SzLvR1sXxPl8diN8R//D4cDzWM5FZz9xg8mfbaNBMB2JEv8PJlZ tuII/fFF0yUyBX/L41olfaMDt/YGlFB3UJNUhIWA= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 26948F805D8; Sat, 20 May 2023 09:02:43 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id BFE4DF805D7; Sat, 20 May 2023 09:02:42 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 331B6F8025A; Sat, 20 May 2023 09:01:51 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id AEF28F80544 for ; Sat, 20 May 2023 09:00:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AEF28F80544 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=2AWmzGvx; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=k1XyaL5i Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9236E220DA; Sat, 20 May 2023 07:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fJegDoYiJ8WeRtzRfbaFkcbgy2+RCEIHxHTeLpwWoHM=; b=2AWmzGvx9SLWem8enHoZjZo0qryd6MCgUYlc39bcrAGgaAmCMv+JVmFZnqmJ4dNOkmcuC0 u75YUZ6gUa9Gqdiedd0ZwMf19JrWkOGgROgBkuZz0Z9w1VfmfflX97Q0wkZ6T3gUobenSU /fwG3wuz62gahZ/8a+2YowYnrFLDz7k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684566026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fJegDoYiJ8WeRtzRfbaFkcbgy2+RCEIHxHTeLpwWoHM=; b=k1XyaL5iqe2F+m+G0+TY1vAgwrAylIR0ip16LhVPRx9zidTb3mXhGKgiXX6RVQ/6FhyUUe aVdpo0osFkMkYqAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6D32D134F5; Sat, 20 May 2023 07:00:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gKrPGQpwaGTwGwAAMHmgww (envelope-from ); Sat, 20 May 2023 07:00:26 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib 8/8] seq: Add UMP support Date: Sat, 20 May 2023 09:00:21 +0200 Message-Id: <20230520070021.1301-9-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230520070021.1301-1-tiwai@suse.de> References: <20230520070021.1301-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: SK4LCRBFVBGMZX33ND7LX5OCIRRDMING X-Message-ID-Hash: SK4LCRBFVBGMZX33ND7LX5OCIRRDMING X-MailFrom: tiwai@suse.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This patch adds the basic support of UMP on ALSA sequencer API. An extended event type, snd_seq_ump_event_t, is defined. It's compatible with the existing type, snd_seq_event_t, but it has a larger payload of 16 bytes instead of 12 bytes, for holding the full 128bit UMP packet. The new snd_seq_ump_event_t must have the bit SND_SEQ_EVENT_UMP in the event flags. A few new API functions have been added such as snd_seq_ump_event_output() and snd_seq_ump_event_input() for reading/writing this new event object. The support of UMP in the sequencer client is switched by the function snd_seq_client_set_midi_version(). It can switch from the default legacy MIDI to UMP MIDI 1.0 or 2.0 on the fly. The automatic event conversion among UMP and legacy clients can be suppressed via snd_seq_client_set_ump_conversion(). The inquiry of the associated UMP Endpoints and UMP Blocks can be done via snd_seq_get_ump_endpoint_info() and snd_seq_get_ump_block_info(). Signed-off-by: Takashi Iwai --- include/local.h | 2 + include/seq.h | 44 +++++ include/seq_event.h | 42 +++-- include/seqmid.h | 24 +++ src/Versions.in | 17 ++ src/seq/seq.c | 410 ++++++++++++++++++++++++++++++++++++++++---- src/seq/seq_hw.c | 72 +++++++- src/seq/seq_local.h | 6 +- src/seq/seqmid.c | 38 ++++ 9 files changed, 604 insertions(+), 51 deletions(-) diff --git a/include/local.h b/include/local.h index 51042d764f65..0a19e70192d5 100644 --- a/include/local.h +++ b/include/local.h @@ -195,7 +195,9 @@ #define snd_seq_real_time sndrv_seq_real_time #define snd_seq_timestamp sndrv_seq_timestamp #define snd_seq_event_type_t sndrv_seq_event_type_t +#define snd_seq_event_data sndrv_seq_event_data #define snd_seq_event sndrv_seq_event +#define snd_seq_ump_event sndrv_seq_ump_event #define snd_seq_connect sndrv_seq_connect #define snd_seq_ev_note sndrv_seq_ev_note #define snd_seq_ev_ctrl sndrv_seq_ev_ctrl diff --git a/include/seq.h b/include/seq.h index 123a1057f568..7faf4367df3d 100644 --- a/include/seq.h +++ b/include/seq.h @@ -130,6 +130,13 @@ typedef enum snd_seq_client_type { SND_SEQ_KERNEL_CLIENT = 2 /**< kernel client */ } snd_seq_client_type_t; +/** client MIDI version */ +enum { + SND_SEQ_CLIENT_LEGACY_MIDI = 0, /**< Legacy client */ + SND_SEQ_CLIENT_UMP_MIDI_1_0 = 1, /**< UMP MIDI 1.0 */ + SND_SEQ_CLIENT_UMP_MIDI_2_0 = 2 /**< UMP MIDI 2.0 */ +}; + size_t snd_seq_client_info_sizeof(void); /** allocate a #snd_seq_client_info_t container on stack */ #define snd_seq_client_info_alloca(ptr) \ @@ -149,11 +156,19 @@ const unsigned char *snd_seq_client_info_get_event_filter(const snd_seq_client_i int snd_seq_client_info_get_num_ports(const snd_seq_client_info_t *info); int snd_seq_client_info_get_event_lost(const snd_seq_client_info_t *info); +int snd_seq_client_info_get_midi_version(const snd_seq_client_info_t *info); +int snd_seq_client_info_get_ump_group_enabled(const snd_seq_client_info_t *info, + int group); +int snd_seq_client_info_get_ump_conversion(const snd_seq_client_info_t *info); void snd_seq_client_info_set_client(snd_seq_client_info_t *info, int client); void snd_seq_client_info_set_name(snd_seq_client_info_t *info, const char *name); void snd_seq_client_info_set_broadcast_filter(snd_seq_client_info_t *info, int val); void snd_seq_client_info_set_error_bounce(snd_seq_client_info_t *info, int val); void snd_seq_client_info_set_event_filter(snd_seq_client_info_t *info, unsigned char *filter); +void snd_seq_client_info_set_midi_version(snd_seq_client_info_t *info, int midi_version); +void snd_seq_client_info_set_ump_group_enabled(snd_seq_client_info_t *info, + int group, int enable); +void snd_seq_client_info_set_ump_conversion(snd_seq_client_info_t *info, int enable); void snd_seq_client_info_event_filter_clear(snd_seq_client_info_t *info); void snd_seq_client_info_event_filter_add(snd_seq_client_info_t *info, int event_type); @@ -165,6 +180,11 @@ int snd_seq_get_any_client_info(snd_seq_t *handle, int client, snd_seq_client_in int snd_seq_set_client_info(snd_seq_t *handle, snd_seq_client_info_t *info); int snd_seq_query_next_client(snd_seq_t *handle, snd_seq_client_info_t *info); +int snd_seq_get_ump_endpoint_info(snd_seq_t *seq, int client, void *info); +int snd_seq_get_ump_block_info(snd_seq_t *seq, int client, int blk, void *info); +int snd_seq_set_ump_endpoint_info(snd_seq_t *seq, const void *info); +int snd_seq_set_ump_block_info(snd_seq_t *seq, int blk, const void *info); + /* */ @@ -222,6 +242,14 @@ typedef struct _snd_seq_port_info snd_seq_port_info_t; #define SND_SEQ_PORT_CAP_SUBS_READ (1<<5) /**< allow read subscription */ #define SND_SEQ_PORT_CAP_SUBS_WRITE (1<<6) /**< allow write subscription */ #define SND_SEQ_PORT_CAP_NO_EXPORT (1<<7) /**< routing not allowed */ +#define SND_SEQ_PORT_CAP_INACTIVE (1<<8) /**< inactive port */ +#define SND_SEQ_PORT_CAP_UMP_ENDPOINT (1<<9) /**< UMP Endpoint port */ + +/** port direction */ +#define SND_SEQ_PORT_DIR_UNKNOWN 0 /**< Unknown */ +#define SND_SEQ_PORT_DIR_INPUT 1 /**< Input only */ +#define SND_SEQ_PORT_DIR_OUTPUT 2 /**< Output only */ +#define SND_SEQ_PORT_DIR_BIDIRECTION 3 /**< Input/output bidirectional */ /* port type */ /** Messages sent from/to this port have device-specific semantics. */ @@ -238,6 +266,8 @@ typedef struct _snd_seq_port_info snd_seq_port_info_t; #define SND_SEQ_PORT_TYPE_MIDI_MT32 (1<<5) /** This port is compatible with the General MIDI 2 specification. */ #define SND_SEQ_PORT_TYPE_MIDI_GM2 (1<<6) +/** This port is a UMP port. */ +#define SND_SEQ_PORT_TYPE_MIDI_UMP (1<<7) /** This port understands SND_SEQ_EVENT_SAMPLE_xxx messages (these are not MIDI messages). */ #define SND_SEQ_PORT_TYPE_SYNTH (1<<10) @@ -283,6 +313,8 @@ int snd_seq_port_info_get_port_specified(const snd_seq_port_info_t *info); int snd_seq_port_info_get_timestamping(const snd_seq_port_info_t *info); int snd_seq_port_info_get_timestamp_real(const snd_seq_port_info_t *info); int snd_seq_port_info_get_timestamp_queue(const snd_seq_port_info_t *info); +int snd_seq_port_info_get_direction(const snd_seq_port_info_t *info); +int snd_seq_port_info_get_ump_group(const snd_seq_port_info_t *info); void snd_seq_port_info_set_client(snd_seq_port_info_t *info, int client); void snd_seq_port_info_set_port(snd_seq_port_info_t *info, int port); @@ -297,6 +329,8 @@ void snd_seq_port_info_set_port_specified(snd_seq_port_info_t *info, int val); void snd_seq_port_info_set_timestamping(snd_seq_port_info_t *info, int enable); void snd_seq_port_info_set_timestamp_real(snd_seq_port_info_t *info, int realtime); void snd_seq_port_info_set_timestamp_queue(snd_seq_port_info_t *info, int queue); +void snd_seq_port_info_set_direction(snd_seq_port_info_t *info, int direction); +void snd_seq_port_info_set_ump_gruop(snd_seq_port_info_t *info, int ump_group); int snd_seq_create_port(snd_seq_t *handle, snd_seq_port_info_t *info); int snd_seq_delete_port(snd_seq_t *handle, int port); @@ -572,6 +606,12 @@ void snd_seq_remove_events_set_tag(snd_seq_remove_events_t *info, int tag); int snd_seq_remove_events(snd_seq_t *handle, snd_seq_remove_events_t *info); +int snd_seq_ump_event_output(snd_seq_t *seq, snd_seq_ump_event_t *ev); +int snd_seq_ump_event_output_buffer(snd_seq_t *seq, snd_seq_ump_event_t *ev); +int snd_seq_ump_extract_output(snd_seq_t *seq, snd_seq_ump_event_t **ev_res); +int snd_seq_ump_event_output_direct(snd_seq_t *seq, snd_seq_ump_event_t *ev); +int snd_seq_ump_event_input(snd_seq_t *seq, snd_seq_ump_event_t **ev); + /** \} */ /** @@ -729,6 +769,10 @@ extern const unsigned int snd_seq_event_types[]; #define snd_seq_ev_is_direct(ev) \ ((ev)->queue == SND_SEQ_QUEUE_DIRECT) +/** UMP events */ +#define snd_seq_ev_is_ump(ev) \ + ((ev)->flags & SND_SEQ_EVENT_UMP) + /** \} */ #ifdef __cplusplus diff --git a/include/seq_event.h b/include/seq_event.h index 60727f52a358..9ca384ee4a0a 100644 --- a/include/seq_event.h +++ b/include/seq_event.h @@ -225,6 +225,7 @@ typedef union snd_seq_timestamp { #define SND_SEQ_PRIORITY_HIGH (1<<4) /**< event should be processed before others */ #define SND_SEQ_PRIORITY_MASK (1<<4) /**< mask for priority bits */ +#define SND_SEQ_EVENT_UMP (1<<5) /**< UMP packet event */ /** Note event */ typedef struct snd_seq_ev_note { @@ -291,6 +292,19 @@ typedef struct snd_seq_ev_queue_control { } param; /**< data value union */ } snd_seq_ev_queue_control_t; +/** Sequencer event data */ +typedef union snd_seq_event_data { + snd_seq_ev_note_t note; /**< note information */ + snd_seq_ev_ctrl_t control; /**< MIDI control information */ + snd_seq_ev_raw8_t raw8; /**< raw8 data */ + snd_seq_ev_raw32_t raw32; /**< raw32 data */ + snd_seq_ev_ext_t ext; /**< external data */ + snd_seq_ev_queue_control_t queue; /**< queue control */ + snd_seq_timestamp_t time; /**< timestamp */ + snd_seq_addr_t addr; /**< address */ + snd_seq_connect_t connect; /**< connect information */ + snd_seq_result_t result; /**< operation result code */ +} snd_seq_event_data_t; /** Sequencer event */ typedef struct snd_seq_event { @@ -304,20 +318,24 @@ typedef struct snd_seq_event { snd_seq_addr_t source; /**< source address */ snd_seq_addr_t dest; /**< destination address */ - union { - snd_seq_ev_note_t note; /**< note information */ - snd_seq_ev_ctrl_t control; /**< MIDI control information */ - snd_seq_ev_raw8_t raw8; /**< raw8 data */ - snd_seq_ev_raw32_t raw32; /**< raw32 data */ - snd_seq_ev_ext_t ext; /**< external data */ - snd_seq_ev_queue_control_t queue; /**< queue control */ - snd_seq_timestamp_t time; /**< timestamp */ - snd_seq_addr_t addr; /**< address */ - snd_seq_connect_t connect; /**< connect information */ - snd_seq_result_t result; /**< operation result code */ - } data; /**< event data... */ + snd_seq_event_data_t data; /**< event data... */ } snd_seq_event_t; +/** UMP sequencer event; compatible with legacy sequencer event */ +typedef struct snd_seq_ump_event { + snd_seq_event_type_t type; /**< event type */ + unsigned char flags; /**< event flags */ + unsigned char tag; /**< tag */ + unsigned char queue; /**< schedule queue */ + snd_seq_timestamp_t time; /**< schedule time */ + snd_seq_addr_t source; /**< source address */ + snd_seq_addr_t dest; /**< destination address */ + + union { + snd_seq_event_data_t data; /**< (shared) legacy data */ + unsigned int ump[4]; /**< UMP data bytes */ + }; +} snd_seq_ump_event_t; /** \} */ diff --git a/include/seqmid.h b/include/seqmid.h index 3986628a06f3..4089ac207861 100644 --- a/include/seqmid.h +++ b/include/seqmid.h @@ -284,6 +284,28 @@ extern "C" { (ev)->data.queue.queue = (q),\ (ev)->data.queue.param.time.tick = (ttime)) +/** + * \brief set the event UMP flag + * \param ev event record + */ +static inline void snd_seq_ev_set_ump(snd_seq_ump_event_t *ev) +{ + ev->flags |= SND_SEQ_EVENT_UMP; + ev->type = 0; /* unused for UMP */ +} + +/** + * \brief set the event UMP flag and fill UMP raw bytes + * \param ev event record + * \param data UMP packet data + * \param bytes UMP packet size in bytes + */ +static inline void snd_seq_ev_set_ump_data(snd_seq_ump_event_t *ev, void *data, size_t bytes) +{ + snd_seq_ev_set_ump(ev); + memcpy(ev->ump, data, bytes); +} + /* set and send a queue control event */ int snd_seq_control_queue(snd_seq_t *seq, int q, int type, int value, snd_seq_event_t *ev); @@ -343,6 +365,8 @@ int snd_seq_disconnect_to(snd_seq_t *seq, int my_port, int dest_client, int dest */ int snd_seq_set_client_name(snd_seq_t *seq, const char *name); int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type); +int snd_seq_set_client_midi_version(snd_seq_t *seq, int midi_version); +int snd_seq_set_client_ump_conversion(snd_seq_t *seq, int enable); int snd_seq_set_client_pool_output(snd_seq_t *seq, size_t size); int snd_seq_set_client_pool_output_room(snd_seq_t *seq, size_t size); int snd_seq_set_client_pool_input(snd_seq_t *seq, size_t size); diff --git a/src/Versions.in b/src/Versions.in index 3315fa2840e0..3a6ae5dbbbb0 100644 --- a/src/Versions.in +++ b/src/Versions.in @@ -153,4 +153,21 @@ ALSA_1.2.10 { global: @SYMBOL_PREFIX@snd_ump_*; + @SYMBOL_PREFIX@snd_seq_ump_*; + @SYMBOL_PREFIX@snd_seq_client_info_get_midi_version; + @SYMBOL_PREFIX@snd_seq_seq_client_info_get_ump_group_enabled; + @SYMBOL_PREFIX@snd_seq_seq_client_get_ump_conversion; + @SYMBOL_PREFIX@snd_seq_client_info_set_midi_version; + @SYMBOL_PREFIX@snd_seq_seq_client_info_set_ump_group_enabled; + @SYMBOL_PREFIX@snd_seq_seq_client_set_ump_conversion; + @SYMBOL_PREFIX@snd_seq_get_ump_endpoint_info; + @SYMBOL_PREFIX@snd_seq_get_ump_block_info; + @SYMBOL_PREFIX@snd_seq_set_ump_endpoint_info; + @SYMBOL_PREFIX@snd_seq_set_ump_block_info; + @SYMBOL_PREFIX@snd_seq_port_info_get_direction; + @SYMBOL_PREFIX@snd_seq_port_info_get_ump_group; + @SYMBOL_PREFIX@snd_seq_port_info_set_direction; + @SYMBOL_PREFIX@snd_seq_port_info_set_ump_group; + @SYMBOL_PREFIX@snd_seq_set_client_midi_version; + @SYMBOL_PREFIX@snd_seq_set_client_ump_conversion; } ALSA_1.2.9; diff --git a/src/seq/seq.c b/src/seq/seq.c index f051426f9648..65ccaaed5896 100644 --- a/src/seq/seq.c +++ b/src/seq/seq.c @@ -1204,6 +1204,11 @@ size_t snd_seq_get_output_buffer_size(snd_seq_t *seq) return seq->obufsize; } +static inline size_t get_packet_size(snd_seq_t *seq) +{ + return seq->packet_size ? seq->packet_size : sizeof(snd_seq_event_t); +} + /** * \brief Return the size of input buffer * \param seq sequencer handle @@ -1219,7 +1224,7 @@ size_t snd_seq_get_input_buffer_size(snd_seq_t *seq) assert(seq); if (!seq->ibuf) return 0; - return seq->ibufsize * sizeof(snd_seq_event_t); + return seq->ibufsize * get_packet_size(seq); } /** @@ -1261,13 +1266,17 @@ int snd_seq_set_output_buffer_size(snd_seq_t *seq, size_t size) */ int snd_seq_set_input_buffer_size(snd_seq_t *seq, size_t size) { + size_t packet_size; + assert(seq && seq->ibuf); - assert(size >= sizeof(snd_seq_event_t)); + assert(size >= packet_size); snd_seq_drop_input(seq); - size = (size + sizeof(snd_seq_event_t) - 1) / sizeof(snd_seq_event_t); + packet_size = get_packet_size(seq); + size = (size + packet_size - 1) / packet_size; if (size != seq->ibufsize) { - snd_seq_event_t *newbuf; - newbuf = calloc(sizeof(snd_seq_event_t), size); + char *newbuf; + /* use ump event size for avoiding reallocation at switching */ + newbuf = calloc(sizeof(snd_seq_ump_event_t), size); if (newbuf == NULL) return -ENOMEM; free(seq->ibuf); @@ -1726,6 +1735,47 @@ int snd_seq_client_info_get_event_lost(const snd_seq_client_info_t *info) return info->event_lost; } +/** + * \brief Get the MIDI protocol version number of a client_info container + * \param info client_info container + * \return MIDI protocol version + * + * \sa snd_seq_get_client_info() + */ +int snd_seq_client_info_get_midi_version(const snd_seq_client_info_t *info) +{ + assert(info); + return info->midi_version; +} + +/** + * \brief Get the UMP group filter status + * \param info client_info container + * \param group 0-based group index + * \return 0 if the group is filtered / disabled, 1 if it's processed + * + * \sa snd_seq_get_client_info() + */ +int snd_seq_client_info_get_ump_group_enabled(const snd_seq_client_info_t *info, + int group) +{ + assert(info); + return !(info->group_filter & (1U << group)); +} + +/** + * \brief Get the automatic conversion mode for UMP + * \param info client_info container + * \return 1 if the conversion is enabled, 0 if not + * + * \sa snd_seq_get_client_info() + */ +int snd_seq_client_info_get_ump_conversion(const snd_seq_client_info_t *info) +{ + assert(info); + return info->midi_version; +} + /** * \brief Set the client id of a client_info container * \param info client_info container @@ -1769,6 +1819,54 @@ void snd_seq_client_info_set_broadcast_filter(snd_seq_client_info_t *info, int v info->filter &= ~SNDRV_SEQ_FILTER_BROADCAST; } +/** + * \brief Set the MIDI protocol version of a client_info container + * \param info client_info container + * \param midi_version MIDI protocol version to set + * + * \sa snd_seq_get_client_info(), snd_seq_client_info_get_midi_version() + */ +void snd_seq_client_info_set_midi_version(snd_seq_client_info_t *info, int midi_version) +{ + assert(info); + info->midi_version = midi_version; +} + +/** + * \brief Set the UMP group filter status + * \param info client_info container + * \param group 0-based group index + * \param enable 0 to filter/disable the group, non-zero to enable + * + * \sa snd_seq_set_client_info(), snd_seq_client_info_get_ump_group_enabled() + */ +void snd_seq_client_info_set_ump_group_enabled(snd_seq_client_info_t *info, + int group, int enable) +{ + assert(info); + if (enable) + info->group_filter &= ~(1U << group); + else + info->group_filter |= (1U << group); +} + +/** + * \brief Set the automatic conversion mode for UMP + * \param info client_info container + * \param enable 0 or 1 for disabling/enabling the conversion + * + * \sa snd_seq_set_client_info(), snd_seq_client_info_get_ump_conversion() + */ +void snd_seq_client_info_set_ump_conversion(snd_seq_client_info_t *info, + int enable) +{ + assert(info); + if (enable) + info->filter &= ~SNDRV_SEQ_FILTER_NO_CONVERT; + else + info->filter |= SNDRV_SEQ_FILTER_NO_CONVERT; +} + /** * \brief Set the error-bounce usage of a client_info container * \param info client_info container @@ -1887,6 +1985,65 @@ int snd_seq_query_next_client(snd_seq_t *seq, snd_seq_client_info_t *info) return seq->ops->query_next_client(seq, info); } +/** + * \brief Get UMP Endpoint information + * \param seq sequencer handle + * \param client client number to query + * \param info the pointer to store snd_ump_endpoint_info_t data + * \return 0 on success otherwise a negative error code + */ +int snd_seq_get_ump_endpoint_info(snd_seq_t *seq, int client, void *info) +{ + assert(seq && info); + return seq->ops->get_ump_info(seq, client, + SNDRV_SEQ_CLIENT_UMP_INFO_ENDPOINT, + info); +} + +/** + * \brief Get UMP Block information + * \param seq sequencer handle + * \param client sequencer client number to query + * \param blk UMP block number (0-based) to query + * \param info the pointer to store snd_ump_block_info_t data + * \return 0 on success otherwise a negative error code + */ +int snd_seq_get_ump_block_info(snd_seq_t *seq, int client, int blk, void *info) +{ + assert(seq && info); + return seq->ops->get_ump_info(seq, client, + SNDRV_SEQ_CLIENT_UMP_INFO_BLOCK + blk, + info); +} + +/** + * \brief Set UMP Endpoint information to the current client + * \param seq sequencer handle + * \param info the pointer to send snd_ump_endpoint_info_t data + * \return 0 on success otherwise a negative error code + */ +int snd_seq_set_ump_endpoint_info(snd_seq_t *seq, const void *info) +{ + assert(seq && info); + return seq->ops->set_ump_info(seq, + SNDRV_SEQ_CLIENT_UMP_INFO_ENDPOINT, + info); +} + +/** + * \brief Set UMP Block information to the current client + * \param seq sequencer handle + * \param blk UMP block number (0-based) to send + * \param info the pointer to send snd_ump_block_info_t data + * \return 0 on success otherwise a negative error code + */ +int snd_seq_set_ump_block_info(snd_seq_t *seq, int blk, const void *info) +{ + assert(seq && info); + return seq->ops->set_ump_info(seq, + SNDRV_SEQ_CLIENT_UMP_INFO_BLOCK + blk, + info); +} /*----------------------------------------------------------------*/ @@ -2134,6 +2291,32 @@ int snd_seq_port_info_get_timestamp_queue(const snd_seq_port_info_t *info) return info->time_queue; } +/** + * \brief Get the direction of the port + * \param info port_info container + * \return the direction of the port + * + * \sa snd_seq_get_port_info(), snd_seq_port_info_set_direction() + */ +int snd_seq_port_info_get_direction(const snd_seq_port_info_t *info) +{ + assert(info); + return info->direction; +} + +/** + * \brief Get the UMP Group assigned to the port + * \param info port_info container + * \return 0 for no conversion, or the (1-based) UMP Group number assigned to the port + * + * \sa snd_seq_get_port_info(), snd_seq_port_info_set_ump_group() + */ +int snd_seq_port_info_get_ump_group(const snd_seq_port_info_t *info) +{ + assert(info); + return info->ump_group; +} + /** * \brief Set the client id of a port_info container * \param info port_info container @@ -2312,6 +2495,31 @@ void snd_seq_port_info_set_timestamp_queue(snd_seq_port_info_t *info, int queue) info->time_queue = queue; } +/** + * \brief Set the direction of the port + * \param info port_info container + * \param direction the port direction + * + * \sa snd_seq_get_port_info(), snd_seq_port_info_get_direction() + */ +void snd_seq_port_info_set_direction(snd_seq_port_info_t *info, int direction) +{ + assert(info); + info->direction = direction; +} + +/** + * \brief Set the UMP Group assigned to the port + * \param info port_info container + * \param ump_group 0 for no conversion, or the (1-based) UMP Group number + * + * \sa snd_seq_get_port_info(), snd_seq_port_info_get_ump_gruop() + */ +void snd_seq_port_info_set_ump_group(snd_seq_port_info_t *info, int ump_group) +{ + assert(info); + info->ump_group = ump_group; +} /** * \brief create a sequencer port on the current client @@ -3874,7 +4082,9 @@ ssize_t snd_seq_event_length(snd_seq_event_t *ev) { ssize_t len = sizeof(snd_seq_event_t); assert(ev); - if (snd_seq_ev_is_variable(ev)) + if (snd_seq_ev_is_ump(ev)) + len = sizeof(snd_seq_ump_event_t); + else if (snd_seq_ev_is_variable(ev)) len += ev->data.ext.len; return len; } @@ -3925,7 +4135,10 @@ int snd_seq_event_output(snd_seq_t *seq, snd_seq_event_t *ev) * * This function doesn't drain buffer unlike snd_seq_event_output(). * - * \sa snd_seq_event_output() + * \note + * For a UMP event, use snd_seq_ump_event_output_buffer() instead. + * + * \sa snd_seq_event_output(), snd_seq_ump_event_output_buffer() */ int snd_seq_event_output_buffer(snd_seq_t *seq, snd_seq_event_t *ev) { @@ -3938,12 +4151,15 @@ int snd_seq_event_output_buffer(snd_seq_t *seq, snd_seq_event_t *ev) return -EINVAL; if ((seq->obufsize - seq->obufused) < (size_t) len) return -EAGAIN; - memcpy(seq->obuf + seq->obufused, ev, sizeof(snd_seq_event_t)); - seq->obufused += sizeof(snd_seq_event_t); - if (snd_seq_ev_is_variable(ev)) { - memcpy(seq->obuf + seq->obufused, ev->data.ext.ptr, ev->data.ext.len); - seq->obufused += ev->data.ext.len; + if (snd_seq_ev_is_ump(ev)) { + memcpy(seq->obuf + seq->obufused, ev, sizeof(snd_seq_ump_event_t)); + } else { + memcpy(seq->obuf + seq->obufused, ev, sizeof(snd_seq_event_t)); + if (snd_seq_ev_is_variable(ev)) + memcpy(seq->obuf + seq->obufused + sizeof(snd_seq_event_t), + ev->data.ext.ptr, ev->data.ext.len); } + seq->obufused += len; return seq->obufused; } @@ -3991,7 +4207,7 @@ int snd_seq_event_output_direct(snd_seq_t *seq, snd_seq_event_t *ev) len = snd_seq_event_length(ev); if (len < 0) return len; - else if (len == sizeof(*ev)) { + if (snd_seq_ev_is_ump(ev) || !snd_seq_ev_is_variable(ev)) { buf = ev; } else { if (alloc_tmpbuf(seq, (size_t)len) < 0) @@ -4049,6 +4265,36 @@ int snd_seq_drain_output(snd_seq_t *seq) return 0; } +static int extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res, int ump_allowed) +{ + size_t len, olen; + assert(seq); + if (ev_res) + *ev_res = NULL; + repeat: + if ((olen = seq->obufused) < sizeof(snd_seq_event_t)) + return -ENOENT; + len = snd_seq_event_length((snd_seq_event_t *)seq->obuf); + if (olen < len) + return -ENOENT; + /* skip invalid UMP events */ + if (snd_seq_ev_is_ump((snd_seq_event_t *)seq->obuf) && !ump_allowed) { + seq->obufused -= len; + memmove(seq->obuf, seq->obuf + len, seq->obufused); + goto repeat; + } + if (ev_res) { + /* extract the event */ + if (alloc_tmpbuf(seq, len) < 0) + return -ENOMEM; + memcpy(seq->tmpbuf, seq->obuf, len); + *ev_res = (snd_seq_event_t *)seq->tmpbuf; + } + seq->obufused = olen - len; + memmove(seq->obuf, seq->obuf + len, seq->obufused); + return 0; +} + /** * \brief extract the first event in output buffer * \param seq sequencer handle @@ -4062,25 +4308,7 @@ int snd_seq_drain_output(snd_seq_t *seq) */ int snd_seq_extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res) { - size_t len, olen; - snd_seq_event_t ev; - assert(seq); - if (ev_res) - *ev_res = NULL; - if ((olen = seq->obufused) < sizeof(snd_seq_event_t)) - return -ENOENT; - memcpy(&ev, seq->obuf, sizeof(snd_seq_event_t)); - len = snd_seq_event_length(&ev); - if (ev_res) { - /* extract the event */ - if (alloc_tmpbuf(seq, len) < 0) - return -ENOMEM; - memcpy(seq->tmpbuf, seq->obuf, len); - *ev_res = seq->tmpbuf; - } - seq->obufused = olen - len; - memmove(seq->obuf, seq->obuf + len, seq->obufused); - return 0; + return extract_output(seq, ev_res, 0); } /*----------------------------------------------------------------*/ @@ -4094,32 +4322,35 @@ int snd_seq_extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res) */ static ssize_t snd_seq_event_read_buffer(snd_seq_t *seq) { + size_t packet_size = get_packet_size(seq); ssize_t len; - len = (seq->ops->read)(seq, seq->ibuf, seq->ibufsize * sizeof(snd_seq_event_t)); + + len = (seq->ops->read)(seq, seq->ibuf, seq->ibufsize * packet_size); if (len < 0) return len; - seq->ibuflen = len / sizeof(snd_seq_event_t); + seq->ibuflen = len / packet_size; seq->ibufptr = 0; return seq->ibuflen; } static int snd_seq_event_retrieve_buffer(snd_seq_t *seq, snd_seq_event_t **retp) { + size_t packet_size = get_packet_size(seq); size_t ncells; snd_seq_event_t *ev; - *retp = ev = &seq->ibuf[seq->ibufptr]; + *retp = ev = (snd_seq_event_t *)(seq->ibuf + seq->ibufptr * packet_size); seq->ibufptr++; seq->ibuflen--; if (! snd_seq_ev_is_variable(ev)) return 1; - ncells = (ev->data.ext.len + sizeof(snd_seq_event_t) - 1) / sizeof(snd_seq_event_t); + ncells = (ev->data.ext.len + packet_size - 1) / packet_size; if (seq->ibuflen < ncells) { seq->ibuflen = 0; /* clear buffer */ *retp = NULL; return -EINVAL; } - ev->data.ext.ptr = ev + 1; + ev->data.ext.ptr = (char *)ev + packet_size; seq->ibuflen -= ncells; seq->ibufptr += ncells; return 1; @@ -4212,6 +4443,111 @@ int snd_seq_event_input_pending(snd_seq_t *seq, int fetch_sequencer) /*----------------------------------------------------------------*/ +/* + * I/O for UMP packets + */ + +/** + * \brief output a UMP event + * \param seq sequencer handle + * \param ev UMP event to be output + * \return the number of remaining events or a negative error code + * + * Just like snd_seq_event_output(), it puts an event onto the buffer, + * draining the buffer automatically when needed, but the event is + * snd_seq_ump_event_t type instead snd_seq_event_t. + * + * Calling this function is allowed only when the client is set to + * \c SND_SEQ_CLIENT_UMP_MIDI_1_0 or \c SND_SEQ_CLIENT_UMP_MIDI_2_0. + * + * The flushing and clearing of the buffer is done via the same functions, + * snd_seq_event_drain_output() and snd_seq_drop_output(). + * + * \sa snd_seq_event_output() + */ +int snd_seq_ump_event_output(snd_seq_t *seq, snd_seq_ump_event_t *ev) +{ + if (!seq->midi_version) + return -EBADFD; + return snd_seq_event_output(seq, (snd_seq_event_t *)ev); +} + +/** + * \brief output an event onto the lib buffer without draining buffer + * \param seq sequencer handle + * \param ev UMP event to be output + * \return the byte size of remaining events. \c -EAGAIN if the buffer becomes full. + * + * This is a UMP event version of snd_seq_event_output_buffer(). + * + * \sa snd_seq_event_output_buffer(), snd_seq_ump_event_output() + */ +int snd_seq_ump_event_output_buffer(snd_seq_t *seq, snd_seq_ump_event_t *ev) +{ + if (!seq->midi_version) + return -EBADFD; + return snd_seq_event_output_buffer(seq, (snd_seq_event_t *)ev); +} + +/** + * \brief extract the first UMP event in output buffer + * \param seq sequencer handle + * \param ev_res UMP event pointer to be extracted + * \return 0 on success otherwise a negative error code + * + * This is a UMP event version of snd_seq_extract_output(). + * + * \sa snd_seq_extract_output(), snd_seq_ump_event_output() + */ +int snd_seq_ump_extract_output(snd_seq_t *seq, snd_seq_ump_event_t **ev_res) +{ + if (!seq->midi_version) + return -EBADFD; + return extract_output(seq, (snd_seq_event_t **)ev_res, 1); +} + +/** + * \brief output a UMP event directly to the sequencer NOT through output buffer + * \param seq sequencer handle + * \param ev UMP event to be output + * \return the byte size sent to sequencer or a negative error code + * + * This is a UMP event version of snd_seq_event_output_direct(). + * + * \sa snd_seq_event_output_direct() + */ +int snd_seq_ump_event_output_direct(snd_seq_t *seq, snd_seq_ump_event_t *ev) +{ + if (!seq->midi_version) + return -EBADFD; + return snd_seq_event_output_direct(seq, (snd_seq_event_t *)ev); +} + +/** + * \brief retrieve a UMP event from sequencer + * \param seq sequencer handle + * \param ev UMP event pointer to be stored + * + * Like snd_seq_event_input(), this reads out the input event, but in + * snd_seq_ump_event_t type instead of snd_seq_event_t type. + * + * Calling this function is allowed only when the client is set to + * \c SND_SEQ_CLIENT_UMP_MIDI_1_0 or \c SND_SEQ_CLIENT_UMP_MIDI_2_0. + * + * For other input operations, the same function like + * snd_seq_event_input_pending() or snd_seq_drop_input() can be still used. + * + * \sa snd_seq_event_input() + */ +int snd_seq_ump_event_input(snd_seq_t *seq, snd_seq_ump_event_t **ev) +{ + if (!seq->midi_version) + return -EBADFD; + return snd_seq_event_input(seq, (snd_seq_event_t **)ev); +} + +/*----------------------------------------------------------------*/ + /* * clear event buffers */ diff --git a/src/seq/seq_hw.c b/src/seq/seq_hw.c index e4b4d2a02a0d..196de970f6f3 100644 --- a/src/seq/seq_hw.c +++ b/src/seq/seq_hw.c @@ -94,6 +94,20 @@ static int snd_seq_hw_system_info(snd_seq_t *seq, snd_seq_system_info_t * info) return 0; } +static void update_midi_version(snd_seq_t *seq, snd_seq_client_info_t *info) +{ + snd_seq_hw_t *hw = seq->private_data; + + if (SNDRV_PROTOCOL_VERSION(1, 0, 3) <= hw->version && + seq->midi_version != (int)info->midi_version) { + seq->midi_version = info->midi_version; + if (info->midi_version > 0) + seq->packet_size = sizeof(snd_seq_ump_event_t); + else + seq->packet_size = sizeof(snd_seq_event_t); + } +} + static int snd_seq_hw_get_client_info(snd_seq_t *seq, snd_seq_client_info_t * info) { snd_seq_hw_t *hw = seq->private_data; @@ -105,16 +119,64 @@ static int snd_seq_hw_get_client_info(snd_seq_t *seq, snd_seq_client_info_t * in info->card = -1; info->pid = -1; } + update_midi_version(seq, info); return 0; } static int snd_seq_hw_set_client_info(snd_seq_t *seq, snd_seq_client_info_t * info) { snd_seq_hw_t *hw = seq->private_data; + if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, info) < 0) { /*SYSERR("SNDRV_SEQ_IOCTL_SET_CLIENT_INFO failed");*/ return -errno; } + update_midi_version(seq, info); + return 0; +} + +static int snd_seq_hw_get_ump_info(snd_seq_t *seq, int client, int type, void *info) +{ + snd_seq_hw_t *hw = seq->private_data; + struct snd_seq_client_ump_info buf; + size_t size; + + if (type < 0 || type >= SNDRV_SEQ_CLIENT_UMP_INFO_BLOCK + 32) + return -EINVAL; + if (hw->version < SNDRV_PROTOCOL_VERSION(1, 0, 3)) + return -ENOTTY; + if (type == SNDRV_SEQ_CLIENT_UMP_INFO_ENDPOINT) + size = sizeof(struct snd_ump_endpoint_info); + else + size = sizeof(struct snd_ump_block_info); + buf.client = client; + buf.type = type; + if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_CLIENT_UMP_INFO, &buf) < 0) + return -errno; + memcpy(info, buf.info, size); + return 0; +} + +static int snd_seq_hw_set_ump_info(snd_seq_t *seq, int type, const void *info) +{ + snd_seq_hw_t *hw = seq->private_data; + struct snd_seq_client_ump_info buf; + size_t size; + + if (type < 0 || type >= SNDRV_SEQ_CLIENT_UMP_INFO_BLOCK + 32) + return -EINVAL; + if (hw->version < SNDRV_PROTOCOL_VERSION(1, 0, 3)) + return -ENOTTY; + if (type == SNDRV_SEQ_CLIENT_UMP_INFO_ENDPOINT) + size = sizeof(struct snd_ump_endpoint_info); + else + size = sizeof(struct snd_ump_block_info); + buf.client = seq->client; + buf.type = type; + memcpy(buf.info, info, size); + *(int *)buf.info = -1; /* invalidate the card number */ + if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_CLIENT_UMP_INFO, &buf) < 0) + return -errno; return 0; } @@ -396,6 +458,8 @@ static const snd_seq_ops_t snd_seq_hw_ops = { .system_info = snd_seq_hw_system_info, .get_client_info = snd_seq_hw_get_client_info, .set_client_info = snd_seq_hw_set_client_info, + .get_ump_info = snd_seq_hw_get_ump_info, + .set_ump_info = snd_seq_hw_set_ump_info, .create_port = snd_seq_hw_create_port, .delete_port = snd_seq_hw_delete_port, .get_port_info = snd_seq_hw_get_port_info, @@ -476,6 +540,11 @@ int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode) close(fd); return -SND_ERROR_INCOMPATIBLE_VERSION; } + if (SNDRV_PROTOCOL_VERSION(1, 0, 3) <= ver) { + /* inform the protocol version we're supporting */ + unsigned int user_ver = SNDRV_SEQ_VERSION; + ioctl(fd, SNDRV_SEQ_IOCTL_USER_PVERSION, &user_ver); + } hw = calloc(1, sizeof(snd_seq_hw_t)); if (hw == NULL) { close(fd); @@ -500,7 +569,7 @@ int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode) } } if (streams & SND_SEQ_OPEN_INPUT) { - seq->ibuf = (snd_seq_event_t *) calloc(sizeof(snd_seq_event_t), seq->ibufsize = SND_SEQ_IBUF_SIZE); + seq->ibuf = (char *) calloc(sizeof(snd_seq_ump_event_t), seq->ibufsize = SND_SEQ_IBUF_SIZE); if (!seq->ibuf) { free(seq->obuf); free(hw); @@ -519,6 +588,7 @@ int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode) seq->poll_fd = fd; seq->ops = &snd_seq_hw_ops; seq->private_data = hw; + seq->packet_size = sizeof(snd_seq_event_t); client = snd_seq_hw_client_id(seq); if (client < 0) { snd_seq_close(seq); diff --git a/src/seq/seq_local.h b/src/seq/seq_local.h index f97a5200397a..9b4a65459d3d 100644 --- a/src/seq/seq_local.h +++ b/src/seq/seq_local.h @@ -41,6 +41,8 @@ typedef struct { int (*system_info)(snd_seq_t *seq, snd_seq_system_info_t * info); int (*get_client_info)(snd_seq_t *seq, snd_seq_client_info_t * info); int (*set_client_info)(snd_seq_t *seq, snd_seq_client_info_t * info); + int (*get_ump_info)(snd_seq_t *seq, int client, int type, void *info); + int (*set_ump_info)(snd_seq_t *seq, int type, const void *info); int (*create_port)(snd_seq_t *seq, snd_seq_port_info_t * port); int (*delete_port)(snd_seq_t *seq, snd_seq_port_info_t * port); int (*get_port_info)(snd_seq_t *seq, snd_seq_port_info_t * info); @@ -84,12 +86,14 @@ struct _snd_seq { char *obuf; /* output buffer */ size_t obufsize; /* output buffer size */ size_t obufused; /* output buffer used size */ - snd_seq_event_t *ibuf; /* input buffer */ + char *ibuf; /* input buffer */ size_t ibufptr; /* current pointer of input buffer */ size_t ibuflen; /* queued length */ size_t ibufsize; /* input buffer size */ snd_seq_event_t *tmpbuf; /* temporary event for extracted event */ size_t tmpbufsize; /* size of errbuf */ + size_t packet_size; /* input packet alignment size */ + int midi_version; /* current protocol version */ }; int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode); diff --git a/src/seq/seqmid.c b/src/seq/seqmid.c index 75061a577ef3..55651f3896f3 100644 --- a/src/seq/seqmid.c +++ b/src/seq/seqmid.c @@ -255,6 +255,44 @@ int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type) return snd_seq_set_client_info(seq, &info); } +/** + * \brief set client MIDI protocol version + * \param seq sequencer handle + * \param midi_version MIDI protocol version to set + * \return 0 on success or negative error code + * + * \sa snd_seq_set_client_info() + */ +int snd_seq_set_client_midi_version(snd_seq_t *seq, int midi_version) +{ + snd_seq_client_info_t info; + int err; + + if ((err = snd_seq_get_client_info(seq, &info)) < 0) + return err; + snd_seq_client_info_set_midi_version(&info, midi_version); + return snd_seq_set_client_info(seq, &info); +} + +/** + * \brief enable/disable client's automatic conversion of UMP/legacy events + * \param seq sequencer handle + * \param enable 0 or 1 to disable/enable the conversion + * \return 0 on success or negative error code + * + * \sa snd_seq_set_client_info() + */ +int snd_seq_set_client_ump_conversion(snd_seq_t *seq, int enable) +{ + snd_seq_client_info_t info; + int err; + + if ((err = snd_seq_get_client_info(seq, &info)) < 0) + return err; + snd_seq_client_info_set_ump_conversion(&info, enable); + return snd_seq_set_client_info(seq, &info); +} + /** * \brief change the output pool size of the given client * \param seq sequencer handle