From 25593e614eb3ef6a62a603aa4704d9a4ff49364d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 16 Nov 2024 14:59:31 -0500 Subject: Factor out jalv_write_get_message() from process callbacks --- src/jack.c | 6 +----- src/portaudio.c | 7 +------ src/process.c | 13 +++++++++++++ src/process.h | 11 +++++++++++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/jack.c b/src/jack.c index 62100a9..c4d8411 100644 --- a/src/jack.c +++ b/src/jack.c @@ -182,11 +182,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) if (jalv->request_update) { // Plugin state has changed, request an update - const LV2_Atom_Object get = { - {sizeof(LV2_Atom_Object_Body), jalv->urids.atom_Object}, - {0, jalv->urids.patch_Get}}; - lv2_evbuf_write( - &iter, 0, 0, get.atom.type, get.atom.size, LV2_ATOM_BODY_CONST(&get)); + jalv_write_get_message(&iter, &jalv->urids); } if (port->sys_port) { diff --git a/src/portaudio.c b/src/portaudio.c index 869385c..d509d04 100644 --- a/src/portaudio.c +++ b/src/portaudio.c @@ -11,7 +11,6 @@ #include "types.h" #include "lilv/lilv.h" -#include "lv2/atom/atom.h" #include "zix/attributes.h" #include @@ -55,12 +54,8 @@ pa_process_cb(const void* inputs, if (jalv->request_update) { // Plugin state has changed, request an update - const LV2_Atom_Object get = { - {sizeof(LV2_Atom_Object_Body), jalv->urids.atom_Object}, - {0, jalv->urids.patch_Get}}; LV2_Evbuf_Iterator iter = lv2_evbuf_begin(port->evbuf); - lv2_evbuf_write( - &iter, 0, 0, get.atom.type, get.atom.size, LV2_ATOM_BODY(&get)); + jalv_write_get_message(&iter, &jalv->urids); } } else if (port->type == TYPE_EVENT) { // Clear event output for plugin to write to diff --git a/src/process.c b/src/process.c index d069851..2b5a11e 100644 --- a/src/process.c +++ b/src/process.c @@ -18,6 +18,19 @@ #include #include +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) { diff --git a/src/process.h b/src/process.h index 366d30e..35acd24 100644 --- a/src/process.h +++ b/src/process.h @@ -5,7 +5,9 @@ #define JALV_PROCESS_H #include "attributes.h" +#include "lv2_evbuf.h" #include "types.h" +#include "urids.h" #include #include @@ -14,6 +16,15 @@ 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. -- cgit v1.2.1