Update of /cvsroot/audacity/audacity-src/src/effects/nyquist
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv10447/src/effects/nyquist

Modified Files:
        Nyquist.cpp 
Log Message:
Improve Nyquist effect input dialog to allow easier entry of exact numbers


Index: Nyquist.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/effects/nyquist/Nyquist.cpp,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- Nyquist.cpp 18 Sep 2009 08:18:49 -0000      1.84
+++ Nyquist.cpp 28 Oct 2009 23:27:20 -0000      1.85
@@ -1049,22 +1049,48 @@
       wxASSERT(slider && text);
       
       int val = slider->GetValue();
-      ctrl->val = (val / (double)ctrl->ticks)*
+
+      double newVal = (val / (double)ctrl->ticks)*
          (ctrl->high - ctrl->low) + ctrl->low;
-      
+
+      // Determine precision for displayed number
+      int precision = ctrl->high - ctrl->low < 1 ? 3 :
+                      ctrl->high - ctrl->low < 10 ? 2 :
+                      ctrl->high - ctrl->low < 100 ? 1 :
+                      0;
+
+      // If the value is at least one tick different from the current value
+      // change it (this prevents changes from manually entered values unless
+      // the slider actually moved)
+      if (fabs(newVal - ctrl->val) >= (1 / (double)ctrl->ticks) *
+                                      (ctrl->high - ctrl->low) && 
+          fabs(newVal - ctrl->val) >= pow(0.1, precision) / 2 )
+      {
+         // First round to the appropriate precision
+         newVal *= pow(10.0, precision);
+         newVal = floor(newVal + 0.5);
+         newVal /= pow(10.0, precision);
+
+         ctrl->val = newVal;
+      }
+
       wxString valStr;
       if (ctrl->type == NYQ_CTRL_REAL) {
-         if (ctrl->high - ctrl->low < 1) {
-            valStr = Internat::ToDisplayString(ctrl->val, 3);
-         }
-         else if (ctrl->high - ctrl->low < 10) {
-            valStr = Internat::ToDisplayString(ctrl->val, 2);
-         }
-         else if (ctrl->high - ctrl->low < 100) {
-            valStr = Internat::ToDisplayString(ctrl->val, 1);
+         // If this is a user-typed value, allow unlimited precision
+         if (ctrl->val != newVal)
+         {
+            valStr = Internat::ToDisplayString(ctrl->val);
          }
-         else {
-            valStr.Printf(wxT("%d"), (int)floor(ctrl->val + 0.5));
+         else
+         {
+            if (precision == 0)
+            {
+               valStr.Printf(wxT("%d"), (int)floor(ctrl->val + 0.5));
+            }
+            else
+            {
+               valStr = Internat::ToDisplayString(ctrl->val, precision);
+            }
          }
       }
       else if (ctrl->type == NYQ_CTRL_INT) {


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Audacity-cvs mailing list
Audacity-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to