From 7ae1f870faebb65e9ee3a064fc43ef2fc6955a84 Mon Sep 17 00:00:00 2001 From: Comment Date: Thu, 29 Nov 2012 19:13:19 +0000 Subject: work on asterisk plugin --- vfg/src/music.cpp | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'vfg/src/music.cpp') diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index 32f9d3e..d3d7807 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -124,6 +124,12 @@ void musicscore::parseMidi(string filename){ iter1--; printf("processed %s: length %f, %i notes in %f seconds\n",filename.c_str(),((float)(iter1->first+iter1->second->duration)*.001f),notes.size(),ofGetElapsedTimef()-wt); } +void musicscore::printNotes() { + map::iterator iter; + for (iter = notes.begin(); iter != notes.end(); iter++) { + printf("%i: %i, %i for %i\n",iter->first,iter->second->num,iter->second->velocity,iter->second->duration); + } +} void musicscore::makeFlakes(int threshStart,int threshEnd,levelscore *levels){ flakes.clear(); //decimate notes to generate flakes that can be interacted with @@ -147,10 +153,12 @@ void musicscore::makeFlakes(int threshStart,int threshEnd,levelscore *levels){ missedFlake=flakes.end(); missedNote=-1; } -void musicscore::setTimeframe(int millis) {timeframe=millis;} -void musicscore::setNowpoint(float pct) {nowpoint=pct;} +void musicscore::setTimeframe(int millis) { + timeframe=millis; + nowpoint=timeframe*0.33f; +} void musicscore::drawNotes(levelscore *levels) { - int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe); + int scoreStart=ofGetElapsedTimeMillis()-startTime-nowpoint; int scoreEnd=scoreStart+timeframe; //note drawing 46h - 52h int numnotes=16; @@ -167,12 +175,16 @@ void musicscore::drawNotes(levelscore *levels) { ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100),(((float)(thisstart*heightStep))/ofGetHeight()*128)+32); ofRect(thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep)); } + //visualise keyThreshold + ofSetColor(255,0,0,70); + ofRect(0,ofGetHeight()-(nowpoint*heightStep),ofGetWidth(),keyThresh*heightStep); } void musicscore::drawFlakes(levelscore *levels,float scale) { ofEnableAlphaBlending(); - int scoreStart=ofGetElapsedTimeMillis()-startTime-((1.0f-nowpoint)*timeframe); - int scoreEnd=scoreStart+timeframe; + int now=ofGetElapsedTimeMillis()-startTime; + int screenStart=now-nowpoint; + int screenEnd=screenStart+timeframe; //note drawing 46h - 52h int numnotes=16; int firstnote=70; @@ -180,9 +192,9 @@ void musicscore::drawFlakes(levelscore *levels,float scale) { float heightStep=((float)ofGetHeight())/timeframe; map::iterator iter; //draw flakes - for (iter = flakes.lower_bound(scoreStart); iter != flakes.upper_bound(scoreEnd); iter++) { + for (iter = flakes.lower_bound(screenStart); iter != flakes.upper_bound(screenEnd); iter++) { int thisnote=iter->second->num-firstnote; - int thisstart=iter->first-scoreStart; + int thisstart=iter->first-screenStart; int thislength=iter->second->duration; //if (iter->second->activated) ofSetColor(255,255,255); @@ -195,21 +207,24 @@ void musicscore::drawFlakes(levelscore *levels,float scale) { //todo - make all drawing resolution independent } - //check for unactivated flakes within this segment: is there a more efficient way? - //need to know when a flake has just been missed - + //check for unactivated flakes within this level: is there a more efficient way? + //need to know when a flake has just been missed + //this seems to mess up a little bit when switching levels + //also: when the window for hitting flakes gets too big, it messes up missedFlakes=0; missedLast=false; map::iterator missed=flakes.end(); - int scoreTime=ofGetElapsedTimeMillis()-startTime; - for (iter = flakes.lower_bound(levels->getLowerBound(levels->getLevel(scoreStart))); iter != flakes.lower_bound(scoreStart); iter++){ + int lvlstart=levels->getLowerBound(levels->getLevel(now)); + int window=max(lvlstart,now-keyThresh); + for (iter = flakes.lower_bound(lvlstart); iter != flakes.lower_bound(window); iter++){ if (!iter->second->activated) { missedFlakes++; missed=iter; } missedLast=!iter->second->activated; } - //at this point missed points to the latest unactivated flake in the level if there is one + //at this point missed points to the latest unactivated flake in the level if there is one or else flakes.end() + if ((missed!=flakes.end())&&(missedFlake!=missed)) { missedFlake=missed; missedNote=notemap(missed->second->num); @@ -218,10 +233,10 @@ void musicscore::drawFlakes(levelscore *levels,float scale) { ofDisableAlphaBlending(); } -void musicscore::playerControl(int key,int threshold){ +void musicscore::playerControl(int key){ map::iterator iter; - int scoreTime=ofGetElapsedTimeMillis()-startTime; - for (iter = flakes.lower_bound(scoreTime-threshold); iter != flakes.upper_bound(scoreTime+threshold); iter++) { + int now=ofGetElapsedTimeMillis()-startTime; + for (iter = flakes.lower_bound(now-keyThresh); iter != flakes.upper_bound(now); iter++) { if (key==notemap(iter->second->num)) { iter->second->activate(); hitNote=key; @@ -236,11 +251,9 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string lyrics.load(lyricfile); levels.load(levelfile); isPlaying=false; - keyThresh=500; - notes.setNowpoint(0.8f); } void song::setTimeframe(int millis) {notes.setTimeframe(millis);} -void song::setKeythresh(int millis) {keyThresh=millis;} +void song::setKeyThresh(int millis) {notes.keyThresh=millis;} void song::setFlakeThresh(int tS,int tE) { fThreshStart=tS; fThreshEnd=tE; @@ -304,7 +317,7 @@ void song::draw(float scale){ ofDrawBitmapString(ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime)),10,(ofGetHeight()*gridY[1])-3); } void song::playerControl(int key){ - notes.playerControl(key,keyThresh); + notes.playerControl(key); } int song::missedNote(){ return notes.missedNote; -- cgit v1.2.3