aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-11-15 09:43:43 -0500
committerDavid Robillard <d@drobilla.net>2024-11-24 18:53:10 -0500
commit7c9858897ff6014a6cf36cefbd05f1f4f63817c4 (patch)
tree266ef6241d7d6463816c485a75749bce8818882c
parente517361e4e9d8eae572a89a761a4def3ad8870eb (diff)
downloadjalv-7c9858897ff6014a6cf36cefbd05f1f4f63817c4.tar.gz
jalv-7c9858897ff6014a6cf36cefbd05f1f4f63817c4.tar.bz2
jalv-7c9858897ff6014a6cf36cefbd05f1f4f63817c4.zip
Move ring error handling and logging to a higher level
This removes the dependency on the "global" Jalv object from the low-level message sending functions.
-rw-r--r--.clang-format1
-rw-r--r--src/jack.c9
-rw-r--r--src/jalv.c78
-rw-r--r--src/jalv_internal.h17
-rw-r--r--src/portaudio.c9
-rw-r--r--src/state.c11
6 files changed, 72 insertions, 53 deletions
diff --git a/.clang-format b/.clang-format
index 6332390..d3ca92c 100644
--- a/.clang-format
+++ b/.clang-format
@@ -32,5 +32,4 @@ KeepEmptyLinesAtTheStartOfBlocks: false
SpacesInContainerLiterals: false
StatementMacros:
- Q_OBJECT
- - _Pragma
...
diff --git a/src/jack.c b/src/jack.c
index e6ed812..212db43 100644
--- a/src/jack.c
+++ b/src/jack.c
@@ -232,12 +232,17 @@ jack_process_cb(jack_nframes_t nframes, void* data)
if (jalv->has_ui) {
// Forward event to UI
- jalv_write_event(jalv, jalv->plugin_to_ui, p, size, type, body);
+ jalv_write_event(jalv->plugin_to_ui,
+ p,
+ jalv->urids.atom_eventTransfer,
+ size,
+ type,
+ body);
}
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- jalv_write_control(jalv, jalv->plugin_to_ui, p, port->control);
+ jalv_write_control(jalv->plugin_to_ui, p, port->control);
}
}
diff --git a/src/jalv.c b/src/jalv.c
index 5c91791..49489c9 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -494,22 +494,21 @@ jalv_ui_is_resizable(Jalv* jalv)
return !fs_matches && !nrs_matches;
}
-static void
+static ZixStatus
jalv_send_control_to_plugin(Jalv* const jalv,
uint32_t port_index,
uint32_t buffer_size,
const void* buffer)
{
if (buffer_size != sizeof(float)) {
- jalv_log(JALV_LOG_ERR, "UI wrote invalid control size %u\n", buffer_size);
-
- } else {
- jalv_write_control(
- jalv, jalv->ui_to_plugin, port_index, *(const float*)buffer);
+ return ZIX_STATUS_BAD_ARG;
}
+
+ return jalv_write_control(
+ jalv->ui_to_plugin, port_index, *(const float*)buffer);
}
-static void
+static ZixStatus
jalv_send_event_to_plugin(Jalv* const jalv,
uint32_t port_index,
uint32_t buffer_size,
@@ -525,9 +524,15 @@ jalv_send_event_to_plugin(Jalv* const jalv,
} else {
jalv_dump_atom(jalv, stdout, "UI => Plugin", atom, 36);
- jalv_write_event(
- jalv, jalv->ui_to_plugin, port_index, atom->size, atom->type, atom + 1U);
+ return jalv_write_event(jalv->ui_to_plugin,
+ port_index,
+ jalv->urids.atom_eventTransfer,
+ atom->size,
+ atom->type,
+ atom + 1U);
}
+
+ return ZIX_STATUS_SUCCESS;
}
static void
@@ -538,15 +543,16 @@ jalv_send_to_plugin(void* const jalv_handle,
const void* buffer)
{
Jalv* const jalv = (Jalv*)jalv_handle;
+ ZixStatus st = ZIX_STATUS_SUCCESS;
if (port_index >= jalv->num_ports) {
jalv_log(JALV_LOG_ERR, "UI wrote to invalid port index %u\n", port_index);
} else if (protocol == 0U) {
- jalv_send_control_to_plugin(jalv, port_index, buffer_size, buffer);
+ st = jalv_send_control_to_plugin(jalv, port_index, buffer_size, buffer);
} else if (protocol == jalv->urids.atom_eventTransfer) {
- jalv_send_event_to_plugin(jalv, port_index, buffer_size, buffer);
+ st = jalv_send_event_to_plugin(jalv, port_index, buffer_size, buffer);
} else {
jalv_log(JALV_LOG_ERR,
@@ -554,6 +560,12 @@ jalv_send_to_plugin(void* const jalv_handle,
protocol,
unmap_uri(jalv, protocol));
}
+
+ if (st) {
+ jalv_log(JALV_LOG_ERR,
+ "Failed to write to plugin from UI (%s)\n",
+ zix_strerror(st));
+ }
}
static void
@@ -630,31 +642,28 @@ jalv_init_ui(Jalv* jalv)
}
}
-static int
-jalv_write_control_change(const Jalv* const jalv,
- ZixRing* const target,
+static ZixStatus
+jalv_write_control_change(ZixRing* const target,
const void* const header,
const uint32_t header_size,
const void* const body,
const uint32_t body_size)
{
ZixRingTransaction tx = zix_ring_begin_write(target);
- if (zix_ring_amend_write(target, &tx, header, header_size) ||
- zix_ring_amend_write(target, &tx, body, body_size)) {
- jalv_log(JALV_LOG_ERR,
- target == jalv->plugin_to_ui ? "Plugin => UI buffer overflow"
- : "UI => Plugin buffer overflow");
- return -1;
+
+ ZixStatus st = ZIX_STATUS_SUCCESS;
+ if (!(st = zix_ring_amend_write(target, &tx, header, header_size)) &&
+ !(st = zix_ring_amend_write(target, &tx, body, body_size))) {
+ st = zix_ring_commit_write(target, &tx);
}
- zix_ring_commit_write(target, &tx);
- return 0;
+ return st;
}
-int
-jalv_write_event(const Jalv* const jalv,
- ZixRing* const target,
+ZixStatus
+jalv_write_event(ZixRing* const target,
const uint32_t port_index,
+ const uint32_t protocol,
const uint32_t size,
const LV2_URID type,
const void* const body)
@@ -666,24 +675,21 @@ jalv_write_event(const Jalv* const jalv,
LV2_Atom atom;
} Header;
- const Header header = {
- {port_index, jalv->urids.atom_eventTransfer, sizeof(LV2_Atom) + size},
- {size, type}};
+ const Header header = {{port_index, protocol, sizeof(LV2_Atom) + size},
+ {size, type}};
- return jalv_write_control_change(
- jalv, target, &header, sizeof(header), body, size);
+ return jalv_write_control_change(target, &header, sizeof(header), body, size);
}
-int
-jalv_write_control(const Jalv* const jalv,
- ZixRing* const target,
- const uint32_t port_index,
- const float value)
+ZixStatus
+jalv_write_control(ZixRing* const target,
+ const uint32_t port_index,
+ const float value)
{
const ControlChange header = {port_index, 0, sizeof(value)};
return jalv_write_control_change(
- jalv, target, &header, sizeof(header), &value, sizeof(value));
+ target, &header, sizeof(header), &value, sizeof(value));
}
void
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index d4606f5..3ace59e 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -17,6 +17,7 @@
#include "zix/ring.h"
#include "zix/sem.h"
+#include "zix/status.h"
#include "lilv/lilv.h"
#include "serd/serd.h"
@@ -161,18 +162,18 @@ jalv_ui_is_resizable(Jalv* jalv);
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 protocol Port protocol (0 for float control, or atom:eventTransfer).o
@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(const Jalv* jalv,
- ZixRing* target,
+ZixStatus
+jalv_write_event(ZixRing* target,
uint32_t port_index,
+ uint32_t protocol,
uint32_t size,
LV2_URID type,
const void* body);
@@ -183,17 +184,13 @@ jalv_write_event(const Jalv* jalv,
This is used to transfer control port value changes between the plugin and
UI.
- @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 value New control port value.
@return 0 on success, non-zero on failure (overflow).
*/
-int
-jalv_write_control(const Jalv* jalv,
- ZixRing* target,
- uint32_t port_index,
- float value);
+ZixStatus
+jalv_write_control(ZixRing* target, uint32_t port_index, float value);
/// Dump an atom to stdout in a "developer-readable" format (Turtle)
void
diff --git a/src/portaudio.c b/src/portaudio.c
index 6088773..dff77b3 100644
--- a/src/portaudio.c
+++ b/src/portaudio.c
@@ -86,12 +86,17 @@ pa_process_cb(const void* inputs,
if (jalv->has_ui) {
// Forward event to UI
- jalv_write_event(jalv, jalv->plugin_to_ui, p, size, type, body);
+ jalv_write_event(jalv->plugin_to_ui,
+ p,
+ jalv->urids.atom_eventTransfer,
+ size,
+ type,
+ body);
}
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- jalv_write_control(jalv, jalv->plugin_to_ui, p, port->control);
+ jalv_write_control(jalv->plugin_to_ui, p, port->control);
}
}
diff --git a/src/state.c b/src/state.c
index 5bc781c..7e25f2d 100644
--- a/src/state.c
+++ b/src/state.c
@@ -13,6 +13,7 @@
#include "lv2/state/state.h"
#include "zix/attributes.h"
#include "zix/sem.h"
+#include "zix/status.h"
#include <stdbool.h>
#include <stdint.h>
@@ -146,17 +147,23 @@ set_port_value(const char* port_symbol,
return;
}
+ ZixStatus st = ZIX_STATUS_SUCCESS;
if (jalv->play_state != JALV_RUNNING) {
// Set value on port struct directly
port->control = fvalue;
} else {
// Send value to plugin (as if from UI)
- jalv_write_control(jalv, jalv->ui_to_plugin, port->index, fvalue);
+ st = jalv_write_control(jalv->ui_to_plugin, port->index, fvalue);
}
if (jalv->has_ui) {
// Update UI (as if from plugin)
- jalv_write_control(jalv, jalv->plugin_to_ui, port->index, fvalue);
+ st = jalv_write_control(jalv->plugin_to_ui, port->index, fvalue);
+ }
+
+ if (st) {
+ jalv_log(
+ JALV_LOG_ERR, "Failed to write control change (%s)\n", zix_strerror(st));
}
}