diff mbox series

[alsa-lib,3/5] rawmidi: Extensions for tied device and substream inactive flag

Message ID 20250114085515.11880-4-tiwai@suse.de (mailing list archive)
State Superseded
Headers show
Series Updates for rawmidi / sequencer | expand

Commit Message

Takashi Iwai Jan. 14, 2025, 8:55 a.m. UTC
This is the enhancements of rawmidi API for the new feature added in
6.14 kernel: the indication of a tied device and the inactive flag for
the selected substream.

The new function is added for obtaining the tied device,
snd_rawmidi_info_get_tied_device().

And the new bit flag is defined for indicating the inactive
substream, SNDRV_RAWMIDI_INFO_STREAM_INACTIVE, which is exposed via
snd_rawmidi_info_get_flags().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/rawmidi.h     |  2 ++
 src/rawmidi/rawmidi.c | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/rawmidi.h b/include/rawmidi.h
index 2630d1e67572..af734b21db60 100644
--- a/include/rawmidi.h
+++ b/include/rawmidi.h
@@ -95,6 +95,7 @@  typedef enum _snd_rawmidi_read_mode {
 
 /** rawmidi info bit flags */
 #define SND_RAWMIDI_INFO_UMP			0x00000008	/* rawmidi is UMP */
+#define SNDRV_RAWMIDI_INFO_STREAM_INACTIVE	0x00000010	/* the selected substream is inactive */
 
 int snd_rawmidi_open(snd_rawmidi_t **in_rmidi, snd_rawmidi_t **out_rmidi,
 		     const char *name, int mode);
@@ -124,6 +125,7 @@  const char *snd_rawmidi_info_get_name(const snd_rawmidi_info_t *obj);
 const char *snd_rawmidi_info_get_subdevice_name(const snd_rawmidi_info_t *obj);
 unsigned int snd_rawmidi_info_get_subdevices_count(const snd_rawmidi_info_t *obj);
 unsigned int snd_rawmidi_info_get_subdevices_avail(const snd_rawmidi_info_t *obj);
+int snd_rawmidi_info_get_tied_device(const snd_rawmidi_info_t *obj);
 void snd_rawmidi_info_set_device(snd_rawmidi_info_t *obj, unsigned int val);
 void snd_rawmidi_info_set_subdevice(snd_rawmidi_info_t *obj, unsigned int val);
 void snd_rawmidi_info_set_stream(snd_rawmidi_info_t *obj, snd_rawmidi_stream_t val);
diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c
index c4b45fa227f1..017b01c24b2b 100644
--- a/src/rawmidi/rawmidi.c
+++ b/src/rawmidi/rawmidi.c
@@ -639,6 +639,20 @@  unsigned int snd_rawmidi_info_get_subdevices_avail(const snd_rawmidi_info_t *inf
 	return info->subdevices_avail;
 }
 
+/**
+ * \brief get the tied device number for the given rawmidi device
+ * \param info pointer to a snd_rawmidi_info_t structure
+ * \return the device number for the tied device, or -1 if untied / unknown.
+ *
+ * This function is useful for UMP rawmidi devices where each of them may
+ * have the mirroring legacy rawmidi device. Those are shown as "tied".
+ */
+int snd_rawmidi_info_get_tied_device(const snd_rawmidi_info_t *info)
+{
+	assert(info);
+	return info->tied_device;
+}
+
 /**
  * \brief set rawmidi device number
  * \param info pointer to a snd_rawmidi_info_t structure
@@ -680,9 +694,15 @@  void snd_rawmidi_info_set_stream(snd_rawmidi_info_t *info, snd_rawmidi_stream_t
  */
 int snd_rawmidi_info(snd_rawmidi_t *rawmidi, snd_rawmidi_info_t * info)
 {
+	int ret;
 	assert(rawmidi);
 	assert(info);
-	return rawmidi->ops->info(rawmidi, info);
+	ret = rawmidi->ops->info(rawmidi, info);
+	if (ret)
+		return ret;
+	if (rawmidi->version < SNDRV_PROTOCOL_VERSION(2, 0, 5))
+		info->tied_device = -1;
+	return 0;
 }
 
 /**