X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fslur.cc;h=3e8cbdfe26d5eb40667d4bd5a07fc1bb4297f792;hb=472c212541034e95c30f5a1a6bc99d7f36f15b68;hp=7ad52ce6d2e1e43fe834f8f2ac2d653c89984e62;hpb=234697355e387e3349018823d259c35f4ee49713;p=lilypond.git diff --git a/lily/slur.cc b/lily/slur.cc index 7ad52ce6d2..3e8cbdfe26 100644 --- a/lily/slur.cc +++ b/lily/slur.cc @@ -4,14 +4,16 @@ source file of the GNU LilyPond music typesetter (c) 1996, 1997 Han-Wen Nienhuys + Jan Nieuwenhuizen */ /* - TODO: - - think about crossing stems. - Begin and end should be treated as a Script. + [TODO] + * begin and end should be treated as a Script. + * damping + * slur from notehead to stemend: c''()b'' */ + #include "slur.hh" #include "scalar.hh" #include "lookup.hh" @@ -24,6 +26,13 @@ #include "boxes.hh" #include "bezier.hh" +//IMPLEMENT_IS_TYPE_B1(Slur,Spanner); +IMPLEMENT_IS_TYPE_B1(Slur,Bow); + +Slur::Slur () +{ +} + void Slur::add (Note_column*n) { @@ -111,138 +120,119 @@ Slur::do_post_processing () do { - if (extrema[d] != spanned_drul_[d]) + if (extrema[d] != spanned_drul_[d]) { dx_f_drul_[d] = -d *(spanned_drul_[d]->width ().length () -0.5*nw_f); + Direction u = d; + flip(&u); + if ((extrema[u] == spanned_drul_[u]) && extrema[u]->stem_l_) + { + dy_f_drul_[d] = extrema[u]->stem_l_->height ()[dir_]; + dy_f_drul_[u] = extrema[u]->stem_l_->height ()[dir_]; + } } else if (extrema[d]->stem_l_ && !extrema[d]->stem_l_->transparent_b_) { dy_f_drul_[d] = (int)rint (extrema[d]->stem_l_->height ()[dir_]); - /* normal slur from notehead centre to notehead centre, minus gap */ - dx_f_drul_[d] += -d * gap_f; + dx_f_drul_[d] += 0.5 * nw_f - d * gap_f; + if (dir_ == extrema[d]->stem_l_->dir_) + { + if (dir_ == d) + dx_f_drul_[d] += 0.5 * (dir_ * d) * d * nw_f; + else + dx_f_drul_[d] += 0.25 * (dir_ * d) * d * nw_f; + } } else { - dy_f_drul_[d] = (int)rint (extrema[d]->head_positions_interval ()[dir_])* inter_f; + dy_f_drul_[d] = (int)rint (extrema[d]->head_positions_interval () + [dir_])* inter_f; } dy_f_drul_[d] += dir_ * interline_f; } while (flip(&d) != LEFT); } -static Real -pos_correct (Real x, Real dx, Real dy) -{ - /* - guess how much we can safely increase 'h' - parameter of bow without taking too large - or too many steps. - empiric computer science - */ -// return (1.0 + 2.0 * x / dx) / 4.0; - return 1.0; -} - -Real -Slur::height_f () const +Array +Slur::get_encompass_offset_arr () const { - return 0.0; - Real interline = paper ()->interline_f (); Real notewidth = paper ()->note_width (); Real internote = interline / 2; - /* - having the correct (i.e. exactly the same as the ps stuff) - x,y coordinates is essential. - getting them is quite a mess, currently. - */ - - Stem* left_stem =encompass_arr_[0]->stem_l_; + Stem* left_stem = encompass_arr_[0]->stem_l_; Real left_x = left_stem->hpos_f (); - // ugh, do bow corrections (see brew_mol) - left_x += dx_f_drul_[LEFT] + 0.5 * notewidth; - -// Real left_y = left_stem->dir_ == dir_ ? left_stem->stem_end_f () + dir_ -// : left_stem->stem_begin_f () + 0.5 * dir_; -// left_y *= internote; - // ugh, do bow corrections (see brew_mol) -// left_y = dy_f_drul_[LEFT]; + left_x += dx_f_drul_[LEFT]; - // ugh, do bow corrections (see brew_mol) Real left_y = dy_f_drul_[LEFT]; - // ugh, where does this asymmetry come from? - if (dir_ == DOWN) - left_y -= dir_ * internote; - Real dx = width ().length (); - Real dy = (dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]); - Real centre_x = dx / 2; - + dx += (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]); + dx = dx ? 2 * interline; - // ugh, need staffheight for bow damping - Bezier_bow b (paper ()); + Real dy = (dy_f_drul_[RIGHT] - dy_f_drul_[LEFT]); + if (abs (dy) > 1000) + dy = sign (dy) * 1000; - if (check_debug && !monitor->silent_b ("Slur")) + int first = 1; + int last = encompass_arr_.size () - 1; + if (encompass_arr_[0] != spanned_drul_[LEFT]) { - cout << "*****************" << endl; - cout << "dir: " << (int)dir_ << endl; - cout << "dx: " << dx << endl; - cout << "dy: " << dy << endl; - cout << "centre: " << centre_x << endl; - for (int i = 0; i < encompass_arr_.size (); i++) - cout << "i: " << i << " x: " - << encompass_arr_[i]->stem_l_->hpos_f () - left_x << endl; + first = 0; + left_x = spanned_drul_[LEFT]->width ().length (); + left_x -= 2 * notewidth; +// left_y = 0; + Stem* stem = encompass_arr_[last]->stem_l_; + left_y = stem->dir_ == dir_ ? stem->stem_end_f () + : stem->stem_begin_f () + 0.5 * dir_; + dy = 0; } - Real height = 0; - Real dh = 0; - do + if (encompass_arr_.top () != spanned_drul_[RIGHT]) { - height += dh; - dh = 0; - b.calc (dx, dy, height, dir_); - - if (check_debug && !monitor->silent_b ("Slur")) - cout << "----" << endl; - for (int i = 1; i < encompass_arr_.size () - 1; i++) - { - Stem* stem = encompass_arr_[i]->stem_l_; - /* - set x to middle of notehead or on exact x position of stem, - according to slur direction - */ - Real x = stem->hpos_f () - left_x + notewidth / 2; - if (stem->dir_ != dir_) - x += notewidth / 2; - else if (stem->dir_ == UP) - x += notewidth; - Real y = stem->dir_ == dir_ ? stem->stem_end_f () - : stem->stem_begin_f () + 1.5 * dir_; - - /* - leave a gap: slur mustn't touch head/stem + last += 1; + dy = 0; + } + + Array notes; + notes.push (Offset (0,0)); + for (int i = first; i < last; i++) + { + Stem* stem = encompass_arr_[i]->stem_l_; + /* + set x to middle of notehead or on exact x position of stem, + according to slur direction */ - y += 2.5 * dir_; - y *= internote; - y -= left_y; + Real x = stem->hpos_f (); - Real shift = dir_ * (y - b.y (x)); + if (stem->dir_ != dir_) + x += 0.5 * notewidth; + else if (stem->dir_ == UP) + x += 1.0 * notewidth; - if (check_debug && !monitor->silent_b ("Slur")) - { - cout << "x: " << x << " (" << abs (centre_x - x) << ")" << endl; - cout << "y: " << y << ", curve: " << b.y (x) << endl; - cout << "shift: " << shift << endl; - } + x -= left_x; - if (shift > 0.1 * internote) - dh = dh >? shift * pos_correct (abs (centre_x - x), dx, dy); - } - } while (dh); + Real y = stem->dir_ == dir_ ? stem->stem_end_f () + : stem->stem_begin_f () + 0.5 * dir_; + + /* + leave a gap: slur mustn't touch head/stem + */ + y += 2.5 * dir_; + + // ugh: huh? + if (dir_ == DOWN) + y += 1.5 * dir_; + + y *= internote; + y -= left_y; + + notes.push (Offset (x, y)); + } + + notes.push (Offset (dx, dy)); - return height; + return notes; } -IMPLEMENT_IS_TYPE_B1(Slur,Spanner);