From 53812b2fc4aa809bf8156faee88b59cc69d1b9ec Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 10 Aug 2022 14:26:06 -0400 Subject: Factor out jalv_write_event() --- src/jack.c | 5 +++-- src/jalv.c | 24 ++++++++++++------------ src/jalv_internal.h | 26 ++++++++++++++++++++------ src/portaudio.c | 2 +- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/jack.c b/src/jack.c index 5050fd3..2a4852c 100644 --- a/src/jack.c +++ b/src/jack.c @@ -17,6 +17,7 @@ #include "lilv/lilv.h" #include "lv2/atom/atom.h" #include "lv2/atom/forge.h" +#include "lv2/urid/urid.h" #include "zix/sem.h" #include @@ -227,7 +228,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) // Get event from LV2 buffer uint32_t frames = 0; uint32_t subframes = 0; - uint32_t type = 0; + LV2_URID type = 0; uint32_t size = 0; void* body = NULL; lv2_evbuf_get(i, &frames, &subframes, &type, &size, &body); @@ -239,7 +240,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) if (jalv->has_ui) { // Forward event to UI - jalv_send_to_ui(jalv, p, type, size, body); + jalv_write_event(jalv, jalv->plugin_to_ui, p, size, type, body); } } } else if (send_ui_updates && port->flow == FLOW_OUTPUT && diff --git a/src/jalv.c b/src/jalv.c index e932f8e..8b41ac1 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -592,12 +592,13 @@ jalv_init_ui(Jalv* jalv) } } -bool -jalv_send_to_ui(Jalv* jalv, - uint32_t port_index, - uint32_t type, - uint32_t size, - const void* body) +int +jalv_write_event(Jalv* const jalv, + ZixRing* const target, + const uint32_t port_index, + const uint32_t size, + const LV2_URID type, + const void* const body) { // TODO: Be more disciminate about what to send char evbuf[sizeof(ControlChange) + sizeof(LV2_Atom)]; @@ -610,14 +611,13 @@ jalv_send_to_ui(Jalv* jalv, atom->type = type; atom->size = size; - if (zix_ring_write_space(jalv->plugin_to_ui) >= sizeof(evbuf) + size) { - zix_ring_write(jalv->plugin_to_ui, evbuf, sizeof(evbuf)); - zix_ring_write(jalv->plugin_to_ui, (const char*)body, size); - return true; + if (zix_ring_write_space(target) >= sizeof(evbuf) + size) { + zix_ring_write(target, evbuf, sizeof(evbuf)); + zix_ring_write(target, (const char*)body, size); + return 0; } - jalv_log(JALV_LOG_ERR, "Plugin => UI buffer overflow\n"); - return false; + return 1; } int diff --git a/src/jalv_internal.h b/src/jalv_internal.h index df03379..8028bcc 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -175,12 +175,26 @@ jalv_ui_port_event(Jalv* jalv, uint32_t protocol, const void* buffer); -bool -jalv_send_to_ui(Jalv* jalv, - uint32_t port_index, - uint32_t type, - uint32_t size, - const void* body); +/** + Write a port event using the atom:eventTransfer protocol. + + This is used to transfer atoms between the plugin and UI via sequence ports. + + @param jalv Jalv instance. + @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin). + @param port_index Index of the port this change is for. + @param size Size of body in bytes. + @param type Atom type URID. + @param body Atom body. + @return 0 on success, non-zero on failure (overflow). +*/ +int +jalv_write_event(Jalv* jalv, + ZixRing* target, + uint32_t port_index, + uint32_t size, + LV2_URID type, + const void* body); /** Write a control port change using the default (0) protocol. diff --git a/src/portaudio.c b/src/portaudio.c index f7b7e45..f9283dd 100644 --- a/src/portaudio.c +++ b/src/portaudio.c @@ -75,7 +75,7 @@ pa_process_cb(const void* inputs, if (jalv->has_ui) { // Forward event to UI - jalv_send_to_ui(jalv, p, type, size, body); + jalv_write_event(jalv, jalv->plugin_to_ui, p, size, type, body); } } } else if (send_ui_updates && port->flow == FLOW_OUTPUT && -- cgit v1.2.1