2021-11-11 10:03:30 +00:00
|
|
|
String baseaddress="/oscplayer/";
|
|
|
|
|
|
|
|
import oscP5.*;
|
|
|
|
import netP5.*;
|
|
|
|
|
|
|
|
OscP5 oscP5;
|
|
|
|
NetAddress myRemoteLocation;
|
|
|
|
|
|
|
|
Table data;
|
|
|
|
TableRow datarow;
|
|
|
|
|
|
|
|
int rowid=0;
|
|
|
|
long time=0;
|
2021-11-11 10:21:52 +00:00
|
|
|
long starttime=0;
|
2021-11-11 10:03:30 +00:00
|
|
|
|
2021-11-11 10:21:52 +00:00
|
|
|
public enum Playmode {
|
|
|
|
STOP, LOOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
Playmode playmode=Playmode.LOOP;
|
|
|
|
|
|
|
|
boolean play=false;
|
2021-11-11 10:03:30 +00:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
size(400,400);
|
|
|
|
frameRate(60);
|
|
|
|
|
|
|
|
data = loadTable("data.csv", "header, csv");
|
|
|
|
println(data.getRowCount() + " total rows in data");
|
|
|
|
println("Header:");
|
|
|
|
for (String title : data.getColumnTitles()) {
|
|
|
|
print(title+", ");
|
|
|
|
}
|
|
|
|
println();
|
|
|
|
datarow = data.getRow(rowid); //get first row
|
|
|
|
|
|
|
|
oscP5 = new OscP5(this,12000); //Port for input OSC Messages
|
|
|
|
myRemoteLocation = new NetAddress("127.0.0.1",7000); //connect to remote, IP, Port
|
2021-11-11 10:21:52 +00:00
|
|
|
|
|
|
|
restart(); //start automatically
|
2021-11-11 10:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void draw() {
|
2021-11-11 10:21:52 +00:00
|
|
|
time=millis()-starttime;
|
|
|
|
datarow = data.getRow(rowid);
|
2021-11-11 10:03:30 +00:00
|
|
|
background(0);
|
|
|
|
|
2021-11-11 10:21:52 +00:00
|
|
|
if (play){
|
|
|
|
text("Playing",10,10);
|
|
|
|
}else{
|
|
|
|
text("Stopped",10,10);
|
|
|
|
}
|
|
|
|
|
|
|
|
text("Time="+time+" ms",100,10);
|
|
|
|
text("row="+rowid,200,10);
|
2021-11-11 10:03:30 +00:00
|
|
|
|
2021-11-11 10:21:52 +00:00
|
|
|
switch(playmode) {
|
|
|
|
case STOP:
|
|
|
|
text("Mode=Stop",10,30);
|
|
|
|
break;
|
|
|
|
case LOOP:
|
|
|
|
text("Mode=Loop",10,30);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (play)
|
2021-11-11 10:03:30 +00:00
|
|
|
{
|
2021-11-11 10:21:52 +00:00
|
|
|
long rowtime=datarow.getInt("time"); //time of the currently loaded row (next to send)
|
2021-11-11 10:03:30 +00:00
|
|
|
|
2021-11-11 10:21:52 +00:00
|
|
|
if (time>=rowtime) //time to send next row
|
|
|
|
{
|
|
|
|
//Send all columns
|
|
|
|
for (String title : data.getColumnTitles()) {
|
|
|
|
sendOSC(title,datarow.getFloat(title));
|
|
|
|
}
|
|
|
|
|
|
|
|
rowid++; //load next row
|
|
|
|
}
|
|
|
|
if (rowid>=data.getRowCount()) { //reached end
|
|
|
|
switch(playmode) {
|
|
|
|
case STOP:
|
|
|
|
play=false;
|
|
|
|
break;
|
|
|
|
case LOOP:
|
|
|
|
restart();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 10:03:30 +00:00
|
|
|
}
|
2021-11-11 10:21:52 +00:00
|
|
|
|
|
|
|
|
2021-11-11 10:03:30 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-11-11 10:21:52 +00:00
|
|
|
void restart() {
|
|
|
|
play=true;
|
|
|
|
starttime=millis();
|
|
|
|
rowid=0;
|
|
|
|
}
|
|
|
|
|
2021-11-11 10:03:30 +00:00
|
|
|
|
|
|
|
void sendOSC(String name,float data) {
|
|
|
|
OscMessage myMessage = new OscMessage(baseaddress+name);
|
|
|
|
//println("Sending name="+name+" with data="+data);
|
|
|
|
myMessage.add(data);
|
|
|
|
oscP5.send(myMessage, myRemoteLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* incoming osc message are forwarded to the oscEvent method. */
|
|
|
|
void oscEvent(OscMessage theOscMessage) {
|
|
|
|
/* print the address pattern and the typetag of the received OscMessage */
|
|
|
|
print("### received an osc message.");
|
|
|
|
print(" addrpattern: "+theOscMessage.addrPattern());
|
|
|
|
println(" typetag: "+theOscMessage.typetag());
|
|
|
|
}
|