diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend.h | 3 | ||||
-rw-r--r-- | src/control.c | 41 | ||||
-rw-r--r-- | src/control.h | 67 | ||||
-rw-r--r-- | src/frontend.h | 1 | ||||
-rw-r--r-- | src/jack.c | 6 | ||||
-rw-r--r-- | src/jack_impl.h | 4 | ||||
-rw-r--r-- | src/jalv.c | 11 | ||||
-rw-r--r-- | src/jalv_console.c | 11 | ||||
-rw-r--r-- | src/jalv_gtk.c | 47 | ||||
-rw-r--r-- | src/jalv_qt.cpp | 3 | ||||
-rw-r--r-- | src/log.h | 1 | ||||
-rw-r--r-- | src/mapper.h | 2 | ||||
-rw-r--r-- | src/port.h | 2 | ||||
-rw-r--r-- | src/process.h | 2 | ||||
-rw-r--r-- | src/process_setup.c | 1 | ||||
-rw-r--r-- | src/state.c | 12 | ||||
-rw-r--r-- | src/worker.c | 2 |
17 files changed, 111 insertions, 105 deletions
diff --git a/src/backend.h b/src/backend.h index facecd1..2f34c58 100644 --- a/src/backend.h +++ b/src/backend.h @@ -10,6 +10,9 @@ #include "types.h" #include "urids.h" +#include <zix/attributes.h> +#include <zix/sem.h> + #include <stdbool.h> #include <stdint.h> diff --git a/src/control.c b/src/control.c index c384165..41a2b70 100644 --- a/src/control.c +++ b/src/control.c @@ -32,22 +32,21 @@ scale_point_cmp(const ScalePoint* a, const ScalePoint* b) } ControlID* -new_port_control(LilvWorld* const world, - const LilvPlugin* const plugin, - const LilvPort* const port, - uint32_t port_index, - const float sample_rate, - const JalvNodes* const nodes, - LV2_Atom_Forge* const forge) +new_port_control(LilvWorld* const world, + const LilvPlugin* const plugin, + const LilvPort* const port, + uint32_t port_index, + const float sample_rate, + const JalvNodes* const nodes, + const LV2_Atom_Forge* const forge) { ControlID* id = (ControlID*)calloc(1, sizeof(ControlID)); id->type = PORT; + id->id.index = port_index; id->node = lilv_node_duplicate(lilv_port_get_node(plugin, port)); id->symbol = lilv_node_duplicate(lilv_port_get_symbol(plugin, port)); id->label = lilv_port_get_name(plugin, port); - id->forge = forge; - id->index = port_index; id->group = lilv_port_get(plugin, port, nodes->pg_group); id->value_type = forge->Float; id->is_writable = lilv_port_is_a(plugin, port, nodes->lv2_InputPort); @@ -122,18 +121,17 @@ has_range(LilvWorld* const world, } ControlID* -new_property_control(LilvWorld* const world, - const LilvNode* property, - const JalvNodes* const nodes, - LV2_URID_Map* const map, - LV2_Atom_Forge* const forge) +new_property_control(LilvWorld* const world, + const LilvNode* property, + const JalvNodes* const nodes, + LV2_URID_Map* const map, + const LV2_Atom_Forge* const forge) { - ControlID* id = (ControlID*)calloc(1, sizeof(ControlID)); - id->type = PROPERTY; - id->node = lilv_node_duplicate(property); - id->symbol = lilv_world_get_symbol(world, property); - id->forge = forge; - id->property = map->map(map->handle, lilv_node_as_uri(property)); + ControlID* id = (ControlID*)calloc(1, sizeof(ControlID)); + id->type = PROPERTY; + id->id.property = map->map(map->handle, lilv_node_as_uri(property)); + id->node = lilv_node_duplicate(property); + id->symbol = lilv_world_get_symbol(world, property); id->label = lilv_world_get(world, property, nodes->rdfs_label, NULL); id->min = lilv_world_get(world, property, nodes->lv2_minimum, NULL); @@ -198,7 +196,8 @@ ControlID* get_property_control(const Controls* controls, LV2_URID property) { for (size_t i = 0; i < controls->n_controls; ++i) { - if (controls->controls[i]->property == property) { + if (controls->controls[i]->type == PROPERTY && + controls->controls[i]->id.property == property) { return controls->controls[i]; } } diff --git a/src/control.h b/src/control.h index 661eb21..0109e60 100644 --- a/src/control.h +++ b/src/control.h @@ -32,27 +32,28 @@ typedef struct { /// Plugin control typedef struct { - ControlType type; ///< Type of control - LilvNode* node; ///< Port or property - LilvNode* symbol; ///< Symbol - LilvNode* label; ///< Human readable label - LV2_Atom_Forge* forge; ///< Forge (for URIDs) - LV2_URID property; ///< Iff type == PROPERTY - uint32_t index; ///< Iff type == PORT - LilvNode* group; ///< Port/control group, or NULL - void* widget; ///< Control Widget - size_t n_points; ///< Number of scale points - ScalePoint* points; ///< Scale points - LV2_URID value_type; ///< Type of control value - LilvNode* min; ///< Minimum value - LilvNode* max; ///< Maximum value - LilvNode* def; ///< Default value - bool is_toggle; ///< Boolean (0 and 1 only) - bool is_integer; ///< Integer values only - bool is_enumeration; ///< Point values only - bool is_logarithmic; ///< Logarithmic scale - bool is_writable; ///< Writable (input) - bool is_readable; ///< Readable (output) + ControlType type; ///< Type of control + union { + LV2_URID property; ///< Iff type == PROPERTY + uint32_t index; ///< Iff type == PORT + } id; + LilvNode* node; ///< Port or property + LilvNode* symbol; ///< Symbol + LilvNode* label; ///< Human readable label + LilvNode* group; ///< Port/control group, or NULL + void* widget; ///< Control Widget + size_t n_points; ///< Number of scale points + ScalePoint* points; ///< Scale points + LV2_URID value_type; ///< Type of control value + LilvNode* min; ///< Minimum value + LilvNode* max; ///< Maximum value + LilvNode* def; ///< Default value + bool is_toggle; ///< Boolean (0 and 1 only) + bool is_integer; ///< Integer values only + bool is_enumeration; ///< Point values only + bool is_logarithmic; ///< Logarithmic scale + bool is_writable; ///< Writable (input) + bool is_readable; ///< Readable (output) } ControlID; /// Set of plugin controls @@ -63,21 +64,21 @@ typedef struct { /// Create a new ID for a control port ControlID* -new_port_control(LilvWorld* world, - const LilvPlugin* plugin, - const LilvPort* port, - uint32_t port_index, - float sample_rate, - const JalvNodes* nodes, - LV2_Atom_Forge* forge); +new_port_control(LilvWorld* world, + const LilvPlugin* plugin, + const LilvPort* port, + uint32_t port_index, + float sample_rate, + const JalvNodes* nodes, + const LV2_Atom_Forge* forge); /// Create a new ID for a property-based parameter ControlID* -new_property_control(LilvWorld* world, - const LilvNode* property, - const JalvNodes* nodes, - LV2_URID_Map* map, - LV2_Atom_Forge* forge); +new_property_control(LilvWorld* world, + const LilvNode* property, + const JalvNodes* nodes, + LV2_URID_Map* map, + const LV2_Atom_Forge* forge); /// Free a control allocated with new_port_control() or new_property_control() void diff --git a/src/frontend.h b/src/frontend.h index f18fb86..e95fa6d 100644 --- a/src/frontend.h +++ b/src/frontend.h @@ -11,6 +11,7 @@ #include <lilv/lilv.h> #include <stdbool.h> +#include <stdint.h> // Interface that must be implemented by UIs JALV_BEGIN_DECLS @@ -102,8 +102,8 @@ static int process_silent(JalvProcess* const proc, const jack_nframes_t nframes) { for (uint32_t p = 0U; p < proc->num_ports; ++p) { - JalvProcessPort* const port = &proc->ports[p]; - jack_port_t* const jport = (jack_port_t*)proc->ports[p].sys_port; + const JalvProcessPort* const port = &proc->ports[p]; + jack_port_t* const jport = (jack_port_t*)proc->ports[p].sys_port; if (jport && port->flow == FLOW_OUTPUT) { void* const buf = jack_port_get_buffer(jport, nframes); if (port->type == TYPE_EVENT) { @@ -264,7 +264,7 @@ latency_cb(const jack_latency_callback_mode_t mode, void* const data) { // Calculate latency assuming all ports depend on each other - JalvBackend* const backend = (JalvBackend*)data; + const JalvBackend* const backend = (JalvBackend*)data; const JalvProcess* const proc = backend->process; const PortFlow flow = ((mode == JackCaptureLatency) ? FLOW_INPUT : FLOW_OUTPUT); diff --git a/src/jack_impl.h b/src/jack_impl.h index cc922a9..241ea85 100644 --- a/src/jack_impl.h +++ b/src/jack_impl.h @@ -5,10 +5,12 @@ #define JALV_JACK_IMPL_H #include "attributes.h" +#include "process.h" #include "settings.h" #include "urids.h" -#include <jack/jack.h> +#include <jack/types.h> +#include <zix/sem.h> #include <stdbool.h> @@ -326,7 +326,8 @@ jalv_set_control(Jalv* jalv, const void* body) { if (control->type == PORT && type == jalv->forge.Float) { - jalv->process.controls_buf[control->index] = *(const float*)body; + const float value = *(const float*)body; + jalv_write_control(jalv->process.ui_to_plugin, control->id.index, value); } else if (control->type == PROPERTY && jalv->process.control_in != UINT32_MAX) { LV2_Atom_Forge_Frame frame; @@ -334,7 +335,7 @@ jalv_set_control(Jalv* jalv, lv2_atom_forge_object(&jalv->forge, &frame, 0, jalv->urids.patch_Set); lv2_atom_forge_key(&jalv->forge, jalv->urids.patch_property); - lv2_atom_forge_urid(&jalv->forge, control->property); + lv2_atom_forge_urid(&jalv->forge, control->id.property); lv2_atom_forge_key(&jalv->forge, jalv->urids.patch_value); lv2_atom_forge_atom(&jalv->forge, size, type); lv2_atom_forge_write(&jalv->forge, body, size); @@ -363,7 +364,7 @@ void jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent) { #if USE_SUIL - LilvInstance* const instance = jalv->process.instance; + const LilvInstance* const instance = jalv->process.instance; jalv->ui_host = suil_host_new(jalv_send_to_plugin, jalv_ui_port_index, NULL, NULL); @@ -637,8 +638,8 @@ jalv_init_features(Jalv* const jalv) static void jalv_init_ui_settings(Jalv* const jalv) { - JalvOptions* const opts = &jalv->opts; - JalvSettings* const settings = &jalv->settings; + const JalvOptions* const opts = &jalv->opts; + JalvSettings* const settings = &jalv->settings; if (!settings->ring_size) { /* The UI ring is fed by plugin output ports (usually one), and the UI diff --git a/src/jalv_console.c b/src/jalv_console.c index 1f97572..fe92cd7 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -1,6 +1,7 @@ // Copyright 2007-2024 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC +#include "comm.h" #include "control.h" #include "frontend.h" #include "jalv.h" @@ -200,7 +201,7 @@ print_controls(const Jalv* const jalv, const bool writable, const bool readable) jalv_log(JALV_LOG_INFO, "%s = %f\n", lilv_node_as_string(control->symbol), - jalv->process.controls_buf[control->index]); + jalv->process.controls_buf[control->id.index]); } } @@ -249,14 +250,14 @@ jalv_process_command(Jalv* jalv, const char* cmd) print_controls(jalv, false, true); } else if (sscanf(cmd, "set %u %f", &index, &value) == 2) { if (index < jalv->num_ports) { - jalv->process.controls_buf[index] = value; + jalv_write_control(jalv->process.ui_to_plugin, index, value); print_control_port(jalv, &jalv->ports[index], value); } else { fprintf(stderr, "error: port index out of range\n"); } } 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) { - JalvPort* const port = jalv_port_by_symbol(jalv, sym); + const JalvPort* const port = jalv_port_by_symbol(jalv, sym); if (port) { jalv->process.controls_buf[port->index] = value; print_control_port(jalv, port, value); @@ -342,9 +343,9 @@ jalv_frontend_open(Jalv* jalv) 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 JalvPort* const port = &jalv->ports[control->index]; + const JalvPort* const port = &jalv->ports[control->id.index]; print_control_port( - jalv, port, jalv->process.controls_buf[control->index]); + jalv, port, jalv->process.controls_buf[control->id.index]); } } diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index 4a8930d..16cff34 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -48,10 +48,10 @@ static Jalv* s_jalv = NULL; static GtkCheckMenuItem* active_preset_item = NULL; static bool updating = false; -/// Widget for a control +/// Widget(s) for a control port or parameter typedef struct { - GtkSpinButton* spin; - GtkWidget* control; + GtkSpinButton* spin; ///< Spinner for numbers, or null + GtkWidget* control; ///< Primary value control } Controller; static float @@ -586,20 +586,21 @@ differ_enough(float a, float b) static void set_float_control(const ControlID* control, float value) { - if (control->value_type == control->forge->Int) { + const LV2_Atom_Forge* const forge = &s_jalv->forge; + if (control->value_type == forge->Int) { const int32_t ival = lrintf(value); - set_control(control, sizeof(ival), control->forge->Int, &ival); - } else if (control->value_type == control->forge->Long) { + set_control(control, sizeof(ival), forge->Int, &ival); + } else if (control->value_type == forge->Long) { const int64_t lval = lrintf(value); - set_control(control, sizeof(lval), control->forge->Long, &lval); - } else if (control->value_type == control->forge->Float) { - set_control(control, sizeof(value), control->forge->Float, &value); - } else if (control->value_type == control->forge->Double) { + set_control(control, sizeof(lval), forge->Long, &lval); + } else if (control->value_type == forge->Float) { + set_control(control, sizeof(value), forge->Float, &value); + } else if (control->value_type == forge->Double) { const double dval = value; - set_control(control, sizeof(dval), control->forge->Double, &dval); - } else if (control->value_type == control->forge->Bool) { + set_control(control, sizeof(dval), forge->Double, &dval); + } else if (control->value_type == forge->Bool) { const int32_t ival = value; - set_control(control, sizeof(ival), control->forge->Bool, &ival); + set_control(control, sizeof(ival), forge->Bool, &ival); } Controller* controller = (Controller*)control->widget; @@ -789,17 +790,13 @@ jalv_frontend_port_event(Jalv* jalv, return; } - if (protocol == 0 && (Controller*)jalv->ports[port_index].widget) { - control_changed(jalv, - (Controller*)jalv->ports[port_index].widget, - buffer_size, - jalv->forge.Float, - buffer); - return; - } - if (protocol == 0) { - return; // No widget (probably notOnGUI) + Controller* const controller = (Controller*)jalv->ports[port_index].widget; + if (controller) { + control_changed(jalv, controller, buffer_size, jalv->forge.Float, buffer); + } + + return; } if (protocol != jalv->urids.atom_eventTransfer) { @@ -905,7 +902,7 @@ string_changed(GtkEntry* widget, gpointer data) const ControlID* control = (const ControlID*)data; const char* string = gtk_entry_get_text(widget); - set_control(control, strlen(string) + 1, control->forge->String, string); + set_control(control, strlen(string) + 1, s_jalv->forge.String, string); } static void @@ -1211,7 +1208,7 @@ build_control_widget(Jalv* jalv, GtkWidget* window) record->widget = controller; if (record->type == PORT) { - jalv->ports[record->index].widget = controller; + jalv->ports[record->id.index].widget = controller; } if (controller) { // Add row to table for this controller diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp index 9b3b145..7d99118 100644 --- a/src/jalv_qt.cpp +++ b/src/jalv_qt.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: ISC #include "jalv_qt.hpp" +#include "comm.h" #include "frontend.h" #include "jalv.h" #include "nodes.h" @@ -499,7 +500,7 @@ Control::dialChanged(int) const float value = getValue(); _label->setText(getValueLabel(value)); - _jalv->process.controls_buf[_port->index] = value; + jalv_write_control(_jalv->process.ui_to_plugin, _port->index, value); } namespace { @@ -10,6 +10,7 @@ #include <lv2/log/log.h> #include <lv2/urid/urid.h> +#include <stdarg.h> #include <stdbool.h> #include <stdio.h> diff --git a/src/mapper.h b/src/mapper.h index 4d541f6..ac4c53e 100644 --- a/src/mapper.h +++ b/src/mapper.h @@ -27,7 +27,7 @@ jalv_mapper_free(JalvMapper* mapper); LV2_URID_Map* jalv_mapper_urid_map(JalvMapper* mapper); -/// Return a poitner to the mapper's LV2 URID unmap +/// Return a pointer to the mapper's LV2 URID unmap LV2_URID_Unmap* jalv_mapper_urid_unmap(JalvMapper* mapper); @@ -5,12 +5,10 @@ #define JALV_PORT_H #include "attributes.h" -#include "lv2_evbuf.h" #include "types.h" #include <lilv/lilv.h> -#include <stddef.h> #include <stdint.h> // Application port state diff --git a/src/process.h b/src/process.h index c5d049b..cb6a122 100644 --- a/src/process.h +++ b/src/process.h @@ -32,7 +32,7 @@ typedef struct { LV2_Evbuf* evbuf; ///< Sequence port event buffer uint32_t buf_size; ///< Custom buffer size, or 0 bool reports_latency; ///< Whether control port reports latency - bool is_primary; ///< True for main control/reponse channel + bool is_primary; ///< True for main control/response channel bool supports_midi; ///< Whether event port supports MIDI } JalvProcessPort; diff --git a/src/process_setup.c b/src/process_setup.c index 66078a9..169ddcd 100644 --- a/src/process_setup.c +++ b/src/process_setup.c @@ -180,6 +180,7 @@ jalv_process_port_init(JalvProcessPort* const port, LilvNode* const name = lilv_port_get_name(lilv_plugin, lilv_port); port->symbol = symbol ? jalv_strdup(lilv_node_as_string(symbol)) : NULL; port->label = name ? jalv_strdup(lilv_node_as_string(name)) : NULL; + lilv_node_free(name); // Set buffer size LilvNode* const min_size = diff --git a/src/state.c b/src/state.c index 1b79b34..472244e 100644 --- a/src/state.c +++ b/src/state.c @@ -26,7 +26,7 @@ #include <stdio.h> #include <stdlib.h> -char* +ZIX_MALLOC_FUNC char* jalv_make_path(LV2_State_Make_Path_Handle handle, const char* path) { Jalv* jalv = (Jalv*)handle; @@ -42,8 +42,8 @@ get_port_value(const char* port_symbol, uint32_t* size, uint32_t* type) { - Jalv* const jalv = (Jalv*)user_data; - JalvPort* const port = jalv_port_by_symbol(jalv, port_symbol); + Jalv* const jalv = (Jalv*)user_data; + const 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; @@ -130,9 +130,9 @@ set_port_value(const char* port_symbol, uint32_t ZIX_UNUSED(size), uint32_t type) { - Jalv* const jalv = (Jalv*)user_data; - JalvProcess* const proc = &jalv->process; - JalvPort* const port = jalv_port_by_symbol(jalv, port_symbol); + Jalv* const jalv = (Jalv*)user_data; + JalvProcess* const proc = &jalv->process; + const 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; diff --git a/src/worker.c b/src/worker.c index b131b3e..f03c823 100644 --- a/src/worker.c +++ b/src/worker.c @@ -153,7 +153,7 @@ jalv_worker_launch(JalvWorker* const worker) worker->state = STATE_LAUNCHED; } - return ZIX_STATUS_SUCCESS; + return st; } void |