From afbd9c01a9c686f3a9746f5ba5d7f6dab671e3f4 Mon Sep 17 00:00:00 2001 From: "mr.fantastic" Date: Fri, 28 Jun 2024 17:09:39 +0300 Subject: [PATCH] Adding support to enumeration parameter type in lv2 module --- src/modules/jackrack/factory.c | 61 ++++++++++++++++++++++++++++++- src/modules/jackrack/lv2_plugin.c | 15 +++++++- src/modules/jackrack/plugin_mgr.c | 1 + 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/modules/jackrack/factory.c b/src/modules/jackrack/factory.c index 52b15a67e..973973809 100644 --- a/src/modules/jackrack/factory.c +++ b/src/modules/jackrack/factory.c @@ -264,7 +264,62 @@ static void lv2_add_port_to_metadata(mlt_properties p, lv2_plugin_desc_t *desc, } if (LADSPA_IS_HINT_ENUMERATION(hint_descriptor)) { - /* WIP */ + mlt_properties_set(p, "type", "string"); + + char *str_ptr = strchr(desc->uri, '<'); + while (str_ptr != NULL) { + *str_ptr++ = ':'; + str_ptr = strchr(str_ptr, '<'); + } + + LilvNode* puri_temp = lilv_new_uri(g_lv2_plugin_mgr->lv2_world, desc->uri); + + str_ptr = strchr(desc->uri, ':'); + while (str_ptr != NULL) { + *str_ptr++ = '<'; + str_ptr = strchr(str_ptr, ':'); + } + + const LilvPlugin* p_temp = lilv_plugins_get_by_uri(g_lv2_plugin_mgr->plugin_list, puri_temp); + const LilvPort *port_temp = lilv_plugin_get_port_by_index(p_temp, j); + + lilv_node_free(puri_temp); + + mlt_properties values_temp = mlt_properties_new(); + mlt_properties_set_data(p, + "values", + values_temp, + 0, + (mlt_destructor) mlt_properties_close, + NULL); + + // Fill scalePoints Map + LilvScalePoints* sp = lilv_port_get_scale_points(p_temp, port_temp); + if (sp) { + LILV_FOREACH (scale_points, s, sp) { + const LilvScalePoint* p = lilv_scale_points_get(sp, s); + const LilvNode* val = lilv_scale_point_get_value(p); + if (!lilv_node_is_float(val) && !lilv_node_is_int(val)) { + continue; + } + + const float f = lilv_node_as_float(val); + + + char key_temp[20]; + + if (lilv_node_is_float(val)) { + snprintf(key_temp, 20, "%f", f); + } else if (lilv_node_is_int(val)) { + snprintf(key_temp, 20, "%d", (int) f); + } + + mlt_properties_set(values_temp, key_temp, lilv_node_as_string(lilv_scale_point_get_label(p))); + + } + + lilv_scale_points_free(sp); + } } if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) @@ -412,6 +467,10 @@ MLT_REPOSITORY #ifdef WITH_LV2 g_lv2_plugin_mgr = lv2_mgr_new(); + char global_lv2_world[20]; + snprintf (global_lv2_world, 20, "%p", g_lv2_plugin_mgr->lv2_world); + mlt_environment_set ("global_lv2_world", global_lv2_world); + for (list = g_lv2_plugin_mgr->all_plugins; list; list = g_slist_next(list)) { lv2_plugin_desc_t *desc = (lv2_plugin_desc_t *) list->data; char *s = NULL; diff --git a/src/modules/jackrack/lv2_plugin.c b/src/modules/jackrack/lv2_plugin.c index 784a440f5..a7eb056a0 100644 --- a/src/modules/jackrack/lv2_plugin.c +++ b/src/modules/jackrack/lv2_plugin.c @@ -38,6 +38,8 @@ #define CONTROL_FIFO_SIZE 128 +extern char *mlt_environment(const char *name); + extern const LV2_Feature *features[]; #ifdef WITH_JACK @@ -272,8 +274,19 @@ static int lv2_plugin_instantiate(const LilvPlugin *plugin, gint copies, LilvInstance **instances) { - gint i; + char *lv2context_can_ui = mlt_environment ("lv2context_can_ui"); + if (lv2context_can_ui != NULL) + { + /* Video editors and other hosts that support custom GUI should use mlt_environment_set ("lv2context_can_ui", "1") + to inform mlt lv2 plugin manager and set UI features and extensions if not set. + */ + if (lv2context_can_ui[0] == '1') + { + //WIP: if support UI + } + } + gint i; for (i = 0; i < copies; i++) { instances[i] = lilv_plugin_instantiate(plugin, lv2_sample_rate, features); diff --git a/src/modules/jackrack/plugin_mgr.c b/src/modules/jackrack/plugin_mgr.c index 9eeaf0ce1..24391770e 100644 --- a/src/modules/jackrack/plugin_mgr.c +++ b/src/modules/jackrack/plugin_mgr.c @@ -57,6 +57,7 @@ #include #include #include +#include #include "lv2_urid_helper.h"