From patchwork Tue May 23 12:22:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252193 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 A419BC7EE26 for ; Tue, 23 May 2023 12:26:46 +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 95AD0209; Tue, 23 May 2023 14:25:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 95AD0209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844804; bh=oiud/ZlM4kK33vHhsj3MIL7CUDa5QSEYT0FLhtFE9DU=; 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=RIzoQIsR3aLSgjRoLTi7ez3GCPEAiajIk5kJsjvZ8BKV+h7nzO2dkrtYirT27kf5O VYcM46u1NmKlKlQV2dM5vO59d9qKb5pYHZg7RFFDgbAfuXY6hKx4JZlazccgJKEDoS JR7xXHH0OSuuAX5KkVY/T/7tSTXmk3dJnNNpaRxE= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1A07CF80542; Tue, 23 May 2023 14:24:14 +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 BBFD6F8024E; Tue, 23 May 2023 14:24:13 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1658AF80552; Tue, 23 May 2023 14:24:11 +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 2A2B8F8053D for ; Tue, 23 May 2023 14:22:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2A2B8F8053D 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=pZaE0sDw; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6dCskRCD 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 0A5D322A2F; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=1SA5jaqw22IxWLCnvDr3XuBPFUCHep+nAHdIHTF48KU=; b=pZaE0sDwUrkyFWH1FONYTzP/pRW+xDmRhWS1eIXt6GuFnhWK6YxU0uNCnMTDyuwRhUKCh5 Thm6l0XVLPPHoZ2sq8aV5woB30tEoI+4FkgJZ4/4UtZuoi5sR/vAtnevx0VzqeEvdCbCyz 09b6Js5apLlpQBDUs3g2p/YcgegN79o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=1SA5jaqw22IxWLCnvDr3XuBPFUCHep+nAHdIHTF48KU=; b=6dCskRCDbTN6bvyldOWjFLlAgV2p3wub7wBEfXRs/FC7InxyIPxY7BZz5rKhzlzUSzyzKe eLl7GW5P/2Oy5mAg== 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 E333713A1A; Tue, 23 May 2023 12:22:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KMO/Nh2wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:53 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 01/10] uapi: Update rawmidi API to 2.0.3 Date: Tue, 23 May 2023 14:22:38 +0200 Message-Id: <20230523122247.11744-2-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: L6QNK6WOZHBVVY3KCR22APHAW4CMHE7W X-Message-ID-Hash: L6QNK6WOZHBVVY3KCR22APHAW4CMHE7W 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 | 57 ++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/include/sound/uapi/asound.h b/include/sound/uapi/asound.h index 62a0364fc3cd..cf11a6b73e2d 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 From patchwork Tue May 23 12:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252185 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 7E180C7EE26 for ; Tue, 23 May 2023 12:24:28 +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 2361820C; Tue, 23 May 2023 14:23:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2361820C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844666; bh=FFTV97KGwlzyZT7eZUaMnRLOwkX3bb0oBudnDcRbf30=; 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=tGn+Ue1/69GNvOb0FwQtvsscQCKeUMkHFMckT/doZ7icE4P+AF4nO2M0hutp4tpwU C7Mz2P1X3H95WnV5h9rS6L6agH8YXECrMFB7NVHy7tn2I1Xy0ZzDs2nsXAf0+VUFh2 oTXwv0i7wMWwCPDCwkqqmW/QLyaYkkDMNF7kk4hQ= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 49C18F80553; Tue, 23 May 2023 14:23:01 +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 E0B19F80552; Tue, 23 May 2023 14:23:00 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id EBF28F80553; Tue, 23 May 2023 14:22:57 +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 976FFF8016A for ; Tue, 23 May 2023 14:22:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 976FFF8016A 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=gjvqb+em; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=MMBEzgIU 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 2A78622A32; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=62pj/mPtBE9uzih/1y6PBxRI1aKgGvmc6jZMFMDUQP0=; b=gjvqb+emvtRLu2bQgEVQ0+8TRwi4aduTUzonPHy3Fp+rRg/R6lePw74PyGWEGC+u1t755S E3JyK9SwgaFazOJMytaLW438gPumHmLrRVI6agiMdgort/jYXoA/UtzYmvo84Jy2kEzpyh mv2KtGYtbbWWSngqB+v8/p0Um1XJemc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=62pj/mPtBE9uzih/1y6PBxRI1aKgGvmc6jZMFMDUQP0=; b=MMBEzgIUV2cB5mkq4KD9hVVkTP/45JLZ8HZOJDeb6//3yr4XhzKQuyka/TMeoNNZs6gNaY ilMtAveYTQgB9pBA== 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 0FB3A13588; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wAKVAh6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 02/10] uapi: Update control API to 2.0.9 Date: Tue, 23 May 2023 14:22:39 +0200 Message-Id: <20230523122247.11744-3-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: KTJAW6HHD4EYK5TD76TEW7ALZVK5Z7XC X-Message-ID-Hash: KTJAW6HHD4EYK5TD76TEW7ALZVK5Z7XC 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 control API. A few new ioctls have been added for the support of UMP next device and inquiries of UMP Endpoint and Block info. Signed-off-by: Takashi Iwai --- include/sound/uapi/asound.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/sound/uapi/asound.h b/include/sound/uapi/asound.h index cf11a6b73e2d..80cd57e968e5 100644 --- a/include/sound/uapi/asound.h +++ b/include/sound/uapi/asound.h @@ -1008,7 +1008,7 @@ struct snd_timer_tread { * * ****************************************************************************/ -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 8) +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 9) struct snd_ctl_card_info { int card; /* card number */ @@ -1169,6 +1169,9 @@ 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_UMP_ENDPOINT_INFO _IOWR('U', 0x44, struct snd_ump_endpoint_info) +#define SNDRV_CTL_IOCTL_UMP_BLOCK_INFO _IOWR('U', 0x45, struct snd_ump_block_info) #define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int) #define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int) From patchwork Tue May 23 12:22:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252186 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 31D8FC7EE23 for ; Tue, 23 May 2023 12:24:44 +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 39CF66C0; Tue, 23 May 2023 14:23:52 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 39CF66C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844682; 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=ATQ+sTWV31na62sSGpuy7muF8TDh6rfN26nK2pE//j+Nd+NPxyY1G/v9/HUd+jcSv 5zD2fmfihijrfHe1pBb9+hu7Upvmho/0l4UeX0Kx81NDIuNch4Q5KSBWutm4lP/H1Q xMJxzN4KtxgLwXon3LM7Z3N6gCRhtu1G0699MFQA= Received: by alsa1.perex.cz (Postfix, from userid 50401) id B005CF80568; Tue, 23 May 2023 14:23:04 +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 5F126F8055B; Tue, 23 May 2023 14:23:04 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 98CF3F80552; Tue, 23 May 2023 14:23:00 +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 AB3B7F80249 for ; Tue, 23 May 2023 14:22:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AB3B7F80249 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=sLng8hpL; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tjf3kukG 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 4A70222A34; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=sLng8hpLOTaHmI2gUnABnmk0BkUDSqxUTkVGxObrr2XknLLtrGmgj8+mXxzh+aXLJcVOvQ 3WDIAOBFoJYam5kU0esq4tpmifSLO/cYnyRulGQVX4xam7AuHZ0iDpVTaugRc7+1246shV UO//h/aAUC6fdzwRDN/0H87ylwIBEEI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=tjf3kukG2jj3HLbgMXSGNRUVEzGgnnAfcdZKEu6++ibH5fQeEGZptsPcgNi2KdgQHzuwhY VYBW+IZr7Po8p3Cg== 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 2E72813588; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KNiLCh6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 03/10] rawmidi: Add UMP ioctl support Date: Tue, 23 May 2023 14:22:40 +0200 Message-Id: <20230523122247.11744-4-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: HICO7ILHUPHGR7DCLF4K42ADPSRJ3S67 X-Message-ID-Hash: HICO7ILHUPHGR7DCLF4K42ADPSRJ3S67 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 Tue May 23 12:22:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252195 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 BE67BC7EE26 for ; Tue, 23 May 2023 12:27: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 3AA5282C; Tue, 23 May 2023 14:26:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3AA5282C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844824; 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=UqpM6iqhrgRyuRBI5NGTHIsUGtAicYp4IDgnr/94zJE47/ygA5Idpo8qYJUhK2tFH U76Zxh/n2hEs8qX/XgciSJPf5TFf/FnmYxC/PsvBQOxvaAjEqP2m6BnbDf5rt5/O1l q+YvbRe8pBIrkQiVjhG0uQFGxLL1DKlyKcli6qJs= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5E319F805EF; Tue, 23 May 2023 14:24:19 +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 D30FAF805E2; Tue, 23 May 2023 14:24:18 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 06A67F805ED; Tue, 23 May 2023 14:24:15 +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 1FEB3F80425 for ; Tue, 23 May 2023 14:22:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1FEB3F80425 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=eoZq8i2c; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=07/L+pZt 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 8382F22A35; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=eoZq8i2cy3ckHW+yPp4HopJdfw1TTlBk8iGi//TZyKQ+czwiCRgyVRorMwgnPrqfzWVNdG NsrqvOk7d126MxdXM0MtwWzeFPEN6+PAxtRPQlHV8Jno4AkxG7vS1uJ6YWVgH9W7IumohA FdlMPVDzDfiNGLZIXRiMxT62Fxd7gCI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=07/L+pZtHtUrUhnHhtqOIUK1tIMuQifqsvQB+oKoDnh9jn6sb4YW/THvXw+hQz6t6QpA59 d8G+RpIP0gGd5ACQ== 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 4FC9F13588; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qI+wEh6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 04/10] ump: Add initial support Date: Tue, 23 May 2023 14:22:41 +0200 Message-Id: <20230523122247.11744-5-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: 3RH7X7Y5UAYJFIENN25FVL5XA53B7G5P X-Message-ID-Hash: 3RH7X7Y5UAYJFIENN25FVL5XA53B7G5P 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 Tue May 23 12:22:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252191 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 4D0E1C7EE26 for ; Tue, 23 May 2023 12:26:04 +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 F264484B; Tue, 23 May 2023 14:25:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz F264484B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844762; bh=uIRF7YUMcqAUv9gr4mBtNuIQ9LUbXgLFMm1+YfPeWG0=; 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=AMdfSJTBO6cnpfSljbcIVBdL1TyS6bn+EPHqn3NYCeQg7T1VkFj70dTjepXrqk+lK c/w8gXLMXJx5oAi9k/5YTAE/JHXn/EBVQw3CCpFk93+30NS0LCYXEGdfvSVO+bEzAW KTgfz9b/msVh51HhHeHgF3xPLYbMOWxR1EyWHFHQ= Received: by alsa1.perex.cz (Postfix, from userid 50401) id F3781F805CA; Tue, 23 May 2023 14:23:23 +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 2ED89F805BA; Tue, 23 May 2023 14:23:23 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B2EC1F805BB; Tue, 23 May 2023 14:23:16 +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 1B909F8026A for ; Tue, 23 May 2023 14:22:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 1B909F8026A 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=G5/vUFAO; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=OxfHcbUa 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 916E122A36; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=mMgAk9rt80QYNVvFx6zLOlDT3gjpSGtg9Th+NNk5PPc=; b=G5/vUFAOjihSsLb3V++lrWFUqVk0gumFOzEiNwIvNQc/jD61csikGhrrBmCRcqn9W+LRhU sQvbyPhd9pNBu3wqUtogabeEGF+LStHO5N34eSSO2Ax0r9a5yhiLM42WsBkGerbJt2JQh0 QtTSO3QObUtA0THRePZeRkNakuyi68k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=mMgAk9rt80QYNVvFx6zLOlDT3gjpSGtg9Th+NNk5PPc=; b=OxfHcbUaYPyqJe/OOn7/2vV68vQvtPnSOivGhL7VZHjQayMKSRbSEwJSxvc6JsK5priQZu p2t3icNCR2YXoWDw== 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 77FB713A1A; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8OrRGx6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 05/10] control: Add UMP device query support Date: Tue, 23 May 2023 14:22:42 +0200 Message-Id: <20230523122247.11744-6-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: ACS6MDDMMUFIHMJMP5TZS4WMDB32GCOT X-Message-ID-Hash: ACS6MDDMMUFIHMJMP5TZS4WMDB32GCOT 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/Versions.in | 1 + src/control/control.c | 14 ++++++++++++++ src/control/control_hw.c | 9 +++++++++ src/control/control_local.h | 1 + 5 files changed, 26 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/Versions.in b/src/Versions.in index 3315fa2840e0..ee17cf289c0e 100644 --- a/src/Versions.in +++ b/src/Versions.in @@ -153,4 +153,5 @@ ALSA_1.2.10 { global: @SYMBOL_PREFIX@snd_ump_*; + @SYMBOL_PREFIX@snd_ctl_ump_next_device; } ALSA_1.2.9; 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 Tue May 23 12:22:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252188 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 8CD44C7EE26 for ; Tue, 23 May 2023 12:25:13 +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 53E7883B; Tue, 23 May 2023 14:24:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 53E7883B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844711; bh=nONOXSbFMiwElQJipkdF24VFZRg60YNtTgwHyUBSzxg=; 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=XYW3TFQR/M/kqT1Odwfw3te3HVx8rPfmE4CcPJXMBk2SZ7AG/0o8rQLvVgac7GjmD AuGDeK2aeojv+UKLEPPZN29U29cN600Z58+H1RFEMYkDs4z8sOO0qIe9CEcQEMK6JO McwhxLiI/2GnO2taqDCp7f9OjDXlc6daHI+SpQfk= Received: by alsa1.perex.cz (Postfix, from userid 50401) id F293EF805AA; Tue, 23 May 2023 14:23:12 +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 4D20AF805AA; Tue, 23 May 2023 14:23:12 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 97617F8057A; Tue, 23 May 2023 14:23:06 +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 CC601F80548 for ; Tue, 23 May 2023 14:22:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz CC601F80548 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=Mv4JkHu2; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8Lsi1Pwi 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 ADE1F22A37; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=0cWWz/aLfQeZl8Vs1rQItBp3JG8lIh3S8QX4KKp33Zc=; b=Mv4JkHu2D7uM2XMRgbb3+Y5VR5Q6GtukVFJ4CEVAySmuGPZN8xGUUGdZmXe4Td3RuE5fTj kvXzYxNaYPXNTyEzwncolZVL8JtmlKJ9Lqs7+rNnF56cGleAEIbC3jhZL2KF21ugzJWa0J a5IMiOeO70OaW3zjLHypEDlEl5wOmNs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=0cWWz/aLfQeZl8Vs1rQItBp3JG8lIh3S8QX4KKp33Zc=; b=8Lsi1PwijaIcA8+yk7YBqE2llJBYrrt+UBg45/0Al4u2ctgFocN6psVZWgwGvsPM0s0/91 pfWdnoXN8LQ51gCw== 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 94D4913588; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gKmoIx6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 06/10] control: Add UMP Endpoint and Block info query support Date: Tue, 23 May 2023 14:22:43 +0200 Message-Id: <20230523122247.11744-7-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: WPFSMHGJIKROCSFBYCO7KI7OEB3DOTEF X-Message-ID-Hash: WPFSMHGJIKROCSFBYCO7KI7OEB3DOTEF 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 functions to query the UMP Endpoint and Block info via control interface. Signed-off-by: Takashi Iwai --- include/control.h | 2 ++ include/local.h | 1 + src/Versions.in | 2 ++ src/control/control.c | 24 ++++++++++++++++++++++++ src/control/control_hw.c | 20 ++++++++++++++++++++ src/control/control_local.h | 2 ++ 6 files changed, 51 insertions(+) diff --git a/include/control.h b/include/control.h index a2439d78057a..41892de20fd3 100644 --- a/include/control.h +++ b/include/control.h @@ -418,6 +418,8 @@ 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); +int snd_ctl_ump_endpoint_info(snd_ctl_t *ctl, snd_ump_endpoint_info_t *info); +int snd_ctl_ump_block_info(snd_ctl_t *ctl, snd_ump_block_info_t *info); #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/include/local.h b/include/local.h index 151e3fd4d39b..4206d68137d9 100644 --- a/include/local.h +++ b/include/local.h @@ -180,6 +180,7 @@ #include "pcm.h" #include "pcm_plugin.h" #include "rawmidi.h" +#include "ump.h" #include "timer.h" #include "hwdep.h" #include "control.h" diff --git a/src/Versions.in b/src/Versions.in index ee17cf289c0e..2acf3d1889df 100644 --- a/src/Versions.in +++ b/src/Versions.in @@ -154,4 +154,6 @@ ALSA_1.2.10 { @SYMBOL_PREFIX@snd_ump_*; @SYMBOL_PREFIX@snd_ctl_ump_next_device; + @SYMBOL_PREFIX@snd_ctl_ump_endpoint_info; + @SYMBOL_PREFIX@snd_ctl_ump_block_info; } ALSA_1.2.9; diff --git a/src/control/control.c b/src/control/control.c index 615a66906414..9b6bf893581b 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -1281,6 +1281,30 @@ int snd_ctl_ump_next_device(snd_ctl_t *ctl, int *device) return -ENXIO; } +/** + * \brief Get UMP Endpoint info about a UMP RawMidi device + * \param ctl CTL handle + * \param info UMP Endpoint info pointer + * \return 0 on success otherwise a negative error code + */ +int snd_ctl_ump_endpoint_info(snd_ctl_t *ctl, snd_ump_endpoint_info_t *info) +{ + assert(ctl && info); + return ctl->ops->ump_endpoint_info(ctl, info); +} + +/** + * \brief Get UMP Block info about a UMP RawMidi device + * \param ctl CTL handle + * \param info UMP Block info pointer + * \return 0 on success otherwise a negative error code + */ +int snd_ctl_ump_block_info(snd_ctl_t *ctl, snd_ump_block_info_t *info) +{ + assert(ctl && info); + return ctl->ops->ump_block_info(ctl, info); +} + /** * \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 ffb6f17325a7..a2f1bdc50cea 100644 --- a/src/control/control_hw.c +++ b/src/control/control_hw.c @@ -333,6 +333,24 @@ static int snd_ctl_hw_ump_next_device(snd_ctl_t *handle, int *device) return 0; } +static int snd_ctl_hw_ump_endpoint_info(snd_ctl_t *handle, + snd_ump_endpoint_info_t *info) +{ + snd_ctl_hw_t *hw = handle->private_data; + if (ioctl(hw->fd, SNDRV_CTL_IOCTL_UMP_ENDPOINT_INFO, info) < 0) + return -errno; + return 0; +} + +static int snd_ctl_hw_ump_block_info(snd_ctl_t *handle, + snd_ump_block_info_t *info) +{ + snd_ctl_hw_t *hw = handle->private_data; + if (ioctl(hw->fd, SNDRV_CTL_IOCTL_UMP_BLOCK_INFO, info) < 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; @@ -388,6 +406,8 @@ static const snd_ctl_ops_t snd_ctl_hw_ops = { .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, + .ump_endpoint_info = snd_ctl_hw_ump_endpoint_info, + .ump_block_info = snd_ctl_hw_ump_block_info, .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 aa05bac84913..2afa62cceee3 100644 --- a/src/control/control_local.h +++ b/src/control/control_local.h @@ -48,6 +48,8 @@ typedef struct _snd_ctl_ops { 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 (*ump_endpoint_info)(snd_ctl_t *handle, snd_ump_endpoint_info_t *info); + int (*ump_block_info)(snd_ctl_t *handle, snd_ump_block_info_t *info); 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 Tue May 23 12:22:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252190 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 AD5FBC7EE2A for ; Tue, 23 May 2023 12:25:41 +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 A73C484D; Tue, 23 May 2023 14:24:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A73C484D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844739; bh=dzYHRJG0hh7gnFyvqR6tLjiwTHXQJat2qRqmXVr/RB0=; 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=Y+l9j7gjotXWI2/top/Hc1bTIllIeIPK8LiKPN2aGR/u6FTOWuLv70UO9IgsyBAF4 JP5plAP76nyHsMZeCiVrEzXJcQ5F6tVmIBrXziQQGf8im1pmX7tfYLWoVRu4JMxRCb A0Mckf+XGsxVt1oCKJOhiU21dgGVCkZd/AOeeqew= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8AA47F805BD; Tue, 23 May 2023 14:23:20 +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 B3F4EF805BB; Tue, 23 May 2023 14:23:19 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0506CF805B3; Tue, 23 May 2023 14:23:15 +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 2BD2DF80549 for ; Tue, 23 May 2023 14:22:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2BD2DF80549 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=th0+SV6e; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=oQnBqqJX 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 CDA1020576; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=IxTcWFSla4fi3NI23l54+64BDaBH2PE6U8hgY8bo7zI=; b=th0+SV6e05B8ssmgFqrbL+fWTJ1aC0YYo0jrnH8BuIC49pG4H15T4BiMwKotCxqw+jjfXX C5ZiGomVRw6dFEFumLJOlMdNl+m6DVKWDXBAvfRMVpvmpG1M5k9OEWlnxLMVguu0wQxg4q mZy1ot8tXkAeEq6GjjL3IwsL7VxM5t4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=IxTcWFSla4fi3NI23l54+64BDaBH2PE6U8hgY8bo7zI=; b=oQnBqqJX9Wm7PXjTSkMYTqqc4F86kjngpG3tXTBaypnmXKZZ/2nlI5FgCaybFBE+JalLli dwmD+CJRjqegAxBg== 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 B2FC713A1A; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0Bw5Kh6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 07/10] ump: Add helpers to parse / set UMP packet data Date: Tue, 23 May 2023 14:22:44 +0200 Message-Id: <20230523122247.11744-8-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: 4QBGBAFNO6KDJS4B6S6Q5YMKXMBACS7U X-Message-ID-Hash: 4QBGBAFNO6KDJS4B6S6Q5YMKXMBACS7U 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 4206d68137d9..c6be21ee20ca 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 Tue May 23 12:22:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252194 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 335E7C7EE23 for ; Tue, 23 May 2023 12:27:00 +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 5ADEE84A; Tue, 23 May 2023 14:26:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5ADEE84A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844818; 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=SRNiAQsClmQ+Dt+GZOD9D3QcFVQsfRChoccY3PoH3xFpnlBIfn1BMIRhOCETExrd8 XIS4QOKxmRnmF8CjJW17lH9Y3Art9vCg0aQ4OiNtCdUjKFAGmXCJWAs6RTmDt7mE1G hAMT4EHDUoZrsVSxOmiwk2JFE1rROC+TyFBFaXAE= Received: by alsa1.perex.cz (Postfix, from userid 50401) id E9FB3F805EC; Tue, 23 May 2023 14:24:15 +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 1DFBBF805E2; Tue, 23 May 2023 14:24:15 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 90B2FF80542; Tue, 23 May 2023 14:24:11 +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 52B6AF8024E for ; Tue, 23 May 2023 14:22:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 52B6AF8024E 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=h0m2CAWy; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=2kORBajt 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 EA2AC20577; Tue, 23 May 2023 12:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844574; 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=h0m2CAWy8wBaHwV0xqCMQu7b2kNlO6OKFvH2NoK61KwWzgWI34yXnlmoZz8Spx2sMrzZUx d2HshVtrn3q8lKCH9vP9QO1EiYdAsZq2UVoJyPh2L+ezoZGpHPbC9lXApW9au6zLxFtcex IKNRf5ie+CTXjf5H/djcecgn37vLWSI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844574; 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=2kORBajtYUJ5ttoDm2xny7JOh5h5RlZUPf1R/+RBm/2R27WjJG/yIfqECbXO9RnUQ8tSNd eJqlwIlfAVP1ClAQ== 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 CFF2D13588; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MBMIMh6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 08/10] ump: Add helpers for handling SysEx data Date: Tue, 23 May 2023 14:22:45 +0200 Message-Id: <20230523122247.11744-9-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: ZK4IWNY3M4JRXKJYWHUG6OVGTKKNN665 X-Message-ID-Hash: ZK4IWNY3M4JRXKJYWHUG6OVGTKKNN665 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 Tue May 23 12:22:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252189 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 BA30BC7EE23 for ; Tue, 23 May 2023 12:25:35 +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 E71DF1ED; Tue, 23 May 2023 14:24:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E71DF1ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844733; 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=l9SJ88QIHsaBpyrh39GnaoS7bFDJO8NkElucLU+yK1sLDm9+PnBfxBIsBIdDw0yrd XztAohc7KghAqLrX2D5PmYjtUJMrKLor5OEYEdKPBjNLPVtUPskQCq1FmukzGf4psS Y/pmolPH2Yl1zrDTqgHZBFrb7VpomxJ43bm7QVdg= Received: by alsa1.perex.cz (Postfix, from userid 50401) id E898CF805AE; Tue, 23 May 2023 14:23:15 +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 F301EF805AE; Tue, 23 May 2023 14:23:14 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E8A21F80588; Tue, 23 May 2023 14:23:10 +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 6273FF80544 for ; Tue, 23 May 2023 14:22:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6273FF80544 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=ztCaQu+u; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=38HEXNlJ 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 12B9620578; Tue, 23 May 2023 12:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844575; 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=ztCaQu+u3Ea0nVotWAowZ4nOAMJy38WYYNgUVTvyEpCevE4OuKvGCZbsv6zWJPFmyCiAqW yxCqdxnlgwE1FrJnMFv9gHaTsUyIP7P22ryNBFf+O/xhKGNRrlE4m7pvRSyiVsx8x28nO6 Hr/uweg/jSCkNkh+VOyWhVqvc6hZhHM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844575; 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=38HEXNlJ2Yeji9jKzctqmE5SDYNROltrIBXWpzcgBntRMTM+QPYWEyhr8Jvwz0YJzj1sPA StDY22acTsLlkWBw== 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 ED16113A1A; Tue, 23 May 2023 12:22:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mCIlOR6wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:54 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 09/10] uapi: Update asequencer.h definitions for 1.0.3 Date: Tue, 23 May 2023 14:22:46 +0200 Message-Id: <20230523122247.11744-10-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: JRH6CINEJE2MXC4HGZEZXPVDBOVOGITG X-Message-ID-Hash: JRH6CINEJE2MXC4HGZEZXPVDBOVOGITG 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 Tue May 23 12:22:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13252192 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 08F26C7EE23 for ; Tue, 23 May 2023 12:26:16 +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 9165D6C0; Tue, 23 May 2023 14:25:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9165D6C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684844773; bh=FN1iPRn/OM71K+z9mqgksCnRn2tUkyxRNXXuYERcsH4=; 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=W5Xm5PWOeG74t3dEvkuYvtAIOdLEq2+y1OgXYc4jb10Zk9o4GDmnCVdgWsXbudoTE bt4cnj3tCcf7P+Uj4D702oy/qVS6TVHsFaZdCXSbQdd4z390ccTImGin7zLKKXNHON 24GD2TU1EvSabo73foBNBc8trq82oKtGHbQoq0Es= Received: by alsa1.perex.cz (Postfix, from userid 50401) id D4973F805D2; Tue, 23 May 2023 14:23:30 +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 EF0C7F805D6; Tue, 23 May 2023 14:23:29 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A6E63F805BE; Tue, 23 May 2023 14:23:25 +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 35D99F80551 for ; Tue, 23 May 2023 14:22:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 35D99F80551 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=H4XuebYu; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ysMzFdO4 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 4A70B22A38; Tue, 23 May 2023 12:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684844575; 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=scExec/caLmoo02tSL9ky10a3sVY7N+z8rVlKrGWHhg=; b=H4XuebYullfVCDStBMiICrHpNz2sI4pF+npWGt2CqtKLopXmt7Qpa4TylFtGvQL9g2LQdN 1/7siIPOK26dmU9pbuq8WToocDtbyXJJSpgVCjrN5zlEZw2fw+Rms/9aJhWEc2WQaD8gpI S3mvb+e5gBykVSFyGnLBGR1+LTmtJsE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684844575; 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=scExec/caLmoo02tSL9ky10a3sVY7N+z8rVlKrGWHhg=; b=ysMzFdO4OZkKWOFzHv/mEF9yTi9sjzcnS8s6eKhJnc54S1+YxMf///yelqMnSRe2gwnj1M I2Nv+GVzqZjrQLBQ== 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 1DEE613588; Tue, 23 May 2023 12:22:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sDMbBh+wbGQNKAAAMHmgww (envelope-from ); Tue, 23 May 2023 12:22:55 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-lib v2 10/10] seq: Add UMP support Date: Tue, 23 May 2023 14:22:47 +0200 Message-Id: <20230523122247.11744-11-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230523122247.11744-1-tiwai@suse.de> References: <20230523122247.11744-1-tiwai@suse.de> MIME-Version: 1.0 Message-ID-Hash: NPMFRXAISQLXYURQFRYKERNGKR77YHDM X-Message-ID-Hash: NPMFRXAISQLXYURQFRYKERNGKR77YHDM 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 c6be21ee20ca..512e44555361 100644 --- a/include/local.h +++ b/include/local.h @@ -196,7 +196,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 2acf3d1889df..0c2837305039 100644 --- a/src/Versions.in +++ b/src/Versions.in @@ -156,4 +156,21 @@ ALSA_1.2.10 { @SYMBOL_PREFIX@snd_ctl_ump_next_device; @SYMBOL_PREFIX@snd_ctl_ump_endpoint_info; @SYMBOL_PREFIX@snd_ctl_ump_block_info; + @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