aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-11-16 18:26:31 -0500
committerDavid Robillard <d@drobilla.net>2024-11-24 19:03:54 -0500
commit06bd42a00bd86f5d487727ff8f08797f9286b27f (patch)
treef0240d6095ebdbb7ddf5ff4f099db45c919b3425
parentd52d38ccdc9bc38fe5c62eb2458be30b3cf6ca59 (diff)
downloadjalv-06bd42a00bd86f5d487727ff8f08797f9286b27f.tar.gz
jalv-06bd42a00bd86f5d487727ff8f08797f9286b27f.tar.bz2
jalv-06bd42a00bd86f5d487727ff8f08797f9286b27f.zip
Use message mechanism to request plugin state updates
Replaces highly questionable cross-thread use of the request_update flag.
-rw-r--r--src/comm.h1
-rw-r--r--src/jack.c6
-rw-r--r--src/jalv_internal.h1
-rw-r--r--src/portaudio.c11
-rw-r--r--src/process.c28
-rw-r--r--src/process.h11
-rw-r--r--src/state.c6
7 files changed, 21 insertions, 43 deletions
diff --git a/src/comm.h b/src/comm.h
index 11d7dc3..d570b3a 100644
--- a/src/comm.h
+++ b/src/comm.h
@@ -23,6 +23,7 @@ typedef enum {
CONTROL_PORT_CHANGE, ///< Value change for a control port (float)
EVENT_TRANSFER, ///< Event transfer for a sequence port (atom)
LATENCY_CHANGE, ///< Change to plugin latency
+ STATE_REQUEST, ///< Request for a plugin state update (no payload)
} JalvMessageType;
/**
diff --git a/src/jack.c b/src/jack.c
index a138f57..5ea9065 100644
--- a/src/jack.c
+++ b/src/jack.c
@@ -199,11 +199,6 @@ jack_process_cb(jack_nframes_t nframes, void* data)
&iter, 0, 0, lv2_pos->type, lv2_pos->size, LV2_ATOM_BODY(lv2_pos));
}
- if (port->is_primary && jalv->request_update) {
- // Plugin state has changed, request an update
- jalv_write_get_message(&iter, &jalv->urids);
- }
-
if (port->sys_port) {
// Write Jack MIDI input
void* buf = jack_port_get_buffer(port->sys_port, nframes);
@@ -219,7 +214,6 @@ jack_process_cb(jack_nframes_t nframes, void* data)
lv2_evbuf_reset(port->evbuf, false);
}
}
- jalv->request_update = false;
// Run plugin for this cycle
const bool send_ui_updates = jalv_run(jalv, nframes);
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 77f9993..db9ec68 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -116,7 +116,6 @@ struct JalvImpl {
bool rolling; ///< Transport speed (0=stop, 1=play)
bool buf_size_set; ///< True iff buffer size callback fired
bool has_ui; ///< True iff a control UI is present
- bool request_update; ///< True iff a plugin update is needed
bool safe_restore; ///< Plugin restore() is thread-safe
JalvFeatures features;
const LV2_Feature** feature_list;
diff --git a/src/portaudio.c b/src/portaudio.c
index 0a7fa5a..d0c4aa3 100644
--- a/src/portaudio.c
+++ b/src/portaudio.c
@@ -49,19 +49,10 @@ pa_process_cb(const void* inputs,
lilv_instance_connect_port(
jalv->instance, i, ((float**)outputs)[out_index++]);
}
- } else if (port->type == TYPE_EVENT && port->flow == FLOW_INPUT) {
- lv2_evbuf_reset(port->evbuf, true);
- if (port->is_primary && jalv->request_update) {
- // Plugin state has changed, request an update
- LV2_Evbuf_Iterator iter = lv2_evbuf_begin(port->evbuf);
- jalv_write_get_message(&iter, &jalv->urids);
- }
} else if (port->type == TYPE_EVENT) {
- // Clear event output for plugin to write to
- lv2_evbuf_reset(port->evbuf, false);
+ lv2_evbuf_reset(port->evbuf, port->flow == FLOW_INPUT);
}
}
- jalv->request_update = false;
// Run plugin for this cycle
const bool send_ui_updates = jalv_run(jalv, nframes);
diff --git a/src/process.c b/src/process.c
index 2b5a11e..49e5a1f 100644
--- a/src/process.c
+++ b/src/process.c
@@ -18,19 +18,6 @@
#include <assert.h>
#include <stddef.h>
-int
-jalv_write_get_message(LV2_Evbuf_Iterator* const iter,
- const JalvURIDs* const urids)
-{
- const LV2_Atom_Object get = {
- {sizeof(LV2_Atom_Object_Body), urids->atom_Object},
- {0U, urids->patch_Get},
- };
-
- return lv2_evbuf_write(
- iter, 0, 0, get.atom.type, get.atom.size, LV2_ATOM_BODY_CONST(&get));
-}
-
static int
ring_error(const char* const message)
{
@@ -79,6 +66,21 @@ apply_ui_events(Jalv* const jalv, const uint32_t nframes)
lv2_evbuf_write(
&e, nframes, 0U, atom->type, atom->size, LV2_ATOM_BODY_CONST(atom));
+ } else if (header.type == STATE_REQUEST) {
+ JalvPort* const port = &jalv->ports[jalv->control_in];
+ assert(port->type == TYPE_EVENT);
+ assert(port->flow == FLOW_INPUT);
+ assert(port->evbuf);
+
+ LV2_Evbuf_Iterator iter = lv2_evbuf_end(port->evbuf);
+ const LV2_Atom_Object get = {
+ {sizeof(LV2_Atom_Object_Body), jalv->urids.atom_Object},
+ {0U, jalv->urids.patch_Get},
+ };
+
+ lv2_evbuf_write(
+ &iter, nframes, 0U, get.atom.type, get.atom.size, &get.body);
+
} else {
return ring_error("Unknown message type received from UI ring\n");
}
diff --git a/src/process.h b/src/process.h
index 35acd24..366d30e 100644
--- a/src/process.h
+++ b/src/process.h
@@ -5,9 +5,7 @@
#define JALV_PROCESS_H
#include "attributes.h"
-#include "lv2_evbuf.h"
#include "types.h"
-#include "urids.h"
#include <stdbool.h>
#include <stdint.h>
@@ -17,15 +15,6 @@ JALV_BEGIN_DECLS
// Code and data used in the realtime process thread
/**
- Write a patch:Get message to an event buffer.
-
- This is used to request an update of plugin state when it has changed or the
- UI needs updating for whatever reason.
-*/
-int
-jalv_write_get_message(LV2_Evbuf_Iterator* iter, const JalvURIDs* urids);
-
-/**
Run the plugin for a block of frames.
Applies any pending messages from the UI, runs the plugin instance, and
diff --git a/src/state.c b/src/state.c
index e75ab3c..1bfe6ce 100644
--- a/src/state.c
+++ b/src/state.c
@@ -13,6 +13,7 @@
#include "lv2/core/lv2.h"
#include "lv2/state/state.h"
#include "zix/attributes.h"
+#include "zix/ring.h"
#include "zix/sem.h"
#include "zix/status.h"
@@ -193,8 +194,9 @@ jalv_apply_state(Jalv* jalv, const LilvState* state)
state, jalv->instance, set_port_value, jalv, 0, state_features);
if (must_pause) {
- jalv->request_update = true;
- jalv->play_state = JALV_RUNNING;
+ const JalvMessageHeader msg = {STATE_REQUEST, 0U};
+ zix_ring_write(jalv->ui_to_plugin, &msg, sizeof(msg));
+ jalv->play_state = JALV_RUNNING;
}
}