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.load(theFileName);
Page Index Toggle Pages: 1
controlP5.load(theFileName); (Read 782 times)
controlP5.load(theFileName);
Jun 8th, 2008, 6:50am
 
Hi,

I'm building an GUI using ControlP5, and I'm encountering some difficulties with the 'load' method.

Does the controlP5 setup loaded from a file go through the 'controlEvent' method ?

I'm using the method 'controlEvent' to send OSC messages. When I load a setup XML file the values/state of all the Controllers need to be sent via OSC.
Can It be done ?

Thanks.
Re: controlP5.load(theFileName);
Reply #1 - Jun 8th, 2008, 9:05am
 
hi,
with
Code:

controlP5.setAutoInitialization(true);

you can instruct controllers to update (call controlEvent) immediately after they have been created. same goes for loading a setup. i updated to 0.2.10 which can be downloaded from the website, the update fixes an issue with detecting the id of a controller when loaded. see the ControlP5load example for details.

best,
andi
Re: controlP5.load(theFileName);
Reply #2 - Jun 8th, 2008, 4:23pm
 
Hi Andi,

Thanks for the reply and update.

The download link doesn't seem to work.

Best,

Hugues
Re: controlP5.load(theFileName);
Reply #3 - Jun 8th, 2008, 4:31pm
 
fixed.
Re: controlP5.load(theFileName);
Reply #4 - Jun 8th, 2008, 5:42pm
 
Half of my problem is fixed with :

Code:

controlP5.setAutoInitialization(true);


but I still have a problem with the ScrollList and Groups.
I'm using a Scrolllist in order to access/show Groups. Everything works fine until I load a setup file.

When a setup file is loaded, the GUI is set to the loaded configuration, but I'm not anymore able to show/hide Groups using the ScrollList.

Here is an example of what I'm doing.

Code:

import controlP5.*;

ControlP5 controlP5;
ControlGroup groups[];

void setup() {
size(400,400);
frameRate(30);
controlP5 = new ControlP5(this);
controlP5.setAutoInitialization(true);

ScrollList l = controlP5.addScrollList("myList",10,10,120,280);

l.setLabel("something else");
for(int i=0;i<5;i++) {
controlP5.Button b = l.addItem("a"+i,i);
b.setId(100 + i);
}

groups = new ControlGroup[5];

for(int i=0;i<5;i++) {
groups[i] = controlP5.addGroup(i+"_gp",210,10+(50*i));
groups[i].hide();
groups[i].setMoveable(false);
}

}

void controlEvent(ControlEvent theEvent) {
println(theEvent.controller().id()+" / "+
theEvent.controller()+" / "+
theEvent.controller().value()
);

int controllerID = theEvent.controller().id();

if (controllerID > 99 && controllerID < 200 ) {
for(int i=0;i<5;i++) {
ControlGroup gp = (ControlGroup)groups[i];
gp.hide();
}
}

ControlGroup gp = (ControlGroup)groups[controllerID-100];
gp.show();
}


void draw() {
background(0);
}

void keyPressed() {
if(key=='s') {
controlP5.save("controlP5.xml");
} else if (key=='l') {
controlP5.load("controlP5.xml");
}
}




Use the ScrollList to display a specific group. Save the state by pressing 's'. Relaunch the applet or play with it, and then load the saved setup file. The saved stated will be activated. But it is not possbile to display other groups, even if the scroollist is firing events.

What am I missing ?

Thanks,
Re: controlP5.load(theFileName);
Reply #5 - Jun 8th, 2008, 9:39pm
 
hi,
when you load a setup, all controller and group references that have been made before are obsolete, so is the group array in setup. hence, for (ControlGroup)groups[i] in controlEvent there is no reference to a dedicated group anymore. the xml file that saves the setup does not save the reference of a controller or group, a better strategy would be to call controllers and groups by name. see the code below to work around it. hope this helps.



Quote:


import controlP5.*;

ControlP5 controlP5;
ControlGroup groups[];

void setup() {
 size(400,400);
 frameRate(30);
 controlP5 = new ControlP5(this);
 controlP5.setAutoInitialization(true);

 ScrollList l = controlP5.addScrollList("myList",10,10,120,280);

 l.setLabel("something else");
 for(int i=0;i<5;i++) {
   controlP5.Button b = l.addItem("a"+i,i);
   b.setId(100 + i);
 }

 groups = new ControlGroup[5];

 for(int i=0;i<5;i++) {
   groups[i] = controlP5.addGroup(i+"_gp",210,10+(50*i));
   groups[i].hide();
   groups[i].setMoveable(false);
 }

}

void controlEvent(ControlEvent theEvent) {
 println(theEvent.controller().id()+"  /  "+
   theEvent.controller()+"  /  "+
   theEvent.controller().value()
   );

 int controllerID = theEvent.controller().id();  

 if (controllerID > 99 && controllerID < 200 ) {
   for(int i=0;i<5;i++) {
     controlP5.group(i+"_gp").hide();
   }
   controlP5.group((controllerID-100)+"_gp").show();
 }
}


void draw() {
 background(0);
}

void keyPressed() {
 if(key=='s') {
   controlP5.save("controlP5.xml");
 }
 else if (key=='l') {
   controlP5.load("controlP5.xml");
   for(int i=0;i<5;i++) {
     controlP5.group(i+"_gp").hide();
   }
 }
}


Re: controlP5.load(theFileName);
Reply #6 - Jun 10th, 2008, 4:18am
 
Hi,

Thanks.
I'm ashamed of that one Smiley

best.

Hugues.
Page Index Toggle Pages: 1