[SCM] calf/master: + GUI: try harder at rounding parameter values properly

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:37:10 UTC 2013


The following commit has been merged in the master branch:
commit a5d009137f70875068041b52847c567e0502d51a
Author: kfoltman <kfoltman at 78b06b96-2940-0410-b7fc-879d825d01d8>
Date:   Wed Apr 30 19:21:34 2008 +0000

    + GUI: try harder at rounding parameter values properly
    
    
    
    git-svn-id: https://calf.svn.sourceforge.net/svnroot/calf/trunk@164 78b06b96-2940-0410-b7fc-879d825d01d8

diff --git a/src/calf/giface.h b/src/calf/giface.h
index eefc55b..5598af8 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -98,8 +98,8 @@ struct parameter_properties
     uint32_t flags;
     const char **choices;
     const char *short_name, *name;
-    float from_01(float value01) const;
-    float to_01(float value) const;
+    float from_01(double value01) const;
+    double to_01(float value) const;
     std::string to_string(float value) const;
     int get_char_count() const;
     float get_increment() const;
diff --git a/src/custom_ctl.cpp b/src/custom_ctl.cpp
index ce36d07..10b14af 100644
--- a/src/custom_ctl.cpp
+++ b/src/custom_ctl.cpp
@@ -376,9 +376,7 @@ calf_knob_incr (GtkWidget *widget, int dir_down)
         step = oldstep + 1;
     
     // trying to reduce error cumulation here, by counting from lowest or from highest
-    float value = adj->lower + step * adj->step_increment;
-    if (step >= nsteps / 2)
-        value = adj->upper - (nsteps - step) * adj->step_increment;
+    float value = adj->lower + step * (adj->upper - adj->lower) / nsteps;
     gtk_range_set_value(GTK_RANGE(widget), value);
     // printf("step %d:%d nsteps %d value %f:%f\n", oldstep, step, nsteps, oldvalue, value);
 }
diff --git a/src/giface.cpp b/src/giface.cpp
index 928d6d3..2182b7d 100644
--- a/src/giface.cpp
+++ b/src/giface.cpp
@@ -44,9 +44,9 @@ static string f2s(double value)
     return buf;
 }
 
-float parameter_properties::from_01(float value01) const
+float parameter_properties::from_01(double value01) const
 {
-    float value = dsp::clip(value01, 0.f, 1.f);
+    double value = dsp::clip(value01, 0., 1.);
     switch(flags & PF_SCALEMASK)
     {
     case PF_SCALE_DEFAULT:
@@ -59,14 +59,14 @@ float parameter_properties::from_01(float value01) const
         value = min + (max - min) * value01 * value01;
         break;
     case PF_SCALE_LOG:
-        value = min * pow(max / min, value01);
+        value = min * pow(double(max / min), value01);
         break;
     case PF_SCALE_GAIN:
         if (value01 < 0.00001)
             value = min;
         else {
             float rmin = std::max(1.0f / 1024.0f, min);
-            value = rmin * pow(max / rmin, value01);
+            value = rmin * pow(double(max / rmin), value01);
         }
         break;
     }
@@ -85,7 +85,7 @@ float parameter_properties::from_01(float value01) const
     return value;
 }
 
-float parameter_properties::to_01(float value) const
+double parameter_properties::to_01(float value) const
 {
     switch(flags & PF_SCALEMASK)
     {
@@ -93,18 +93,18 @@ float parameter_properties::to_01(float value) const
     case PF_SCALE_LINEAR:
     case PF_SCALE_PERC:
     default:
-        return (value - min) / (max - min);
+        return double(value - min) / (max - min);
     case PF_SCALE_QUAD:
-        return sqrt((value - min) / (max - min));
+        return sqrt(double(value - min) / (max - min));
     case PF_SCALE_LOG:
         value /= min;
-        return log(value) / log(max / min);
+        return log((double)value) / log((double)max / min);
     case PF_SCALE_GAIN:
         if (value < 1.0 / 1024.0) // new bottom limit - 60 dB
             return 0;
-        float rmin = std::max(1.0f / 1024.0f, min);
+        double rmin = std::max(1.0f / 1024.0f, min);
         value /= rmin;
-        return log(value) / log(max / rmin);
+        return log((double)value) / log(max / rmin);
     }
 }
 

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list