mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
jack: fix midi events in destination buffer
Don't fix up the midi events in the (read only) input buffer but after we have converted it into the JACK midi buffer. See #3560
This commit is contained in:
parent
e90bf4701c
commit
45bab72abc
1 changed files with 25 additions and 18 deletions
|
|
@ -1332,15 +1332,6 @@ static size_t convert_from_midi(void *midi, void *buffer, size_t size)
|
||||||
return b.state.offset;
|
return b.state.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fix_midi_event(uint8_t *data, size_t size)
|
|
||||||
{
|
|
||||||
/* fixup NoteOn with vel 0 */
|
|
||||||
if (size > 2 && (data[0] & 0xF0) == 0x90 && data[2] == 0x00) {
|
|
||||||
data[0] = 0x80 + (data[0] & 0x0F);
|
|
||||||
data[2] = 0x40;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int event_sort(struct spa_pod_control *a, struct spa_pod_control *b)
|
static inline int event_sort(struct spa_pod_control *a, struct spa_pod_control *b)
|
||||||
{
|
{
|
||||||
if (a->offset < b->offset)
|
if (a->offset < b->offset)
|
||||||
|
|
@ -1373,6 +1364,29 @@ static inline int event_sort(struct spa_pod_control *a, struct spa_pod_control *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void fix_midi_event(uint8_t *data, size_t size)
|
||||||
|
{
|
||||||
|
/* fixup NoteOn with vel 0 */
|
||||||
|
if (size > 2 && (data[0] & 0xF0) == 0x90 && data[2] == 0x00) {
|
||||||
|
data[0] = 0x80 + (data[0] & 0x0F);
|
||||||
|
data[2] = 0x40;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int midi_event_write(void *port_buffer,
|
||||||
|
jack_nframes_t time,
|
||||||
|
const jack_midi_data_t *data,
|
||||||
|
size_t data_size, bool fix)
|
||||||
|
{
|
||||||
|
jack_midi_data_t *retbuf = jack_midi_event_reserve (port_buffer, time, data_size);
|
||||||
|
if (SPA_UNLIKELY(retbuf == NULL))
|
||||||
|
return -ENOBUFS;
|
||||||
|
memcpy (retbuf, data, data_size);
|
||||||
|
if (fix)
|
||||||
|
fix_midi_event(retbuf, data_size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void convert_to_midi(struct spa_pod_sequence **seq, uint32_t n_seq, void *midi, bool fix)
|
static void convert_to_midi(struct spa_pod_sequence **seq, uint32_t n_seq, void *midi, bool fix)
|
||||||
{
|
{
|
||||||
struct spa_pod_control *c[n_seq];
|
struct spa_pod_control *c[n_seq];
|
||||||
|
|
@ -1405,10 +1419,7 @@ static void convert_to_midi(struct spa_pod_sequence **seq, uint32_t n_seq, void
|
||||||
uint8_t *data = SPA_POD_BODY(&next->value);
|
uint8_t *data = SPA_POD_BODY(&next->value);
|
||||||
size_t size = SPA_POD_BODY_SIZE(&next->value);
|
size_t size = SPA_POD_BODY_SIZE(&next->value);
|
||||||
|
|
||||||
if (fix)
|
if ((res = midi_event_write(midi, next->offset, data, size, fix)) < 0)
|
||||||
fix_midi_event(data, size);
|
|
||||||
|
|
||||||
if ((res = jack_midi_event_write(midi, next->offset, data, size)) < 0)
|
|
||||||
pw_log_warn("midi %p: can't write event: %s", midi,
|
pw_log_warn("midi %p: can't write event: %s", midi,
|
||||||
spa_strerror(res));
|
spa_strerror(res));
|
||||||
break;
|
break;
|
||||||
|
|
@ -6924,11 +6935,7 @@ int jack_midi_event_write(void *port_buffer,
|
||||||
const jack_midi_data_t *data,
|
const jack_midi_data_t *data,
|
||||||
size_t data_size)
|
size_t data_size)
|
||||||
{
|
{
|
||||||
jack_midi_data_t *retbuf = jack_midi_event_reserve (port_buffer, time, data_size);
|
return midi_event_write(port_buffer, time, data, data_size, false);
|
||||||
if (SPA_UNLIKELY(retbuf == NULL))
|
|
||||||
return -ENOBUFS;
|
|
||||||
memcpy (retbuf, data, data_size);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue