From 51eda45715625b6da768e670388510c91b01ff5c Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 11 Apr 2011 12:41:47 +0000 Subject: fixed division bug by adding divide_floor() function previously, integer divisions were used. however, i need rounding always down, but operator/ rounds towards zero. ( -2 / 7 = 0, but should be -1) plus some cosmetic stuff (ints->unsigneds, removed some warnings) --- muse2/muse/midiedit/scoreedit.cpp | 72 ++++++++++++++++++++++++++++++--------- muse2/muse/midiedit/scoreedit.h | 8 +++-- 2 files changed, 61 insertions(+), 19 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index 62250bea..a796d862 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -178,7 +178,7 @@ void ScoreCanvas::song_changed(int) { cout << "song changed!" << endl; pos_add_list.clear(); - eventlist=createAppropriateEventList(editor->parts()); + eventlist=create_appropriate_eventlist(editor->parts()); itemlist=create_itemlist(eventlist); process_itemlist(itemlist); // do note- and rest-grouping and collision avoiding calc_item_pos(itemlist); @@ -281,6 +281,11 @@ int modulo(int a, int b) // similar to a % b return (((a%b)+b)%b); } +int divide_floor(int a, int b) // similar to a / b +{ //TODO can be done better :/ + return int(floor(float(a)/float(b))); +} + #define DEFAULT_REST_HEIGHT 6 // TODO @@ -330,7 +335,7 @@ int flo_quantize_floor(int tick) return int(tick / FLO_QUANT) * FLO_QUANT; } -ScoreEventList ScoreCanvas::createAppropriateEventList(PartList* pl) +ScoreEventList ScoreCanvas::create_appropriate_eventlist(PartList* pl) { using AL::sigmap; using AL::iSigEvent; @@ -502,9 +507,9 @@ note_pos_t ScoreCanvas::note_pos_(int note, tonart_t key) // in violin clef, line 2 is E4 // in bass clef, line 2 is G2 -note_pos_t ScoreCanvas::note_pos (int note, tonart_t key, clef_t clef) +note_pos_t ScoreCanvas::note_pos (unsigned note, tonart_t key, clef_t clef) { - int octave=(note/12)-1; //integer division + int octave=(note/12)-1; //integer division. note is unsigned note=note%12; //now octave contains the octave the note is in @@ -536,7 +541,7 @@ int ScoreCanvas::calc_len(int l, int d) int tmp=0; for (int i=0;i<=d;i++) - tmp+=TICKS_PER_WHOLE / pow(2, l+i); + tmp+=TICKS_PER_WHOLE / (1 << (l+i)); return tmp; } @@ -631,6 +636,11 @@ list ScoreCanvas::parse_note_len(int len_ticks, int begin_tick, vect { list retval; + if (len_ticks<0) + cout << "WARNING: ILLEGAL FUNCTION CALL in parse_note_len: len_ticks < 0" << endl; + if (begin_tick<0) + cout << "WARNING: ILLEGAL FUNCTION CALL in parse_note_len: begin_tick < 0" << endl; + if (allow_normal) { int dot_max = allow_dots ? quant_max : 0; @@ -649,7 +659,7 @@ list ScoreCanvas::parse_note_len(int len_ticks, int begin_tick, vect int begin=begin_tick * 64 / TICKS_PER_WHOLE; int len=len_ticks * 64 / TICKS_PER_WHOLE; - int pos=begin; + unsigned pos=begin; int len_done=0; while (len_done 1,2,3,4" or "display per-track in existing..." + * + * ScoreCanvas has a list of note systems, consisting of the following: + * * all parts included in that view + * * eventlist, itemlist + * * used clef, transposing/octave settings + * * enum { NOT_GROUPED, I_AM_TOP, I_AM_BOTTOM } group_state + * NOT_GROUPED means "single note system" + * I_AM_TOP and I_AM_BOTTOM mean that the two systems belong + * together + * + * when redrawing, we iterate through all systems. + * we add a distance according to group_state + * then we draw the system. if group_state is I_AM_BOTTOM, we + * draw our beams longer/higher, and we draw a bracket + * + * when clicking around, we first determine which system has been clicked in + * (the systems have enough space in between, so there won't be notes + * from sys1 in sys2. if there are, they're ignored for simplicity) + * then we proceed as usual (adding, removing, changing notes) + */ + diff --git a/muse2/muse/midiedit/scoreedit.h b/muse2/muse/midiedit/scoreedit.h index 3542a529..2d301d92 100644 --- a/muse2/muse/midiedit/scoreedit.h +++ b/muse2/muse/midiedit/scoreedit.h @@ -1,7 +1,7 @@ //========================================================= // MusE // Linux Music Editor -// scoreedit.cpp +// scoreedit.h // (C) Copyright 2011 Florian Jung (florian.a.jung@web.de) //========================================================= @@ -420,9 +420,9 @@ class ScoreCanvas : public View Q_OBJECT private: void load_pixmaps(); - ScoreEventList createAppropriateEventList(PartList* pl); + ScoreEventList create_appropriate_eventlist(PartList* pl); note_pos_t note_pos_(int note, tonart_t key); - note_pos_t note_pos (int note, tonart_t key, clef_t clef); + note_pos_t note_pos (unsigned note, tonart_t key, clef_t clef); int calc_len(int l, int d); 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, QColor color=Qt::black); @@ -483,6 +483,8 @@ class ScoreCanvas : public View // will be drawn exactly at the left beginning of the item's area // x_left could also be called "preamble's width". it defines // where the item's area begins + // when multiple note systems are drawn into one window, the + // preamble's length is the same for each system int x_pos; int x_left; -- cgit v1.2.3