[LV2] [PATCH] add UI scale factor option
Alexandros Theodotou
alex at zrythm.org
Fri Feb 12 03:07:58 PST 2021
Add support for scaleFactor added in LV2 0.18.0.
---
src/jalv.c | 12 ++++++++++++
src/jalv_console.c | 6 ++++++
src/jalv_gtk.c | 15 +++++++++++++++
src/jalv_gtkmm2.cpp | 6 ++++++
src/jalv_internal.h | 8 +++++++-
src/jalv_qt.cpp | 10 ++++++++++
wscript | 2 +-
7 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/src/jalv.c b/src/jalv.c
index 25a49c3..91e32e9 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -887,6 +887,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->urids.time_beatsPerMinute = symap_map(jalv->symap, LV2_TIME__beatsPerMinute);
jalv->urids.time_frame = symap_map(jalv->symap, LV2_TIME__frame);
jalv->urids.time_speed = symap_map(jalv->symap, LV2_TIME__speed);
+ jalv->urids.ui_scaleFactor = symap_map(jalv->symap, LV2_UI__scaleFactor);
jalv->urids.ui_updateRate = symap_map(jalv->symap, LV2_UI__updateRate);
#ifdef _WIN32
@@ -1105,11 +1106,20 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
jalv->ui_update_hz = MAX(1.0f, jalv->ui_update_hz);
}
+ if (jalv->opts.scale_factor == 0.0) {
+ /* calculate the monitor's scale factor. */
+ jalv->ui_scale_factor = jalv_ui_scale_factor(jalv);
+ } else {
+ /* Use user-specified UI scale factor. */
+ jalv->ui_scale_factor = jalv->opts.scale_factor;
+ }
+
/* The UI can only go so fast, clamp to reasonable limits */
jalv->ui_update_hz = MIN(60, jalv->ui_update_hz);
jalv->opts.buffer_size = MAX(4096, jalv->opts.buffer_size);
fprintf(stderr, "Comm buffers: %u bytes\n", jalv->opts.buffer_size);
fprintf(stderr, "Update rate: %.01f Hz\n", jalv->ui_update_hz);
+ fprintf(stderr, "Scale factor: %.01f\n", jalv->ui_scale_factor);
/* Build options array to pass to plugin */
const LV2_Options_Option options[ARRAY_SIZE(jalv->features.options)] = {
@@ -1123,6 +1133,8 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv)
sizeof(int32_t), jalv->urids.atom_Int, &jalv->midi_buf_size },
{ LV2_OPTIONS_INSTANCE, 0, jalv->urids.ui_updateRate,
sizeof(float), jalv->urids.atom_Float, &jalv->ui_update_hz },
+ { LV2_OPTIONS_INSTANCE, 0, jalv->urids.ui_scaleFactor,
+ sizeof(float), jalv->urids.atom_Float, &jalv->ui_scale_factor },
{ LV2_OPTIONS_INSTANCE, 0, 0, 0, 0, NULL }
};
memcpy(jalv->features.options, options, sizeof(jalv->features.options));
diff --git a/src/jalv_console.c b/src/jalv_console.c
index ccfe916..a08f08a 100644
--- a/src/jalv_console.c
+++ b/src/jalv_console.c
@@ -266,6 +266,12 @@ jalv_ui_refresh_rate(Jalv* ZIX_UNUSED(jalv))
return 30.0f;
}
+float
+jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv))
+{
+ return 1.0f;
+}
+
int
jalv_open_ui(Jalv* jalv)
{
diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c
index 3403146..2e32c98 100644
--- a/src/jalv_gtk.c
+++ b/src/jalv_gtk.c
@@ -127,6 +127,8 @@ jalv_init(int* argc, char*** argv, JalvOptions* opts)
"Buffer size for plugin <=> UI communication", "SIZE"},
{ "update-frequency", 'r', 0, G_OPTION_ARG_DOUBLE, &opts->update_rate,
"UI update frequency", NULL},
+ { "scale-factor", 0, 0, G_OPTION_ARG_DOUBLE, &opts->scale_factor,
+ "UI scale factor", NULL},
{ "control", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &opts->controls,
"Set control value (e.g. \"vol=1.4\")", NULL},
{ "print-controls", 'p', 0, G_OPTION_ARG_NONE, &opts->print_controls,
@@ -1222,6 +1224,19 @@ jalv_ui_refresh_rate(Jalv* ZIX_UNUSED(jalv))
#endif
}
+float
+jalv_ui_scale_factor(Jalv* ZIX_UNUSED(jalv))
+{
+#if GTK_MAJOR_VERSION == 2
+ return 1.0f;
+#else
+ GdkDisplay* const display = gdk_display_get_default();
+ GdkMonitor* const monitor = gdk_display_get_primary_monitor(display);
+
+ return (float)gdk_monitor_get_scale_factor(monitor);
+#endif
+}
+
int
jalv_open_ui(Jalv* jalv)
{
diff --git a/src/jalv_gtkmm2.cpp b/src/jalv_gtkmm2.cpp
index 9d88cd7..7c4c594 100644
--- a/src/jalv_gtkmm2.cpp
+++ b/src/jalv_gtkmm2.cpp
@@ -71,6 +71,12 @@ jalv_ui_refresh_rate(Jalv*)
return 30.0f;
}
+float
+jalv_ui_scale_factor(Jalv*)
+{
+ return 1.0f;
+}
+
int
jalv_open_ui(Jalv* jalv)
{
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 40b22bd..e14dab6 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -180,6 +180,7 @@ typedef struct {
char** controls; ///< Control values
uint32_t buffer_size; ///< Plugin <= >UI communication buffer size
double update_rate; ///< UI update rate in Hz
+ double scale_factor; ///< UI scale factor
int dump; ///< Dump communication iff true
int trace; ///< Print trace log iff true
int generic_ui; ///< Use generic UI iff true
@@ -220,6 +221,7 @@ typedef struct {
LV2_URID time_beatsPerMinute;
LV2_URID time_frame;
LV2_URID time_speed;
+ LV2_URID ui_scaleFactor;
LV2_URID ui_updateRate;
} JalvURIDs;
@@ -292,7 +294,7 @@ typedef struct {
LV2_Feature state_sched_feature;
LV2_Log_Log llog;
LV2_Feature log_feature;
- LV2_Options_Option options[6];
+ LV2_Options_Option options[7];
LV2_Feature options_feature;
LV2_Feature safe_restore_feature;
LV2UI_Request_Value request_value;
@@ -345,6 +347,7 @@ struct Jalv {
uint32_t num_ports; ///< Size of the two following arrays:
uint32_t plugin_latency; ///< Latency reported by plugin (if any)
float ui_update_hz; ///< Frequency of UI updates
+ float ui_scale_factor; ///< UI scale factor
float sample_rate; ///< Sample rate
uint32_t event_delta_t; ///< Frames since last update sent to UI
uint32_t position; ///< Transport position in frames
@@ -414,6 +417,9 @@ 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);
diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp
index 165ac50..a52c1ca 100644
--- a/src/jalv_qt.cpp
+++ b/src/jalv_qt.cpp
@@ -724,6 +724,16 @@ jalv_ui_refresh_rate(Jalv*)
#endif
}
+float
+jalv_ui_scale_factor(Jalv*)
+{
+#if QT_VERSION >= 0x050000
+ return (float)QGuiApplication::primaryScreen()->devicePixelRatio();
+#else
+ return 1.0f;
+#endif
+}
+
int
jalv_open_ui(Jalv* jalv)
{
diff --git a/wscript b/wscript
index ad062c8..6fd5505 100644
--- a/wscript
+++ b/wscript
@@ -111,7 +111,7 @@ def configure(conf):
],
})
- conf.check_pkg('lv2 >= 1.17.2', uselib_store='LV2')
+ conf.check_pkg('lv2 >= 1.18.0', 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')
--
2.30.0
More information about the Devel
mailing list