From bbeed54d2c0572d9fc12edab14781dd544dc149a Mon Sep 17 00:00:00 2001 From: Comment Date: Fri, 30 Nov 2012 13:30:48 +0000 Subject: demo v0.9 --- vfg/src/music.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'vfg/src/music.cpp') diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index d3d7807..30af87b 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -13,7 +13,7 @@ int notemap(int n) { else return 2; } //---------------------------------------------------------------------------------------------------------- -void lyricscore::draw(){ +void lyricscore::draw(float hOffs){ int scoreTime=ofGetElapsedTimeMillis()-startTime; map::iterator iter; iter=lyrics.upper_bound(scoreTime); @@ -22,7 +22,7 @@ void lyricscore::draw(){ if ((iter->first+iter->second->duration)>scoreTime) { //outpoint of lyric previous to the one next soonest is afterwards => this lyric is visible int alpha=((iter->first+iter->second->duration)-scoreTime)first+iter->second->duration)-scoreTime))/((float)fadeout))*255.0f):255; ofSetColor(255,255,255,alpha); - font.drawString(iter->second->text,(ofGetWidth()/2)-(font.stringWidth(iter->second->text)/2.0f), gridY[1]*ofGetHeight()); + font.drawString(iter->second->text,hOffs+(ofGetHeight()/2)-(font.stringWidth(iter->second->text)/2.0f), gridY[1]*ofGetHeight()); } } } @@ -62,10 +62,12 @@ void musicscore::parseMidi(string filename){ float time=0; //counts up in float seconds to avoid rounding errors but converts to millis for map index map events; + int startnote; if( !XML.loadFile(filename) ){ printf("unable to load %s check data/ folder\n",filename.c_str()); }else{ + startnote=XML.getAttribute("MidiFile", "startnote",70,0); if(XML.pushTag("MidiFile")) { for (int i=0;i::iterator iter; @@ -173,14 +175,14 @@ void musicscore::drawNotes(levelscore *levels) { int thisstart=iter->first-scoreStart; int thislength=iter->second->duration; ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100),(((float)(thisstart*heightStep))/ofGetHeight()*128)+32); - ofRect(thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep)); + ofRect(hOffs+thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep)); } //visualise keyThreshold ofSetColor(255,0,0,70); - ofRect(0,ofGetHeight()-(nowpoint*heightStep),ofGetWidth(),keyThresh*heightStep); + ofRect(hOffs,ofGetHeight()-(nowpoint*heightStep),ofGetHeight(),keyThresh*heightStep); } -void musicscore::drawFlakes(levelscore *levels,float scale) { +void musicscore::drawFlakes(float hOffs,levelscore *levels,float scale) { ofEnableAlphaBlending(); int now=ofGetElapsedTimeMillis()-startTime; int screenStart=now-nowpoint; @@ -188,7 +190,7 @@ void musicscore::drawFlakes(levelscore *levels,float scale) { //note drawing 46h - 52h int numnotes=16; int firstnote=70; - float widthStep=((float)ofGetWidth())/numnotes; + float widthStep=((float)ofGetHeight())/numnotes; float heightStep=((float)ofGetHeight())/timeframe; map::iterator iter; //draw flakes @@ -203,7 +205,7 @@ void musicscore::drawFlakes(levelscore *levels,float scale) { //if (iter->second->activated&&(!iter->second->disintegrated)) iter->second->disintegrate(); ofSetColor(255,255,255); - iter->second->draw(gridX[notemap(iter->second->num)+1]*ofGetWidth(),ofGetHeight()-(thisstart*heightStep),scale); + iter->second->draw((gridX[notemap(iter->second->num)+1]*ofGetHeight())+hOffs,ofGetHeight()-(thisstart*heightStep),scale); //todo - make all drawing resolution independent } @@ -283,10 +285,10 @@ void song::preRoll(long preroll) { isPlaying=true; notes.makeFlakes(fThreshStart,fThreshEnd,&levels); } -void song::drawNotes(){ - notes.drawNotes(&levels); +void song::drawNotes(float hOffs){ + notes.drawNotes(hOffs,&levels); } -void song::draw(float scale){ +void song::draw(float hOffs,float scale){ int songTime=ofGetElapsedTimeMillis()-startTime; if (isPlaying) { if (isPreroll) { @@ -306,15 +308,15 @@ void song::draw(float scale){ } } else melody.setVolume(1.0f); - notes.drawFlakes(&levels,scale); - lyrics.draw(); + notes.drawFlakes(hOffs,&levels,scale); + lyrics.draw(hOffs); if (songTime>levels.length) { printf("stopping: %i (%i)\n",songTime,levels.length); stop(); } } - ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,(ofGetHeight()*gridY[1])-3); + ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),hOffs+10,(ofGetHeight()*gridY[1])-3); } void song::playerControl(int key){ notes.playerControl(key); -- cgit v1.2.3