aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-08-10 14:26:05 -0400
committerDavid Robillard <d@drobilla.net>2022-08-17 13:51:05 -0400
commit8e5bf419f1938fb2b97cd984641e51727a7673aa (patch)
tree2cd77bdc6b0068a90ddfadc6810003ccc80c923f /src
parentcdfc39737361d4514fc7dfeb355d0eb011ade1bd (diff)
downloadjalv-8e5bf419f1938fb2b97cd984641e51727a7673aa.tar.gz
jalv-8e5bf419f1938fb2b97cd984641e51727a7673aa.tar.bz2
jalv-8e5bf419f1938fb2b97cd984641e51727a7673aa.zip
Factor out jalv_write_control()
Diffstat (limited to 'src')
-rw-r--r--src/jack.c12
-rw-r--r--src/jalv.c19
-rw-r--r--src/jalv_internal.h18
-rw-r--r--src/portaudio.c10
-rw-r--r--src/state.c16
5 files changed, 43 insertions, 32 deletions
diff --git a/src/jack.c b/src/jack.c
index b538b5c..5050fd3 100644
--- a/src/jack.c
+++ b/src/jack.c
@@ -3,7 +3,6 @@
#include "backend.h"
-#include "control.h"
#include "frontend.h"
#include "jalv_config.h"
#include "jalv_internal.h"
@@ -18,7 +17,6 @@
#include "lilv/lilv.h"
#include "lv2/atom/atom.h"
#include "lv2/atom/forge.h"
-#include "zix/ring.h"
#include "zix/sem.h"
#include <jack/jack.h>
@@ -246,15 +244,7 @@ jack_process_cb(jack_nframes_t nframes, void* data)
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- char buf[sizeof(ControlChange) + sizeof(float)];
- ControlChange* ev = (ControlChange*)buf;
- ev->index = p;
- ev->protocol = 0;
- ev->size = sizeof(float);
- *(float*)(ev + 1) = port->control;
- if (zix_ring_write(jalv->plugin_to_ui, buf, sizeof(buf)) < sizeof(buf)) {
- jalv_log(JALV_LOG_ERR, "Plugin => UI buffer overflow\n");
- }
+ jalv_write_control(jalv, jalv->plugin_to_ui, p, port->control);
}
}
diff --git a/src/jalv.c b/src/jalv.c
index c5dd442..e932f8e 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -620,6 +620,25 @@ jalv_send_to_ui(Jalv* jalv,
return false;
}
+int
+jalv_write_control(Jalv* const jalv,
+ ZixRing* const target,
+ const uint32_t port_index,
+ const float value)
+{
+ (void)jalv;
+
+ char buf[sizeof(ControlChange) + sizeof(value)];
+
+ ControlChange* const ev = (ControlChange*)buf;
+ ev->index = port_index;
+ ev->protocol = 0U;
+ ev->size = sizeof(value);
+ *(float*)(ev + 1) = value;
+
+ return zix_ring_write(target, buf, sizeof(buf)) != sizeof(buf);
+}
+
void
jalv_dump_atom(Jalv* const jalv,
FILE* const stream,
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index ab7a1eb..df03379 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -182,6 +182,24 @@ jalv_send_to_ui(Jalv* jalv,
uint32_t size,
const void* body);
+/**
+ Write a control port change using the default (0) protocol.
+
+ 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(Jalv* jalv,
+ ZixRing* target,
+ uint32_t port_index,
+ float value);
+
void
jalv_dump_atom(Jalv* jalv,
FILE* stream,
diff --git a/src/portaudio.c b/src/portaudio.c
index c15ed07..f7b7e45 100644
--- a/src/portaudio.c
+++ b/src/portaudio.c
@@ -80,15 +80,7 @@ pa_process_cb(const void* inputs,
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- char buf[sizeof(ControlChange) + sizeof(float)];
- ControlChange* ev = (ControlChange*)buf;
- ev->index = p;
- ev->protocol = 0;
- ev->size = sizeof(float);
- *(float*)(ev + 1) = port->control;
- if (zix_ring_write(jalv->plugin_to_ui, buf, sizeof(buf)) < sizeof(buf)) {
- jalv_log(JALV_LOG_ERR, "Plugin => UI buffer overflow\n");
- }
+ jalv_write_control(jalv, jalv->plugin_to_ui, p, port->control);
}
}
diff --git a/src/state.c b/src/state.c
index 5b57026..d8002f4 100644
--- a/src/state.c
+++ b/src/state.c
@@ -3,7 +3,6 @@
#include "state.h"
-#include "control.h"
#include "jalv_internal.h"
#include "log.h"
#include "nodes.h"
@@ -15,7 +14,6 @@
#include "lv2/state/state.h"
#include "lv2/urid/urid.h"
#include "zix/common.h"
-#include "zix/ring.h"
#include "zix/sem.h"
#include <stdbool.h>
@@ -154,19 +152,13 @@ set_port_value(const char* port_symbol,
// Set value on port struct directly
port->control = fvalue;
} else {
- // Send value to running plugin
- jalv_send_to_plugin(jalv, port->index, sizeof(fvalue), 0, &fvalue);
+ // Send value to plugin (as if from UI)
+ jalv_write_control(jalv, jalv->ui_to_plugin, port->index, fvalue);
}
if (jalv->has_ui) {
- // Update UI
- char buf[sizeof(ControlChange) + sizeof(fvalue)];
- ControlChange* ev = (ControlChange*)buf;
- ev->index = port->index;
- ev->protocol = 0;
- ev->size = sizeof(fvalue);
- *(float*)(ev + 1) = fvalue;
- zix_ring_write(jalv->plugin_to_ui, buf, sizeof(buf));
+ // Update UI (as if from plugin)
+ jalv_write_control(jalv, jalv->plugin_to_ui, port->index, fvalue);
}
}