summaryrefslogtreecommitdiff
path: root/vfg/src/music.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vfg/src/music.cpp')
-rwxr-xr-xvfg/src/music.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp
index bbdfdc9..286bdcb 100755
--- a/vfg/src/music.cpp
+++ b/vfg/src/music.cpp
@@ -6,6 +6,7 @@ note::note(int n,int v,int d){
num=n;
velocity=v;
duration=d;
+ activated=false;
}
//---------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------
@@ -98,7 +99,7 @@ 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);
- //decimate notes to generate flakes that can be interacted with
+//decimate notes to generate flakes that can be interacted with
int noteThresh=1000;
note *lastNote=notes.begin()->second;
int lastTime=0;
@@ -111,6 +112,10 @@ void musicscore::parseMidi(string filename){
lastTime=iter1->first;
}
+ interactionThresh=100; //how long player has to respond
+ missedTime=-1;
+
+
}
void musicscore::setTimeframe(int millis) {timeframe=millis;}
void musicscore::draw() {
@@ -144,17 +149,38 @@ void musicscore::draw() {
int thisnote=iter->second->num-firstnote;
int thisstart=iter->first-scoreStart;
int thislength=iter->second->duration;
- ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255));
+
+ // check player interaction
+ if (thisstart<interactionThresh) {
+ //this star needs to be interacted with
+ if (((thisnote/5)+1)==playerKey) {
+ //success!
+ iter->second->playerActivated();
+ }
+ }
+ if (iter->second->activated) ofSetColor(255,255,255);
+ else ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255));
flake.draw((((thisnote/5)*5)+3.5f)*widthStep,ofGetHeight()-(thisstart*heightStep));
}
+ //check for unactivated stars. must be a better way
+ missedTime=-1;
+ for (iter = stars.upper_bound(scoreStart); iter != stars.lower_bound(0); --iter) {
+ if (!iter->second->activated) missedTime=scoreStart-iter->first;
+ else break;
+ }
ofDisableAlphaBlending();
}
+void musicscore::playerControl(int key){
+ //0-3 - 0 is off
+ playerKey=key;
+}
//---------------------------------------------------------------------------------------------------------------------------------------------
song::song(string backfile,string melfile,string notefile) {
backing.loadSound(backfile);
melody.loadSound(melfile);
notes.parseMidi(notefile);
- isPlaying=false;
+ isPlaying=false;
+ missedInterval=5000;
}
void song::setTimeframe(int millis) {notes.setTimeframe(millis);}
void song::play() {
@@ -184,5 +210,14 @@ void song::draw(){
isPreroll=false;
}
}
+ if (notes.missedTime>0) {
+ if (notes.missedTime>missedInterval) stop();
+ else melody.setVolume(1.0f-((float)notes.missedTime/(float)missedInterval));
+ }
+ else melody.setVolume(1.0f);
notes.draw();
+}
+void song::playerControl(int key){
+ //0-3 - 0 is off
+ notes.playerControl(key);
}