Can I send back Slider Values from Processing to Touch OSC?
in
Integration and Hardware
•
7 months ago
Hi,
is it possible that if I change a slider on Page1 and send the value to Processing, that processing sends this value back to Touch OSC, e.g. if I switch to page two with a slider? TO be more clearly:
If I change "/1/fader1" it should also change "/2/fader1"
I attached you my code so you see what I do. The code worx so far, I just added the "synch" void which synchs all fader values in Processing (not compiled yet). However, it would be much better if the values would also be received by my iOS application.
Hope someone can help
Best//
Thorsten
is it possible that if I change a slider on Page1 and send the value to Processing, that processing sends this value back to Touch OSC, e.g. if I switch to page two with a slider? TO be more clearly:
If I change "/1/fader1" it should also change "/2/fader1"
I attached you my code so you see what I do. The code worx so far, I just added the "synch" void which synchs all fader values in Processing (not compiled yet). However, it would be much better if the values would also be received by my iOS application.
Hope someone can help
Best//
Thorsten
- import oscP5.*;
import netP5.*;
import processing.serial.*;
Serial myPort;
OscP5 oscP5;
int [] fader = new int [5];
int [] out = new int [5];
int button = 0;
int page = 1;
int pageNow = 1;
int [] [] array = { { 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0} };
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/button")) {
button = (int) val;
}
for (int i=1; i<5; i++) {
if(addr.indexOf("/"+i+"/fader") !=-1){
String list[] = split(addr,'/');
int j = int(list[2].charAt(5) - 0x30);
fader[j] = (int) val;
page = int (list[1].charAt(0) - 0x30);
synch();
}
}
}
void synch() {
if (pageNow == 1 && page == 1) {
for (int k=0; k<5; k++) {
array [1] [k] = fader[0];
array [2] [k] = fader[1];
if (k<2) array [3] [k] = fader[2];
if (k>1) array [3] [k] = fader[3];
}
}
if ((pageNow == 1 && page!=1) || (pageNow != page && pageNow != 1 && page!=1)) {
for (int k=0; k<5; k++) {
if (page == 2) fader[k] = array [1] [k];
if (page == 3) fader[k] = array [2] [k];
if (page == 4) fader[k] = array [3] [k];
}
}
if (pageNow == page && pageNow != 1 && page!=1) {
for (int k=0; k<5; k++) {
if (page == 2) array [1] [k] = fader[k];
if (page == 3) array [2] [k] = fader[k];
if (page == 4) array [3] [k] = fader[k];
}
if (pageNow != 1 && page ==1) {
fader[0] = ((array[1][0] + array[1][1] + array[1][2] + array[1][3] + array[1][4])/5);
fader[1] = ((array[2][0] + array[2][1] + array[2][2] + array[2][3] + array[2][4])/5);
fader[2] = ((array[3][0] + array[3][1])/2);
fader[3] = ((array[3][2] + array[3][3] + array[3][4])/3);
fader[4] = fader[4];
}
pageNow = page;
}
void draw() {
while (button==1) {
synch();
for (int i=0; i<5; i++) {
if (fader[i] != out[i]) {
out[i] = (int) (fader[i]);
myPort.write(button);
myPort.write(page);
println(page);
for (int j=0; j<5; j++) {
myPort.write(out[j]);
println(out[j]);
}
}
}
}
}
1