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

@ -1824,18 +1824,20 @@ static int apply_props(struct impl *this, const struct spa_pod *param)
static int apply_midi(struct impl *this, const struct spa_pod *value)
{
struct props *p = &this->props;
uint8_t data[8];
int size;
uint8_t ev[8];
int ev_size;
const uint32_t *body = SPA_POD_BODY_CONST(value);
size_t size = SPA_POD_BODY_SIZE(value);
uint64_t state = 0;
size = spa_ump_to_midi(SPA_POD_BODY(value), SPA_POD_BODY_SIZE(value),
data, sizeof(data));
if (size < 3)
ev_size = spa_ump_to_midi(&body, &size, ev, sizeof(ev), &state);
if (ev_size < 3)
return -EINVAL;
if ((data[0] & 0xf0) != 0xb0 || data[1] != 7)
if ((ev[0] & 0xf0) != 0xb0 || ev[1] != 7)
return 0;
p->volume = data[2] / 127.0f;
p->volume = ev[2] / 127.0f;
set_volume(this);
return 1;
}