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

@ -333,32 +333,36 @@ static void midi_to_netjack2(struct netjack2_peer *peer,
int size;
uint8_t data[16];
bool was_sysex = in_sysex;
size_t c_size = c.value.size;
uint64_t state = 0;
if (c.type != SPA_CONTROL_UMP)
continue;
size = spa_ump_to_midi(c_body, c.value.size, data, sizeof(data));
if (size <= 0)
continue;
while (c_size > 0) {
size = spa_ump_to_midi((const uint32_t**)&c_body, &c_size, data, sizeof(data), &state);
if (size <= 0)
break;
if (c.offset >= n_samples) {
buf->lost_events++;
continue;
if (c.offset >= n_samples) {
buf->lost_events++;
continue;
}
if (!in_sysex && data[0] == 0xf0)
in_sysex = true;
if (!in_sysex && peer->fix_midi)
fix_midi_event(data, size);
if (in_sysex && data[size-1] == 0xf7)
in_sysex = false;
if (was_sysex)
n2j_midi_buffer_append(buf, data, size);
else
n2j_midi_buffer_write(buf, c.offset, data, size);
}
if (!in_sysex && data[0] == 0xf0)
in_sysex = true;
if (!in_sysex && peer->fix_midi)
fix_midi_event(data, size);
if (in_sysex && data[size-1] == 0xf7)
in_sysex = false;
if (was_sysex)
n2j_midi_buffer_append(buf, data, size);
else
n2j_midi_buffer_write(buf, c.offset, data, size);
}
if (buf->write_pos > 0)
memmove(SPA_PTROFF(buf, sizeof(*buf) + buf->event_count * sizeof(struct nj2_midi_event), void),