From 1e92ecea53ce37d1fa1b5adac7e05ff1ccd6c7ac Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 8 Mar 2024 16:31:00 +0100 Subject: [PATCH] jack: fix multiple midi input ports On the midi input ports, do the same trick as on the output ports: first convert the midi to JACK and then copy the whole buffer to the port specific storage. This makes it possible to have a different midi buffer per port and allow multiple threads to get the buffer concurrently. Fixes #3901 --- pipewire-jack/src/pipewire-jack.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index d62a80867..7c0f401ae 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -5267,7 +5267,8 @@ static void *get_buffer_input_float(struct port *p, jack_nframes_t frames) static void *get_buffer_input_midi(struct port *p, jack_nframes_t frames) { struct mix *mix; - void *ptr = midi_scratch; + void *ptr = p->emptyptr; + struct midi_buffer *mb = (struct midi_buffer*)midi_scratch; struct spa_pod_sequence *seq[MAX_MIX]; uint32_t n_seq = 0; @@ -5296,8 +5297,17 @@ static void *get_buffer_input_midi(struct port *p, jack_nframes_t frames) if (n_seq == MAX_MIX) break; } - midi_init_buffer(ptr, MIDI_SCRATCH_FRAMES); - convert_to_midi(seq, n_seq, ptr, p->client->fix_midi_events); + midi_init_buffer(mb, MIDI_SCRATCH_FRAMES); + /* first convert to a thread local scratch buffer, then memcpy into + * the per port buffer. This makes it possible to call this function concurrently + * but also have different pointers per port */ + convert_to_midi(seq, n_seq, mb, p->client->fix_midi_events); + memcpy(ptr, mb, sizeof(struct midi_buffer) + (mb->event_count + * sizeof(struct midi_event))); + if (mb->write_pos) { + size_t offs = mb->buffer_size - 1 - mb->write_pos; + memcpy(ptr, SPA_PTROFF(mb, offs, void), mb->write_pos); + } return ptr; }