X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftie.cc;h=d40b0c33694dfcbb9a23f4dc6429820759a113aa;hb=105fd7580334c8f42838ac62504c5f290f3428c5;hp=8773cf2c784f4ba34d308a008c6d63fda5de6e75;hpb=2873636a53f0011f837aaf6e2072de602730d957;p=lilypond.git diff --git a/lily/tie.cc b/lily/tie.cc index 8773cf2c78..d40b0c3369 100644 --- a/lily/tie.cc +++ b/lily/tie.cc @@ -3,195 +3,299 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1999 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ +#include +#include "spanner.hh" +#include "lookup.hh" #include "paper-def.hh" #include "tie.hh" -#include "note-head.hh" +#include "rhythmic-head.hh" +#include "bezier.hh" #include "paper-column.hh" #include "debug.hh" +#include "staff-symbol-referencer.hh" +#include "directional-element-interface.hh" +#include "molecule.hh" +#include "bezier-bow.hh" +#include "stem.hh" +#include "note-head.hh" + +/* + tie: Connect two noteheads. + + What if we have + + c4 ~ \clef bass ; c4 or + c4 \staffchange c4 + + do we have non-horizontal ties then? + */ void -Tie::set_head (Direction d, Note_head * head_l) +Tie::set_head (Score_element*me,Direction d, Item * head_l) { - assert (!head_l_drul_[d]); - head_l_drul_[d] = head_l; - set_bounds (d, head_l); - - add_dependency (head_l); + assert (!head (me,d)); + index_set_cell (me->get_elt_property ("heads"), d, head_l->self_scm ()); + + dynamic_cast (me)->set_bound (d, head_l); + me->add_dependency (head_l); } -Tie::Tie() +void +Tie::set_interface (Score_element*me) { - head_l_drul_[RIGHT] =0; - head_l_drul_[LEFT] =0; + me->set_elt_property ("heads", gh_cons (SCM_EOL, SCM_EOL)); + me->set_interface (ly_symbol2scm ("tie-interface")); } - -/* - ugh: direction of the Tie is more complicated. See [Ross] p136 and further - */ -Direction -Tie::get_default_dir () const +bool +Tie::has_interface (Score_element*me) { - int m = int (head_l_drul_[LEFT]->position_f () - + head_l_drul_[RIGHT]->position_f ()) /2; - - /* - If dir is not determined: inverse of stem: down - (see stem::get_default_dir ()) - */ - Direction neutral_dir = (Direction)(int)paper_l ()->get_var ("stem_default_neutral_direction"); - return (m == 0) ? other_dir (neutral_dir) : (m < 0) ? DOWN : UP; + return me->has_interface (ly_symbol2scm ("tie-interface")); } -void -Tie::do_add_processing() +Score_element* +Tie::head (Score_element*me, Direction d) { - if (!(head_l_drul_[LEFT] && head_l_drul_[RIGHT])) - warning (_ ("lonely tie")); - - Direction d = LEFT; - Drul_array new_head_drul = head_l_drul_; - do { - if (!head_l_drul_[d]) - new_head_drul[d] = head_l_drul_[(Direction)-d]; - } while (flip(&d) != LEFT); - head_l_drul_ = new_head_drul; + SCM c = me->get_elt_property ("heads"); + c = index_cell (c, d); + + return unsmob_element (c); } -void -Tie::do_post_processing() +Real +Tie::position_f (Score_element*me) { - assert (head_l_drul_[LEFT] || head_l_drul_[RIGHT]); + Direction d = head (me,LEFT) ? LEFT:RIGHT; + return Staff_symbol_referencer::position_f (head (me,d)); +} - Real interline_f = paper_l ()->get_var ("interline"); - Real internote_f = interline_f / 2; - Real x_gap_f = paper_l ()->get_var ("tie_x_gap"); - Real y_gap_f = paper_l ()->get_var ("tie_y_gap"); - /* - Slur and tie placement [OSU] +/* + Default: Put the tie oppositie of the stem [Wanske p231] - Ties: + In case of chords: Tie_column takes over + + The direction of the Tie is more complicated (See [Ross] p136 and + further). +*/ +Direction +Tie::get_default_dir (Score_element*me) +{ + Item * sl = head(me,LEFT) ? Rhythmic_head::stem_l (head (me,LEFT)) :0; + Item * sr = head(me,RIGHT) ? Rhythmic_head::stem_l (head (me,RIGHT)) :0; - * x = inner vertical tangent - d * gap + if (sl && sr) + { + if (Directional_element_interface::get (sl) == UP + && Directional_element_interface::get (sr) == UP) + return DOWN; + } + else if (sl || sr) + { + Item *s = sl ? sl : sr; + return - Directional_element_interface::get (s); + } - */ + + return UP; +} - /* - OSU: not different for outer notes, so why all this code? - ie, can we drop this, or should it be made switchable. - */ -#if 0 - Direction d = LEFT; - do +SCM +Tie::get_control_points (SCM smob) +{ + Spanner*me = dynamic_cast (unsmob_element (smob)); + Direction headdir = CENTER; + if (head (me,LEFT)) + headdir = LEFT; + else if (head(me,RIGHT)) + headdir = RIGHT; + else { - Real head_width_f = head_l_drul_[d] - ? head_l_drul_[d]->extent (X_AXIS).length () - : 0; - /* - side attached to outer (upper or lower) notehead of chord - */ - if (head_l_drul_[d] - /* + programming_error ("Tie without heads."); + me->suicide (); + return SCM_UNSPECIFIED; + } + + if (!Directional_element_interface::get (me)) + Directional_element_interface::set (me, Tie::get_default_dir (me)); + + Real staff_space = Staff_symbol_referencer::staff_space (me); - a~a~a; + Real x_gap_f = me->paper_l ()->get_var ("tie_x_gap"); - to second tie, middle notehead seems not extremal + Score_element* commonx = me->common_refpoint (me->get_bound (LEFT), X_AXIS); + commonx = me->common_refpoint (me->get_bound (RIGHT), X_AXIS); + + Score_element* l = me->get_bound (LEFT); + Score_element* r = me->get_bound (RIGHT); - Getting scared a bit by score-element's comment: - // is this a good idea? - */ - && (head_l_drul_[d]->get_elt_property ("extremal") - != SCM_UNDEFINED)) - { - if (d == LEFT) - dx_f_drul_[d] += head_width_f; - dx_f_drul_[d] += -d * x_gap_f; - } - /* - side attached to inner notehead - */ + Real left_x; + if (Note_head::has_interface (me->get_bound (LEFT))) + left_x = l->extent (X_AXIS)[RIGHT] + x_gap_f; + else + left_x = l->extent (X_AXIS).length () / 2; + + Real width; + if (Note_head::has_interface (me->get_bound (LEFT)) + && Note_head::has_interface (me->get_bound (RIGHT))) + { + width = r->relative_coordinate (commonx, X_AXIS) + + r->extent (X_AXIS)[LEFT] + - l->relative_coordinate (commonx, X_AXIS) + - l->extent (X_AXIS)[RIGHT] + -2 * x_gap_f; + } + else + { + if (Note_head::has_interface (me->get_bound (LEFT))) + width = r->relative_coordinate (commonx, X_AXIS) + - l->relative_coordinate (commonx, X_AXIS) + - l->extent (X_AXIS)[RIGHT] + - 2 * x_gap_f; else - { - dx_f_drul_[d] += -d * head_width_f; - } - } while (flip (&d) != LEFT); + width = r->relative_coordinate (commonx, X_AXIS) + - l->extent (X_AXIS).length () / 2 + + r->extent (X_AXIS)[LEFT] + - l->relative_coordinate (commonx, X_AXIS) + - 2 * x_gap_f; + } + + Direction dir = Directional_element_interface::get(me); + + Real h_inf = me->paper_l ()->get_var ("tie_height_limit_factor") * staff_space; + Real r_0 = me->paper_l ()->get_var ("tie_ratio"); -#else - if (head_l_drul_[LEFT]) - dx_f_drul_[LEFT] = head_l_drul_[LEFT]->extent (X_AXIS).length (); - else - dx_f_drul_[LEFT] = get_broken_left_end_align (); - dx_f_drul_[LEFT] += x_gap_f; - dx_f_drul_[RIGHT] -= x_gap_f; + Bezier b = slur_shape (width, h_inf, r_0); + + Offset leave_dir = b.control_[1] - b.control_[0]; -#endif + Real dx = (head (me, headdir)->extent (X_AXIS).length () + x_gap_f)/2.0; + Real max_gap = leave_dir[Y_AXIS] * dx / leave_dir[X_AXIS]; - /* - Slur and tie placement [OSU] -- check this + /* + for small ties (t small) we want to start in the Y-center (so dy = 0), for + large ties, the tie should appear to come from the center of the + head, so dy = max_gap - Ties: + maybe use a different formula? - * y = dx < 5ss: horizontal tangent - y = dx >= 5ss: y next interline - d * 0.25 ss + TODO: what if 2 heads have different size. - which probably means that OSU assumes that + TODO: for small ties, it is better to start over the heads + iso. next to the heads. + */ + Real t = (width / staff_space - 5.0); // ugh. + Real dy = t > 0 ? max_gap * sqr (t / (1 + t)) : 0.0; - dy <= 5 dx + Real ypos = Tie::position_f (me) * staff_space/2 + dir * dy; - for smal slurs + /* + todo: prevent ending / staffline collision. + + todo: tie / stem collision */ - Real ypos = head_l_drul_[LEFT] ? head_l_drul_[LEFT]->position_f () - : head_l_drul_[RIGHT]->position_f (); + b = slur_shape(width,h_inf, r_0); + b.scale (1, dir); + b.translate (Offset (left_x, ypos)); + + + /* + Avoid colliding of the horizontal part with stafflines. + + should do me for slurs as well. - Real y_f = internote_f * ypos; - int ypos_i = int (ypos); - - Real dx_f = extent (X_AXIS).length () + dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]; - if (dx_f < paper_l ()->get_var ("tie_staffspace_length")) + */ + Array horizontal (b.solve_derivative (Offset (1,0))); + if (horizontal.size ()) { - if (abs (ypos_i) % 2) - y_f += dir_ * internote_f; - y_f += dir_ * y_gap_f; + /* + ugh. Doesnt work for non-horizontal curves. + */ + Real y = b.curve_point (horizontal[0])[Y_AXIS]; + + Real ry = rint (y/staff_space) * staff_space; + Real diff = ry - y; + Real newy = y; + if (fabs (y) <= Staff_symbol_referencer::staff_radius (me) + && fabs (diff) < me->paper_l ()->get_var ("tie_staffline_clearance")) + { + newy = ry - 0.5 * staff_space * sign (diff) ; + } + + Real y0 = b.control_ [0][Y_AXIS]; + b.control_[2][Y_AXIS] = + b.control_[1][Y_AXIS] = + (b.control_[1][Y_AXIS] - y0) * ((newy - y0) / (y - y0)) + y0; } else - { - if (! (abs (ypos_i) % 2)) - y_f += dir_ * internote_f; - y_f += dir_ * internote_f; - y_f -= dir_ * y_gap_f; - } - - dy_f_drul_[LEFT] = dy_f_drul_[RIGHT] = y_f; -} + programming_error ("Tie is nowhere horizontal"); -void -Tie::do_substitute_element_pointer (Score_element*o, Score_element*n) -{ - Note_head *new_l = n ? dynamic_cast (n) : 0; - if (dynamic_cast (o) == head_l_drul_[LEFT]) - head_l_drul_[LEFT] = new_l; - else if (dynamic_cast (o) == head_l_drul_[RIGHT]) - head_l_drul_[RIGHT] = new_l; + + + SCM controls = SCM_EOL; + for (int i= 4; i--;) + controls = gh_cons ( ly_offset2scm (b.control_[i]), controls); + return controls; } +MAKE_SCHEME_CALLBACK(Tie,set_spacing_rods); -Array -Tie::get_rods () const +/* + TODO: set minimum distances for begin/end of line + */ +SCM +Tie::set_spacing_rods (SCM smob) { - Array a; + Score_element*me = unsmob_element (smob); + Spanner*sp = dynamic_cast (me); Rod r; - r.item_l_drul_ = spanned_drul_; - r.distance_f_ = paper_l ()->get_var ("tie_x_minimum"); - a.push (r); - return a; + + r.item_l_drul_ [LEFT]=sp->get_bound (LEFT); + r.item_l_drul_ [RIGHT]=sp->get_bound (RIGHT); + + r.distance_f_ + = gh_scm2double (me->get_elt_property ("minimum-length")) + * me->paper_l ()->get_var ("staffspace"); + r.add_to_cols (); + return SCM_UNSPECIFIED; } +MAKE_SCHEME_CALLBACK(Tie,brew_molecule); +SCM +Tie::brew_molecule (SCM smob) +{ + Score_element*me = unsmob_element (smob); + + SCM cp = me->get_elt_property ("control-points"); + if (cp == SCM_EOL) + { + cp = get_control_points (smob); + me->set_elt_property ("control-points", cp); + } + + Real thick = + gh_scm2double (me->get_elt_property ("thickness")) + * me->paper_l ()->get_var ("stafflinethickness"); + + Bezier b; + int i = 0; + for (SCM s= cp; s != SCM_EOL; s = gh_cdr (s)) + { + b.control_[i] = ly_scm2offset (gh_car (s)); + i++; + } + + Molecule a = me->lookup_l ()->slur (b, Directional_element_interface::get (me) * thick, thick); + + return a.create_scheme (); +} + +