diff options
author | David Robillard <d@drobilla.net> | 2024-11-15 20:38:43 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-24 19:01:17 -0500 |
commit | fb192806333ca88d5acb53b849f268611773230d (patch) | |
tree | 5dc3197e1544a72dd9b64bc805f309c9f816ae05 /src/jack.c | |
parent | e4eaf9b181c121a794f2acaea6e51aeaaf4ecffb (diff) | |
download | jalv-fb192806333ca88d5acb53b849f268611773230d.tar.gz jalv-fb192806333ca88d5acb53b849f268611773230d.tar.bz2 jalv-fb192806333ca88d5acb53b849f268611773230d.zip |
Fix Jack latency recomputation when plugin latency changes
Paul Davis says "jack_recompute_total_latencies() is a server call. It is not
legal to make server calls from within a server callback (like the process
callback)."
Diffstat (limited to 'src/jack.c')
-rw-r--r-- | src/jack.c | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -1,4 +1,4 @@ -// Copyright 2007-2022 David Robillard <d@drobilla.net> +// Copyright 2007-2024 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC #include "backend.h" @@ -46,6 +46,9 @@ struct JalvBackendImpl { bool is_internal_client; ///< Running inside jackd }; +/// Maximum supported latency in frames (at most 2^24 so all integers work) +static const float max_latency = 16777216.0f; + /// Internal Jack client initialization entry point int jack_initialize(jack_client_t* client, const char* load_init); @@ -201,9 +204,19 @@ jack_process_cb(jack_nframes_t nframes, void* data) struct Port* const port = &jalv->ports[p]; if (port->flow == FLOW_OUTPUT && port->type == TYPE_CONTROL && port->reports_latency) { - if (jalv->plugin_latency != port->control) { - jalv->plugin_latency = port->control; - jack_recompute_total_latencies(client); + // Get the latency in frames from the control output truncated to integer + const float value = port->control; + const uint32_t frames = + (value >= 0.0f && value <= max_latency) ? (uint32_t)value : 0U; + + if (jalv->plugin_latency != frames) { + // Update the cached value and notify the UI if the latency changed + jalv->plugin_latency = frames; + + const JalvLatencyChange body = {frames}; + const JalvMessageHeader header = {LATENCY_CHANGE, sizeof(body)}; + jalv_write_split_message( + jalv->plugin_to_ui, &header, sizeof(header), &body, sizeof(body)); } } else if (port->flow == FLOW_OUTPUT && port->type == TYPE_EVENT) { void* buf = NULL; @@ -461,6 +474,12 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index) #endif } +void +jalv_backend_recompute_latencies(Jalv* const jalv) +{ + jack_recompute_total_latencies(jalv->backend->client); +} + int jack_initialize(jack_client_t* const client, const char* const load_init) { |