From 52d6c6347ed4f84077887a7d1359488d0890ac6a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 12 Jan 2014 19:56:04 +0000 Subject: Show newly saved presets in the preset menu. git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@5311 a436a847-0d15-0410-975c-d299462d15a1 --- NEWS | 6 ++++ src/jalv_gtk.c | 94 ++++++++++++++++++++++++++++++++++------------------------ wscript | 2 +- 3 files changed, 62 insertions(+), 40 deletions(-) diff --git a/NEWS b/NEWS index d505013..c4880b6 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +jalv (1.4.5) unstable; + + * Show newly saved presets in the preset menu + + -- David Robillard Sun, 12 Jan 2014 14:53:36 -0500 + jalv (1.4.4) stable; * Add -c option for setting controls from the command line diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index bb92dbb..f6a104b 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -175,6 +175,44 @@ symbolify(const char* in) return out; } +static void +on_preset_activate(GtkWidget* widget, gpointer data) +{ + PresetRecord* record = (PresetRecord*)data; + jalv_apply_preset(record->jalv, record->preset); +} + +static void +on_preset_destroy(gpointer data, GClosure* closure) +{ + PresetRecord* record = (PresetRecord*)data; + lilv_node_free(record->preset); + free(record); +} + +static int +add_preset_to_menu(Jalv* jalv, + const LilvNode* node, + const LilvNode* title, + void* data) +{ + GtkWidget* presets_menu = GTK_WIDGET(data); + const char* label = lilv_node_as_string(title); + GtkWidget* item = gtk_menu_item_new_with_label(label); + + PresetRecord* record = (PresetRecord*)malloc(sizeof(PresetRecord)); + record->jalv = jalv; + record->preset = lilv_node_duplicate(node); + + g_signal_connect_data(G_OBJECT(item), "activate", + G_CALLBACK(on_preset_activate), + record, on_preset_destroy, + 0); + + gtk_menu_shell_append(GTK_MENU_SHELL(presets_menu), item); + return 0; +} + static void on_save_preset_activate(GtkWidget* widget, void* ptr) { @@ -211,12 +249,28 @@ on_save_preset_activate(GtkWidget* widget, void* ptr) char* dirname = g_path_get_dirname(path); char* basename = g_path_get_basename(path); char* sym = symbolify(basename); - char* bundle = g_strjoin(NULL, sym, ".lv2", NULL); + char* bundle = g_strjoin(NULL, sym, ".lv2/", NULL); char* file = g_strjoin(NULL, sym, ".ttl", NULL); char* dir = g_build_filename(dirname, bundle, NULL); jalv_save_preset(jalv, dir, (strlen(uri) ? uri : NULL), basename, file); + // Load preset so it is now known to LilvWorld + SerdNode sdir = serd_node_new_file_uri((const uint8_t*)dir, 0, 0, 0); + LilvNode* ldir = lilv_new_uri(jalv->world, (const char*)sdir.buf); + lilv_world_load_bundle(jalv->world, ldir); + serd_node_free(&sdir); + lilv_node_free(ldir); + + // Rebuild preset menu + GtkContainer* pset_menu = GTK_CONTAINER(gtk_widget_get_parent(widget)); + GList* items = gtk_container_get_children(pset_menu); + for (items = items->next; items; items = items->next) { + gtk_container_remove(pset_menu, items->data); + } + jalv_load_presets(jalv, add_preset_to_menu, pset_menu); + gtk_widget_show_all(GTK_WIDGET(pset_menu)); + g_free(dir); g_free(file); g_free(bundle); @@ -228,44 +282,6 @@ on_save_preset_activate(GtkWidget* widget, void* ptr) gtk_widget_destroy(GTK_WIDGET(dialog)); } -static void -on_preset_activate(GtkWidget* widget, gpointer data) -{ - PresetRecord* record = (PresetRecord*)data; - jalv_apply_preset(record->jalv, record->preset); -} - -static void -on_preset_destroy(gpointer data, GClosure* closure) -{ - PresetRecord* record = (PresetRecord*)data; - lilv_node_free(record->preset); - free(record); -} - -static int -add_preset_to_menu(Jalv* jalv, - const LilvNode* node, - const LilvNode* title, - void* data) -{ - GtkWidget* presets_menu = GTK_WIDGET(data); - const char* label = lilv_node_as_string(title); - GtkWidget* item = gtk_menu_item_new_with_label(label); - - PresetRecord* record = (PresetRecord*)malloc(sizeof(PresetRecord)); - record->jalv = jalv; - record->preset = lilv_node_duplicate(node); - - g_signal_connect_data(G_OBJECT(item), "activate", - G_CALLBACK(on_preset_activate), - record, on_preset_destroy, - 0); - - gtk_menu_shell_append(GTK_MENU_SHELL(presets_menu), item); - return 0; -} - void jalv_ui_port_event(Jalv* jalv, uint32_t port_index, diff --git a/wscript b/wscript index aa466da..6658675 100644 --- a/wscript +++ b/wscript @@ -4,7 +4,7 @@ from waflib.extras import autowaf as autowaf import waflib.Options as Options # Version of this package (even if built as a child) -JALV_VERSION = '1.4.4' +JALV_VERSION = '1.4.5' # Variables for 'waf dist' APPNAME = 'jalv' -- cgit v1.2.1