From 93bcffd919104a69535d31d325026a37bcf0901d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sun, 4 Nov 2012 18:36:39 +0000 Subject: flake decimation --- vfg/src/music.cpp | 30 +++++++++++++++++++++++++----- vfg/src/music.h | 3 ++- 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::iterator iter1; map::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->numsecond->num==note?0:1; - note=iter1->second->num; + iter1->second->updown=iter1->second->numsecond->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::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 notes; + map notes; + map 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 @@ - - + + - + - + -- cgit v1.2.3