From 6dd191bef44ebab3a67a1d76b256386b801350c2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 16 Feb 2020 21:37:27 +0100 Subject: WIP: Implement ui:requestValue --- src/jalv.c | 5 +++++ src/jalv_gtk.c | 38 ++++++++++++++++++++++++++++++++++++++ src/jalv_internal.h | 3 +++ wscript | 2 +- 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/jalv.c b/src/jalv.c index adee072..b48b6b6 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -411,6 +411,7 @@ jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent) &parent_feature, &jalv->features.options_feature, &idle_feature, + &jalv->features.request_value_feature, NULL }; @@ -844,6 +845,10 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) init_feature(&jalv->features.log_feature, LV2_LOG__log, &jalv->features.llog); + jalv->features.request_value.handle = jalv; + init_feature(&jalv->features.request_value_feature, + LV2_UI__requestValue, &jalv->features.request_value); + zix_sem_init(&jalv->done, 0); zix_sem_init(&jalv->paused, 0); diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index 71259bd..5cf9a97 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -630,6 +630,42 @@ patch_put_get(Jalv* jalv, return 0; } +static LV2UI_Request_Value_Status +on_request_value(LV2UI_Feature_Handle handle, + const LV2_URID key, + const LV2_URID type, + const LV2_Feature* const* features) +{ + Jalv* jalv = (Jalv*)handle; + ControlID* control = get_property_control(&jalv->controls, key); + + if (!control) { + return LV2UI_REQUEST_VALUE_ERR_UNKNOWN; + } else if (control->value_type != jalv->forge.Path) { + return LV2UI_REQUEST_VALUE_ERR_UNSUPPORTED; + } + + GtkWidget* dialog = + gtk_file_chooser_dialog_new("Choose file", + GTK_WINDOW(jalv->window), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { + char* path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + set_control(control, strlen(path), jalv->forge.Path, path); + + g_free(path); + } + + gtk_widget_destroy(dialog); + + return 0; +} + static void property_changed(Jalv* jalv, LV2_URID key, const LV2_Atom* value) { @@ -1197,6 +1233,8 @@ jalv_open_ui(Jalv* jalv) jalv_ui_instantiate(jalv, jalv_native_ui_type(), alignment); } + jalv->features.request_value.request = on_request_value; + if (jalv->ui_instance) { GtkWidget* widget = (GtkWidget*)suil_instance_get_widget( jalv->ui_instance); diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 4d25109..b48ca5d 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -39,6 +39,7 @@ #include "lv2/options/options.h" #include "lv2/resize-port/resize-port.h" #include "lv2/state/state.h" +#include "lv2/ui/ui.h" #include "lv2/urid/urid.h" #include "lv2/worker/worker.h" @@ -278,6 +279,8 @@ typedef struct { LV2_Options_Option options[6]; LV2_Feature options_feature; LV2_Feature safe_restore_feature; + LV2UI_Request_Value request_value; + LV2_Feature request_value_feature; LV2_Extension_Data_Feature ext_data; } JalvFeatures; diff --git a/wscript b/wscript index af363ca..1df76d8 100644 --- a/wscript +++ b/wscript @@ -42,7 +42,7 @@ def configure(conf): conf.load('autowaf', cache=True) autowaf.set_c_lang(conf, 'c99') - conf.check_pkg('lv2 >= 1.16.0', uselib_store='LV2') + conf.check_pkg('lv2 >= 1.17.2', uselib_store='LV2') conf.check_pkg('lilv-0 >= 0.24.0', uselib_store='LILV') conf.check_pkg('serd-0 >= 0.24.0', uselib_store='SERD') conf.check_pkg('sord-0 >= 0.14.0', uselib_store='SORD') -- cgit v1.2.1