How to set values of a GUI element in Guido?

edited February 2015 in Library Questions

Hey,

I try to synchronize incoming OSC with the GUI of Guido to be able to use both to modify my sketch parameters. Unfortunately there is no documentation yet and no example for doing this.

So for a start I simply wanted to figure out how to set values of a slider using the mouse. This is my attempt modifying the slider example of the library by adding a set() method to the Slider class:

/**
 *    A slider
 *
 *    .. works with JavaScript mode since Processing 2.0a5
 */

import de.bezier.guido.*;

Slider slider;

void setup ()
{
    size(400, 400);

    // make the manager

    Interactive.make( this );

    // create a slider

    slider = new Slider( 2, 2, width-4, 16 );
}

void draw ()
{
    background( 0 );

    fill( 255 - (slider.value * 255) );
    ellipse( width/2, height/2, 150, 150 );
    fill( slider.value * 255 );
    ellipse( width/2, height/2, 70, 70 );
    slider.set((float)mouseX);
}

public class Slider
{
    float x, y, width, height;
    public float valueX = 0, value;

    Slider ( float xx, float yy, float ww, float hh ) 
    {
        x = xx; 
        y = yy; 
        width = ww; 
        height = hh;

        valueX = x;

        // register it
        Interactive.add( this );
    }

    // called from manager
    void mouseDragged ( float mx, float my )
    {
        valueX = mx - height/2;

        if ( valueX < x ) valueX = x;
        if ( valueX > x+width-height ) valueX = x+width-height;

        value = map( valueX, x, x+width-height, 0, 1 );
    }

    void draw () 
    {
        noStroke();

        fill( 100 );
        rect(x, y, width, height);

        fill( 120 );
        rect( valueX, y, height, height );
    }

    void set (float _value) {
        Interactive.set(this,"value",_value);
    }
}

But I only get Interactive.set() ... unable to find a field with that name in given target. How can I fix this?

Thanks a lot!

Answers

  • I don't know well Guido, so I wonder: why do you use Interactive.set() instead of setting the value directly to the value variable?
    You might need to adjust the value of valueX in this setter as well.

  • Thanks PhiLho!

    Well, I hoped this was something the library would take care of for me and provide such functionality. At least ControlP5 does it.

    If there is no super easy solution as I expected, I'll just go without a GUI in my sketch right now. In case I extend the code in that way later, I can post it here.

  • edited February 2015

    Well, again, isn't just

    void set (float _value) {
        value = _value;
    }
    

    working for you? I am not sure what you try to achieve.
    Perhaps you want valueX = _value; actually, since value is overwritten / computed.

Sign In or Register to comment.