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

@ -788,30 +788,35 @@ static int write_data(struct impl *this, struct spa_data *d)
while (spa_pod_parser_get_control_body(&parser, &c, &c_body) >= 0) {
int size;
uint8_t event[32];
const uint32_t *ump = c_body;
size_t ump_size = c.value.size;
uint64_t state = 0;
if (c.type != SPA_CONTROL_UMP)
continue;
time = SPA_MAX(time, this->current_time + c.offset * SPA_NSEC_PER_SEC / this->rate);
size = spa_ump_to_midi(c_body, c.value.size, event, sizeof(event));
if (size <= 0)
continue;
while (ump_size > 0) {
size = spa_ump_to_midi(&ump, &ump_size, event, sizeof(event), &state);
if (size <= 0)
break;
spa_log_trace(this->log, "%p: output event:0x%x time:%"PRIu64, this,
(size > 0) ? event[0] : 0, time);
spa_log_trace(this->log, "%p: output event:0x%x time:%"PRIu64, this,
(size > 0) ? event[0] : 0, time);
do {
res = spa_bt_midi_writer_write(&this->writer,
time, event, size);
if (res < 0) {
return res;
} else if (res) {
int res2;
if ((res2 = flush_packet(this)) < 0)
return res2;
}
} while (res);
do {
res = spa_bt_midi_writer_write(&this->writer,
time, event, size);
if (res < 0) {
return res;
} else if (res) {
int res2;
if ((res2 = flush_packet(this)) < 0)
return res2;
}
} while (res);
}
}
if ((res = flush_packet(this)) < 0)