diff options
author | David Robillard <d@drobilla.net> | 2024-12-19 21:37:12 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-12-19 21:37:12 -0500 |
commit | 9e2cf8abd624414bae99789345ffbb80b2a26c27 (patch) | |
tree | 127900f6ed63290fa1e48f7a9b24eb970f5dc748 /src | |
parent | efad9a58a085a87157e7b9e56739b64acf958bfd (diff) | |
download | jalv-9e2cf8abd624414bae99789345ffbb80b2a26c27.tar.gz jalv-9e2cf8abd624414bae99789345ffbb80b2a26c27.tar.bz2 jalv-9e2cf8abd624414bae99789345ffbb80b2a26c27.zip |
Merge control index and property fields
Diffstat (limited to 'src')
-rw-r--r-- | src/control.c | 17 | ||||
-rw-r--r-- | src/control.h | 8 | ||||
-rw-r--r-- | src/jalv.c | 4 | ||||
-rw-r--r-- | src/jalv_console.c | 6 | ||||
-rw-r--r-- | src/jalv_gtk.c | 24 |
5 files changed, 29 insertions, 30 deletions
diff --git a/src/control.c b/src/control.c index c384165..1a93fa7 100644 --- a/src/control.c +++ b/src/control.c @@ -43,11 +43,11 @@ new_port_control(LilvWorld* const world, 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); @@ -128,12 +128,12 @@ new_property_control(LilvWorld* const world, LV2_URID_Map* const map, 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->forge = forge; id->label = lilv_world_get(world, property, nodes->rdfs_label, NULL); id->min = lilv_world_get(world, property, nodes->lv2_minimum, NULL); @@ -198,7 +198,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..ad5168a 100644 --- a/src/control.h +++ b/src/control.h @@ -32,13 +32,15 @@ typedef struct { /// Plugin control typedef struct { - ControlType type; ///< Type of control + 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 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 @@ -327,7 +327,7 @@ jalv_set_control(Jalv* jalv, { if (control->type == PORT && type == jalv->forge.Float) { const float value = *(const float*)body; - jalv_write_control(jalv->process.ui_to_plugin, control->index, value); + 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; @@ -335,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); diff --git a/src/jalv_console.c b/src/jalv_console.c index 8a1f712..fba3aa9 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -201,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]); } } @@ -343,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..b599bd4 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 @@ -789,17 +789,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) { @@ -1211,7 +1207,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 |