2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
24 #include "directional-element-interface.hh"
25 #include "font-interface.hh"
26 #include "grob-array.hh"
28 #include "note-head.hh"
29 #include "output-def.hh"
30 #include "paper-column.hh"
31 #include "pointer-group-interface.hh"
32 #include "rhythmic-head.hh"
34 #include "staff-symbol-referencer.hh"
36 #include "text-interface.hh"
37 #include "tie-column.hh"
38 #include "tie-configuration.hh"
39 #include "tie-formatting-problem.hh"
41 #include "semi-tie-column.hh"
44 Tie::less (Grob *const &s1, Grob *const &s2)
46 return Tie::get_position (s1) < Tie::get_position (s2);
50 Tie::set_head (Grob *me, Direction d, Grob *h)
52 dynamic_cast<Spanner *> (me)->set_bound (d, h);
56 Tie::head (Grob *me, Direction d)
58 if (is_direction (me->get_property ("head-direction")))
60 Direction hd = to_dir (me->get_property ("head-direction"));
63 ? unsmob_grob (me->get_object ("note-head"))
67 Item *it = dynamic_cast<Spanner *> (me)->get_bound (d);
68 if (Note_head::has_interface (it))
75 Tie::get_column_rank (Grob *me, Direction d)
78 Spanner *span = dynamic_cast<Spanner *> (me);
80 col = dynamic_cast<Item *> (me)->get_column ();
83 Grob *h = head (me, d);
85 h = span->get_bound (d);
87 col = dynamic_cast<Item *> (h)->get_column ();
89 return Paper_column::get_rank (col);
93 Tie::get_position (Grob *me)
95 for (LEFT_and_RIGHT (d))
97 Grob *h = head (me, d);
99 return (int) rint (Staff_symbol_referencer::get_position (h));
103 TODO: this is theoretically possible for ties across more than 2
104 systems.. We should look at the first broken copy.
107 programming_error ("Tie without heads. Suicide");
113 Default: Put the tie oppositie of the stem [Wanske p231]
115 In case of chords: Tie_column takes over
117 The direction of the Tie is more complicated (See [Ross] p136 and
120 (what about linebreaks? )
123 Tie::get_default_dir (Grob *me)
125 Drul_array<Grob *> stems;
126 for (LEFT_and_RIGHT (d))
128 Grob *one_head = head (me, d);
129 if (!one_head && dynamic_cast<Spanner *> (me))
130 one_head = Tie::head (dynamic_cast<Spanner *> (me)->broken_neighbor (d), d);
132 Grob *stem = one_head ? Rhythmic_head::get_stem (one_head) : 0;
134 stem = Stem::is_invisible (stem) ? 0 : stem;
139 if (stems[LEFT] && stems[RIGHT])
141 if (get_grob_direction (stems[LEFT]) == UP
142 && get_grob_direction (stems[RIGHT]) == UP)
145 else if (stems[LEFT] || stems[RIGHT])
147 Grob *s = stems[LEFT] ? stems[LEFT] : stems[RIGHT];
148 return -get_grob_direction (s);
150 else if (int p = get_position (me))
151 return Direction (sign (p));
153 return to_dir (me->get_property ("neutral-direction"));
156 MAKE_SCHEME_CALLBACK (Tie, calc_direction, 1);
158 Tie::calc_direction (SCM smob)
160 Grob *me = unsmob_grob (smob);
161 Grob *yparent = me->get_parent (Y_AXIS);
162 if ((Tie_column::has_interface (yparent)
163 || Semi_tie_column::has_interface (yparent))
164 && unsmob_grob_array (yparent->get_object ("ties"))
165 // && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1
168 /* trigger positioning. */
169 (void) yparent->get_property ("positioning-done");
171 return me->get_property_data ("direction");
174 return scm_from_int (Tie::get_default_dir (me));
178 Tie::get_default_control_points (Grob *me_grob)
180 Spanner *me = dynamic_cast<Spanner *> (me_grob);
182 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
183 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
185 Tie_formatting_problem problem;
186 problem.from_tie (me);
191 Ties_configuration conf
192 = problem.generate_optimal_configuration ();
194 return get_control_points (me, problem.common_x_refpoint (),
195 conf[0], problem.details_);
199 Tie::get_control_points (Grob *me,
201 Tie_configuration const &conf,
202 Tie_details const &details)
204 Bezier b = conf.get_transformed_bezier (details);
205 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
207 SCM controls = SCM_EOL;
208 for (int i = 4; i--;)
210 if (!b.control_[i].is_sane ())
211 programming_error ("Insane offset");
212 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
217 MAKE_SCHEME_CALLBACK (Tie, calc_control_points, 1);
219 Tie::calc_control_points (SCM smob)
221 Grob *me = unsmob_grob (smob);
223 Grob *yparent = me->get_parent (Y_AXIS);
224 if ((Tie_column::has_interface (yparent)
225 || Semi_tie_column::has_interface (yparent))
226 && unsmob_grob_array (yparent->get_object ("ties")))
228 extract_grob_set (yparent, "ties", ties);
229 if (me->original () && ties.size () == 1
230 && !to_dir (me->get_property_data ("direction")))
232 assert (ties[0] == me);
233 set_grob_direction (me, Tie::get_default_dir (me));
235 /* trigger positioning. */
236 (void) yparent->get_property ("positioning-done");
239 SCM cp = me->get_property_data ("control-points");
240 if (!scm_is_pair (cp))
241 cp = get_default_control_points (me);
247 TODO: merge with Slur::print.
249 MAKE_SCHEME_CALLBACK (Tie, print, 1);
251 Tie::print (SCM smob)
253 Grob *me = unsmob_grob (smob);
255 SCM cp = me->get_property ("control-points");
257 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
258 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
259 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
263 for (SCM s = cp; scm_is_pair (s); s = scm_cdr (s))
265 b.control_[i] = ly_scm2offset (scm_car (s));
271 SCM dash_definition = me->get_property ("dash-definition");
273 get_grob_direction (me) * base_thick,
277 #if DEBUG_TIE_SCORING
278 SCM annotation = me->get_property ("annotation");
279 if (scm_is_string (annotation))
282 SCM properties = Font_interface::text_font_alist_chain (me);
284 Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
285 (me->layout ()->self_scm (), properties,
287 tm.translate (Offset (b.control_[3][X_AXIS] + 0.5,
288 b.control_[0][Y_AXIS] * 2));
289 tm = tm.in_color (1, 0, 0);
292 It would be nice if we could put this in a different layer,
293 but alas, this must be done with a Tie override.
299 return a.smobbed_copy ();
303 "A horizontal curve connecting two noteheads.",
307 "avoid-slur " // UGH.