Skip to content

Commit

Permalink
ump: Add a function to provide the packet word length of a UMP type
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tiwai committed Jul 4, 2024
1 parent ade099f commit 568b2ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/ump_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/Versions.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
17 changes: 17 additions & 0 deletions src/rawmidi/ump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

0 comments on commit 568b2ac

Please sign in to comment.