From 8bc10c83b155c5cff2ae6ddf44a8bf899ff4397c Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Sun, 25 Dec 2022 12:09:51 +0100 Subject: [PATCH] control: Add UMP device query support 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 d0c40d2f..a2439d78 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 3315fa28..ee17cf28 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 d3ecc6e9..7168ff8d 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 a927cdfe..95d6d07d 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 b84dc429..aa05bac8 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); -- 2.47.1