add playmode

This commit is contained in:
Philipp Kramer 2021-11-11 11:21:52 +01:00
parent 16ba9d6f36
commit 0f4c69975a
1 changed files with 63 additions and 11 deletions

View File

@ -11,7 +11,15 @@ TableRow datarow;
int rowid=0;
long time=0;
long starttime=0;
public enum Playmode {
STOP, LOOP;
}
Playmode playmode=Playmode.LOOP;
boolean play=false;
void setup() {
size(400,400);
@ -28,25 +36,69 @@ void setup() {
oscP5 = new OscP5(this,12000); //Port for input OSC Messages
myRemoteLocation = new NetAddress("127.0.0.1",7000); //connect to remote, IP, Port
restart(); //start automatically
}
void draw() {
time=millis();
time=millis()-starttime;
datarow = data.getRow(rowid);
background(0);
long rowtime=datarow.getInt("time"); //time of the currently loaded row (next to send)
if (time>=rowtime) //time to send next row
{
//Send all columns
for (String title : data.getColumnTitles()) {
sendOSC(title,datarow.getFloat(title));
}
datarow = data.getRow(rowid++); //load next row
if (play){
text("Playing",10,10);
}else{
text("Stopped",10,10);
}
text("Time="+time+" ms",100,10);
text("row="+rowid,200,10);
switch(playmode) {
case STOP:
text("Mode=Stop",10,30);
break;
case LOOP:
text("Mode=Loop",10,30);
break;
}
if (play)
{
long rowtime=datarow.getInt("time"); //time of the currently loaded row (next to send)
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;
}
}
}
}
void restart() {
play=true;
starttime=millis();
rowid=0;
}