aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-11-17 09:01:46 -0500
committerDavid Robillard <d@drobilla.net>2024-11-24 19:04:31 -0500
commit4466b8525cd97f5fde392a42f2c730ab46ccb18a (patch)
tree0e019e8ad7e721ee3a29a9efdd0f921d97ba7d86
parent57b544a5b036e671a516192dd2b4c2b84c37a3df (diff)
downloadjalv-4466b8525cd97f5fde392a42f2c730ab46ccb18a.tar.gz
jalv-4466b8525cd97f5fde392a42f2c730ab46ccb18a.tar.bz2
jalv-4466b8525cd97f5fde392a42f2c730ab46ccb18a.zip
Move control port buffers to a separate array
-rw-r--r--src/jack.c7
-rw-r--r--src/jalv.c27
-rw-r--r--src/jalv_console.c11
-rw-r--r--src/jalv_internal.h1
-rw-r--r--src/jalv_qt.cpp10
-rw-r--r--src/jalv_qt.hpp6
-rw-r--r--src/port.h1
-rw-r--r--src/portaudio.c5
-rw-r--r--src/process.c2
-rw-r--r--src/state.c4
10 files changed, 37 insertions, 37 deletions
diff --git a/src/jack.c b/src/jack.c
index da9d45b..2456043 100644
--- a/src/jack.c
+++ b/src/jack.c
@@ -217,7 +217,7 @@ jack_process_cb(jack_nframes_t nframes, void* data)
if (port->flow == FLOW_OUTPUT && port->type == TYPE_CONTROL &&
port->reports_latency) {
// Get the latency in frames from the control output truncated to integer
- const float value = port->control;
+ const float value = jalv->controls_buf[p];
const uint32_t frames =
(value >= 0.0f && value <= max_latency) ? (uint32_t)value : 0U;
@@ -260,7 +260,7 @@ jack_process_cb(jack_nframes_t nframes, void* data)
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- jalv_write_control(jalv->plugin_to_ui, p, port->control);
+ jalv_write_control(jalv->plugin_to_ui, p, jalv->controls_buf[p]);
}
}
@@ -432,7 +432,8 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index)
case TYPE_UNKNOWN:
break;
case TYPE_CONTROL:
- lilv_instance_connect_port(jalv->instance, port_index, &port->control);
+ lilv_instance_connect_port(
+ jalv->instance, port_index, &jalv->controls_buf[port_index]);
break;
case TYPE_AUDIO:
port->sys_port = jack_port_register(
diff --git a/src/jalv.c b/src/jalv.c
index 5243d32..7c022eb 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -48,7 +48,6 @@
# include "suil/suil.h"
#endif
-#include <math.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
@@ -149,7 +148,7 @@ has_designation(const JalvNodes* const nodes,
instance-specific setup (e.g. buffers) is done later in activate_port().
*/
static void
-create_port(Jalv* jalv, uint32_t port_index, float default_value)
+create_port(Jalv* jalv, uint32_t port_index)
{
JalvPort* const port = &jalv->ports[port_index];
@@ -158,7 +157,6 @@ create_port(Jalv* jalv, uint32_t port_index, float default_value)
port->evbuf = NULL;
port->buf_size = 0;
port->index = port_index;
- port->control = 0.0f;
port->flow = FLOW_UNKNOWN;
const bool optional = lilv_port_has_property(
@@ -183,8 +181,7 @@ create_port(Jalv* jalv, uint32_t port_index, float default_value)
// Set control values
if (lilv_port_is_a(
jalv->plugin, port->lilv_port, jalv->nodes.lv2_ControlPort)) {
- port->type = TYPE_CONTROL;
- port->control = isnan(default_value) ? 0.0f : default_value;
+ port->type = TYPE_CONTROL;
if (!hidden) {
add_control(&jalv->controls,
new_port_control(jalv->world,
@@ -247,15 +244,15 @@ jalv_create_ports(Jalv* jalv)
{
jalv->num_ports = lilv_plugin_get_num_ports(jalv->plugin);
jalv->ports = (JalvPort*)calloc(jalv->num_ports, sizeof(JalvPort));
- float* default_values =
- (float*)calloc(lilv_plugin_get_num_ports(jalv->plugin), sizeof(float));
- lilv_plugin_get_port_ranges_float(jalv->plugin, NULL, NULL, default_values);
+
+ // Allocate control port buffers array and set to default values
+ jalv->controls_buf = (float*)calloc(jalv->num_ports, sizeof(float));
+ lilv_plugin_get_port_ranges_float(
+ jalv->plugin, NULL, NULL, jalv->controls_buf);
for (uint32_t i = 0; i < jalv->num_ports; ++i) {
- create_port(jalv, i, default_values[i]);
+ create_port(jalv, i);
}
-
- free(default_values);
}
void
@@ -426,8 +423,7 @@ jalv_set_control(Jalv* jalv,
const void* body)
{
if (control->type == PORT && type == jalv->forge.Float) {
- JalvPort* const port = &jalv->ports[control->index];
- port->control = *(const float*)body;
+ jalv->controls_buf[control->index] = *(const float*)body;
} else if (control->type == PROPERTY && jalv->control_in != UINT32_MAX) {
// Copy forge since it is used by process thread
LV2_Atom_Forge forge = jalv->forge;
@@ -545,7 +541,7 @@ jalv_init_ui(Jalv* jalv)
for (uint32_t i = 0; i < jalv->num_ports; ++i) {
if (jalv->ports[i].type == TYPE_CONTROL) {
jalv_frontend_port_event(
- jalv, i, sizeof(float), 0, &jalv->ports[i].control);
+ jalv, i, sizeof(float), 0, &jalv->controls_buf[i]);
}
}
@@ -1176,7 +1172,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
ControlID* control = jalv->controls.controls[i];
if (control->type == PORT && control->is_writable) {
const JalvPort* const port = &jalv->ports[control->index];
- jalv_print_control(jalv, port, port->control);
+ jalv_print_control(jalv, port, jalv->controls_buf[control->index]);
}
}
@@ -1232,6 +1228,7 @@ jalv_close(Jalv* const jalv)
zix_ring_free(jalv->plugin_to_ui);
zix_free(NULL, jalv->ui_msg);
zix_free(NULL, jalv->audio_msg);
+ free(jalv->controls_buf);
for (LilvNode** n = (LilvNode**)&jalv->nodes; *n; ++n) {
lilv_node_free(*n);
}
diff --git a/src/jalv_console.c b/src/jalv_console.c
index 430dfe1..7a8f5e8 100644
--- a/src/jalv_console.c
+++ b/src/jalv_console.c
@@ -184,13 +184,12 @@ jalv_print_controls(Jalv* jalv, bool writable, bool readable)
{
for (size_t i = 0; i < jalv->controls.n_controls; ++i) {
ControlID* const control = jalv->controls.controls[i];
- if ((control->is_writable && writable) ||
- (control->is_readable && readable)) {
- JalvPort* const port = &jalv->ports[control->index];
+ if (control->type == PORT && ((control->is_writable && writable) ||
+ (control->is_readable && readable))) {
jalv_log(JALV_LOG_INFO,
"%s = %f\n",
lilv_node_as_string(control->symbol),
- port->control);
+ jalv->controls_buf[control->index]);
}
}
@@ -239,7 +238,7 @@ jalv_process_command(Jalv* jalv, const char* cmd)
jalv_print_controls(jalv, false, true);
} else if (sscanf(cmd, "set %u %f", &index, &value) == 2) {
if (index < jalv->num_ports) {
- jalv->ports[index].control = value;
+ jalv->controls_buf[index] = value;
jalv_print_control(jalv, &jalv->ports[index], value);
} else {
fprintf(stderr, "error: port index out of range\n");
@@ -248,7 +247,7 @@ jalv_process_command(Jalv* jalv, const char* cmd)
sscanf(cmd, "%1023[a-zA-Z0-9_] = %f", sym, &value) == 2) {
JalvPort* const port = jalv_port_by_symbol(jalv, sym);
if (port) {
- port->control = value;
+ jalv->controls_buf[port->index] = value;
jalv_print_control(jalv, port, value);
} else {
fprintf(stderr, "error: no control named `%s'\n", sym);
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 4b76162..62cb873 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -101,6 +101,7 @@ struct JalvImpl {
void* window; ///< Window (if applicable)
JalvPort* ports; ///< Port array of size num_ports
Controls controls; ///< Available plugin controls
+ float* controls_buf; ///< Control port buffers array
uint32_t block_length; ///< Audio buffer size (block length)
size_t midi_buf_size; ///< Size of MIDI port buffers
size_t msg_buf_size; ///< Maximum size of a single message
diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp
index 9f4d28d..2718da8 100644
--- a/src/jalv_qt.cpp
+++ b/src/jalv_qt.cpp
@@ -304,12 +304,12 @@ add_preset_to_menu(Jalv* jalv,
Control::Control(PortContainer portContainer, QWidget* parent)
: QGroupBox(parent)
, _dial(new QDial())
- , _plugin(portContainer.jalv->plugin)
+ , _jalv(portContainer.jalv)
, _port(portContainer.port)
, _label(new QLabel())
{
const JalvNodes* nodes = &portContainer.jalv->nodes;
- const LilvPlugin* plugin = _plugin;
+ const LilvPlugin* plugin = portContainer.jalv->plugin;
const LilvPort* lilvPort = _port->lilv_port;
LilvNode* nmin = nullptr;
@@ -362,7 +362,9 @@ Control::Control(PortContainer portContainer, QWidget* parent)
}
// Find and set min, max and default values for port
- const float defaultValue = ndef ? lilv_node_as_float(ndef) : _port->control;
+ const float defaultValue = ndef
+ ? lilv_node_as_float(ndef)
+ : portContainer.jalv->controls_buf[_port->index];
setRange(lilv_node_as_float(nmin), lilv_node_as_float(nmax));
setValue(defaultValue);
@@ -494,7 +496,7 @@ Control::dialChanged(int)
const float value = getValue();
_label->setText(getValueLabel(value));
- _port->control = value;
+ _jalv->controls_buf[_port->index] = value;
}
namespace {
diff --git a/src/jalv_qt.hpp b/src/jalv_qt.hpp
index 10c26fe..19bf408 100644
--- a/src/jalv_qt.hpp
+++ b/src/jalv_qt.hpp
@@ -62,9 +62,9 @@ private:
float getValue();
int stringWidth(const QString& str);
- QDial* _dial;
- const LilvPlugin* _plugin;
- JalvPort* _port;
+ QDial* _dial;
+ Jalv* _jalv;
+ JalvPort* _port;
QLabel* _label;
QString _name;
diff --git a/src/port.h b/src/port.h
index 6b5e522..89185b1 100644
--- a/src/port.h
+++ b/src/port.h
@@ -24,7 +24,6 @@ typedef struct {
void* widget; ///< Control widget, if applicable
size_t buf_size; ///< Custom buffer size, or 0
uint32_t index; ///< Port index
- float control; ///< For control ports, otherwise 0.0f
bool reports_latency; ///< For control port outputs
bool is_primary; ///< True for main control/reponse channel
} JalvPort;
diff --git a/src/portaudio.c b/src/portaudio.c
index 516b1a8..c1ea759 100644
--- a/src/portaudio.c
+++ b/src/portaudio.c
@@ -97,7 +97,7 @@ pa_process_cb(const void* inputs,
}
} else if (send_ui_updates && port->flow == FLOW_OUTPUT &&
port->type == TYPE_CONTROL) {
- jalv_write_control(jalv->plugin_to_ui, p, port->control);
+ jalv_write_control(jalv->plugin_to_ui, p, jalv->controls_buf[p]);
}
}
@@ -217,7 +217,8 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index)
JalvPort* const port = &jalv->ports[port_index];
if (port->type == TYPE_CONTROL) {
- lilv_instance_connect_port(jalv->instance, port_index, &port->control);
+ lilv_instance_connect_port(
+ jalv->instance, port_index, &jalv->controls_buf[port_index]);
}
}
diff --git a/src/process.c b/src/process.c
index fd2aa31..d183238 100644
--- a/src/process.c
+++ b/src/process.c
@@ -50,7 +50,7 @@ apply_ui_events(Jalv* const jalv, const uint32_t nframes)
}
assert(msg.port_index < jalv->num_ports);
- jalv->ports[msg.port_index].control = msg.value;
+ jalv->controls_buf[msg.port_index] = msg.value;
} else if (header.type == EVENT_TRANSFER) {
assert(header.size <= jalv->msg_buf_size);
diff --git a/src/state.c b/src/state.c
index 767db0a..b550c8f 100644
--- a/src/state.c
+++ b/src/state.c
@@ -42,7 +42,7 @@ get_port_value(const char* port_symbol,
if (port && port->flow == FLOW_INPUT && port->type == TYPE_CONTROL) {
*size = sizeof(float);
*type = jalv->forge.Float;
- return &port->control;
+ return &jalv->controls_buf[port->index];
}
*size = *type = 0;
return NULL;
@@ -152,7 +152,7 @@ set_port_value(const char* port_symbol,
ZixStatus st = ZIX_STATUS_SUCCESS;
if (jalv->run_state != JALV_RUNNING) {
// Set value on port struct directly
- port->control = fvalue;
+ jalv->controls_buf[port->index] = fvalue;
} else {
// Send value to plugin (as if from UI)
st = jalv_write_control(jalv->ui_to_plugin, port->index, fvalue);