Add MIDI 2.0 support
cover Add MIDI 2.0 support
This is a series of patches for alsa-lib to add the support of MIDI 2.0 features, corresponding to the kernel patches that have been submitted recently:
https://lore.kernel.org/r/[email protected]
The API extensions are minimalistic, and only a few basic accessors have been defined.
Takashi
---
Takashi Iwai (8):
uapi: Update rawmidi API to 2.0.3
rawmidi: Add UMP ioctl support
ump: Add initial support
control: Add UMP device query support
ump: Add helpers to parse / set UMP packet data
ump: Add helpers for handling SysEx data
uapi: Update asequencer.h definitions for 1.0.3
seq: Add UMP support
configure.ac | 1 + include/Makefile.am | 2 +- include/control.h | 1 + include/local.h | 4 + include/rawmidi.h | 3 + include/seq.h | 44 ++ include/seq_event.h | 42 +- include/seqmid.h | 24 ++ include/sound/uapi/asequencer.h | 91 ++++- include/sound/uapi/asound.h | 58 ++- include/ump.h | 119 ++++++ include/ump_msg.h | 598 +++++++++++++++++++++++++++ src/Versions.in | 23 ++ src/control/control.c | 14 + src/control/control_hw.c | 9 + src/control/control_local.h | 1 + src/rawmidi/Makefile.am | 5 +- src/rawmidi/rawmidi.c | 19 + src/rawmidi/rawmidi_hw.c | 36 +- src/rawmidi/rawmidi_local.h | 7 + src/rawmidi/ump.c | 702 ++++++++++++++++++++++++++++++++ src/rawmidi/ump_local.h | 10 + src/seq/seq.c | 410 +++++++++++++++++-- src/seq/seq_hw.c | 72 +++- src/seq/seq_local.h | 6 +- src/seq/seqmid.c | 38 ++ 26 files changed, 2261 insertions(+), 78 deletions(-) create mode 100644 include/ump.h create mode 100644 include/ump_msg.h create mode 100644 src/rawmidi/ump.c create mode 100644 src/rawmidi/ump_local.h
Signature · 1 line
2.35.3
PATCH 1/8 uapi: Update rawmidi API to 2.0.3
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.
--- include/sound/uapi/asound.h | 58 ++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-)
include/sound/uapi/asound.h +57 -1
@@ -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 0x00000008struct snd_rawmidi_info {unsigned int device;/* RO/WR (control): device number */
@@ -775,6 +776,57 @@ struct snd_rawmidi_status {unsigned char reserved[16 ];/* reserved for future use */ }; +/* UMP EP Protocol / JRTS capability bits */ +#define SNDRV_UMP_EP_INFO_PROTO_MIDI_MASK 0x0300 +#define SNDRV_UMP_EP_INFO_PROTO_MIDI1 0x0100/* MIDI 1.0 */ +#define SNDRV_UMP_EP_INFO_PROTO_MIDI2 0x0200/* MIDI 2.0 */ +#define SNDRV_UMP_EP_INFO_PROTO_JRTS_MASK 0x0003 +#define SNDRV_UMP_EP_INFO_PROTO_JRTS_TX 0x0001/* JRTS Transmit */ +#define SNDRV_UMP_EP_INFO_PROTO_JRTS_RX 0x0002/* JRTS Receive */ + +/* UMP Endpoint information */ +struct snd_ump_endpoint_info { +int card;/* card number */ +int device;/* device number */ +unsigned int flags;/* additional info */ +unsigned int protocol_caps;/* protocol capabilities */ +unsigned int protocol;/* current protocol */ +unsigned int num_blocks;/* # of function blocks */ +unsigned short version;/* UMP major/minor version */ +unsigned short padding[7 ]; +unsigned char name[128 ];/* endpoint name string */ +unsigned char product_id[128 ];/* unique product id string */ +unsigned char reserved[32 ]; +} __packed; + +/* UMP direction */ +#define SNDRV_UMP_DIR_INPUT 0x01 +#define SNDRV_UMP_DIR_OUTPUT 0x02 +#define SNDRV_UMP_DIR_BIDIRECTION 0x03 + +/* UMP block info flags */ +#define SNDRV_UMP_BLOCK_IS_MIDI1 (1U << 0)/* MIDI 1.0 port w/o restrict */ +#define SNDRV_UMP_BLOCK_IS_LOWSPEED (1U << 1)/* 31.25Kbps B/W MIDI1 port */ + +/* UMP groups and blocks */ +#define SNDRV_UMP_MAX_GROUPS 16 +#define SNDRV_UMP_MAX_BLOCKS 32 + +/* UMP Block information */ +struct snd_ump_block_info { +int card;/* card number */ +int device;/* device number */ +unsigned char block_id;/* block ID (R/W) */ +unsigned char direction;/* UMP direction */ +unsigned char active;/* Activeness */ +unsigned char first_group;/* first group ID */ +unsigned char num_groups;/* number of groups */ +unsigned char padding[3 ]; +unsigned int flags;/* various info flags */ +unsigned char name[128 ];/* block name string */ +unsigned char reserved[32 ]; +} __packed; +#define SNDRV_RAWMIDI_IOCTL_PVERSION _IOR('W', 0x00, int)#define SNDRV_RAWMIDI_IOCTL_INFO _IOR('W', 0x01, struct snd_rawmidi_info)#define SNDRV_RAWMIDI_IOCTL_USER_PVERSION _IOW('W', 0x02, int)
@@ -782,6 +834,9 @@ struct snd_rawmidi_status {#define SNDRV_RAWMIDI_IOCTL_STATUS _IOWR('W', 0x20, struct snd_rawmidi_status)#define SNDRV_RAWMIDI_IOCTL_DROP _IOW('W', 0x30, int)#define SNDRV_RAWMIDI_IOCTL_DRAIN _IOW('W', 0x31, int) +/* Additional ioctls for UMP rawmidi devices */ +#define SNDRV_UMP_IOCTL_ENDPOINT_INFO _IOR('W', 0x40, struct snd_ump_endpoint_info) +#define SNDRV_UMP_IOCTL_BLOCK_INFO _IOR('W', 0x41, struct snd_ump_block_info)/* * Timer section - /dev/snd/timer
@@ -1114,6 +1169,7 @@ struct snd_ctl_tlv {#define SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE _IOWR('U', 0x40, int)#define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info)#define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int) +#define SNDRV_CTL_IOCTL_UMP_NEXT_DEVICE _IOWR('U', 0x43, int)#define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int)#define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int)
Signature · 1 line
2.35.3
PATCH 2/8 rawmidi: Add UMP ioctl support
In reply to Takashi IwaiJust implement internal callbacks for two new ioctls for UMP (ump_endpoint_info and ump_block_info). No public API functions are added yet here.
--- src/rawmidi/rawmidi.c | 19 +++++++++++++++++++ src/rawmidi/rawmidi_hw.c | 26 +++++++++++++++++++++++++- src/rawmidi/rawmidi_local.h | 5 +++++ 3 files changed, 49 insertions(+), 1 deletion(-)
src/rawmidi/rawmidi.c +19 -0
@@ -1120,3 +1120,22 @@ ssize_t snd_rawmidi_tread(snd_rawmidi_t *rawmidi, struct timespec *tstamp, voidreturn -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 */
src/rawmidi/rawmidi_hw.c +25 -1
@@ -272,6 +272,28 @@ static ssize_t snd_rawmidi_hw_tread(snd_rawmidi_t *rmidi, struct timespec *tstamreturn 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, };
src/rawmidi/rawmidi_local.h +5 -0
@@ -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);
Signature · 1 line
2.35.3
PATCH 3/8 ump: Add initial support
In reply to Takashi IwaiThis 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.
--- 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
configure.ac +1 -0
@@ -795,6 +795,7 @@ cat >> include/asoundlib.h <<EOF EOF test "$build_pcm" = "yes" && echo "#include <alsa/pcm.h>" >> include/asoundlib.h test "$build_rawmidi" = "yes" && echo "#include <alsa/rawmidi.h>" >> include/asoundlib.h +test "$build_rawmidi" = "yes" && echo "#include <alsa/ump.h>" >> include/asoundlib.h test "$build_pcm" = "yes" && echo "#include <alsa/timer.h>" >> include/asoundlib.h test "$build_hwdep" = "yes" && echo "#include <alsa/hwdep.h>" >> include/asoundlib.h echo "#include <alsa/control.h>" >> include/asoundlib.h
include/Makefile.am +1 -1
@@ -34,7 +34,7 @@ endif endif if BUILD_RAWMIDI -alsainclude_HEADERS += rawmidi.h +alsainclude_HEADERS += rawmidi.h ump.h endif if BUILD_HWDEP
include/rawmidi.h +3 -0
@@ -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,
include/ump.h new file +119 -0
119 lines not on this page · raw message
src/Versions.in +6 -0
@@ -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;
src/rawmidi/Makefile.am +3 -2
@@ -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
src/rawmidi/rawmidi_hw.c +9 -1
@@ -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 ) {
src/rawmidi/rawmidi_local.h +2 -0
@@ -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 */
src/rawmidi/ump.c new file +616 -0
616 lines not on this page · raw message
src/rawmidi/ump_local.h new file +9 -0
@@ -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; +};
Signature · 1 line
2.35.3
PATCH 4/8 control: Add UMP device query support
In reply to Takashi IwaiAdd 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.
--- include/control.h | 1 + src/control/control.c | 14 ++++++++++++++ src/control/control_hw.c | 9 +++++++++ src/control/control_local.h | 1 + 4 files changed, 25 insertions(+)
include/control.h +1 -0
@@ -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);
src/control/control.c +14 -0
@@ -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
src/control/control_hw.c +9 -0
@@ -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,
src/control/control_local.h +1 -0
@@ -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);
Signature · 1 line
2.35.3
PATCH 5/8 ump: Add helpers to parse / set UMP packet data
In reply to Takashi IwaiThis patch defines the structs / unions that can be used for encoding and decoding UMP packets, as well as inline helper functions.
--- 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
include/Makefile.am +1 -1
@@ -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
include/local.h +2 -0
@@ -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
include/ump_msg.h new file +571 -0
571 lines not on this page · raw message
src/rawmidi/ump_local.h +1 -0
@@ -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;
Signature · 1 line
2.35.3
PATCH 6/8 ump: Add helpers for handling SysEx data
In reply to Takashi IwaiYet a few more helpers for handling SysEx data with UMP packets.
--- include/ump_msg.h | 27 +++++++++++++++ src/rawmidi/ump.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+)
include/ump_msg.h +27 -0
@@ -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
src/rawmidi/ump.c +86 -0
89 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH 7/8 uapi: Update asequencer.h definitions for 1.0.3
In reply to Takashi IwaiUpdated from kernel for supporting UMP on sequencer API.
--- include/sound/uapi/asequencer.h | 91 +++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 21 deletions(-)
include/sound/uapi/asequencer.h +70 -21
@@ -26,7 +26,7 @@#include <sound/asound.h> /** 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)
Signature · 1 line
2.35.3
PATCH 8/8 seq: Add UMP support
In reply to Takashi IwaiThis 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().
--- 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(-)
include/local.h +2 -0
@@ -195,7 +195,9 @@#define snd_seq_real_time sndrv_seq_real_time#define snd_seq_timestamp sndrv_seq_timestamp#define snd_seq_event_type_t sndrv_seq_event_type_t +#define snd_seq_event_data sndrv_seq_event_data#define snd_seq_event sndrv_seq_event +#define snd_seq_ump_event sndrv_seq_ump_event#define snd_seq_connect sndrv_seq_connect#define snd_seq_ev_note sndrv_seq_ev_note#define snd_seq_ev_ctrl sndrv_seq_ev_ctrl
include/seq.h +44 -0
103 lines not on this page · raw message
include/seq_event.h +30 -12
62 lines not on this page · raw message
include/seqmid.h +24 -0
@@ -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);
src/Versions.in +17 -0
@@ -153,4 +153,21 @@ ALSA_1.2.10 { global: @SYMBOL_PREFIX@snd_ump_*; + @SYMBOL_PREFIX@snd_seq_ump_*; + @SYMBOL_PREFIX@snd_seq_client_info_get_midi_version; + @SYMBOL_PREFIX@snd_seq_seq_client_info_get_ump_group_enabled; + @SYMBOL_PREFIX@snd_seq_seq_client_get_ump_conversion; + @SYMBOL_PREFIX@snd_seq_client_info_set_midi_version; + @SYMBOL_PREFIX@snd_seq_seq_client_info_set_ump_group_enabled; + @SYMBOL_PREFIX@snd_seq_seq_client_set_ump_conversion; + @SYMBOL_PREFIX@snd_seq_get_ump_endpoint_info; + @SYMBOL_PREFIX@snd_seq_get_ump_block_info; + @SYMBOL_PREFIX@snd_seq_set_ump_endpoint_info; + @SYMBOL_PREFIX@snd_seq_set_ump_block_info; + @SYMBOL_PREFIX@snd_seq_port_info_get_direction; + @SYMBOL_PREFIX@snd_seq_port_info_get_ump_group; + @SYMBOL_PREFIX@snd_seq_port_info_set_direction; + @SYMBOL_PREFIX@snd_seq_port_info_set_ump_group; + @SYMBOL_PREFIX@snd_seq_set_client_midi_version; + @SYMBOL_PREFIX@snd_seq_set_client_ump_conversion; } ALSA_1.2.9;
src/seq/seq.c +373 -37
531 lines not on this page · raw message
src/seq/seq_hw.c +71 -1
118 lines not on this page · raw message
src/seq/seq_local.h +5 -1
@@ -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);
src/seq/seqmid.c +38 -0
@@ -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
Signature · 1 line
2.35.3