2 tie-column.cc -- implement Tie_column
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "tie-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 *s)
27 if (s->get_parent (Y_AXIS)
28 && Tie_column::has_interface (s->get_parent (Y_AXIS)))
31 if (! Pointer_group_interface::count (me, "ties"))
33 dynamic_cast<Spanner*> (me)->set_bound (LEFT, Tie::head (s,LEFT));
34 dynamic_cast<Spanner*> (me)->set_bound (RIGHT, Tie::head (s,RIGHT));
36 s->set_parent (me, Y_AXIS);
37 Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), s);
38 s->add_dependency (me);
43 Tie_column::set_directions (Grob*me)
45 werner_directions (me);
49 tie_compare (Grob* const & s1,
52 return sign (Tie::get_position (s1) - Tie::get_position (s2));
59 In normal chord cases, the outer ties point outwards, and the
60 direction of the rest is determined by their staff position.
62 Ross forgets about the tie that is *on* the middle staff line. We
63 assume it goes UP. (TODO: make me settable) */
65 Tie_column::old_directions (Grob*me)
67 Link_array<Grob> ties =
68 Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
70 for (int i = ties.size (); i--;)
71 if (get_grob_direction (ties[i]))
77 Direction d = get_grob_direction (me);
80 for (int i = ties.size (); i--;)
83 set_grob_direction (t, d);
88 if (ties.size () == 1)
91 set_grob_direction (t,Tie::get_default_dir (t));
95 ties.sort (tie_compare);
96 set_grob_direction (ties[0], DOWN);
99 set_grob_direction (ties.pop (), UP);
100 for (int i = ties.size (); i--;)
103 Real p = Tie::get_position (t);
104 Direction d = (Direction) sign (p);
107 set_grob_direction (t, d);
114 % . The algorithm to choose the direction of the ties doesn't work
115 % properly. I suggest the following for applying ties sequentially
116 % from top to bottom:
118 % + The topmost tie is always `up'.
120 % + If there is a vertical gap to the last note above larger than
121 % or equal to a fifth (or sixth?), the tie is `up', otherwise it
124 % + The bottommost tie is always `down'.
128 Tie_column::werner_directions (Grob *me)
130 Link_array<Grob> ties =
131 Pointer_group_interface__extract_grobs (me, (Grob*)0, "ties");
136 ties.sort (tie_compare);
138 Direction d = get_grob_direction (me);
141 for (int i = ties.size (); i--;)
144 if (!get_grob_direction (t))
145 set_grob_direction (t, d);
150 if (ties.size () == 1)
154 && !get_grob_direction (t))
155 set_grob_direction (t,Tie::get_default_dir (t));
159 Real last_down_pos = 10000;
160 if (!get_grob_direction (ties[0]))
161 set_grob_direction (ties[0], DOWN);
163 for (int i = ties.size (); i--;)
167 Direction d = get_grob_direction (t);
168 Real p = Tie::get_position (t);
171 if (last_down_pos - p > 5)
180 set_grob_direction (t, d);
191 MAKE_SCHEME_CALLBACK (Tie_column,after_line_breaking,1);
193 Tie_column::after_line_breaking (SCM smob)
195 werner_directions (unsmob_grob (smob));
196 return SCM_UNSPECIFIED;
201 ADD_INTERFACE (Tie_column,"tie-column-interface",
202 "Object that sets directions of multiple ties in a tied chord",