From 9ca96aaa57bf101d7b92f3250bac56e356361030 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 8 Aug 2022 18:38:36 -0400 Subject: Simplify atom buffer allocation code --- src/jalv.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/jalv.c b/src/jalv.c index 2b79af7..2b92d63 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -263,25 +263,24 @@ jalv_create_ports(Jalv* jalv) void jalv_allocate_port_buffers(Jalv* jalv) { + const LV2_URID atom_Chunk = jalv->map.map( + jalv->map.handle, lilv_node_as_string(jalv->nodes.atom_Chunk)); + + const LV2_URID atom_Sequence = jalv->map.map( + jalv->map.handle, lilv_node_as_string(jalv->nodes.atom_Sequence)); + for (uint32_t i = 0; i < jalv->num_ports; ++i) { struct Port* const port = &jalv->ports[i]; - switch (port->type) { - case TYPE_EVENT: { + if (port->type == TYPE_EVENT) { lv2_evbuf_free(port->evbuf); - const size_t buf_size = - (port->buf_size > 0) ? port->buf_size : jalv->midi_buf_size; - port->evbuf = lv2_evbuf_new( - buf_size, - jalv->map.map(jalv->map.handle, - lilv_node_as_string(jalv->nodes.atom_Chunk)), - jalv->map.map(jalv->map.handle, - lilv_node_as_string(jalv->nodes.atom_Sequence))); + + const size_t size = port->buf_size ? port->buf_size : jalv->midi_buf_size; + + port->evbuf = lv2_evbuf_new(size, atom_Chunk, atom_Sequence); + lilv_instance_connect_port( jalv->instance, i, lv2_evbuf_get_buffer(port->evbuf)); } - default: - break; - } } } -- cgit v1.2.1