I´m programming an art installation that is controlled by OSC msgs.
I want to create a time counter, lets said 5 minutes, that if app dont get any OSC msg, execute my restart() function.
In update i have the bucle for process OSC msg
while(oscReceiver.hasWaitingMessages()){
// get the next message
ofxOscMessage m;
oscReceiver.getNextMessage(&m);
// OSC from buttons
if(m.getAddress() == "path/button"){
do something
}
lot of else if more....
}
I
Someone would be so nice to advice me or send me the links of some tutorials or post inside the forums. As I read about some functions to get the milliseconds but is not so clear for me now.
I know that I have to declare some variables to compare times. But read some examples will be better for my understanding. As I don’t know where I have to put the update for the variable of the last time I got a msg.
You could use a basic frame counter which resets when a message is received, or you could use elapsed time- ofGetElapsedTimeMillis() which returns the number of milliseconds since the app launched. Here’s a frame counter example-
// be sure to add ‘int frameCounter;’ to your .h, and set ‘frameCounter = 0;’ in the setup.
frameCounter++;
if(frameCounter >= 18000) {
// 18000 = approx 5 minutes if app is running at 60fps (60 * 5 * 60)
frameCounter = 0; // reset
restart();
}
while(oscReceiver.hasWaitingMessages()){
// get the next message
ofxOscMessage m;
oscReceiver.getNextMessage(&m);
frameCounter = 0; // reset the counter when a new message is received
// OSC from buttons
if(m.getAddress() == "path/button"){
do something
}
lot of else if more....
}
}