add playmode

This commit is contained in:
Philipp Kramer 2021-11-11 11:21:52 +01:00
parent 16ba9d6f36
commit 0f4c69975a

View file

@ -11,7 +11,15 @@ TableRow datarow;
int rowid=0; int rowid=0;
long time=0; long time=0;
long starttime=0;
public enum Playmode {
STOP, LOOP;
}
Playmode playmode=Playmode.LOOP;
boolean play=false;
void setup() { void setup() {
size(400,400); size(400,400);
@ -28,13 +36,37 @@ void setup() {
oscP5 = new OscP5(this,12000); //Port for input OSC Messages oscP5 = new OscP5(this,12000); //Port for input OSC Messages
myRemoteLocation = new NetAddress("127.0.0.1",7000); //connect to remote, IP, Port myRemoteLocation = new NetAddress("127.0.0.1",7000); //connect to remote, IP, Port
restart(); //start automatically
} }
void draw() { void draw() {
time=millis(); time=millis()-starttime;
datarow = data.getRow(rowid);
background(0); background(0);
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) long rowtime=datarow.getInt("time"); //time of the currently loaded row (next to send)
if (time>=rowtime) //time to send next row if (time>=rowtime) //time to send next row
@ -44,9 +76,29 @@ void draw() {
sendOSC(title,datarow.getFloat(title)); sendOSC(title,datarow.getFloat(title));
} }
datarow = data.getRow(rowid++); //load next row 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;
} }