diff options
author | Alexandros Theodotou <alex@zrythm.org> | 2019-10-18 18:59:56 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-05-27 18:30:20 -0400 |
commit | a42336f7d93bcf94bf1f13c97cfaf66f4bd3a1e6 (patch) | |
tree | 898236f94756bc34762dd53a795154a086328f1b /src | |
parent | 21ef4be1d84d2adad374c7e6127149cee6eb3bde (diff) | |
download | jalv-a42336f7d93bcf94bf1f13c97cfaf66f4bd3a1e6.tar.gz jalv-a42336f7d93bcf94bf1f13c97cfaf66f4bd3a1e6.tar.bz2 jalv-a42336f7d93bcf94bf1f13c97cfaf66f4bd3a1e6.zip |
Add Gtk plugin selector UI
Diffstat (limited to 'src')
-rw-r--r-- | src/jalv.c | 4 | ||||
-rw-r--r-- | src/jalv_console.c | 7 | ||||
-rw-r--r-- | src/jalv_gtk.c | 115 | ||||
-rw-r--r-- | src/jalv_gtkmm2.cpp | 7 | ||||
-rw-r--r-- | src/jalv_internal.h | 3 | ||||
-rw-r--r-- | src/jalv_qt.cpp | 6 |
6 files changed, 142 insertions, 0 deletions
@@ -1011,6 +1011,10 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } if (!plugin_uri) { + plugin_uri = jalv_select_plugin(jalv); + } + + if (!plugin_uri) { fprintf(stderr, "Missing plugin URI, try lv2ls to list plugins\n"); jalv_close(jalv); return -3; diff --git a/src/jalv_console.c b/src/jalv_console.c index 8c3eaf7..a9597e3 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -291,6 +291,13 @@ jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv)) return 1.0f; } +LilvNode* +jalv_select_plugin(Jalv* jalv) +{ + (void)jalv; + return NULL; +} + int jalv_open_ui(Jalv* jalv) { diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index a8835ff..348dd3c 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -1360,6 +1360,121 @@ jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv)) #endif } +static void +on_row_activated(GtkTreeView* const tree_view, + GtkTreePath* const path, + GtkTreeViewColumn* const column, + const void* const user_data) +{ + (void)tree_view; + (void)path; + (void)column; + + gtk_dialog_response(GTK_DIALOG(user_data), GTK_RESPONSE_ACCEPT); +} + +LilvNode* +jalv_select_plugin(Jalv* jalv) +{ + // Create the dialog + GtkWidget* const dialog = gtk_dialog_new_with_buttons("Plugin Selector", + NULL, + (GtkDialogFlags)0, + "_OK", + GTK_RESPONSE_ACCEPT, + "_Cancel", + GTK_RESPONSE_REJECT, + NULL); + + gtk_window_set_role(GTK_WINDOW(dialog), "plugin_selector"); + gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 600); + + // Build the treeview + + GtkTreeView* const tree_view = GTK_TREE_VIEW(gtk_tree_view_new()); + { + // Add treeview to the content area of the dialog + GtkWidget* content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + GtkContainer* scroll = GTK_CONTAINER(gtk_scrolled_window_new(NULL, NULL)); + gtk_container_add(scroll, GTK_WIDGET(tree_view)); + gtk_container_add(GTK_CONTAINER(content), GTK_WIDGET(scroll)); + gtk_widget_set_visible(GTK_WIDGET(tree_view), TRUE); + gtk_widget_set_visible(GTK_WIDGET(scroll), TRUE); + gtk_box_set_child_packing( + GTK_BOX(content), GTK_WIDGET(scroll), TRUE, TRUE, 2, GTK_PACK_START); + gtk_scrolled_window_set_policy( + GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + } + + // Set treeview columns (all strings) + static const char* const col_labels[] = {"Name", "Type", "Author", "URI"}; + for (unsigned i = 0; i < 4; ++i) { + GtkTreeViewColumn* const column = gtk_tree_view_column_new_with_attributes( + col_labels[i], gtk_cell_renderer_text_new(), "text", i, NULL); + + gtk_tree_view_column_set_sort_column_id(column, i); + gtk_tree_view_append_column(tree_view, column); + } + + // Build the model + GtkListStore* const store = gtk_list_store_new( + 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + const LilvPlugins* plugins = lilv_world_get_all_plugins(jalv->world); + LILV_FOREACH (plugins, i, plugins) { + const LilvPlugin* const p = lilv_plugins_get(plugins, i); + LilvNode* const name = lilv_plugin_get_name(p); + const LilvPluginClass* const klass = lilv_plugin_get_class(p); + const LilvNode* const type = lilv_plugin_class_get_label(klass); + LilvNode* const author = lilv_plugin_get_author_name(p); + const LilvNode* const uri = lilv_plugin_get_uri(p); + + if (name && type && uri) { + GtkTreeIter iter; + gtk_list_store_insert_with_values(store, + &iter, + -1, + 0, + lilv_node_as_string(name), + 1, + lilv_node_as_string(type), + 2, + lilv_node_as_string(author), + 3, + lilv_node_as_string(uri), + -1); + } + + lilv_node_free(name); + lilv_node_free(author); + } + + gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(store)); + + g_signal_connect(GTK_WIDGET(tree_view), + "row-activated", + G_CALLBACK(on_row_activated), + dialog); + + // Get URI from selection + LilvNode* selected_uri = NULL; + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + GtkTreeSelection* selection = gtk_tree_view_get_selection(tree_view); + GtkTreeModel* model = GTK_TREE_MODEL(store); + GtkTreeIter selected; + if (gtk_tree_selection_get_selected(selection, &model, &selected)) { + GValue val = G_VALUE_INIT; + gtk_tree_model_get_value(model, &selected, 3, &val); + + selected_uri = lilv_new_uri(jalv->world, g_value_get_string(&val)); + + g_value_unset(&val); + } + } + gtk_widget_destroy(dialog); + + return selected_uri; +} + int jalv_open_ui(Jalv* jalv) { diff --git a/src/jalv_gtkmm2.cpp b/src/jalv_gtkmm2.cpp index a967563..f29ee14 100644 --- a/src/jalv_gtkmm2.cpp +++ b/src/jalv_gtkmm2.cpp @@ -16,6 +16,7 @@ #include "jalv_internal.h" +#include "lilv/lilv.h" #include "lv2/core/attributes.h" #include "suil/suil.h" #include "zix/sem.h" @@ -77,6 +78,12 @@ jalv_ui_scale_factor(Jalv*) return 1.0f; } +LilvNode* +jalv_select_plugin(Jalv*) +{ + return nullptr; +} + int jalv_open_ui(Jalv* jalv) { diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 36b63ed..0737582 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -402,6 +402,9 @@ jalv_ui_scale_factor(Jalv* jalv); int jalv_open_ui(Jalv* jalv); +LilvNode* +jalv_select_plugin(Jalv* jalv); + void jalv_init_ui(Jalv* jalv); diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp index 746ecdc..79de303 100644 --- a/src/jalv_qt.cpp +++ b/src/jalv_qt.cpp @@ -711,6 +711,12 @@ jalv_ui_scale_factor(Jalv*) return (float)QGuiApplication::primaryScreen()->devicePixelRatio(); } +LilvNode* +jalv_select_plugin(Jalv*) +{ + return nullptr; +} + int jalv_open_ui(Jalv* jalv) { |