diff options
author | David Robillard <d@drobilla.net> | 2024-11-15 18:45:56 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-24 19:00:56 -0500 |
commit | b56679c566dfd01a3b09958e98dcadbbd306bfcb (patch) | |
tree | a9cdee57620f629b87b9124e2102705ef329cafc /src/comm.h | |
parent | 417f76f18194ab6edf7e77d771037cf3ff8059e1 (diff) | |
download | jalv-b56679c566dfd01a3b09958e98dcadbbd306bfcb.tar.gz jalv-b56679c566dfd01a3b09958e98dcadbbd306bfcb.tar.bz2 jalv-b56679c566dfd01a3b09958e98dcadbbd306bfcb.zip |
Generalize audio/main thread communication
Defines a more general message structure that can also accommodate internal
use (not just as a channel for plugin/UI message), and cleans up the ring
reading/writing code to prepare for such use.
Diffstat (limited to 'src/comm.h')
-rw-r--r-- | src/comm.h | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -6,6 +6,7 @@ #include "attributes.h" +#include "lv2/atom/atom.h" #include "lv2/urid/urid.h" #include "zix/ring.h" #include "zix/status.h" @@ -16,6 +17,47 @@ JALV_BEGIN_DECLS // Communication between the audio and main threads via rings +/// Type of an internal message in a communication ring +typedef enum { + NO_MESSAGE, ///< Sentinel type for uninitialized messages + CONTROL_PORT_CHANGE, ///< Value change for a control port (float) + EVENT_TRANSFER, ///< Event transfer for a sequence port (atom) +} JalvMessageType; + +/** + Message between the audio thread and the main thread. + + This is the general header for any type of message in a communication ring. + The type determines how the message must be handled by the receiver. This + header is followed immediately by `size` bytes of data in the ring. +*/ +typedef struct { + JalvMessageType type; ///< Type of this message + uint32_t size; ///< Size of payload following this header in bytes +} JalvMessageHeader; + +/** + The payload of a CONTROL_PORT_CHANGE message. + + This message has a fixed sized, and is described in its entirety by this + struct. +*/ +typedef struct { + uint32_t port_index; ///< Control port index + float value; ///< Control value +} JalvControlChange; + +/** + The start of the payload of an EVENT_TRANSFER message. + + This message has a variable size, the start described by this struct is + followed immediately by `atom.size` bytes of data (the atom body). +*/ +typedef struct { + uint32_t port_index; ///< Sequence port index + LV2_Atom atom; ///< Event payload header +} JalvEventTransfer; + /** Write a message in two parts to a ring. @@ -43,7 +85,6 @@ jalv_write_split_message(ZixRing* target, @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. @@ -52,7 +93,6 @@ jalv_write_split_message(ZixRing* target, ZixStatus jalv_write_event(ZixRing* target, uint32_t port_index, - uint32_t protocol, uint32_t size, LV2_URID type, const void* body); |