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>
10 #include "tie-column.hh"
11 #include "paper-column.hh"
13 #include "group-interface.hh"
15 #include "directional-element-interface.hh"
16 #include "rhythmic-head.hh"
19 tie dir depends on what Tie_column does.
22 TODO: this doesn't follow standard pattern. Regularize.
25 Tie_column::add_tie (Grob*me, Grob *tie)
27 if (tie->get_parent (Y_AXIS)
28 && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
32 if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
34 dynamic_cast<Spanner*> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
35 dynamic_cast<Spanner*> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
39 tie->set_parent (me, Y_AXIS);
40 Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
41 tie->add_dependency (me);
45 Tie_column::set_directions (Grob*me)
47 werner_directions (me);
51 tie_compare (Grob* const & s1,
54 return sign (Tie::get_position (s1) - Tie::get_position (s2));
60 . The algorithm to choose the direction of the ties doesn't work
61 properly. I suggest the following for applying ties sequentially
64 + The topmost tie is always `up'.
66 + If there is a vertical gap to the last note above larger than
67 or equal to a fifth (or sixth?), the tie is `up', otherwise it
70 + The bottommost tie is always `down'.
74 Tie_column::werner_directions (Grob *me)
76 Link_array<Grob> ties =
77 extract_grob_array (me, ly_symbol2scm ("ties"));
82 ties.sort (tie_compare);
84 Direction d = get_grob_direction (me);
87 for (int i = ties.size (); i--;)
90 if (!get_grob_direction (t))
91 set_grob_direction (t, d);
96 if (ties.size () == 1)
100 && !get_grob_direction (t))
101 set_grob_direction (t, Tie::get_default_dir (t));
105 Real last_down_pos = 10000;
106 if (!get_grob_direction (ties[0]))
107 set_grob_direction (ties[0], DOWN);
113 for (int i = ties.size (); i--;)
117 Direction d = get_grob_direction (t);
118 Real p = Tie::get_position (t);
122 && Tie::get_column_rank (t, LEFT)
123 < Tie::get_column_rank (last_tie, LEFT))
127 else if (last_down_pos - p > 5)
136 set_grob_direction (t, d);
149 MAKE_SCHEME_CALLBACK (Tie_column, after_line_breaking, 1);
151 Tie_column::after_line_breaking (SCM smob)
153 werner_directions (unsmob_grob (smob));
154 return SCM_UNSPECIFIED;
158 Extend the spanner over its Tie constituents.
160 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
162 Tie_column::before_line_breaking (SCM smob)
164 Spanner *me = dynamic_cast<Spanner*> (unsmob_grob (smob));
165 for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
167 Spanner *tie = dynamic_cast<Spanner*> (unsmob_grob (scm_car (s)));
168 Direction dir = LEFT;
171 if (dir * Paper_column::get_rank (tie->get_bound (dir)->get_column ())
172 > dir * Paper_column::get_rank (me->get_bound (dir)->get_column ()))
174 me->set_bound (dir, Tie::head (tie, dir));
177 while (flip (&dir) != LEFT);
179 return SCM_UNSPECIFIED;
182 ADD_INTERFACE (Tie_column, "tie-column-interface",
183 "Object that sets directions of multiple ties in a tied chord",