g4p library, slider problem

edited February 2018 in Library Questions

Hello,

I have a slight problem with a slider.

sliderR.setValue(1.0) //input: float
println(sliderR.getValueF()); //returns 0.0

I do not understand why it doesn't return "1.0";

thank you very much

Answers

  • What are the slider limits (min & max)?

  • sliderR.setLimits(0, 0 , 1);

  • I will test it tomorrow and get back to you.

  • thank you for your time ! I appreciate !

  • Answer ✓

    @quark

    I tried this example. I noticed that the correct value is not displayed right away but only after at least one draw cycle goes through. In the example below, just press any key to update the value of the slider.

    Kf

    import g4p_controls.*;
    
    GCustomSlider slider; 
    
    void setup() {
      size(500, 200);
      slider = new GCustomSlider(this, 50, 50, 400, 100, "metallic");
      slider.setShowValue(true);
      slider.setShowLimits(true);
      slider.setLimits(38, 0, 100);
      slider.setNbrTicks(11);
      slider.setShowTicks(true);
      slider.setEasing(6.0);
      slider.setNumberFormat(G4P.INTEGER, 0);
      slider.setOpaque(true);
    }
    
    void draw() {
      background(200, 200, 220);
    }
    
    void keyPressed(){
      slider.setValue(random(5,95));  //slider.setValue(50);
      println(slider.getValueS());
    }
    
  • Answer ✓

    I noticed that the correct value is not displayed right away but only after at least one draw cycle goes through

    @kfrajer very well spotted :) and is true for both sliders and knobs because they use easing.

    Both sliders and knobs have two values, actual value the currently displayed value in the GUI and target value the value we want it to be. When you use the statement

    sliderR.setValue(1.0);

    you are setting the target value NOT the actual value. Before each frame the the actual value is adjusted towards to target value depending on the amount of easing. If easing is 0 (zero) then the actual value is set equal to the target value so takes 1 frame. If easing > 0 then it will take several frames to before the actual value becomes equal to the target value thus smoothing the movement of the slider's thumb.

  • Alright, thank you guys !

Sign In or Register to comment.