aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-08-10 14:26:06 -0400
committerDavid Robillard <d@drobilla.net>2022-08-17 13:51:06 -0400
commit53812b2fc4aa809bf8156faee88b59cc69d1b9ec (patch)
treed3973385b33dcac5ff23d8fca280bbc10d863960
parent8e5bf419f1938fb2b97cd984641e51727a7673aa (diff)
downloadjalv-53812b2fc4aa809bf8156faee88b59cc69d1b9ec.tar.gz
jalv-53812b2fc4aa809bf8156faee88b59cc69d1b9ec.tar.bz2
jalv-53812b2fc4aa809bf8156faee88b59cc69d1b9ec.zip
Factor out jalv_write_event()
-rw-r--r--src/jack.c5
-rw-r--r--src/jalv.c24
-rw-r--r--src/jalv_internal.h26
-rw-r--r--src/portaudio.c2
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 <jack/jack.h>
@@ -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 &&