diff options
Diffstat (limited to 'vfg/src/music.cpp')
| -rwxr-xr-x | vfg/src/music.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index 30af87b..8f3b767 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -132,6 +132,15 @@ void musicscore::printNotes() { printf("%i: %i, %i for %i\n",iter->first,iter->second->num,iter->second->velocity,iter->second->duration);
}
}
+void musicscore::makeRandomNotes(int length,int startFreq,int endFreq){
+ notes.clear();
+ int time=startFreq;
+ while (time<length) {
+ notes[time]=new note(ofRandom(16)+70,128,100);
+ float frac=(float)time/(float)length;
+ time+=(frac*endFreq)+((1.0f-frac)*startFreq);
+ }
+}
void musicscore::makeFlakes(int threshStart,int threshEnd,levelscore *levels){
flakes.clear();
//decimate notes to generate flakes that can be interacted with
@@ -233,7 +242,6 @@ void musicscore::drawFlakes(float hOffs,levelscore *levels,float scale) { } else missedNote=-1; - ofDisableAlphaBlending();
}
void musicscore::playerControl(int key){
map<int,flake*>::iterator iter;
@@ -246,6 +254,13 @@ void musicscore::playerControl(int key){ }
}
//---------------------------------------------------------------------------------------------------------------------------------------------
+song::song(){
+ isPractice=true;
+}
+song::~song(){
+ backing.unloadSound();
+ melody.unloadSound();
+}
song::song(string backfile,string melfile,string musfile,string lyricfile,string levelfile) {
backing.loadSound(backfile);
melody.loadSound(melfile);
@@ -253,6 +268,7 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string lyrics.load(lyricfile);
levels.load(levelfile);
isPlaying=false;
+ isPractice=false;
}
void song::setTimeframe(int millis) {notes.setTimeframe(millis);}
void song::setKeyThresh(int millis) {notes.keyThresh=millis;}
@@ -264,13 +280,7 @@ int song::getCurrentTime(){ return ofGetElapsedTimeMillis()-startTime;
}
void song::play() {
- backing.play();
- melody.play();
- startTime=ofGetElapsedTimeMillis();
- notes.start(); - lyrics.start();
- isPlaying=true;
- notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
+ preRoll(0);
}
void song::stop() {
backing.stop();
@@ -279,25 +289,36 @@ void song::stop() { }
void song::preRoll(long preroll) {
startTime=ofGetElapsedTimeMillis()+preroll;
- notes.start(startTime); - lyrics.start(startTime);
+ if (isPractice) {
+ notes.makeRandomNotes(20000,4000,1000);
+ levels.makePractice(20000);
+ }
+ else {
+ lyrics.start(startTime);
+ }
+ notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
+ notes.start(startTime);
isPreroll=true;
isPlaying=true;
- notes.makeFlakes(fThreshStart,fThreshEnd,&levels);
}
void song::drawNotes(float hOffs){
notes.drawNotes(hOffs,&levels);
}
+string song::getScoreString(){
+ int songTime=ofGetElapsedTimeMillis()-startTime;
+ return ofToString((float)songTime/1000.0f,1)+" "+ofToString(levels.getLevel(songTime))+" "+ofToString(notes.missedFlakes)+" of "+ofToString(levels.getLives(songTime));
+}
void song::draw(float hOffs,float scale){
int songTime=ofGetElapsedTimeMillis()-startTime;
if (isPlaying) {
- if (isPreroll) {
+ if (isPreroll&&(!isPractice)) {
if (startTime<ofGetElapsedTimeMillis()) {
backing.play();
melody.play();
isPreroll=false;
}
}
+ notes.drawFlakes(hOffs,&levels,scale);
if (notes.missedLast) {
melody.setVolume(0.0f);
if (levels.getLives(songTime)) {
@@ -307,16 +328,13 @@ void song::draw(float hOffs,float scale){ }
}
}
- else melody.setVolume(1.0f);
- notes.drawFlakes(hOffs,&levels,scale); - lyrics.draw(hOffs);
+ else melody.setVolume(1.0f); + if (!isPractice) 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)),hOffs+10,(ofGetHeight()*gridY[1])-3);
}
void song::playerControl(int key){
notes.playerControl(key);
|
