summaryrefslogtreecommitdiff
path: root/vfg/src/music.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vfg/src/music.cpp')
-rwxr-xr-xvfg/src/music.cpp30
1 files changed, 25 insertions, 5 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();