We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › controlP5 group event
Page Index Toggle Pages: 1
controlP5 group event (Read 635 times)
controlP5 group event
Dec 8th, 2008, 6:47am
 
hi,
i started using the controlp5 library and it helps me a lot - great work. i tried to get an event from a control group by opening/closing it, but it does not work. do theese elements generate any event, when the state is changed?

thanks,
stefan
Re: controlP5 group event
Reply #1 - Dec 9th, 2008, 3:53am
 
this is implemented now (0.3.6). when opening/closing a group, an event is sent to the controlEvent method. in order to receive events with controlEvent, the event has to be activated in the group, see example:

Quote:
import controlP5.*;

ControlP5 controlP5;

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

 controlP5 = new ControlP5(this);
 ControlGroup l = controlP5.addGroup("myGroup",100,200);
 // in order to receive events with controlEvent,
 // the event has to be activated in the group.
 // use:
 l.activateEvent(true);
 
 controlP5.addBang("A-1",0,4,20,20).setGroup(l);
 controlP5.addBang("A-2",30,4,20,20).setGroup(l);  
 
}

void draw() {
 background(0);
}


void controlEvent(ControlEvent theEvent) {
 if(theEvent.isGroup()) {
   println("got an event from group "+theEvent.group().name()+", isOpen? "+theEvent.group().isOpen());  
 } else if (theEvent.isController()){
   println("got something from a controller "+theEvent.controller().name());
 }
}
Re: controlP5 group event
Reply #2 - Dec 9th, 2008, 5:46am
 
thanks a lot. great work.

just another question concerning controlP5. i use many different controls for similar things and store the controller handlers in two arrays:

 // P5groupAdc
 ControlGroup P5groupAdc = controlP5.addGroup("Analog Input",20,200, 300);
 for (int i = 0; i < 8; i++) {
   P5groupAdcID[i][0] = controlP5.addToggle("channelOnOff" + i, true, 5, 15*i + 5 + 15, 10, 10);
   P5groupAdcID[i][0].setGroup(P5groupAdc);
   P5groupAdcID[i][0].setLabel("");

   P5groupAdcID[i][1] = controlP5.addSlider("channelThreshold" + i, 0, 4095, 1000, 20, 15*i + 5 + 15, 155, 10);
   P5groupAdcID[i][1].setGroup(P5groupAdc);
   P5groupAdcID[i][1].setLabelVisible(false);

   P5groupAdcID[i][2] = controlP5.addTextlabel("channelText" + i,""+i, 8, 15*i + 7 + 15);
   P5groupAdcID[i][2].setGroup(P5groupAdc);  

   P5groupAdcID[i][3] = controlP5.addSlider("channelColor" + i, 0, 100, 12*i + 6, 180, 15*i + 5 + 15, 80, 10);
   P5groupAdcID[i][3].setGroup(P5groupAdc);                          // set group
   P5groupAdcID[i][3].setLabelVisible(false);                        // label off
   
   P5groupAdcIDtxt[i] = controlP5.addTextlabel("channelThresLabel" + i,"       ", 25, 15*i + 7 + 15);
   P5groupAdcIDtxt[i].setGroup(P5groupAdc);
 }


in order to change the label of the textlabel during runtime and change the other controllers as well, i declared two arrays:

Controller P5groupAdcID[][] = new Controller[8][4];
Textlabel P5groupAdcIDtxt[] = new Textlabel[8];

is there a possibilty to overcome this and store all controller handlers in one array?


Re: controlP5 group event
Reply #3 - Dec 9th, 2008, 6:43am
 
yes. Textlabel extends Controller, therefore it is fairly easy to go with one array, just add the Textlabel to your P5groupAdcID array as 5th element.
Re: controlP5 group event
Reply #4 - Jan 25th, 2009, 4:24am
 
this is quite useful to see how to make an array of controls.  but how do you define an array of functions?  

Code:

int numControls = 10;
for (int i=0; i<numControls; i++) {
controlP5.addSlider("slider"+i, 0,100, x[i], 10, i*30, 100,15);
}
// ...

// how do you avoid this? not to mention, you don't know value of numControls...

void slider0(int _x) {
x[0] = _x;
}
void slider1(int _x) {
x[1] = _x;
}
void slider2(int _x) {
x[2] = _x;
}
// ...
Page Index Toggle Pages: 1