add playmode
This commit is contained in:
parent
16ba9d6f36
commit
0f4c69975a
1 changed files with 63 additions and 11 deletions
|
@ -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,13 +36,37 @@ 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);
|
||||
|
||||
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
|
||||
|
@ -44,12 +76,32 @@ void draw() {
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
void sendOSC(String name,float data) {
|
||||
OscMessage myMessage = new OscMessage(baseaddress+name);
|
||||
//println("Sending name="+name+" with data="+data);
|
||||
|
|
Loading…
Reference in a new issue