2 tie-column.cc -- implement Tie_column
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "tie-column.hh"
10 #include "paper-column.hh"
12 #include "pointer-group-interface.hh"
14 #include "directional-element-interface.hh"
15 #include "rhythmic-head.hh"
18 tie dir depends on what Tie_column does.
21 TODO: this doesn't follow standard pattern. Regularize.
24 Tie_column::add_tie (Grob *me, Grob *tie)
26 if (tie->get_parent (Y_AXIS)
27 && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
30 if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
32 dynamic_cast<Spanner *> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
33 dynamic_cast<Spanner *> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
36 tie->set_parent (me, Y_AXIS);
37 Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
38 tie->add_dependency (me);
42 Tie_column::set_directions (Grob *me)
44 werner_directions (me);
48 tie_compare (Grob *const &s1,
51 return sign (Tie::get_position (s1) - Tie::get_position (s2));
57 . The algorithm to choose the direction of the ties doesn't work
58 properly. I suggest the following for applying ties sequentially
61 + The topmost tie is always `up'.
63 + If there is a vertical gap to the last note above larger than
64 or equal to a fifth (or sixth?), the tie is `up', otherwise it
67 + The bottommost tie is always `down'.
70 Tie_column::werner_directions (Grob *me)
72 extract_grob_set (me, "ties", ro_ties);
73 Link_array<Grob> ties (ro_ties);
77 ties.sort (tie_compare);
79 Direction d = get_grob_direction (me);
82 for (int i = ties.size (); i--;)
85 if (!get_grob_direction (t))
86 set_grob_direction (t, d);
91 if (ties.size () == 1)
95 && !get_grob_direction (t))
96 set_grob_direction (t, Tie::get_default_dir (t));
100 Real last_down_pos = 10000;
101 if (!get_grob_direction (ties[0]))
102 set_grob_direction (ties[0], DOWN);
108 for (int i = ties.size (); i--;)
112 Direction d = get_grob_direction (t);
113 Real p = Tie::get_position (t);
117 && Tie::get_column_rank (t, LEFT)
118 < Tie::get_column_rank (last_tie, LEFT))
120 else if (last_down_pos - p > 5)
125 set_grob_direction (t, d);
137 MAKE_SCHEME_CALLBACK (Tie_column, after_line_breaking, 1);
139 Tie_column::after_line_breaking (SCM smob)
141 werner_directions (unsmob_grob (smob));
142 return SCM_UNSPECIFIED;
146 Extend the spanner over its Tie constituents.
148 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
150 Tie_column::before_line_breaking (SCM smob)
152 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
153 for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
155 Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
156 Direction dir = LEFT;
159 if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
160 > dir * me->get_bound (dir)->get_column ()->get_rank ())
161 me->set_bound (dir, Tie::head (tie, dir));
163 while (flip (&dir) != LEFT);
165 return SCM_UNSPECIFIED;
168 ADD_INTERFACE (Tie_column, "tie-column-interface",
169 "Object that sets directions of multiple ties in a tied chord",