diff options
Diffstat (limited to 'vfg/src/music.cpp')
| -rwxr-xr-x | vfg/src/music.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
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<int,lyric*>::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)<fadeout?(int)((((float)((iter->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<int,note*> 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<XML.getNumTags("TrackChunk");i++) {
XML.pushTag("TrackChunk",i);
@@ -87,7 +89,7 @@ void musicscore::parseMidi(string filename){ int d1=strtoul(data.substr(0,2).c_str(),&endptr,16);
int d2=strtoul(data.substr(3,2).c_str(),&endptr,16);
int id=strtoul(XML.getAttribute("Event", "Id","",i).c_str(),&endptr,16);
- if (id==128||id==144) events[(int)(time*1000.0f)]=new note(d1,d2,id); //noteon/off
+ if (id==128||id==144) events[(int)(time*1000.0f)]=new note(d1-startnote+70,d2,id); //noteon/off
}
}
XML.popTag();
@@ -157,13 +159,13 @@ void musicscore::setTimeframe(int millis) { timeframe=millis;
nowpoint=timeframe*0.33f;
}
-void musicscore::drawNotes(levelscore *levels) {
+void musicscore::drawNotes(float hOffs,levelscore *levels) {
int scoreStart=ofGetElapsedTimeMillis()-startTime-nowpoint;
int scoreEnd=scoreStart+timeframe;
//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<int,note*>::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<int,flake*>::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);
|
