summaryrefslogtreecommitdiff
path: root/muse2
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2011-04-10 15:32:37 +0000
committerFlorian Jung <flo@windfisch.org>2011-04-10 15:32:37 +0000
commitda8810c2e943da0c3ca6c44cbaa28a6c9470eac3 (patch)
treeb51c7c097b024db09cf6e32814ebeff84da0d4af /muse2
parent41ae38dea50566b54aa117fec1bc4fc173d29924 (diff)
fixed bugs with overlapping notes and hardcoded song length
Diffstat (limited to 'muse2')
-rw-r--r--muse2/muse/midiedit/scoreedit.cpp40
-rw-r--r--muse2/muse/midiedit/scoreedit.h4
2 files changed, 36 insertions, 8 deletions
diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp
index 7222d18a..2688f52b 100644
--- a/muse2/muse/midiedit/scoreedit.cpp
+++ b/muse2/muse/midiedit/scoreedit.cpp
@@ -228,7 +228,7 @@ bool operator< (const note_pos_t& a, const note_pos_t& b)
//TODO: all das unten richtig machen!
#define TICKS_PER_WHOLE (config.division*4)
-#define SONG_LENGTH (TICKS_PER_WHOLE*8)
+#define SONG_LENGTH (song->len())
#define quant_max 3 //whole, half, quarter = 0,1,2
#define quant_max_fraction (1 << quant_max) //whole, half, quarter= 1,2,4
@@ -271,7 +271,9 @@ ScoreEventList ScoreCanvas::createAppropriateEventList(PartList* pl, Track* trac
ScoreEventList result;
- //insert note on/off events
+ // phase one: fill the list -----------------------------------------
+
+ //insert note on events
for (iPart partIt=pl->begin(); partIt!=pl->end(); partIt++)
{
Part* part=partIt->second;
@@ -289,9 +291,7 @@ ScoreEventList ScoreCanvas::createAppropriateEventList(PartList* pl, Track* trac
begin=flo_quantize(event.tick()+part->tick());
end=flo_quantize(event.endTick()+part->tick());
cout <<"inserting note on at "<<begin<<" with pitch="<<event.pitch()<<" and len="<<end-begin<<endl;
- cout<< "\tinserting corresponding note off at "<<endl;
result.insert(pair<unsigned, FloEvent>(begin, FloEvent(begin,event.pitch(), event.velo(),end-begin,FloEvent::NOTE_ON,part,&it->second)));
- result.insert(pair<unsigned, FloEvent>(end, FloEvent(end,event.pitch(), event.veloOff(),0,FloEvent::NOTE_OFF,part,&it->second)));
}
//else ignore it
}
@@ -322,6 +322,31 @@ ScoreEventList ScoreCanvas::createAppropriateEventList(PartList* pl, Track* trac
//TODO FINDMICH MARKER
result.insert(pair<unsigned, FloEvent>(0, FloEvent(0,FloEvent::KEY_CHANGE, C ) ) );
+
+ // phase two: deal with overlapping notes ---------------------------
+ ScoreEventList::iterator it, it2;
+
+ //iterate through all note_on - events
+ for (it=result.begin(); it!=result.end(); it++)
+ if (it->second.type==FloEvent::NOTE_ON)
+ {
+ int end_tick=it->first + it->second.len;
+
+ //iterate though all (relevant) later note_ons which are
+ //at the same pitch. if there's a collision, shorten it's len
+ for (it2=it, it2++; it2!=result.end() && it2->first < end_tick; it2++)
+ if ((it2->second.type==FloEvent::NOTE_ON) && (it2->second.pitch == it->second.pitch))
+ it->second.len=it2->first - it->first;
+ }
+
+
+ // phase three: eliminate zero-length-notes -------------------------
+ for (it=result.begin(); it!=result.end();)
+ if ((it->second.type==FloEvent::NOTE_ON) && (it->second.len<=0))
+ result.erase(it++);
+ else
+ it++;
+
return result;
}
@@ -613,7 +638,7 @@ list<note_len_t> ScoreCanvas::parse_note_len(int len_ticks, int begin_tick, vect
}
-#define USED_CLEF BASS
+#define USED_CLEF VIOLIN
#define YLEN 10
#define YDIST (2*YLEN)
@@ -794,7 +819,7 @@ ScoreItemList ScoreCanvas::create_itemlist(ScoreEventList& eventlist)
tmplen=next_measure-t;
tied_note=true;
- //append the "rest" of the note to our EventList, so that
+ //append the "remainder" of the note to our EventList, so that
//it gets processed again when entering the new measure
int newlen=len-tmplen;
eventlist.insert(pair<unsigned, FloEvent>(next_measure, FloEvent(actual_tick,pitch, velo,0,FloEvent::NOTE_OFF, it->second.source_part, it->second.source_event)));
@@ -806,6 +831,9 @@ ScoreItemList ScoreCanvas::create_itemlist(ScoreEventList& eventlist)
{
tmplen=len;
tied_note=false;
+
+ cout << "\t\tinserting NOTE OFF at "<<t+len<<endl;
+ eventlist.insert(pair<unsigned, FloEvent>(t+len, FloEvent(t+len,pitch, velo,0,FloEvent::NOTE_OFF,it->second.source_part, it->second.source_event)));
}
list<note_len_t> lens=parse_note_len(tmplen,t-last_measure,emphasize_list,true,true);
diff --git a/muse2/muse/midiedit/scoreedit.h b/muse2/muse/midiedit/scoreedit.h
index 6c2a75ce..9382029d 100644
--- a/muse2/muse/midiedit/scoreedit.h
+++ b/muse2/muse/midiedit/scoreedit.h
@@ -149,8 +149,8 @@ class FloEvent
Event* source_event;
int pitch;
- int vel;
- int len;
+ mutable int vel;
+ mutable int len;
int num;
int denom;