diff options
Diffstat (limited to 'vfg')
| -rwxr-xr-x | vfg/src/music.cpp | 30 | ||||
| -rwxr-xr-x | vfg/src/music.h | 3 | ||||
| -rw-r--r-- | vfg/vfg.layout | 8 |
3 files changed, 31 insertions, 10 deletions
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index 74c5c0b..bbdfdc9 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -72,12 +72,12 @@ void musicscore::parseMidi(string filename){ //iterate events and compute durations now the absolute times are established: extract to notes map<int,note*>::iterator iter1; map<int,note*>::iterator iter2; - int note;
+ int n;
bool started=false; for (iter1 = events.begin(); iter1 != events.end(); ++iter1) { if (iter1->second->duration==144) {
if (!started) {
- note=iter1->second->num;
+ n=iter1->second->num;
started=true;
} iter1->second->duration=0; @@ -85,8 +85,8 @@ void musicscore::parseMidi(string filename){ while (++iter2 != events.end()) { if ((iter1->second->num==iter2->second->num)&&(iter2->second->duration==128)) { iter1->second->duration=iter2->first-iter1->first;
- iter1->second->updown=iter1->second->num<note?-1:iter1->second->num==note?0:1;
- note=iter1->second->num; + iter1->second->updown=iter1->second->num<n?-1:iter1->second->num==n?0:1;
+ n=iter1->second->num; notes[iter1->first]=iter1->second; printf("%i: noteon %i %i %i\n",iter1->first,iter1->second->num,iter1->second->duration,iter1->second->updown); break; @@ -99,6 +99,17 @@ void musicscore::parseMidi(string filename){ 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
+ int noteThresh=1000;
+ note *lastNote=notes.begin()->second;
+ int lastTime=0;
+ stars[notes.begin()->first]=notes.begin()->second;
+ for (iter1 = notes.begin(); iter1 != notes.end(); iter1++) {
+ if ((iter1->second->num/5!=lastNote->num/5)||(lastTime-iter1->first>noteThresh)) {
+ stars[iter1->first]=iter1->second;
+ }
+ lastNote=iter1->second;
+ lastTime=iter1->first;
+ }
}
void musicscore::setTimeframe(int millis) {timeframe=millis;}
@@ -112,19 +123,28 @@ void musicscore::draw() { float widthStep=((float)ofGetWidth())/numnotes;
float heightStep=((float)ofGetHeight())/timeframe;
map<int,note*>::iterator iter;
+
for (iter = notes.lower_bound(scoreStart); iter != notes.upper_bound(scoreEnd); ++iter) {
int thisnote=iter->second->num-firstnote;
int thisstart=iter->first-scoreStart;
int thislength=iter->second->duration;
ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,100));
ofRect(thisnote*widthStep,ofGetHeight()-(thisstart*heightStep),widthStep,-(thislength*heightStep));
- ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255));
//different methods for generating flakes
//ideally theres a variable clumping factor, this means pre-processing the flakes though
+ //ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255));
+
//flake.draw((thisnote+0.5f)*widthStep,ofGetHeight()-(thisstart*heightStep));
//flake.draw((iter->second->updown*ofGetWidth()*0.33)+(ofGetWidth()*0.5),ofGetHeight()-(thisstart*heightStep));
+ //flake.draw((((thisnote/5)*5)+3.5f)*widthStep,ofGetHeight()-(thisstart*heightStep));
+ }
+ for (iter = stars.lower_bound(scoreStart); iter != stars.upper_bound(scoreEnd); ++iter) {
+ 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));
flake.draw((((thisnote/5)*5)+3.5f)*widthStep,ofGetHeight()-(thisstart*heightStep));
}
ofDisableAlphaBlending();
diff --git a/vfg/src/music.h b/vfg/src/music.h index ecec8f2..aa38f46 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -35,7 +35,8 @@ class musicscore: public score { void setTimeframe(int millis);
void draw();
private:
- map<int,note*> notes;
+ map<int,note*> notes; + map<int,note*> stars;
int timeframe;
ofImage flake;
};
diff --git a/vfg/vfg.layout b/vfg/vfg.layout index 9b5ee28..ba46475 100644 --- a/vfg/vfg.layout +++ b/vfg/vfg.layout @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> - <File name="src/music.cpp" open="1" top="0" tabpos="4"> - <Cursor position="5044" topLine="88" /> + <File name="src/music.cpp" open="1" top="1" tabpos="4"> + <Cursor position="4138" topLine="72" /> </File> <File name="src/music.h" open="1" top="0" tabpos="3"> - <Cursor position="1817" topLine="20" /> + <Cursor position="1389" topLine="6" /> </File> - <File name="src/testApp.cpp" open="1" top="1" tabpos="2"> + <File name="src/testApp.cpp" open="1" top="0" tabpos="2"> <Cursor position="357" topLine="0" /> </File> <File name="src/testApp.h" open="1" top="0" tabpos="1"> |
