Loading...
Logo
Processing Forum

Hi,

I've been the whole day struggling with some weird numbers in my application, and after checking absolutely everything I finally found that the problem was not in my calculations, but in how the RangeSlider from ControlP5 was actually showing them... the good thing is that I actually cleaned the code.


I'm attaching a sample code, just a simplified version of the library example, adding three range sliders.

The issue shows when trying to set the value in the slider (you can hide decimals, but actually that they explains a lot)


This is the results you get if you run the code below:

Slider from 0-40000 set as 100-35000 shows 0.00-34947.36

Slider from 0-4000 set as 100-3500 shows 94.73-3494.73

Slider from 0-400 set as 100-350 shows 100.00-349.47


It seems clearly a problem in how is internally dealing with the decimals.

The only way you get the precise result you are asking, is if your slider is from 0-100. Anything bigger than that will be adjusted sliding the decimal period (multiplying by 10, 100, 1000… etc) resulting in an every time more inaccurate output.


I tried to send the values as floats, but it actually doesn't change anything.

I can imagine a workaround using sliders under 100 and then scaling them myself to the right value (avoiding the float issue)... but as you can imagine that would be quite nasty in terms of keeping the code as simple as it needs.


Do you have any simpler solution for this? Otherwise I just prefer to remove the GUI.

I'd much appreciate the help.



//// EXAMPLE CODE TO SHOW THE ISSUE

Copy code

import controlP5.*;

ControlP5 cp5;

Range rangeL;

Range rangeS;

Range range;


void setup() {

 size(700, 400);


 cp5 = new ControlP5(this);

 rangeL = cp5.addRange("Range 10K")

   //.setDecimalPrecision(0)

       .setPosition(50, 50)

         .setSize(400, 10)

             .setRange(0, 40000)

               .setRangeValues(100, 35000)

                   ;


 rangeS = cp5.addRange("Range K")

   //.setDecimalPrecision(0)

       .setPosition(50, 100)

         .setSize(400, 10)

             .setRange(0, 4000)

               .setRangeValues(100, 3500)

                   ;


 range = cp5.addRange("Range")  

   //.setDecimalPrecision(0)

       .setPosition(50, 150)

         .setSize(400, 10)

             .setRange(0, 400)

               .setRangeValues(100, 350)

                   ;

}


void draw() {

 background(0);

}

Replies(3)

I have moved this to Contributed Library forum - more likely get a response here since controlP5 is a contributed library.

So far I didn't found how to solve this, and sadly I also didn't get response from the developer, but in the meantime I found a few more issues that makes the library quite hard to use.

I was trying the general sliders, and they work great even when you set them up for values over few thousands... the annoying thing is that when you use 'ticks', the progression in the slider works perfectly, but the visual marks under it won't be not placed in the right place. It will depend of how many you want and how long is the slider... again seems a decimal precision issue... so although the slider will be working as expected, the marks will end before reaching the end of the slider.

Don't misunderstand me, I'm grateful for the library, the guy put a lot of time and effort to make it, but pointing this stuff hopefully will make some people won't loose time (as I did) looking what is wrong in their code, when actually is a library issue.
Hi, I need to make changes to the Range and Slider controller could you file an issue here  code.google.com/p/controlp5/issues/list and I will follow up as soon as I find some spare time. 

andreas schlegel, http://www.sojamo.de