diff options
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) { |