Skip to contentSkip to conversation

Updates for rawmidi / sequencer

PATCH Superseded Takashi Iwai 1 participant 6 messages Jan 14, 2025 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Updates for rawmidi / sequencer

The kernel 6.14 will receive a few small enhancements for rawmidi and sequencer APIs, and this patch set covers those.

Takashi

===

Takashi Iwai (5):
Sync UAPI asound.h with 6.14 kernel
Sync UAPI asequencer.h with 6.14 kernel
rawmidi: Extensions for tied device and substream inactive flag
rawmidi: Make rawmidi flag bits doxygen-style comments
seq: Define new events for UMP EP/FB change notifications

 include/local.h                 |  1 +
 include/rawmidi.h               |  4 +++-
 include/seq_event.h             | 12 ++++++++++++
 include/sound/uapi/asequencer.h | 12 +++++++++++-
 include/sound/uapi/asound.h     |  8 ++++++--
 src/rawmidi/rawmidi.c           | 22 +++++++++++++++++++++-
 6 files changed, 54 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 Sync UAPI asound.h with 6.14 kernel

There is a small update of rawmidi API for supporting the UMP tied device info and inactive flag.

---
 include/sound/uapi/asound.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
include/sound/uapi/asound.h +6 -2
index 533b7e46cd17..d97433c9dc26 100644
@@ -708,7 +708,7 @@ enum {
  *  Raw MIDI section - /dev/snd/midi??
  */
 
-#define SNDRV_RAWMIDI_VERSION		SNDRV_PROTOCOL_VERSION(2, 0, 4)
+#define SNDRV_RAWMIDI_VERSION		SNDRV_PROTOCOL_VERSION(2, 0, 5)
 
 enum {
 	SNDRV_RAWMIDI_STREAM_OUTPUT = 0,
@@ -720,6 +720,9 @@ enum {
 #define SNDRV_RAWMIDI_INFO_INPUT		0x00000002
 #define SNDRV_RAWMIDI_INFO_DUPLEX		0x00000004
 #define SNDRV_RAWMIDI_INFO_UMP			0x00000008
+#define SNDRV_RAWMIDI_INFO_STREAM_INACTIVE	0x00000010
+
+#define SNDRV_RAWMIDI_DEVICE_UNKNOWN		-1
 
 struct snd_rawmidi_info {
 	unsigned int device;		/* RO/WR (control): device number */
@@ -732,7 +735,8 @@ struct snd_rawmidi_info {
 	unsigned char subname[32];	/* name of active or selected subdevice */
 	unsigned int subdevices_count;
 	unsigned int subdevices_avail;
-	unsigned char reserved[64];	/* reserved for future use */
+	int tied_device;		/* R: tied rawmidi device (UMP/legacy) */
+	unsigned char reserved[60];	/* reserved for future use */
 };
 
 #define SNDRV_RAWMIDI_MODE_FRAMING_MASK		(7<<0)
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/5 Sync UAPI asequencer.h with 6.14 kernel

In reply to Takashi Iwai

There are the new event types for UMP EP and FB notifications as well as the new struct for them.

---
 include/sound/uapi/asequencer.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
include/sound/uapi/asequencer.h +11 -1
index bd3c7a317f24..9682795bba87 100644
@@ -10,7 +10,7 @@
 #include <sound/asound.h>
 
 /** version of the sequencer */
-#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 4)
+#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION(1, 0, 5)
 
 /**
  * definition of sequencer event types
@@ -92,6 +92,9 @@
 #define SNDRV_SEQ_EVENT_PORT_SUBSCRIBED	66	/* ports connected */
 #define SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED 67	/* ports disconnected */
 
+#define SNDRV_SEQ_EVENT_UMP_EP_CHANGE	68	/* UMP EP info has changed */
+#define SNDRV_SEQ_EVENT_UMP_BLOCK_CHANGE 69	/* UMP block info has changed */
+
 /* 70-89:  synthesizer events - obsoleted */
 
 /** user-defined events with fixed length
@@ -253,6 +256,12 @@ struct snd_seq_ev_quote {
 	struct snd_seq_event *event;		/* quoted event */
 } __attribute__((packed));
 
+	/* UMP info change notify */
+struct snd_seq_ev_ump_notify {
+	unsigned char client;	/* Client number */
+	unsigned char block;	/* Block number (optional) */
+};
+
 union snd_seq_event_data { /* event data... */
 	struct snd_seq_ev_note note;
 	struct snd_seq_ev_ctrl control;
@@ -265,6 +274,7 @@ union snd_seq_event_data { /* event data... */
 	struct snd_seq_connect connect;
 	struct snd_seq_result result;
 	struct snd_seq_ev_quote quote;
+	struct snd_seq_ev_ump_notify ump_notify;
 };
 
 	/* sequencer event */
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/5 rawmidi: Extensions for tied device and substream inactive flag

In reply to Takashi Iwai

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().

---
 include/rawmidi.h     |  2 ++
 src/rawmidi/rawmidi.c | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
include/rawmidi.h +2 -0
index 2630d1e67572..af734b21db60 100644
@@ -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);
src/rawmidi/rawmidi.c +21 -1
index c4b45fa227f1..017b01c24b2b 100644
@@ -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;
 }
 
 /**
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/5 rawmidi: Make rawmidi flag bits doxygen-style comments

In reply to Takashi Iwai

We forgot to put the markers in rawmidi info bit flags.

---
 include/rawmidi.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/rawmidi.h +2 -2
index af734b21db60..713258f2cd80 100644
@@ -94,8 +94,8 @@ typedef enum _snd_rawmidi_read_mode {
 } snd_rawmidi_read_mode_t;
 
 /** 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 */
+#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);
Signature · 1 line
2.43.0
#5 lore raw

PATCH 5/5 seq: Define new events for UMP EP/FB change notifications

In reply to Takashi Iwai

Two new sequencer event types are added for notifications of UMP info
changes: SND_SEQ_EVENT_UMP_EP_CHANGE (68) and SND_SEQ_EVENT_UMP_BLOCK_CHANGE (69).

---
 include/local.h     |  1 +
 include/seq_event.h | 12 ++++++++++++
 2 files changed, 13 insertions(+)
include/local.h +1 -0
index 512e44555361..2b38ce647243 100644
@@ -208,6 +208,7 @@
 #define snd_seq_result		sndrv_seq_result
 #define snd_seq_queue_skew	sndrv_seq_queue_skew
 #define snd_seq_ev_queue_control	sndrv_seq_ev_queue_control
+#define snd_seq_ev_ump_notify	sndrv_seq_ev_ump_notify
 #define snd_seq_client_t	sndrv_seq_client_t
 #define snd_seq_client_type_t	sndrv_seq_client_type_t
 
include/seq_event.h +12 -0
index 0b59202f6e62..da542b106a48 100644
@@ -135,6 +135,11 @@ enum snd_seq_event_type {
 	/** Ports disconnected; event data type = #snd_seq_connect_t */
 	SND_SEQ_EVENT_PORT_UNSUBSCRIBED,
 
+	/** UMP Endpoint info has changed; event data type = #snd_seq_ev_ump_notify_t */
+	SND_SEQ_EVENT_UMP_EP_CHANGE,
+	/** UMP Block info has changed; event data type = #snd_seq_ev_ump_notify_t */
+	SND_SEQ_EVENT_UMP_BLOCK_CHANGE,
+
 	/** user-defined event; event data type = any (fixed size) */
 	SND_SEQ_EVENT_USR0 = 90,
 	/** user-defined event; event data type = any (fixed size) */
@@ -294,6 +299,12 @@ typedef struct snd_seq_ev_queue_control {
 	} param;				/**< data value union */
 } snd_seq_ev_queue_control_t;
 
+/** UMP info change notify */
+typedef struct snd_seq_ev_ump_notify {
+	unsigned char client;	/**< Client number */
+	unsigned char block;	/**< Block number (optional) */
+} snd_seq_ev_ump_notify_t;
+
 /** Sequencer event data */
 typedef union snd_seq_event_data {
 	snd_seq_ev_note_t note;		/**< note information */
@@ -306,6 +317,7 @@ typedef union snd_seq_event_data {
 	snd_seq_addr_t addr;		/**< address */
 	snd_seq_connect_t connect;	/**< connect information */
 	snd_seq_result_t result;	/**< operation result code */
+	snd_seq_ev_ump_notify_t ump_notify; /**< UMP info change notification */
 } snd_seq_event_data_t;
 
 /** Sequencer event */
Signature · 1 line
2.43.0