From bfbdc36053a4a10f7a3d933a2303d57ba0f557e9 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 10 Apr 2011 15:20:00 +0000 Subject: fixed bug with parse_note_len() --- muse2/muse/midiedit/scoreedit.cpp | 203 +++++++++++++++++++++++++++----------- muse2/muse/midiedit/scoreedit.h | 9 +- 2 files changed, 153 insertions(+), 59 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index 6a302486..d483b5e7 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -1,4 +1,6 @@ -//change FONT_PATH to the correct directory +//you need to download http://home.arcor.de/michael.jung11/glyphs.tar.bz2 +//and extract it somewhere. then change FONT_PATH to the correct directory +//the trailing slash is necessary #define FONT_PATH "/home/flo/muse-glyphs/" //========================================================= @@ -170,6 +172,7 @@ string IntToStr(int i) +#define FONT_PATH "/home/flo/AKTENKOFFER/programme/museueberlegungen/glyphs/" void ScoreCanvas::load_pixmaps() { pix_whole.load(FONT_PATH "whole.png"); @@ -435,11 +438,86 @@ bool operator< (const note_len_t& a,const note_len_t& b) //TODO sane sorting ord else return false; } + + +int calc_measure_len(const list& nums, int denom) +{ + int sum=0; + + for (list::const_iterator it=nums.begin(); it!=nums.end(); it++) + sum+=*it; + + return 64* sum/denom; +} + +vector create_emphasize_list(const list& nums, int denom) +{ + cout << "creating emphasize list for "; + for (list::const_iterator it=nums.begin(); it!=nums.end(); it++) + cout << *it << " "; + cout << "/ "< result(len); + + for (int i=0;i::const_iterator it=nums.begin(); it!=nums.end(); it++) + { + result[pos]=1; + for (int i=1;i<*it;i++) + result[pos + i*64/denom]=2; + pos+= *it * 64 / denom; + } + + result[0]=0; + + for (int i=0;i create_emphasize_list(int num, int denom) //TODO FINDMICH +{ + list nums; + + if (num%3 ==0) + { + for (int i=0;i ScoreCanvas::parse_note_len(int len_ticks, bool allow_dots, bool allow_normal, int begin_tick) +list ScoreCanvas::parse_note_len(int len_ticks, int begin_tick, vector& foo, bool allow_dots, bool allow_normal) { list retval; @@ -458,10 +536,6 @@ list ScoreCanvas::parse_note_len(int len_ticks, bool allow_dots, boo //if !allow_normal or if the above failed - // 1 e + e 2 e + e 3 e + e 4 e + e - int foo[]={1,7,6,7,5,7,6,7,4,7,6,7,5,7,6,7,3,7,6,7,5,7,6,7,4,7,6,7,5,7,6,7,2,7,6,7,5,7,6,7,4,7,6,7,5,7,6,7,3,7,6,7,5,7,6,7,4,7,6,7,5,7,6,7}; - #define foo_len (sizeof(foo)/sizeof(*foo)) - int begin=begin_tick * 64 / TICKS_PER_WHOLE; int len=len_ticks * 64 / TICKS_PER_WHOLE; @@ -473,26 +547,42 @@ list ScoreCanvas::parse_note_len(int len_ticks, bool allow_dots, boo int len_now=0; int last_number=foo[pos]; - while (! ((foo[pos] lens=parse_note_len(rest,DOTTED_RESTS,UNSPLIT_RESTS,lastevent); + list lens=parse_note_len(rest,lastevent-last_measure,emphasize_list,DOTTED_RESTS,UNSPLIT_RESTS); unsigned tmppos=lastevent; for (list::iterator x=lens.begin(); x!=lens.end(); x++) { @@ -641,6 +733,7 @@ ScoreItemList ScoreCanvas::create_itemlist(ScoreEventList& eventlist) } lastevent=t; + last_measure=t; next_measure=t+len; itemlist[t].insert( FloItem(FloItem::BAR,no_notepos,0,0) ); @@ -654,7 +747,7 @@ ScoreItemList ScoreCanvas::create_itemlist(ScoreEventList& eventlist) // no need to check if the rest crosses measure boundaries; // it can't. - list lens=parse_note_len(rest,DOTTED_RESTS,UNSPLIT_RESTS,lastevent); + list lens=parse_note_len(rest,lastevent-last_measure,emphasize_list,DOTTED_RESTS,UNSPLIT_RESTS); unsigned tmppos=lastevent; for (list::iterator x=lens.begin(); x!=lens.end(); x++) { @@ -692,7 +785,7 @@ ScoreItemList ScoreCanvas::create_itemlist(ScoreEventList& eventlist) tied_note=false; } - list lens=parse_note_len(tmplen,true,true,t); + list lens=parse_note_len(tmplen,t-last_measure,emphasize_list,true,true); unsigned tmppos=t; int n_lens=lens.size(); int count=0; @@ -721,6 +814,8 @@ ScoreItemList ScoreCanvas::create_itemlist(ScoreEventList& eventlist) { cout << "inserting TIME SIGNATURE "<second.num<<"/"<second.denom<<" at "<second.num, it->second.denom) ); + + emphasize_list=create_emphasize_list(it->second.num, it->second.denom); } else if (type==FloEvent::KEY_CHANGE) { @@ -736,6 +831,8 @@ ScoreItemList ScoreCanvas::create_itemlist(ScoreEventList& eventlist) void ScoreCanvas::process_itemlist(ScoreItemList& itemlist) { stdmap occupied; + int last_measure=0; + vector emphasize_list=create_emphasize_list(4,4); //unneccessary, only for safety //iterate through all times with items for (ScoreItemList::iterator it2=itemlist.begin(); it2!=itemlist.end(); it2++) @@ -744,14 +841,19 @@ void ScoreCanvas::process_itemlist(ScoreItemList& itemlist) cout << "at t="<first<::iterator it=curr_items.begin(); it!=curr_items.end(); it++) { if ((it->type==FloItem::NOTE) || (it->type==FloItem::REST)) occupied[it->pos.height]++; else if ((it->type==FloItem::NOTE_END) || (it->type==FloItem::REST_END)) occupied[it->pos.height]--; + else if (it->type==FloItem::BAR) + last_measure=it2->first; + else if (it->type==FloItem::TIME_SIG) + emphasize_list=create_emphasize_list(it->num, it->denom); } cout << "occupied: "; @@ -1080,7 +1182,7 @@ group_them_again: itemlist[t].insert( FloItem(FloItem::NOTE_END,tmp.pos,0,0) ); - list lens=parse_note_len(len_ticks_remaining,true,true,t); + list lens=parse_note_len(len_ticks_remaining,t-last_measure,emphasize_list,true,true); unsigned tmppos=t; int n_lens=lens.size(); int count=0; @@ -1125,7 +1227,7 @@ group_them_again: itemlist[t].insert( FloItem(FloItem::NOTE_END,tmp.pos,0,0) ); - list lens=parse_note_len(len_ticks_remaining,true,true,t); + list lens=parse_note_len(len_ticks_remaining,t-last_measure,emphasize_list,true,true); unsigned tmppos=t; int n_lens=lens.size(); int count=0; @@ -1882,38 +1984,23 @@ void ScoreCanvas::scroll_event(int x) // every time something changes. - - - -//TODO WICHTIG TÖDLICH: -// bei parse_note_len: BUG (siehe auch bug.mpt) -// die anfangszeit wird in absoluten ticks statt -// ticks seit taktbeginn gegeben -> fehler1 -// außerdem funzt die funktion nicht richtig, wenn -// der takt nicht 4/4 ist! - - -// TODO FINDMICH: tonart aus muses eventliste in meine übernehmen! - -// TODO: schöne funktionen fürs takt- und tonart-vorzeichen zeichnen -// (mit längenangabe!) - - -// TODO: notenschlüssel zeichen! -// TODO: balken bei 8teln und 16teln etc -// TODO: die ItemList als map< pos_t , der_rest_t > umändern - -//TODO: ausweichen bei ganzen noten! - - - -//TODO: while dragging notes: -// send the correct events -// do undo() stuff -// etc. - -//TODO: support inserting and deleting notes -//TODO: when a note gets resized so that len=0, erase it -// but watch out for quantisation stuff then! -// (when the start is slightly before the beat, len is 2 instead of 0) -//TODO: deal with double notes? +/* IMPORTANT TODO + * o use a function for drawing timesig changes. support two(or more)-digit-numbers + * o create nice functions for drawing keychange-accidentials + * o draw clef, maybe support clef changes. support violin and bass at one time + * o support inserting notes + * o support erasing notes (resize to len=0? watch out for quantisation stuff) + * o support undo when dragging notes + * o eliminate overlapping notes (e.g. C from 0 with len=10 and C from 5 with len=10) + * + * less important stuff + * o check if "moving away" works for whole notes + * o use bars instead of flags over groups of 8ths / 16ths etc + * o (change ItemList into map< pos_t , mutable_stuff_t >) [no] + * + * stuff for the other muse developers + * o check if dragging notes works correctly (the pianoroll seems to be not informed :/ ) + * o process key from muse's event list (has to be implemented first in muse) + * o process accurate timesignatures from muse's list (has to be implemented first in muse) + * ( (2+2+3)/4 or (3+2+2)/4 instead of 7/4 ) + */ diff --git a/muse2/muse/midiedit/scoreedit.h b/muse2/muse/midiedit/scoreedit.h index 340d8c02..fbda4579 100644 --- a/muse2/muse/midiedit/scoreedit.h +++ b/muse2/muse/midiedit/scoreedit.h @@ -26,11 +26,13 @@ #include #include #include +#include using std::set; using std::pair; using std::map; using std::list; +using std::vector; class MidiPart; class TimeLabel; @@ -404,7 +406,7 @@ class ScoreCanvas : public View note_pos_t note_pos_(int note, tonart_t key); note_pos_t note_pos (int note, tonart_t key, clef_t clef); int calc_len(int l, int d); - list parse_note_len(int len_ticks, bool allow_dots=true, bool allow_normal=true, int begin_tick=0); + list parse_note_len(int len_ticks, int begin_tick, vector& foo, bool allow_dots=true, bool allow_normal=true); void draw_tie (QPainter& p, int x1, int x4, int yo, bool up=true); ScoreItemList create_itemlist(ScoreEventList& eventlist); void process_itemlist(ScoreItemList& itemlist); @@ -467,5 +469,10 @@ class ScoreCanvas : public View ~ScoreCanvas(){}; }; + +int calc_measure_len(const list& nums, int denom); +vector create_emphasize_list(const list& nums, int denom); +vector create_emphasize_list(int num, int denom); + #endif -- cgit v1.2.3