OSC code question
I am using TouchOSC to control a multiple LED light.
Thus I created a TouchOSC Layout with 4 pages, each containing 5 faders.
The faders are named fader0....fader4 on each page.
I am already able to control my arduino with the fist page using following code.
It sends 7 bytes to my arduino via serial:
1) a or b (button that switches control on or off
2) c,d,e or f => these should tell my arduino on which page I am
3) fader 0 to fader 4 (0-255)
-
import oscP5.*;
import netP5.*;
import processing.serial.*;
Serial myPort;
OscP5 oscP5;
int [] fader = new int [5];
float button0;
int [] out = new int [5];
int [] menu = new int [5];
void setup() {
oscP5 = new OscP5(this,8000);
myPort = new Serial(this, "COM13", 19200); }
void oscEvent(OscMessage theOscMessage) {
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();
if(addr.equals("/1/button0")) {
button0 = val;
}
if(addr.indexOf("/1/fader") !=-1){
String list[] = split(addr,'/');
int i = int(list[2].charAt(5) - 0x30);
fader[i] = (int) val;
}
}
void draw() {
while (button0==1) {
for (int i=0; i<5; i++) {
if (fader[i] != out[i]) {
out[i] = (int) (fader[i]);
myPort.write('a');
myPort.write('d');
for (int j=0; j<5; j++) {
myPort.write(out[j]);
println(out[j]);
}
}
}
}
}
My question is: How do I have to change my "void oscEvent(OscMessage theOscMessage)", to split the adress names, so that page-number is dynamic?
if(addr.indexOf("/1/fader") !=-1){
String list[] = split(addr,'/');
int i = int(list[2].charAt(5) - 0x30);
fader[i] = (int) val;
}
=> /1/fader/ should also become /2/fader, /3/fader and /4/fader. Of course I could create this part four times but I was thinking of some better solution by splitting this value. Any idea?Thx