From ea920d63439a97d9e1593dcf075ba0b2bd3f2b85 Mon Sep 17 00:00:00 2001 From: "Geoffrey D. Bennett" Date: Sun, 1 Oct 2023 00:05:26 +0930 Subject: [PATCH] Apply correction curve to the dials Display the volume levels on the dials with a correction curve that resembles what the volume knob on the hardware does. --- src/gtkdial.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gtkdial.c b/src/gtkdial.c index 21cd2e1..ce06515 100644 --- a/src/gtkdial.c +++ b/src/gtkdial.c @@ -141,7 +141,19 @@ static void dial_measure(GtkWidget *widget, static inline double calc_valp(double val, double mn, double mx) { - return (val - mn)/(mx-mn); + if (val <= mn) + return 0.0; + if (val >= mx) + return 1.0; + + // convert val from mn..mx to 0..1 + val = (val - mn)/(mx-mn); + + // 10^(val - 1) converts it to 0.1..1 with a nice curve + val = pow(10, val - 1); + + // convert to 0..1 again + return (val - 0.1) / 0.9; } static inline double calc_val(double valp, double mn, double mx)