diff options
author | David Robillard <d@drobilla.net> | 2024-11-15 10:08:24 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-24 18:59:41 -0500 |
commit | 800356e507c5cc098e89b1cbe96f5f150dc12d96 (patch) | |
tree | 0859bac836bc25f147a5d51cdb67fc619d2726c8 /src | |
parent | 7c9858897ff6014a6cf36cefbd05f1f4f63817c4 (diff) | |
download | jalv-800356e507c5cc098e89b1cbe96f5f150dc12d96.tar.gz jalv-800356e507c5cc098e89b1cbe96f5f150dc12d96.tar.bz2 jalv-800356e507c5cc098e89b1cbe96f5f150dc12d96.zip |
Move low-level event sending functions to a separate file
Takes advantage of the dependency trimming of the previous commit to work
towards separating things more cleanly.
Diffstat (limited to 'src')
-rw-r--r-- | src/comm.c | 59 | ||||
-rw-r--r-- | src/comm.h | 76 | ||||
-rw-r--r-- | src/jack.c | 1 | ||||
-rw-r--r-- | src/jalv.c | 51 | ||||
-rw-r--r-- | src/jalv_internal.h | 36 | ||||
-rw-r--r-- | src/portaudio.c | 1 | ||||
-rw-r--r-- | src/state.c | 1 |
7 files changed, 139 insertions, 86 deletions
diff --git a/src/comm.c b/src/comm.c new file mode 100644 index 0000000..ef83c8e --- /dev/null +++ b/src/comm.c @@ -0,0 +1,59 @@ +// Copyright 2007-2024 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#include "comm.h" + +#include "control.h" + +#include "lv2/atom/atom.h" +#include "lv2/urid/urid.h" + +ZixStatus +jalv_write_split_message(ZixRing* const target, + const void* const header, + const uint32_t header_size, + const void* const body, + const uint32_t body_size) +{ + ZixRingTransaction tx = zix_ring_begin_write(target); + + ZixStatus st = ZIX_STATUS_SUCCESS; + if (!(st = zix_ring_amend_write(target, &tx, header, header_size)) && + !(st = zix_ring_amend_write(target, &tx, body, body_size))) { + st = zix_ring_commit_write(target, &tx); + } + + return st; +} + +ZixStatus +jalv_write_event(ZixRing* const target, + const uint32_t port_index, + const uint32_t protocol, + const uint32_t size, + const LV2_URID type, + const void* const body) +{ + // TODO: Be more discriminate about what to send + + typedef struct { + ControlChange change; + LV2_Atom atom; + } Header; + + const Header header = {{port_index, protocol, sizeof(LV2_Atom) + size}, + {size, type}}; + + return jalv_write_split_message(target, &header, sizeof(header), body, size); +} + +ZixStatus +jalv_write_control(ZixRing* const target, + const uint32_t port_index, + const float value) +{ + const ControlChange header = {port_index, 0, sizeof(value)}; + + return jalv_write_split_message( + target, &header, sizeof(header), &value, sizeof(value)); +} diff --git a/src/comm.h b/src/comm.h new file mode 100644 index 0000000..75f098b --- /dev/null +++ b/src/comm.h @@ -0,0 +1,76 @@ +// Copyright 2007-2024 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#ifndef JALV_COMM_H +#define JALV_COMM_H + +#include "attributes.h" + +#include "lv2/urid/urid.h" +#include "zix/ring.h" +#include "zix/status.h" + +#include <stdint.h> + +JALV_BEGIN_DECLS + +// Communication between the audio and main threads via rings + +/** + Write a message in two parts to a ring. + + This is used to conveniently write a message with a fixed-size header and + possibly variably-sized body in a single call. + + @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin). + @param header Pointer to start of header data. + @param header_size Size of header in bytes. + @param body Pointer to start of body data. + @param body_size Size of body in bytes. + @return 0 on success, non-zero on failure (overflow). +*/ +ZixStatus +jalv_write_split_message(ZixRing* target, + const void* header, + uint32_t header_size, + const void* body, + uint32_t body_size); + +/** + Write a port event using the atom:eventTransfer protocol. + + This is used to transfer atoms between the plugin and UI via sequence ports. + + @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin). + @param port_index Index of the port this change is for. + @param protocol Port protocol (0 for float control, or atom:eventTransfer).o + @param size Size of body in bytes. + @param type Atom type URID. + @param body Atom body. + @return 0 on success, non-zero on failure (overflow). +*/ +ZixStatus +jalv_write_event(ZixRing* target, + uint32_t port_index, + uint32_t protocol, + uint32_t size, + LV2_URID type, + const void* body); + +/** + Write a control port change using the default (0) protocol. + + This is used to transfer control port value changes between the plugin and + UI. + + @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin). + @param port_index Index of the port this change is for. + @param value New control port value. + @return 0 on success, non-zero on failure (overflow). +*/ +ZixStatus +jalv_write_control(ZixRing* target, uint32_t port_index, float value); + +JALV_END_DECLS + +#endif // JALV_COMM_H @@ -3,6 +3,7 @@ #include "backend.h" +#include "comm.h" #include "frontend.h" #include "jalv_config.h" #include "jalv_internal.h" @@ -2,6 +2,7 @@ // SPDX-License-Identifier: ISC #include "backend.h" +#include "comm.h" #include "control.h" #include "frontend.h" #include "jalv_config.h" @@ -642,56 +643,6 @@ jalv_init_ui(Jalv* jalv) } } -static ZixStatus -jalv_write_control_change(ZixRing* const target, - const void* const header, - const uint32_t header_size, - const void* const body, - const uint32_t body_size) -{ - ZixRingTransaction tx = zix_ring_begin_write(target); - - ZixStatus st = ZIX_STATUS_SUCCESS; - if (!(st = zix_ring_amend_write(target, &tx, header, header_size)) && - !(st = zix_ring_amend_write(target, &tx, body, body_size))) { - st = zix_ring_commit_write(target, &tx); - } - - return st; -} - -ZixStatus -jalv_write_event(ZixRing* const target, - const uint32_t port_index, - const uint32_t protocol, - const uint32_t size, - const LV2_URID type, - const void* const body) -{ - // TODO: Be more discriminate about what to send - - typedef struct { - ControlChange change; - LV2_Atom atom; - } Header; - - const Header header = {{port_index, protocol, sizeof(LV2_Atom) + size}, - {size, type}}; - - return jalv_write_control_change(target, &header, sizeof(header), body, size); -} - -ZixStatus -jalv_write_control(ZixRing* const target, - const uint32_t port_index, - const float value) -{ - const ControlChange header = {port_index, 0, sizeof(value)}; - - return jalv_write_control_change( - target, &header, sizeof(header), &value, sizeof(value)); -} - void jalv_dump_atom(Jalv* const jalv, FILE* const stream, diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 3ace59e..08c78cf 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -17,7 +17,6 @@ #include "zix/ring.h" #include "zix/sem.h" -#include "zix/status.h" #include "lilv/lilv.h" #include "serd/serd.h" @@ -157,41 +156,6 @@ jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent); bool jalv_ui_is_resizable(Jalv* jalv); -/** - Write a port event using the atom:eventTransfer protocol. - - This is used to transfer atoms between the plugin and UI via sequence ports. - - @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin). - @param port_index Index of the port this change is for. - @param protocol Port protocol (0 for float control, or atom:eventTransfer).o - @param size Size of body in bytes. - @param type Atom type URID. - @param body Atom body. - @return 0 on success, non-zero on failure (overflow). -*/ -ZixStatus -jalv_write_event(ZixRing* target, - uint32_t port_index, - uint32_t protocol, - uint32_t size, - LV2_URID type, - const void* body); - -/** - Write a control port change using the default (0) protocol. - - This is used to transfer control port value changes between the plugin and - UI. - - @param target Communication ring (jalv->plugin_to_ui or jalv->ui_to_plugin). - @param port_index Index of the port this change is for. - @param value New control port value. - @return 0 on success, non-zero on failure (overflow). -*/ -ZixStatus -jalv_write_control(ZixRing* target, uint32_t port_index, float value); - /// Dump an atom to stdout in a "developer-readable" format (Turtle) void jalv_dump_atom(Jalv* jalv, diff --git a/src/portaudio.c b/src/portaudio.c index dff77b3..0c73ceb 100644 --- a/src/portaudio.c +++ b/src/portaudio.c @@ -2,6 +2,7 @@ // SPDX-License-Identifier: ISC #include "backend.h" +#include "comm.h" #include "jalv_internal.h" #include "log.h" #include "lv2_evbuf.h" diff --git a/src/state.c b/src/state.c index 7e25f2d..1d473eb 100644 --- a/src/state.c +++ b/src/state.c @@ -3,6 +3,7 @@ #include "state.h" +#include "comm.h" #include "jalv_internal.h" #include "log.h" #include "port.h" |