diff mbox series

[alsa-lib,1/4] ump: Add missing *_set variants for snd_ump_endpoint_info and snd_ump_block_info

Message ID 20240619152855.6809-2-tiwai@suse.de
State New
Headers show
Series Add API helper functions for creating UMP Endpoint and Blocks | expand

Commit Message

Takashi Iwai June 19, 2024, 3:28 p.m. UTC
The API functions to fill the data on snd_ump_endpoint_info and
snd_ump_block_info were missing.  Let's add them.

They can be used to construct a virtual UMP endpoint and block.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/ump.h     |  30 ++++-
 src/rawmidi/ump.c | 304 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 322 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/include/ump.h b/include/ump.h
index 1e5e053454b3..45b3ad270db7 100644
--- a/include/ump.h
+++ b/include/ump.h
@@ -77,6 +77,7 @@  size_t snd_ump_endpoint_info_sizeof(void);
 #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_clear(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);
@@ -93,6 +94,20 @@  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);
 
+void snd_ump_endpoint_info_set_card(snd_ump_endpoint_info_t *info, unsigned int card);
+void snd_ump_endpoint_info_set_device(snd_ump_endpoint_info_t *info, unsigned int device);
+void snd_ump_endpoint_info_set_flags(snd_ump_endpoint_info_t *info, unsigned int flags);
+void snd_ump_endpoint_info_set_protocol_caps(snd_ump_endpoint_info_t *info, unsigned int caps);
+void snd_ump_endpoint_info_set_protocol(snd_ump_endpoint_info_t *info, unsigned int protocols);
+void snd_ump_endpoint_info_set_num_blocks(snd_ump_endpoint_info_t *info, unsigned int num_blocks);
+void snd_ump_endpoint_info_set_version(snd_ump_endpoint_info_t *info, unsigned int version);
+void snd_ump_endpoint_info_set_manufacturer_id(snd_ump_endpoint_info_t *info, unsigned int id);
+void snd_ump_endpoint_info_set_family_id(snd_ump_endpoint_info_t *info, unsigned int id);
+void snd_ump_endpoint_info_set_model_id(snd_ump_endpoint_info_t *info, unsigned int id);
+void snd_ump_endpoint_info_set_sw_revision(snd_ump_endpoint_info_t *info, const unsigned char *id);
+void snd_ump_endpoint_info_set_name(snd_ump_endpoint_info_t *info, const char *name);
+void snd_ump_endpoint_info_set_product_id(snd_ump_endpoint_info_t *info, const char *id);
+
 /** 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 */
@@ -118,11 +133,11 @@  size_t snd_ump_block_info_sizeof(void);
 #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_clear(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);
@@ -134,6 +149,19 @@  unsigned int snd_ump_block_info_get_ui_hint(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);
 
+void snd_ump_block_info_set_card(snd_ump_block_info_t *info, unsigned int card);
+void snd_ump_block_info_set_device(snd_ump_block_info_t *info, unsigned int device);
+void snd_ump_block_info_set_block_id(snd_ump_block_info_t *info, unsigned int id);
+void snd_ump_block_info_set_active(snd_ump_block_info_t *info, unsigned int active);
+void snd_ump_block_info_set_flags(snd_ump_block_info_t *info, unsigned int flags);
+void snd_ump_block_info_set_direction(snd_ump_block_info_t *info, unsigned int direction);
+void snd_ump_block_info_set_first_group(snd_ump_block_info_t *info, unsigned int first_group);
+void snd_ump_block_info_set_num_groups(snd_ump_block_info_t *info, unsigned int num_groups);
+void snd_ump_block_info_set_midi_ci_version(snd_ump_block_info_t *info, unsigned int version);
+void snd_ump_block_info_set_sysex8_streams(snd_ump_block_info_t *info, unsigned int streams);
+void snd_ump_block_info_set_ui_hint(snd_ump_block_info_t *info, unsigned int hint);
+void snd_ump_block_info_set_name(snd_ump_block_info_t *info, const char *name);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/rawmidi/ump.c b/src/rawmidi/ump.c
index 39c1c4a91928..6c1097a7452b 100644
--- a/src/rawmidi/ump.c
+++ b/src/rawmidi/ump.c
@@ -337,6 +337,17 @@  void snd_ump_endpoint_info_free(snd_ump_endpoint_info_t *info)
 	free(info);
 }
 
+/**
+ * \brief clears the snd_ump_endpoint_info_t structure
+ * \param info pointer to the snd_ump_endpoint_info_t structure to clear
+ *
+ * Zero-clear the snd_ump_endpoint_info_t object.
+ */
+void snd_ump_endpoint_info_clear(snd_ump_endpoint_info_t *info)
+{
+	memset(info, 0, sizeof(*info));
+}
+
 /**
  * \brief copy one snd_ump_endpoint_info_t structure to another
  * \param dst destination snd_ump_endpoint_info_t structure
@@ -478,6 +489,149 @@  const char *snd_ump_endpoint_info_get_product_id(const snd_ump_endpoint_info_t *
 	return (const char *)info->product_id;
 }
 
+/**
+ * \brief set card number of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param card the card number of the given UMP endpoint
+ */
+void snd_ump_endpoint_info_set_card(snd_ump_endpoint_info_t *info,
+				    unsigned int card)
+{
+	info->card = card;
+}
+
+/**
+ * \brief set device number of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param device the device number of the given UMP endpoint
+ */
+void snd_ump_endpoint_info_set_device(snd_ump_endpoint_info_t *info,
+				      unsigned int device)
+{
+	info->device = device;
+}
+
+/**
+ * \brief set info flags of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param flags UMP endpoint flag bits
+ */
+void snd_ump_endpoint_info_set_flags(snd_ump_endpoint_info_t *info,
+				     unsigned int flags)
+{
+	info->flags = flags;
+}
+
+/**
+ * \brief set protocol capability bits of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param caps UMP endpoint protocol capability bits
+ */
+void snd_ump_endpoint_info_set_protocol_caps(snd_ump_endpoint_info_t *info,
+					     unsigned int caps)
+{
+	info->protocol_caps = caps;
+}
+
+/**
+ * \brief set the current protocol of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param caps the UMP endpoint protocol bits
+ */
+void snd_ump_endpoint_info_set_protocol(snd_ump_endpoint_info_t *info,
+					unsigned int protocol)
+{
+	info->protocol = protocol;
+}
+
+/**
+ * \brief set the number of UMP blocks of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param blocks the number of UMP blocks
+ */
+void snd_ump_endpoint_info_set_num_blocks(snd_ump_endpoint_info_t *info,
+					  unsigned int blocks)
+{
+	info->num_blocks = blocks;
+}
+
+/**
+ * \brief set the UMP version number of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param version the UMP version number
+ */
+void snd_ump_endpoint_info_set_version(snd_ump_endpoint_info_t *info,
+				       unsigned int version)
+{
+	info->version = version;
+}
+
+/**
+ * \brief set the UMP manufacturer ID of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param id UMP manufacturer ID
+ */
+void snd_ump_endpoint_info_set_manufacturer_id(snd_ump_endpoint_info_t *info,
+					       unsigned int id)
+{
+	info->manufacturer_id = id;
+}
+
+/**
+ * \brief set the UMP family ID of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param id UMP family ID
+ */
+void snd_ump_endpoint_info_set_family_id(snd_ump_endpoint_info_t *info,
+					 unsigned int id)
+{
+	info->family_id = id;
+}
+
+/**
+ * \brief set the UMP model ID of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param id UMP model ID
+ */
+void snd_ump_endpoint_info_set_model_id(snd_ump_endpoint_info_t *info,
+					unsigned int id)
+{
+	info->model_id = id;
+}
+
+/**
+ * \brief set the UMP software revision of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param id UMP software revision in 4 bytes array
+ */
+void snd_ump_endpoint_info_set_sw_revision(snd_ump_endpoint_info_t *info,
+					   const unsigned char *id)
+{
+	memcpy(info->sw_revision, id, sizeof(info->sw_revision));
+}
+
+/**
+ * \brief set the name of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param name UMP endpoint name string
+ */
+void snd_ump_endpoint_info_set_name(snd_ump_endpoint_info_t *info,
+				    const char *name)
+{
+	snd_strlcpy((char *)info->name, name, sizeof(info->name));
+}
+
+/**
+ * \brief set the product ID string of UMP endpoint
+ * \param info pointer to a snd_ump_endpoint_info_t structure
+ * \param id UMP endpoint product ID string
+ */
+void snd_ump_endpoint_info_set_product_id(snd_ump_endpoint_info_t *info,
+					  const char *id)
+{
+	snd_strlcpy((char *)info->product_id, id, sizeof(info->product_id));
+}
+
 /**
  * \brief get endpoint information about UMP handle
  * \param ump UMP handle
@@ -526,6 +680,17 @@  void snd_ump_block_info_free(snd_ump_block_info_t *info)
 	free(info);
 }
 
+/**
+ * \brief clears the snd_ump_block_info_t structure
+ * \param info pointer to the snd_ump_block_info_t structure to clear
+ *
+ * Zero-clear the snd_ump_block_info_t object.
+ */
+void snd_ump_block_info_clear(snd_ump_block_info_t *info)
+{
+	memset(info, 0, sizeof(*info));
+}
+
 /**
  * \brief copy one snd_ump_block_info_t structure to another
  * \param dst destination snd_ump_block_info_t structure
@@ -567,17 +732,6 @@  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
@@ -668,6 +822,134 @@  const char *snd_ump_block_info_get_name(const snd_ump_block_info_t *info)
 	return (const char *)info->name;
 }
 
+/**
+ * \brief set card number to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param card the card number
+ */
+void snd_ump_block_info_set_card(snd_ump_block_info_t *info, unsigned int card)
+{
+	info->card = card;
+}
+
+/**
+ * \brief set device number to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param device the device number
+ */
+void snd_ump_block_info_set_device(snd_ump_block_info_t *info, unsigned int device)
+{
+	info->device = device;
+}
+
+/**
+ * \brief set UMP block ID to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param id the ID number
+ *
+ * This function is mostly used for setting the block ID to query.
+ */
+void snd_ump_block_info_set_block_id(snd_ump_block_info_t *info,
+				     unsigned int id)
+{
+	info->block_id = id;
+}
+
+/**
+ * \brief set activeness to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param active 1 if the block is active or 0 if inactive
+ */
+void snd_ump_block_info_set_active(snd_ump_block_info_t *info, unsigned int active)
+{
+	info->active = !!active;
+}
+
+/**
+ * \brief set UMP block information flags to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param flags flag bits for the given UMP block
+ */
+void snd_ump_block_info_set_flags(snd_ump_block_info_t *info, unsigned int flags)
+{
+	info->flags = flags;
+}
+
+/**
+ * \brief set UMP block direction to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param direction direction of UMP block (input,output,bidirectional)
+ */
+void snd_ump_block_info_set_direction(snd_ump_block_info_t *info, unsigned int direction)
+{
+	info->direction = direction;
+}
+
+/**
+ * \brief set first UMP group to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param first_group the first UMP group ID belonging to the block
+ */
+void snd_ump_block_info_set_first_group(snd_ump_block_info_t *info,
+					unsigned int first_group)
+{
+	info->first_group = first_group;
+}
+
+/**
+ * \brief set number of UMP groups to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param num_groups the number of UMP groups belonging to the block
+ */
+void snd_ump_block_info_set_num_groups(snd_ump_block_info_t *info,
+				       unsigned int num_groups)
+{
+	info->num_groups = num_groups;
+}
+
+/**
+ * \brief set MIDI-CI version number to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param version MIDI-CI version number
+ */
+void snd_ump_block_info_set_midi_ci_version(snd_ump_block_info_t *info,
+					    unsigned int version)
+{
+	info->midi_ci_version = version;
+}
+
+/**
+ * \brief set number of supported SysEx8 streams to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param streams number of supported SysEx8 streams
+ */
+void snd_ump_block_info_set_sysex8_streams(snd_ump_block_info_t *info,
+					   unsigned int streams)
+{
+	info->sysex8_streams = streams;
+}
+
+/**
+ * \brief set UI Hint to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param hint the hint bits
+ */
+void snd_ump_block_info_set_ui_hint(snd_ump_block_info_t *info, unsigned int hint)
+{
+	info->ui_hint = hint;
+}
+
+/**
+ * \brief set the name string to snd_ump_block_info_t structure
+ * \param info pointer to a snd_ump_block_info_t structure
+ * \param name the name string of UMP block
+ */
+void snd_ump_block_info_set_name(snd_ump_block_info_t *info,
+				 const char *name)
+{
+	snd_strlcpy((char *)info->name, name, sizeof(info->name));
+}
+
 /**
  * \brief get UMP block information
  * \param ump UMP handle