diff options
author | David Robillard <d@drobilla.net> | 2024-11-20 16:14:04 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-24 19:11:32 -0500 |
commit | 724aab7a868ed0200afbeecf056e53b5ea16b23d (patch) | |
tree | 1f18f1d9185465b253c4de21112e05aeb6739e2f /src/jalv.c | |
parent | 9ff22388ddcb5ae22aed51302889098cb246a47c (diff) | |
download | jalv-724aab7a868ed0200afbeecf056e53b5ea16b23d.tar.gz jalv-724aab7a868ed0200afbeecf056e53b5ea16b23d.tar.bz2 jalv-724aab7a868ed0200afbeecf056e53b5ea16b23d.zip |
Simplify port buffer allocation
Diffstat (limited to 'src/jalv.c')
-rw-r--r-- | src/jalv.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -219,21 +219,28 @@ jalv_allocate_port_buffers(Jalv* jalv) for (uint32_t i = 0; i < jalv->num_ports; ++i) { JalvPort* const port = &jalv->ports[i]; if (port->type == TYPE_EVENT) { - lv2_evbuf_free(port->evbuf); - const size_t size = port->buf_size ? port->buf_size : jalv->midi_buf_size; + lv2_evbuf_free(port->evbuf); port->evbuf = lv2_evbuf_new(size, urids->atom_Chunk, urids->atom_Sequence); + lv2_evbuf_reset(port->evbuf, port->flow == FLOW_INPUT); lilv_instance_connect_port( jalv->instance, i, lv2_evbuf_get_buffer(port->evbuf)); - - lv2_evbuf_reset(port->evbuf, port->flow == FLOW_INPUT); } } } +void +jalv_free_port_buffers(Jalv* const jalv) +{ + for (uint32_t i = 0; i < jalv->num_ports; ++i) { + lv2_evbuf_free(jalv->ports[i].evbuf); + lilv_instance_connect_port(jalv->instance, i, NULL); + } +} + /** Get a port structure by symbol. @@ -1017,9 +1024,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->state_worker, worker_iface, jalv->instance->lv2_handle); jalv_log(JALV_LOG_INFO, "\n"); - if (!jalv->buf_size_set) { - jalv_allocate_port_buffers(jalv); - } + jalv_allocate_port_buffers(jalv); // Apply loaded state to plugin instance if necessary if (state) { @@ -1080,18 +1085,13 @@ jalv_deactivate(Jalv* const jalv) int jalv_close(Jalv* const jalv) { + // Stop audio processing, free event port buffers, and close backend jalv_deactivate(jalv); + jalv_free_port_buffers(jalv); if (jalv->backend) { jalv_backend_close(jalv); } - // Free event port buffers - for (uint32_t i = 0; i < jalv->num_ports; ++i) { - if (jalv->ports[i].evbuf) { - lv2_evbuf_free(jalv->ports[i].evbuf); - } - } - // Destroy the worker jalv_worker_free(jalv->worker); jalv_worker_free(jalv->state_worker); |