diff options
author | David Robillard <d@drobilla.net> | 2022-05-30 18:17:40 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-08-17 13:50:20 -0400 |
commit | d0a79a7547369bdb341af5bc5f7b52b879a89d03 (patch) | |
tree | 373b61fc40d6162b5d8e48ebef38567029d82816 /src | |
parent | 0f84c369fe82c6228b4827b54d6402ff894c6f92 (diff) | |
download | jalv-d0a79a7547369bdb341af5bc5f7b52b879a89d03.tar.gz jalv-d0a79a7547369bdb341af5bc5f7b52b879a89d03.tar.bz2 jalv-d0a79a7547369bdb341af5bc5f7b52b879a89d03.zip |
Clearly separate frontends from common internals
Diffstat (limited to 'src')
-rw-r--r-- | src/frontend.h | 55 | ||||
-rw-r--r-- | src/jack.c | 3 | ||||
-rw-r--r-- | src/jalv.c | 20 | ||||
-rw-r--r-- | src/jalv_console.c | 20 | ||||
-rw-r--r-- | src/jalv_gtk.c | 20 | ||||
-rw-r--r-- | src/jalv_internal.h | 3 | ||||
-rw-r--r-- | src/jalv_qt.cpp | 20 | ||||
-rw-r--r-- | src/ui.h | 44 |
8 files changed, 97 insertions, 88 deletions
diff --git a/src/frontend.h b/src/frontend.h new file mode 100644 index 0000000..b2e722d --- /dev/null +++ b/src/frontend.h @@ -0,0 +1,55 @@ +// Copyright 2007-2022 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#ifndef JALV_UI_H +#define JALV_UI_H + +#include "jalv_internal.h" + +#include "lilv/lilv.h" + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// Interface that must be implemented by UIs + +/// Read command-line arguments and set `opts` accordingly +int +jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts); + +/// Return the URI of the "native" LV2 UI type +const char* +jalv_frontend_ui_type(void); + +/// Return true if an interactive frontend is available +bool +jalv_frontend_discover(Jalv* jalv); + +/// Return the ideal refresh rate of the frontend in Hz +float +jalv_frontend_refresh_rate(Jalv* jalv); + +/// Return the scale factor of the frontend (for example 2.0 for double sized) +float +jalv_frontend_scale_factor(Jalv* jalv); + +/// Attempt to get a plugin URI selection from the user +LilvNode* +jalv_frontend_select_plugin(Jalv* jalv); + +/// Open and run the frontend interface, signalling jalv.done when finished +int +jalv_frontend_open(Jalv* jalv); + +/// Quit and close the frontend interface +int +jalv_frontend_close(Jalv* jalv); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // JALV_UI_H @@ -3,6 +3,7 @@ #include "backend.h" +#include "frontend.h" #include "jalv_config.h" #include "jalv_internal.h" #include "log.h" @@ -64,7 +65,7 @@ static void jack_shutdown_cb(void* data) { Jalv* const jalv = (Jalv*)data; - jalv_close_ui(jalv); + jalv_frontend_close(jalv); zix_sem_post(&jalv->done); } @@ -7,12 +7,12 @@ #include "backend.h" #include "control.h" +#include "frontend.h" #include "jalv_config.h" #include "jalv_internal.h" #include "log.h" #include "lv2_evbuf.h" #include "state.h" -#include "ui.h" #include "worker.h" #include "lilv/lilv.h" @@ -653,7 +653,7 @@ jalv_update(Jalv* jalv) { // Check quit flag and close if set if (zix_sem_try_wait(&jalv->done)) { - jalv_close_ui(jalv); + jalv_frontend_close(jalv); return 0; } @@ -755,7 +755,7 @@ setup_signals(Jalv* const jalv) static const LilvUI* jalv_select_custom_ui(const Jalv* const jalv) { - const char* const native_ui_type_uri = jalv_native_ui_type(); + const char* const native_ui_type_uri = jalv_frontend_ui_type(); if (jalv->opts.ui_uri) { // Specific UI explicitly requested by user @@ -826,7 +826,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) #endif int ret = 0; - if ((ret = jalv_init(argc, argv, &jalv->opts))) { + if ((ret = jalv_frontend_init(argc, argv, &jalv->opts))) { jalv_close(jalv); return ret; } @@ -1012,7 +1012,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } if (!plugin_uri) { - plugin_uri = jalv_select_plugin(jalv); + plugin_uri = jalv_frontend_select_plugin(jalv); } if (!plugin_uri) { @@ -1064,7 +1064,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->uis = lilv_plugin_get_uis(jalv->plugin); if (!jalv->opts.generic_ui) { if ((jalv->ui = jalv_select_custom_ui(jalv))) { - const char* host_type_uri = jalv_native_ui_type(); + const char* host_type_uri = jalv_frontend_ui_type(); if (host_type_uri) { LilvNode* host_type = lilv_new_uri(jalv->world, host_type_uri); @@ -1113,7 +1113,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) if (jalv->opts.update_rate == 0.0) { // Calculate a reasonable UI update frequency - jalv->ui_update_hz = jalv_ui_refresh_rate(jalv); + jalv->ui_update_hz = jalv_frontend_refresh_rate(jalv); } else { // Use user-specified UI update rate jalv->ui_update_hz = jalv->opts.update_rate; @@ -1122,7 +1122,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) if (jalv->opts.scale_factor == 0.0) { // Calculate the monitor's scale factor - jalv->ui_scale_factor = jalv_ui_scale_factor(jalv); + jalv->ui_scale_factor = jalv_frontend_scale_factor(jalv); } else { // Use user-specified UI scale factor jalv->ui_scale_factor = jalv->opts.scale_factor; @@ -1280,7 +1280,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) lilv_instance_activate(jalv->instance); // Discover UI - jalv->has_ui = jalv_discover_ui(jalv); + jalv->has_ui = jalv_frontend_discover(jalv); // Activate Jack jalv_backend_activate(jalv); @@ -1383,7 +1383,7 @@ main(int argc, char** argv) setup_signals(&jalv); // Run UI (or prompt at console) - jalv_open_ui(&jalv); + jalv_frontend_open(&jalv); // Wait for finish signal from UI or signal handler zix_sem_wait(&jalv.done); diff --git a/src/jalv_console.c b/src/jalv_console.c index 5f6a36b..1460668 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -6,11 +6,11 @@ #define _BSD_SOURCE 1 #define _DEFAULT_SOURCE 1 +#include "frontend.h" #include "jalv_config.h" #include "jalv_internal.h" #include "log.h" #include "state.h" -#include "ui.h" #include "lilv/lilv.h" #include "lv2/ui/ui.h" @@ -77,7 +77,7 @@ jalv_ui_port_event(Jalv* jalv, } int -jalv_init(int* argc, char*** argv, JalvOptions* opts) +jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts) { int n_controls = 0; int a = 1; @@ -146,7 +146,7 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts) } const char* -jalv_native_ui_type(void) +jalv_frontend_ui_type(void) { return NULL; } @@ -235,7 +235,7 @@ jalv_process_command(Jalv* jalv, const char* cmd) } bool -jalv_discover_ui(Jalv* jalv) +jalv_frontend_discover(Jalv* jalv) { return jalv->opts.show_ui; } @@ -247,7 +247,7 @@ jalv_run_custom_ui(Jalv* jalv) 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(), NULL); + jalv_ui_instantiate(jalv, jalv_frontend_ui_type(), NULL); idle_iface = (const LV2UI_Idle_Interface*)suil_instance_extension_data( jalv->ui_instance, LV2_UI__idleInterface); show_iface = (const LV2UI_Show_Interface*)suil_instance_extension_data( @@ -280,26 +280,26 @@ jalv_run_custom_ui(Jalv* jalv) } float -jalv_ui_refresh_rate(Jalv* ZIX_UNUSED(jalv)) +jalv_frontend_refresh_rate(Jalv* ZIX_UNUSED(jalv)) { return 30.0f; } float -jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv)) +jalv_frontend_scale_factor(Jalv* ZIX_UNUSED(jalv)) { return 1.0f; } LilvNode* -jalv_select_plugin(Jalv* jalv) +jalv_frontend_select_plugin(Jalv* jalv) { (void)jalv; return NULL; } int -jalv_open_ui(Jalv* jalv) +jalv_frontend_open(Jalv* jalv) { if (!jalv_run_custom_ui(jalv) && !jalv->opts.non_interactive) { // Primitive command prompt for setting control values @@ -323,7 +323,7 @@ jalv_open_ui(Jalv* jalv) } int -jalv_close_ui(Jalv* jalv) +jalv_frontend_close(Jalv* jalv) { zix_sem_post(&jalv->done); return 0; diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index 9ad443c..6c66b43 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -2,9 +2,9 @@ // SPDX-License-Identifier: ISC #include "control.h" +#include "frontend.h" #include "jalv_internal.h" #include "state.h" -#include "ui.h" #include "lilv/lilv.h" #include "lv2/atom/atom.h" @@ -93,7 +93,7 @@ on_window_destroy(GtkWidget* ZIX_UNUSED(widget), gpointer ZIX_UNUSED(data)) } int -jalv_init(int* argc, char*** argv, JalvOptions* opts) +jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts) { GOptionEntry entries[] = { {"load", @@ -219,7 +219,7 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts) } const char* -jalv_native_ui_type(void) +jalv_frontend_ui_type(void) { #if GTK_MAJOR_VERSION == 2 return "http://lv2plug.in/ns/extensions/ui#GtkUI"; @@ -1317,13 +1317,13 @@ build_menu(Jalv* jalv, GtkWidget* window, GtkWidget* vbox) } bool -jalv_discover_ui(Jalv* ZIX_UNUSED(jalv)) +jalv_frontend_discover(Jalv* ZIX_UNUSED(jalv)) { return TRUE; } float -jalv_ui_refresh_rate(Jalv* ZIX_UNUSED(jalv)) +jalv_frontend_refresh_rate(Jalv* ZIX_UNUSED(jalv)) { #if GTK_MAJOR_VERSION == 2 return 30.0f; @@ -1338,7 +1338,7 @@ jalv_ui_refresh_rate(Jalv* ZIX_UNUSED(jalv)) } float -jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv)) +jalv_frontend_scale_factor(Jalv* ZIX_UNUSED(jalv)) { #if GTK_MAJOR_VERSION == 2 return 1.0f; @@ -1364,7 +1364,7 @@ on_row_activated(GtkTreeView* const tree_view, } LilvNode* -jalv_select_plugin(Jalv* jalv) +jalv_frontend_select_plugin(Jalv* jalv) { // Create the dialog GtkWidget* const dialog = gtk_dialog_new_with_buttons("Plugin Selector", @@ -1466,7 +1466,7 @@ jalv_select_plugin(Jalv* jalv) } int -jalv_open_ui(Jalv* jalv) +jalv_frontend_open(Jalv* jalv) { GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); jalv->window = window; @@ -1490,7 +1490,7 @@ jalv_open_ui(Jalv* jalv) // Attempt to instantiate custom UI if necessary if (jalv->ui && !jalv->opts.generic_ui) { - jalv_ui_instantiate(jalv, jalv_native_ui_type(), alignment); + jalv_ui_instantiate(jalv, jalv_frontend_ui_type(), alignment); } jalv->features.request_value.request = on_request_value; @@ -1538,7 +1538,7 @@ jalv_open_ui(Jalv* jalv) } int -jalv_close_ui(Jalv* ZIX_UNUSED(jalv)) +jalv_frontend_close(Jalv* ZIX_UNUSED(jalv)) { gtk_main_quit(); return 0; diff --git a/src/jalv_internal.h b/src/jalv_internal.h index e6977db..800f88a 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -333,9 +333,6 @@ jalv_set_control(const ControlID* control, void jalv_init_ui(Jalv* jalv); -int -jalv_close_ui(Jalv* jalv); - void jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent); diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp index d9bfc57..2aae1b9 100644 --- a/src/jalv_qt.cpp +++ b/src/jalv_qt.cpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: ISC #include "jalv_qt.hpp" +#include "frontend.h" #include "jalv_internal.h" -#include "ui.h" #include "lilv/lilv.h" #include "suil/suil.h" @@ -275,7 +275,7 @@ FlowLayout::smartSpacing(QStyle::PixelMetric pm) const extern "C" { int -jalv_init(int* argc, char*** argv, JalvOptions*) +jalv_frontend_init(int* argc, char*** argv, JalvOptions*) { app = new QApplication(*argc, *argv, true); app->setStyleSheet("QGroupBox::title { subcontrol-position: top center }"); @@ -284,7 +284,7 @@ jalv_init(int* argc, char*** argv, JalvOptions*) } const char* -jalv_native_ui_type(void) +jalv_frontend_ui_type(void) { return "http://lv2plug.in/ns/extensions/ui#Qt5UI"; } @@ -623,31 +623,31 @@ build_control_widget(Jalv* jalv) } bool -jalv_discover_ui(Jalv*) +jalv_frontend_discover(Jalv*) { return true; } float -jalv_ui_refresh_rate(Jalv*) +jalv_frontend_refresh_rate(Jalv*) { return (float)QGuiApplication::primaryScreen()->refreshRate(); } float -jalv_ui_scale_factor(Jalv*) +jalv_frontend_scale_factor(Jalv*) { return (float)QGuiApplication::primaryScreen()->devicePixelRatio(); } LilvNode* -jalv_select_plugin(Jalv*) +jalv_frontend_select_plugin(Jalv*) { return nullptr; } int -jalv_open_ui(Jalv* jalv) +jalv_frontend_open(Jalv* jalv) { auto* const win = new QMainWindow(); QMenu* file_menu = win->menuBar()->addMenu("&File"); @@ -662,7 +662,7 @@ jalv_open_ui(Jalv* jalv) jalv_load_presets(jalv, add_preset_to_menu, presets_menu); if (jalv->ui && !jalv->opts.generic_ui) { - jalv_ui_instantiate(jalv, jalv_native_ui_type(), win); + jalv_ui_instantiate(jalv, jalv_frontend_ui_type(), win); } QWidget* widget = nullptr; @@ -706,7 +706,7 @@ jalv_open_ui(Jalv* jalv) } int -jalv_close_ui(Jalv*) +jalv_frontend_close(Jalv*) { app->quit(); return 0; diff --git a/src/ui.h b/src/ui.h deleted file mode 100644 index 7eddafa..0000000 --- a/src/ui.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2007-2022 David Robillard <d@drobilla.net> -// SPDX-License-Identifier: ISC - -#ifndef JALV_UI_H -#define JALV_UI_H - -#include "jalv_internal.h" - -#include "lilv/lilv.h" - -#include <stdbool.h> - -#ifdef __cplusplus -extern "C" { -#endif - -// Interface that must be implemented by UIs - -int -jalv_init(int* argc, char*** argv, JalvOptions* opts); - -const char* -jalv_native_ui_type(void); - -bool -jalv_discover_ui(Jalv* jalv); - -float -jalv_ui_refresh_rate(Jalv* jalv); - -float -jalv_ui_scale_factor(Jalv* jalv); - -int -jalv_open_ui(Jalv* jalv); - -LilvNode* -jalv_select_plugin(Jalv* jalv); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // JALV_UI_H |