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>
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.
26 TODO: this doesn't follow standard pattern. Regularize.
29 Tie_column::add_tie (Grob
*me
,Grob
*s
)
31 if (s
->get_parent (Y_AXIS
)
32 && Tie_column::has_interface (s
->get_parent (Y_AXIS
)))
35 if (! Pointer_group_interface::count (me
, "ties"))
37 dynamic_cast<Spanner
*> (me
)->set_bound (LEFT
, Tie::head (s
,LEFT
));
38 dynamic_cast<Spanner
*> (me
)->set_bound (RIGHT
, Tie::head (s
,RIGHT
));
40 s
->set_parent (me
, Y_AXIS
);
41 Pointer_group_interface::add_grob (me
, ly_symbol2scm ("ties"), s
);
42 s
->add_dependency (me
);
47 Tie_column::set_directions (Grob
*me
)
49 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
]))
81 Direction d
= get_grob_direction (me
);
84 for (int i
= ties
.size (); i
--;)
87 set_grob_direction (t
, d
);
92 if (ties
.size () == 1)
95 set_grob_direction (t
,Tie::get_default_dir (t
));
99 ties
.sort (tie_compare
);
100 set_grob_direction (ties
[0], DOWN
);
103 set_grob_direction (ties
.pop (), UP
);
104 for (int i
=ties
.size (); i
--;)
107 Real p
= Tie::get_position (t
);
108 Direction d
= (Direction
) sign (p
);
111 set_grob_direction (t
, d
);
118 % . The algorithm to choose the direction of the ties doesn't work
119 % properly. I suggest the following for applying ties sequentially
120 % from top to bottom:
122 % + The topmost tie is always `up'.
124 % + If there is a vertical gap to the last note above larger than
125 % or equal to a fifth (or sixth?), the tie is `up', otherwise it
128 % + The bottommost tie is always `down'.
132 Tie_column::werner_directions (Grob
*me
)
134 Link_array
<Grob
> ties
=
135 Pointer_group_interface__extract_grobs (me
, (Grob
*)0, "ties");
140 ties
.sort (tie_compare
);
142 Direction d
= get_grob_direction (me
);
145 for (int i
= ties
.size (); i
--;)
148 if (!get_grob_direction (t
))
149 set_grob_direction (t
, d
);
154 if (ties
.size () == 1)
158 && !get_grob_direction (t
))
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 "Object that sets directions of multiple ties in a tied chord",