ControlP5: linking sliders
in
Contributed Library Questions
•
6 months ago
Hi there!
In ControlP5 I want to link two sliders. That is, when I move the slider A, the slider B moves too. And when I move the slider B, the slider A moves too. They must have the always the same value.
The sliders are inside a class. I was not sure about the following code (maybe it creates a loop), but it seems that it works correctly:
In ControlP5 I want to link two sliders. That is, when I move the slider A, the slider B moves too. And when I move the slider B, the slider A moves too. They must have the always the same value.
The sliders are inside a class. I was not sure about the following code (maybe it creates a loop), but it seems that it works correctly:
- import controlP5.*;
ControlP5 cp5;
ControlA ctrlA;
ControlB ctrlB;
void setup() {
size(300, 300);
cp5 = new ControlP5(this);
ctrlA = new ControlA();
ctrlB = new ControlB();
}
void draw() {
}
class ControlA {
ControlA() {
cp5.addSlider("SliderA", 0, 1, 0, 10, 10, 50, 10);
}
}
class ControlB {
ControlB() {
cp5.addSlider("SliderB", 0, 1, 0, 10, 30, 50, 10);
}
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom("SliderA")) {
cp5.get(Slider.class, "SliderB").setValue(theEvent.getValue());
}
if (theEvent.isFrom("SliderB")) {
cp5.get(Slider.class, "SliderA").setValue(theEvent.getValue());
}
}
But if I add, for example,
inside a slider construction, then it makes an error message... but it still works correctly. It seems that now it makes a loop.
d.
- .setNumberOfTickMarks(0)
inside a slider construction, then it makes an error message... but it still works correctly. It seems that now it makes a loop.
- class ControlA {
ControlA() {
cp5.addSlider("SliderA", 0, 1, 0, 10, 10, 50, 10)
.setNumberOfTickMarks(0);
}
}
Any idea for solving that problem?
d.
1