control: improve UMP to Midi conversiom

Improve the spa_ump_to_midi function so that it can consume multiple UMP
messages and produce multiple midi messages.

Some UMP messages (like program changes) need to be translated into up
to 3 midi messages. Do this byt adding a state to the function and by
making it consume the input bytes, just like the spa_ump_from_midi
function.

Adapt code to this new world. This is a little API break..
This commit is contained in:
Wim Taymans 2025-08-19 17:41:03 +02:00
parent bf10458604
commit e35a8554f8
13 changed files with 307 additions and 228 deletions

View file

@ -239,27 +239,32 @@ static void vban_midi_flush_packets(struct impl *impl,
while (spa_pod_parser_get_control_body(parser, &c, &c_body) >= 0) {
int size;
uint8_t event[16];
uint64_t state = 0;
size_t c_size = c.value.size;
if (c.type != SPA_CONTROL_UMP)
continue;
size = spa_ump_to_midi(c_body, c.value.size, event, sizeof(event));
if (size <= 0)
continue;
while (c_size > 0) {
size = spa_ump_to_midi((const uint32_t**)&c_body,
&c_size, event, sizeof(event), &state);
if (size <= 0)
break;
if (len == 0) {
/* start new packet */
header.n_frames++;
} else if (len + size > impl->mtu) {
/* flush packet when we have one and when it's too large */
iov[1].iov_len = len;
if (len == 0) {
/* start new packet */
header.n_frames++;
} else if (len + size > impl->mtu) {
/* flush packet when we have one and when it's too large */
iov[1].iov_len = len;
pw_log_debug("sending %d", len);
vban_stream_emit_send_packet(impl, iov, 2);
len = 0;
pw_log_debug("sending %d", len);
vban_stream_emit_send_packet(impl, iov, 2);
len = 0;
}
memcpy(&impl->buffer[len], event, size);
len += size;
}
memcpy(&impl->buffer[len], event, size);
len += size;
}
if (len > 0) {
/* flush last packet */