osctools/oscviewer/oscviewer.pde

77 lines
1.6 KiB
Text
Raw Normal View History

2021-11-11 10:03:30 +00:00
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
String baseaddress="/oscplayer/";
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
class OSCMsg {
long time;
OscArgument arg0;
String address;
OSCMsg (long ptime, OscArgument parg, String paddress) {
time=ptime;
arg0=parg;
address=paddress;
}
String argString(){
return ""+arg0.floatValue(); //TODO
}
}
List<OSCMsg> msglist;;
void setup() {
size(400,400);
frameRate(60);
oscP5 = new OscP5(this,7000); //Port for input OSC Messages
msglist = new CopyOnWriteArrayList<OSCMsg>();
}
void draw() {
background(0);
//positions
int ystart=10; //distance from top
int xstartTime=5;
int xstartAddr=80;
int xstartArg0=200;
int ydist=12;
int row=0;
for (OSCMsg m : msglist) { //check if address already known
text(m.time, xstartTime,ystart+row*ydist);
text(m.address, xstartAddr,ystart+row*ydist);
text(m.argString(), xstartArg0,ystart+row*ydist);
row++;
}
}
void oscEvent(OscMessage cmsg) {
boolean found=false;
for (OSCMsg m : msglist) { //check if address already known
if (m.address.equals(cmsg.addrPattern())) { //found, then update data
m.arg0=cmsg.get(0);
m.time=millis();
found=true;
}
}
if (!found) { //address not known yet
msglist.add(new OSCMsg(millis(),cmsg.get(0),cmsg.addrPattern()));
}
//print("### received an osc message.");
//print(" addrpattern: "+theOscMessage.addrPattern());
//println(" typetag: "+theOscMessage.typetag());
}