diff options
author | David Robillard <d@drobilla.net> | 2024-11-16 07:37:30 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-24 19:01:53 -0500 |
commit | 098ed3f15751b1e25f8a0149d49a78b2e1d3f881 (patch) | |
tree | c84f6f90b1ee65b1f8de371552e54fd24e19238d /src | |
parent | 4e4641d7923217d983ff37b46dcb3f6546843992 (diff) | |
download | jalv-098ed3f15751b1e25f8a0149d49a78b2e1d3f881.tar.gz jalv-098ed3f15751b1e25f8a0149d49a78b2e1d3f881.tar.bz2 jalv-098ed3f15751b1e25f8a0149d49a78b2e1d3f881.zip |
Use a typedef for ports like other structs
Diffstat (limited to 'src')
-rw-r--r-- | src/jack.c | 12 | ||||
-rw-r--r-- | src/jalv.c | 30 | ||||
-rw-r--r-- | src/jalv_console.c | 6 | ||||
-rw-r--r-- | src/jalv_gtk.c | 1 | ||||
-rw-r--r-- | src/jalv_internal.h | 4 | ||||
-rw-r--r-- | src/jalv_qt.cpp | 4 | ||||
-rw-r--r-- | src/jalv_qt.hpp | 9 | ||||
-rw-r--r-- | src/log.c | 6 | ||||
-rw-r--r-- | src/log.h | 5 | ||||
-rw-r--r-- | src/port.h | 4 | ||||
-rw-r--r-- | src/portaudio.c | 6 | ||||
-rw-r--r-- | src/process.c | 2 | ||||
-rw-r--r-- | src/state.c | 8 |
13 files changed, 47 insertions, 50 deletions
@@ -156,7 +156,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) // Prepare port buffers for (uint32_t p = 0; p < jalv->num_ports; ++p) { - struct Port* port = &jalv->ports[p]; + JalvPort* const port = &jalv->ports[p]; if (port->sys_port && (port->type == TYPE_AUDIO || port->type == TYPE_CV)) { // Connect plugin port directly to Jack port buffer lilv_instance_connect_port( @@ -202,7 +202,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) // Deliver MIDI output and UI events for (uint32_t p = 0; p < jalv->num_ports; ++p) { - struct Port* const port = &jalv->ports[p]; + JalvPort* const port = &jalv->ports[p]; if (port->flow == FLOW_OUTPUT && port->type == TYPE_CONTROL && port->reports_latency) { // Get the latency in frames from the control output truncated to integer @@ -268,7 +268,7 @@ jack_latency_cb(const jack_latency_callback_mode_t mode, void* const data) uint32_t ports_found = 0; jack_latency_range_t range = {UINT32_MAX, 0}; for (uint32_t p = 0; p < jalv->num_ports; ++p) { - struct Port* const port = &jalv->ports[p]; + JalvPort* const port = &jalv->ports[p]; if (port->sys_port && port->flow == flow) { jack_latency_range_t r; jack_port_get_latency_range(port->sys_port, mode, &r); @@ -292,7 +292,7 @@ jack_latency_cb(const jack_latency_callback_mode_t mode, void* const data) // Tell Jack about it for (uint32_t p = 0; p < jalv->num_ports; ++p) { - const struct Port* const port = &jalv->ports[p]; + const JalvPort* const port = &jalv->ports[p]; if (port->sys_port && port->flow == flow) { jack_port_set_latency_range(port->sys_port, mode, &range); } @@ -401,8 +401,8 @@ jalv_backend_deactivate(Jalv* jalv) void jalv_backend_activate_port(Jalv* jalv, uint32_t port_index) { - jack_client_t* client = jalv->backend->client; - struct Port* const port = &jalv->ports[port_index]; + jack_client_t* client = jalv->backend->client; + JalvPort* const port = &jalv->ports[port_index]; const LilvNode* sym = lilv_port_get_symbol(jalv->plugin, port->lilv_port); @@ -138,10 +138,10 @@ die(const char* msg) } static bool -has_designation(const JalvNodes* const nodes, - const LilvPlugin* const plugin, - const struct Port* const port, - const LilvNode* const designation) +has_designation(const JalvNodes* const nodes, + const LilvPlugin* const plugin, + const JalvPort* const port, + const LilvNode* const designation) { LilvNodes* const designations = lilv_port_get_value(plugin, port->lilv_port, nodes->lv2_designation); @@ -168,7 +168,7 @@ has_designation(const JalvNodes* const nodes, static void create_port(Jalv* jalv, uint32_t port_index, float default_value) { - struct Port* const port = &jalv->ports[port_index]; + JalvPort* const port = &jalv->ports[port_index]; port->lilv_port = lilv_plugin_get_port_by_index(jalv->plugin, port_index); port->sys_port = NULL; @@ -253,7 +253,7 @@ static void jalv_create_ports(Jalv* jalv) { jalv->num_ports = lilv_plugin_get_num_ports(jalv->plugin); - jalv->ports = (struct Port*)calloc(jalv->num_ports, sizeof(struct Port)); + jalv->ports = (JalvPort*)calloc(jalv->num_ports, sizeof(JalvPort)); float* default_values = (float*)calloc(lilv_plugin_get_num_ports(jalv->plugin), sizeof(float)); lilv_plugin_get_port_ranges_float(jalv->plugin, NULL, NULL, default_values); @@ -288,7 +288,7 @@ jalv_allocate_port_buffers(Jalv* jalv) 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]; + JalvPort* const port = &jalv->ports[i]; if (port->type == TYPE_EVENT) { lv2_evbuf_free(port->evbuf); @@ -310,12 +310,12 @@ jalv_allocate_port_buffers(Jalv* jalv) TODO: Build an index to make this faster, currently O(n) which may be a problem when restoring the state of plugins with many ports. */ -struct Port* +JalvPort* jalv_port_by_symbol(Jalv* jalv, const char* sym) { for (uint32_t i = 0; i < jalv->num_ports; ++i) { - struct Port* const port = &jalv->ports[i]; - const LilvNode* port_sym = + JalvPort* const port = &jalv->ports[i]; + const LilvNode* port_sym = lilv_port_get_symbol(jalv->plugin, port->lilv_port); if (!strcmp(lilv_node_as_string(port_sym), sym)) { @@ -449,8 +449,8 @@ jalv_set_control(Jalv* jalv, const void* body) { if (control->type == PORT && type == jalv->forge.Float) { - struct Port* port = &jalv->ports[control->index]; - port->control = *(const float*)body; + JalvPort* const port = &jalv->ports[control->index]; + port->control = *(const float*)body; } else if (control->type == PROPERTY) { // Copy forge since it is used by process thread LV2_Atom_Forge forge = jalv->forge; @@ -477,8 +477,8 @@ jalv_set_control(Jalv* jalv, static uint32_t jalv_ui_port_index(void* const controller, const char* symbol) { - Jalv* const jalv = (Jalv*)controller; - struct Port* port = jalv_port_by_symbol(jalv, symbol); + Jalv* const jalv = (Jalv*)controller; + JalvPort* const port = jalv_port_by_symbol(jalv, symbol); return port ? port->index : LV2UI_INVALID_PORT_INDEX; } @@ -1286,7 +1286,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) for (size_t i = 0; i < jalv->controls.n_controls; ++i) { ControlID* control = jalv->controls.controls[i]; if (control->type == PORT && control->is_writable) { - const struct Port* port = &jalv->ports[control->index]; + const JalvPort* const port = &jalv->ports[control->index]; jalv_print_control(jalv, port, port->control); } } diff --git a/src/jalv_console.c b/src/jalv_console.c index a95be3b..9ffe42b 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -186,7 +186,7 @@ jalv_print_controls(Jalv* jalv, bool writable, bool readable) ControlID* const control = jalv->controls.controls[i]; if ((control->is_writable && writable) || (control->is_readable && readable)) { - struct Port* const port = &jalv->ports[control->index]; + JalvPort* const port = &jalv->ports[control->index]; jalv_log(JALV_LOG_INFO, "%s = %f\n", lilv_node_as_string(control->symbol), @@ -246,9 +246,9 @@ jalv_process_command(Jalv* jalv, const char* cmd) } } else if (sscanf(cmd, "set %1023[a-zA-Z0-9_] %f", sym, &value) == 2 || sscanf(cmd, "%1023[a-zA-Z0-9_] = %f", sym, &value) == 2) { - struct Port* port = NULL; + JalvPort* port = NULL; for (uint32_t i = 0; i < jalv->num_ports; ++i) { - struct Port* p = &jalv->ports[i]; + JalvPort* const p = &jalv->ports[i]; const LilvNode* s = lilv_port_get_symbol(jalv->plugin, p->lilv_port); if (!strcmp(lilv_node_as_string(s), sym)) { port = p; diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index 7678e88..165243c 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -6,7 +6,6 @@ #include "jalv_internal.h" #include "log.h" #include "options.h" -#include "port.h" #include "state.h" #include "types.h" diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 5b7f341..77f9993 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -99,7 +99,7 @@ struct JalvImpl { SuilInstance* ui_instance; ///< Plugin UI instance (shared library) #endif void* window; ///< Window (if applicable) - struct Port* ports; ///< Port array of size num_ports + JalvPort* ports; ///< Port array of size num_ports Controls controls; ///< Available plugin controls uint32_t block_length; ///< Audio buffer size (block length) size_t midi_buf_size; ///< Size of MIDI port buffers @@ -135,7 +135,7 @@ void jalv_allocate_port_buffers(Jalv* jalv); /// Find a port by symbol -struct Port* +JalvPort* jalv_port_by_symbol(Jalv* jalv, const char* sym); /// Set a control to the given value diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp index 61cf3fb..91c9cf4 100644 --- a/src/jalv_qt.cpp +++ b/src/jalv_qt.cpp @@ -547,8 +547,8 @@ build_control_widget(Jalv* jalv) LilvNode* lastGroup = nullptr; QHBoxLayout* groupLayout = nullptr; for (int i = 0; i < portContainers.count(); ++i) { - const PortContainer portContainer = portContainers[i]; - const Port* const port = portContainer.port; + const PortContainer portContainer = portContainers[i]; + const JalvPort* const port = portContainer.port; auto* const control = new Control(portContainer, nullptr); LilvNode* group = diff --git a/src/jalv_qt.hpp b/src/jalv_qt.hpp index 30138f4..e6b1f35 100644 --- a/src/jalv_qt.hpp +++ b/src/jalv_qt.hpp @@ -1,6 +1,7 @@ // Copyright 2007-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC +#include "port.h" #include "state.h" #include "types.h" @@ -15,8 +16,6 @@ #include <map> #include <vector> -struct Port; - class QDial; class QLabel; class QWidget; @@ -42,8 +41,8 @@ private: }; struct PortContainer { - Jalv* jalv; - Port* port; + Jalv* jalv; + JalvPort* port; }; class Control final : public QGroupBox @@ -65,7 +64,7 @@ private: QDial* dial; const LilvPlugin* plugin; - Port* port; + JalvPort* port; QLabel* label; QString name; @@ -20,9 +20,9 @@ #include <stdio.h> void -jalv_print_control(const Jalv* const jalv, - const struct Port* const port, - const float value) +jalv_print_control(const Jalv* const jalv, + const JalvPort* const port, + const float value) { const LilvNode* sym = lilv_port_get_symbol(jalv->plugin, port->lilv_port); jalv_log(JALV_LOG_INFO, "%s = %f\n", lilv_node_as_string(sym), value); @@ -5,6 +5,7 @@ #define JALV_LOG_H #include "attributes.h" +#include "port.h" #include "types.h" #include "urids.h" @@ -22,8 +23,6 @@ JALV_BEGIN_DECLS -struct Port; - // String and log utilities typedef enum { @@ -40,7 +39,7 @@ typedef struct { /// Print a control value to stderr, like "sym = 1.234" void -jalv_print_control(const Jalv* jalv, const struct Port* port, float value); +jalv_print_control(const Jalv* jalv, const JalvPort* port, float value); /// Print a log message to stderr with a GCC-like prefix and color JALV_LOG_FUNC(2, 3) @@ -18,7 +18,7 @@ enum PortFlow { FLOW_UNKNOWN, FLOW_INPUT, FLOW_OUTPUT }; enum PortType { TYPE_UNKNOWN, TYPE_CONTROL, TYPE_AUDIO, TYPE_EVENT, TYPE_CV }; -struct Port { +typedef struct { const LilvPort* lilv_port; ///< LV2 port enum PortType type; ///< Data type enum PortFlow flow; ///< Data flow direction @@ -29,7 +29,7 @@ struct Port { uint32_t index; ///< Port index float control; ///< For control ports, otherwise 0.0f bool reports_latency; ///< For control port outputs -}; +} JalvPort; JALV_END_DECLS diff --git a/src/portaudio.c b/src/portaudio.c index 3f65a19..869385c 100644 --- a/src/portaudio.c +++ b/src/portaudio.c @@ -41,7 +41,7 @@ pa_process_cb(const void* inputs, uint32_t in_index = 0; uint32_t out_index = 0; for (uint32_t i = 0; i < jalv->num_ports; ++i) { - struct Port* port = &jalv->ports[i]; + JalvPort* const port = &jalv->ports[i]; if (port->type == TYPE_AUDIO) { if (port->flow == FLOW_INPUT) { lilv_instance_connect_port( @@ -74,7 +74,7 @@ pa_process_cb(const void* inputs, // Deliver UI events for (uint32_t p = 0; p < jalv->num_ports; ++p) { - struct Port* const port = &jalv->ports[p]; + JalvPort* const port = &jalv->ports[p]; if (port->flow == FLOW_OUTPUT && port->type == TYPE_EVENT) { for (LV2_Evbuf_Iterator i = lv2_evbuf_begin(port->evbuf); lv2_evbuf_is_valid(i); @@ -211,7 +211,7 @@ jalv_backend_deactivate(Jalv* jalv) void jalv_backend_activate_port(Jalv* jalv, uint32_t port_index) { - struct Port* const port = &jalv->ports[port_index]; + JalvPort* const port = &jalv->ports[port_index]; if (port->type == TYPE_CONTROL) { lilv_instance_connect_port(jalv->instance, port_index, &port->control); diff --git a/src/process.c b/src/process.c index 11cf72e..d069851 100644 --- a/src/process.c +++ b/src/process.c @@ -60,7 +60,7 @@ apply_ui_events(Jalv* const jalv, const uint32_t nframes) const JalvEventTransfer* const msg = (const JalvEventTransfer*)body; assert(msg->port_index < jalv->num_ports); - struct Port* const port = &jalv->ports[msg->port_index]; + JalvPort* const port = &jalv->ports[msg->port_index]; LV2_Evbuf_Iterator e = lv2_evbuf_end(port->evbuf); const LV2_Atom* const atom = &msg->atom; lv2_evbuf_write( diff --git a/src/state.c b/src/state.c index 27be61c..e75ab3c 100644 --- a/src/state.c +++ b/src/state.c @@ -36,8 +36,8 @@ get_port_value(const char* port_symbol, uint32_t* size, uint32_t* type) { - Jalv* jalv = (Jalv*)user_data; - struct Port* port = jalv_port_by_symbol(jalv, port_symbol); + Jalv* const jalv = (Jalv*)user_data; + JalvPort* const port = jalv_port_by_symbol(jalv, port_symbol); if (port && port->flow == FLOW_INPUT && port->type == TYPE_CONTROL) { *size = sizeof(float); *type = jalv->forge.Float; @@ -124,8 +124,8 @@ set_port_value(const char* port_symbol, uint32_t ZIX_UNUSED(size), uint32_t type) { - Jalv* jalv = (Jalv*)user_data; - struct Port* port = jalv_port_by_symbol(jalv, port_symbol); + Jalv* const jalv = (Jalv*)user_data; + JalvPort* const port = jalv_port_by_symbol(jalv, port_symbol); if (!port) { jalv_log(JALV_LOG_ERR, "Preset port `%s' is missing\n", port_symbol); return; |