]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ump: Add a function to provide the packet word length of a UMP type
authorTakashi Iwai <tiwai@suse.de>
Thu, 4 Jul 2024 07:53:20 +0000 (09:53 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 4 Jul 2024 12:44:00 +0000 (14:44 +0200)
Add a helper function to return the number of words of a given UMP
packet type.  Used for parsing MIDI Clip File stream, for example.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/ump_msg.h
src/Versions.in.in
src/rawmidi/ump.c

index 19e4cb28f8e83691acae45215a9f66e6ec01eb44..3d8f95efb57a0d1587282c2f2d6e99c26c2bb8b2 100644 (file)
@@ -1003,6 +1003,7 @@ static inline uint8_t snd_ump_sysex_msg_length(const uint32_t *ump)
 
 int snd_ump_msg_sysex_expand(const uint32_t *ump, uint8_t *buf, size_t maxlen,
                             size_t *filled);
+int snd_ump_packet_length(unsigned int type);
 
 #ifdef __cplusplus
 }
index c945d6dc50718d90b152eb0ee0f795e8782783c0..1c40d461dce459203c592cca864457465ba4ba7c 100644 (file)
@@ -212,5 +212,6 @@ ALSA_1.2.13 {
     @SYMBOL_PREFIX@snd_ump_endpoint_info_set_*;
     @SYMBOL_PREFIX@snd_ump_block_info_clear;
     @SYMBOL_PREFIX@snd_ump_block_info_set_*;
+    @SYMBOL_PREFIX@snd_ump_packet_length;
 #endif
 } ALSA_1.2.10;
index fddb60c2017c11f38c9d51962aae3124d537f406..d3676afbd82b0f87ae585dec7777598ac97dabc8 100644 (file)
@@ -1072,3 +1072,20 @@ int snd_ump_msg_sysex_expand(const uint32_t *ump, uint8_t *buf, size_t maxlen,
                return -EINVAL;
        }
 }
+
+/**
+ * \brief return the length of a UMP packet type
+ * \param type UMP packet type
+ * \return the length of the given UMP packet type in 32bit words (from 1 to 4),
+ *   or 0 for negative inputs.
+ */
+int snd_ump_packet_length(unsigned int type)
+{
+       static int packet_length[16] = {
+               1, 1, 1, 2, 2, 4, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4
+       };
+
+       if (type > 16)
+               return 0;
+       return packet_length[type];
+}