Draw is looping but an inner loop is causing it not to render to the screen
in
Programming Questions
•
5 months ago
Hi, I have a strange problem related to rendering that I'm hoping someone will understand. I have a simple application that draws the circumference of a circle one step at a time in sync with beat data from Echonest.
In order to sync the drawing with each beat, I put a While loop inside Draw that retrieves that next beat from the Echonest data and then keeps looping until the song reaches a short window of time around that beat (i.e., within 13ms before or after it). I then draw the next circle segment, the While loop exits, and Draw completes. The problem is that, even though the code to draw the circle segment is getting performed and even though Draw is in fact looping properly, nothing is getting rendered. I just get a gray viewport. And I know that the While loop is causing the problem because, when I remove the condition that causes the While loop to keep looping until we hit the right window of time, it renders just fine. Moreover, if I leave that condition in, but drop my frame rate down to 3 or lower, then it renders fine as well.
So it seems that the inner loop is causing some sort of havoc with Processing. Does anyone have an idea of what could be happening and what a good solution is? Similarly, does anyone know of a better way to sync music and an animation (I tried doing it real-time with Minim, but I was struggling to get good results, particularly due to apparent latency).
Thanks,
Kevin
while (_currBeatFndInd == false && _currBeatIdx < _beats.length) {
int startTmMsNbr = ( int)(Float.parseFloat( _beats[ _currBeatIdx].get( "start").toString()) * 1000);
if (startTmMsNbr >= _player.position() - MAX_LATENCY_MS_NBR) {
_msToNextBeatNbr = abs(startTmMsNbr - _player.position());
}
if (_msToNextBeatNbr <= MAX_LATENCY_MS_NBR ) {
//if (true) {
circles.get(0).update();
println( _currBeatIdx + " drawn");
_currBeatFndInd = true ;
_currBeatIdx ++;
} else {
// println(_currBeatIdx + " " + _msToNextBeatNbr);
}
} else {
_currBeatIdx ++;
}
1