2 tie-column.cc -- implement Tie_column
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "tie-column.hh"
12 #include "group-interface.hh"
14 #include "directional-element-interface.hh"
15 #include "rhythmic-head.hh"
23 tie dir depends on what Tie_column does.
27 Tie_column::add_tie (Grob*me,Grob *s)
29 if (s->get_parent (Y_AXIS)
30 && Tie_column::has_interface (s->get_parent (Y_AXIS)))
33 if (! Pointer_group_interface::count (me, "ties"))
35 dynamic_cast<Spanner*> (me)->set_bound (LEFT, Tie::head (s,LEFT));
36 dynamic_cast<Spanner*> (me)->set_bound (RIGHT, Tie::head (s,RIGHT));
38 s->set_parent (me, Y_AXIS);
39 Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), s);
40 s->add_dependency (me);
45 Tie_column::set_directions (Grob*me)
47 werner_directions (me);
53 tie_compare (Grob* const & s1,
56 return sign (Tie::get_position (s1) - Tie::get_position (s2));
63 In normal chord cases, the outer ties point outwards, and the
64 direction of the rest is determined by their staff position.
66 Ross forgets about the tie that is *on* the middle staff line. We
67 assume it goes UP. (TODO: make me settable) */
69 Tie_column::old_directions (Grob*me)
71 Link_array<Grob> ties =
72 Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
74 for (int i = ties.size (); i--;)
75 if (get_grob_direction (ties[i]))
83 Direction d = get_grob_direction (me);
86 for (int i = ties.size (); i--;)
89 set_grob_direction (t, d);
94 if (ties.size () == 1)
97 set_grob_direction (t,Tie::get_default_dir (t));
101 ties.sort (tie_compare);
102 set_grob_direction (ties[0], DOWN);
105 set_grob_direction (ties.pop (), UP);
106 for (int i=ties.size (); i--;)
109 Real p = Tie::get_position (t);
110 Direction d = (Direction) sign (p);
113 set_grob_direction (t, d);
120 % . The algorithm to choose the direction of the ties doesn't work
121 % properly. I suggest the following for applying ties sequentially
122 % from top to bottom:
124 % + The topmost tie is always `up'.
126 % + If there is a vertical gap to the last note above larger than
127 % or equal to a fifth (or sixth?), the tie is `up', otherwise it
130 % + The bottommost tie is always `down'.
134 Tie_column::werner_directions (Grob *me)
136 Link_array<Grob> ties =
137 Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
142 ties.sort (tie_compare);
144 Direction d = get_grob_direction (me);
147 for (int i = ties.size (); i--;)
150 if (!get_grob_direction (t))
151 set_grob_direction (t, d);
156 if (ties.size () == 1)
159 set_grob_direction (t,Tie::get_default_dir (t));
163 Real last_down_pos = 10000;
164 if (!get_grob_direction (ties[0]))
165 set_grob_direction (ties[0], DOWN);
167 for (int i = ties.size (); i--;)
171 Direction d = get_grob_direction (t);
172 Real p = Tie::get_position (t);
175 if (last_down_pos - p > 5)
184 set_grob_direction (t, d);
195 MAKE_SCHEME_CALLBACK (Tie_column,after_line_breaking,1);
197 Tie_column::after_line_breaking (SCM smob)
199 werner_directions (unsmob_grob (smob));
200 return SCM_UNSPECIFIED;
205 ADD_INTERFACE (Tie_column,"tie-column-interface",
206 "that sets tie directions in a tied chord",