From dba01ce870165fd8d8a5fea921cb31f7c4e8c25f Mon Sep 17 00:00:00 2001 From: Comment Date: Mon, 10 Dec 2012 19:30:27 +0000 Subject: fixed race condition in asterisk driver --- vfg/src/music.cpp | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'vfg/src/music.cpp') diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index c920a02..4cddab9 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -213,8 +213,8 @@ void musicscore::drawFlakes(float hOffs,levelscore *levels,float scale) { //else ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255)); //if (iter->second->activated&&(!iter->second->disintegrated)) iter->second->disintegrate(); + //ofSetColor(255,255,255); //allow external fading - ofSetColor(255,255,255); iter->second->draw((gridX[notemap(iter->second->num)+1]*ofGetHeight())+hOffs,ofGetHeight()-(thisstart*heightStep),scale); //todo - make all drawing resolution independent @@ -269,7 +269,8 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string lyrics.load(lyricfile); levels.load(levelfile); isPlaying=false; - isPractice=false; + isPractice=false; + fademillis=1000; } void song::setTimeframe(int millis) {notes.setTimeframe(millis);} void song::setKeyThresh(int millis) {notes.keyThresh=millis;} @@ -286,7 +287,8 @@ void song::play() { void song::stop() { backing.stop(); melody.stop(); - isPlaying=false; + isPlaying=false; + printf("stoppping song: %i (%i)\n",ofGetElapsedTimeMillis()-startTime,levels.length); } void song::preRoll(long preroll) { startTime=ofGetElapsedTimeMillis()+preroll; @@ -318,12 +320,18 @@ int song::getLength(){ } bool song::isGameover(){ return gameover; +} +void song::gameOver(){ + + gameover=true; + gameoverTime=ofGetElapsedTimeMillis(); } bool song::isFinished(){ return (ofGetElapsedTimeMillis()-startTime>=levels.length); } void song::draw(float hOffs,float scale){ - int songTime=ofGetElapsedTimeMillis()-startTime; + int songTime=ofGetElapsedTimeMillis()-startTime; + int fadeout=(gameover?max(0,255-((int)((((float)ofGetElapsedTimeMillis()-gameoverTime)/fademillis)*255))):255); if (isPlaying) { if (isPreroll&&(!isPractice)) { if (startTimelevels.getLives(songTime)) { + if (notes.missedFlakes>levels.getLives(songTime)&&!gameover) { //work out score - //stop(); - gameover=true; + //stop(); + printf("game over! %i (%i)\n",songTime,levels.length); + gameOver(); } } } - else melody.setVolume(1.0f); - if (!isPractice) lyrics.draw(hOffs); - if (songTime>levels.length) { - printf("stopping: %i (%i)\n",songTime,levels.length); + if (!notes.missedLast&&!gameover) melody.setVolume(1.0f); + if (!isPractice&&!gameover) lyrics.draw(hOffs); + if (songTime>levels.length&&!gameover) { + printf("finished! %i (%i)\n",songTime,levels.length); + //this played loads of times //stop(); - gameover=true; - } - } - else { - //fade out song + melody :: clean up + gameOver(); + } + ofSetColor(255,255,255); + if (gameover) { + melody.setVolume(notes.missedLast?0.0f:((float)fadeout)/255.0f); + backing.setVolume(((float)fadeout)/255.0f); + if (fadeout==0) stop(); + } } + } void song::playerControl(int key){ notes.playerControl(key); -- cgit v1.2.3