Nice! Yes the last thing you added helped me get to exactly what I wanted. Here is the code that demonstrates exactly what I'm trying to do:
Code:
import java.lang.*;
import java.lang.reflect.*;
class Foo{
public float data; //MUST BE PUBLIC
Foo(){ data=1.001;}
}
Foo f=new Foo();
public float data=100.1; //MUST BE PUBLIC
void setup(){
size(200,200,P3D);
}
void draw(){
noLoop();
println(data+" , "+f.data);
setField(this, "data", PI);
setField(f, "data", PI);
println(data+" , "+f.data);
}
public static void setField(Object o, String fieldName, float val){
Field anyField;
Class theClass=o.getClass();
try{
anyField = theClass.getField(fieldName); //We hope
anyField.setFloat(o,val);
}
catch (Exception e){
e.printStackTrace();
}
}
With this method, I can consolidate my code by hundreds of lines. I can define a class like this:
Code:
class ParameterInfo{
//vars here
ParameterInfo(description, variableName, keyBoard, lowerLimit, upperLimit, incrementAmt, midiCC, includeInSave){
...
}
tmp=new ParameterInfo("any program variable", "var", 'x', 0, 1, .1, 33, false);
So I can use an array of these ParameterInfo objects for everything: keybd input, midi input, saving patches, generating on-screen key reference. Or to randomize all parameters, I can just loop thru all ParameterInfo objects, setting their target field to a random value in their lower/upper range. Etc..
And I only have to change values in 1 place to update the system.
thanks!