diff options
author | David Robillard <d@drobilla.net> | 2024-11-21 18:13:50 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-24 19:11:53 -0500 |
commit | 15324bd2bb040f9dc62769b9355bb31b57a9ae0e (patch) | |
tree | 1fa0bb4a068f972a2909f3488bd3a40d8a1d95cf | |
parent | 2a5bc1ca7aee36cd763ac10c894b84eef347fe25 (diff) | |
download | jalv-15324bd2bb040f9dc62769b9355bb31b57a9ae0e.tar.gz jalv-15324bd2bb040f9dc62769b9355bb31b57a9ae0e.tar.bz2 jalv-15324bd2bb040f9dc62769b9355bb31b57a9ae0e.zip |
Move process thread setup code to a separate file
Towards more cleanly separating the audio thread code from the rest of the
application.
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | src/jack.c | 1 | ||||
-rw-r--r-- | src/jalv.c | 33 | ||||
-rw-r--r-- | src/jalv.h | 8 | ||||
-rw-r--r-- | src/process_setup.c | 46 | ||||
-rw-r--r-- | src/process_setup.h | 23 |
6 files changed, 72 insertions, 40 deletions
diff --git a/meson.build b/meson.build index b995684..5e199e6 100644 --- a/meson.build +++ b/meson.build @@ -424,6 +424,7 @@ common_sources = files( 'src/mapper.c', 'src/nodes.c', 'src/process.c', + 'src/process_setup.c', 'src/query.c', 'src/state.c', 'src/string_utils.c', @@ -12,6 +12,7 @@ #include "lv2_evbuf.h" #include "port.h" #include "process.h" +#include "process_setup.h" #include "settings.h" #include "string_utils.h" #include "types.h" @@ -11,12 +11,12 @@ #include "frontend.h" #include "jalv_config.h" #include "log.h" -#include "lv2_evbuf.h" #include "macros.h" #include "mapper.h" #include "nodes.h" #include "options.h" #include "port.h" +#include "process_setup.h" #include "query.h" #include "settings.h" #include "state.h" @@ -213,37 +213,6 @@ jalv_create_ports(Jalv* jalv) return 0; } -void -jalv_allocate_port_buffers(Jalv* jalv) -{ - const JalvURIDs* const urids = &jalv->urids; - - for (uint32_t i = 0; i < jalv->num_ports; ++i) { - JalvPort* const port = &jalv->ports[i]; - if (port->type == TYPE_EVENT) { - const size_t size = - port->buf_size ? port->buf_size : jalv->settings.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)); - } - } -} - -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. @@ -105,14 +105,6 @@ jalv_activate(Jalv* jalv); int jalv_deactivate(Jalv* jalv); -/// Allocate appropriately-sized port buffers and connect the plugin to them -void -jalv_allocate_port_buffers(Jalv* jalv); - -/// Clean up memory allocated by jalv_process_activate() and disconnect plugin -void -jalv_free_port_buffers(Jalv* jalv); - /// Find a port by symbol JalvPort* jalv_port_by_symbol(Jalv* jalv, const char* sym); diff --git a/src/process_setup.c b/src/process_setup.c new file mode 100644 index 0000000..3f64d02 --- /dev/null +++ b/src/process_setup.c @@ -0,0 +1,46 @@ +// Copyright 2016-2024 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#include "process_setup.h" + +#include "jalv.h" +#include "lv2_evbuf.h" +#include "port.h" +#include "types.h" +#include "urids.h" + +#include <lilv/lilv.h> + +#include <stddef.h> +#include <stdint.h> + +void +jalv_allocate_port_buffers(Jalv* const jalv) +{ + const JalvURIDs* const urids = &jalv->urids; + + for (uint32_t i = 0; i < jalv->num_ports; ++i) { + JalvPort* const port = &jalv->ports[i]; + if (port->type == TYPE_EVENT) { + const size_t size = + port->buf_size ? port->buf_size : jalv->settings.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)); + } + } +} + +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); + } +} diff --git a/src/process_setup.h b/src/process_setup.h new file mode 100644 index 0000000..07a76c2 --- /dev/null +++ b/src/process_setup.h @@ -0,0 +1,23 @@ +// Copyright 2016-2024 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#ifndef JALV_PROCESS_SETUP_H +#define JALV_PROCESS_SETUP_H + +#include "attributes.h" +#include "types.h" + +// Code for setting up the realtime process thread (but that isn't used in it) +JALV_BEGIN_DECLS + +/// Allocate appropriately-sized port buffers and connect the plugin to them +void +jalv_allocate_port_buffers(Jalv* jalv); + +/// Clean up memory allocated by jalv_process_activate() and disconnect plugin +void +jalv_free_port_buffers(Jalv* jalv); + +JALV_END_DECLS + +#endif // JALV_PROCESS_SETUP_H |