From 4e70264247f9314f24a2b32189766c96596bd451 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 27 Apr 2014 00:43:14 +0000 Subject: Support new UI show/hide interface in console version. git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@5377 a436a847-0d15-0410-975c-d299462d15a1 --- src/jalv_console.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'src/jalv_console.c') diff --git a/src/jalv_console.c b/src/jalv_console.c index b75bb3c..c13880b 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -14,13 +14,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#define _XOPEN_SOURCE 500 + #include #include +#include +#include #include "jalv_config.h" #include "jalv_internal.h" +#include "lv2/lv2plug.in/ns/extensions/ui/ui.h" + static int print_usage(const char* name, bool error) { @@ -28,6 +33,7 @@ print_usage(const char* name, bool error) fprintf(os, "Usage: %s [OPTION...] PLUGIN_URI\n", name); fprintf(os, "Run an LV2 plugin as a Jack application.\n"); fprintf(os, " -h Display this help and exit\n"); + fprintf(os, " -s Show non-embedded UI if possible\n"); fprintf(os, " -u UUID UUID for Jack session restoration\n"); fprintf(os, " -l DIR Load state from save directory\n"); fprintf(os, " -d DIR Dump plugin <=> UI communication\n"); @@ -61,6 +67,8 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts) for (; a < *argc && (*argv)[a][0] == '-'; ++a) { if ((*argv)[a][1] == 'h') { return print_usage((*argv)[0], true); + } else if ((*argv)[a][1] == 's') { + opts->show_ui = true; } else if ((*argv)[a][1] == 'u') { if (++a == *argc) { fprintf(stderr, "Missing argument for -u\n"); @@ -108,16 +116,32 @@ jalv_native_ui_type(Jalv* jalv) int jalv_open_ui(Jalv* jalv) { -#ifdef JALV_JACK_SESSION - printf("\nPress Ctrl-C to quit: "); - fflush(stdout); -#else - printf("\nPress enter to quit: "); - fflush(stdout); - getc(stdin); - zix_sem_post(jalv->done); -#endif - printf("\n"); + const LV2UI_Idle_Interface* idle_iface = NULL; + const LV2UI_Show_Interface* show_iface = NULL; + if (jalv->ui && jalv->opts.show_ui) { + jalv_ui_instantiate(jalv, jalv_native_ui_type(jalv), NULL); + idle_iface = (const LV2UI_Idle_Interface*) + suil_instance_extension_data(jalv->ui_instance, LV2_UI__idleInterface); + show_iface = (LV2UI_Show_Interface*) + suil_instance_extension_data(jalv->ui_instance, LV2_UI__showInterface); + } + + if (show_iface && idle_iface) { + show_iface->show(suil_instance_get_handle(jalv->ui_instance)); + + // Drive idle interface until interrupted + while (!zix_sem_try_wait(jalv->done)) { + if (idle_iface->idle(suil_instance_get_handle(jalv->ui_instance))) { + break; + } + usleep(33333); + } + + show_iface->hide(suil_instance_get_handle(jalv->ui_instance)); + + // Caller waits on the done sem, so increment it again to exit + zix_sem_post(jalv->done); + } return 0; } -- cgit v1.2.1