2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 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"
33 #include "semi-tie.hh"
35 #include "staff-symbol-referencer.hh"
37 #include "text-interface.hh"
38 #include "tie-column.hh"
39 #include "tie-configuration.hh"
40 #include "tie-formatting-problem.hh"
42 #include "semi-tie-column.hh"
45 Tie::less (Grob *g1, Grob *g2)
47 Spanner *s1 = dynamic_cast<Spanner *> (g1);
48 Spanner *s2 = dynamic_cast<Spanner *> (g2);
50 return get_position (s1) < get_position (s2);
53 programming_error ("grob is not a tie");
58 Tie::set_head (Spanner *me, Direction d, Grob *h)
64 Tie::head (Spanner *me, Direction d)
66 Item *it = me->get_bound (d);
67 return Note_head::has_interface (it) ? it : 0;
71 Tie::get_column_rank (Spanner *me, Direction d)
73 return Paper_column::get_rank (me->get_bound (d)->get_column ());
77 Tie::get_position (Spanner *me)
79 for (LEFT_and_RIGHT (d))
81 Grob *h = head (me, d);
83 return (int) rint (Staff_symbol_referencer::get_position (h));
87 TODO: this is theoretically possible for ties across more than 2
88 systems.. We should look at the first broken copy.
91 programming_error ("Tie without heads. Suicide");
97 Default: Put the tie oppositie of the stem [Wanske p231]
99 In case of chords: Tie_column takes over
101 The direction of the Tie is more complicated (See [Ross] p136 and
104 (what about linebreaks? )
107 Tie::get_default_dir (Spanner *me)
109 Drul_array<Grob *> stems;
110 for (LEFT_and_RIGHT (d))
112 Grob *one_head = head (me, d);
114 one_head = head (me->broken_neighbor (d), d);
116 Grob *stem = one_head ? Rhythmic_head::get_stem (one_head) : 0;
117 stems[d] = (stem && !Stem::is_invisible (stem)) ? stem : 0;
120 if (stems[LEFT] && stems[RIGHT])
122 if (get_grob_direction (stems[LEFT]) == UP
123 && get_grob_direction (stems[RIGHT]) == UP)
126 // And why not return UP if both stems are DOWN?
128 // And when stems conflict, why fall directly through to using
129 // neutral-direction without considering get_position (me)?
131 else if (stems[LEFT])
132 return -get_grob_direction (stems[LEFT]);
133 else if (stems[RIGHT])
134 return -get_grob_direction (stems[RIGHT]);
135 else if (int p = get_position (me))
136 return Direction (sign (p));
138 return to_dir (me->get_property ("neutral-direction"));
141 MAKE_SCHEME_CALLBACK (Tie, calc_direction, 1);
143 Tie::calc_direction (SCM smob)
145 // In this method, Tie and Semi_tie require the same logic with different
146 // types. It might be clearer to use a template.
147 Grob *me = unsmob<Grob> (smob);
148 Grob *yparent = me->get_parent (Y_AXIS);
149 if ((Tie_column::has_interface (yparent)
150 || Semi_tie_column::has_interface (yparent))
151 && unsmob<Grob_array> (yparent->get_object ("ties"))
152 // && unsmob<Grob_array> (yparent->get_object ("ties"))->size () > 1
155 /* trigger positioning. */
156 (void) yparent->get_property ("positioning-done");
158 return me->get_property_data ("direction");
161 programming_error ("no Tie_column or Semi_tie_column. Killing grob.");
163 return scm_from_int (CENTER);
167 Tie::get_default_control_points (Spanner *me)
170 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
171 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
173 Tie_formatting_problem problem;
174 problem.from_tie (me);
179 Ties_configuration conf
180 = problem.generate_optimal_configuration ();
182 return get_control_points (me, problem.common_x_refpoint (),
183 conf[0], problem.details_);
187 Tie::get_control_points (Grob *me,
189 Tie_configuration const &conf,
190 Tie_details const &details)
192 Bezier b = conf.get_transformed_bezier (details);
193 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
195 SCM controls = SCM_EOL;
196 for (int i = 4; i--;)
198 if (!b.control_[i].is_sane ())
199 programming_error ("Insane offset");
200 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
205 MAKE_SCHEME_CALLBACK (Tie, calc_control_points, 1);
207 Tie::calc_control_points (SCM smob)
209 Spanner *me = LY_ASSERT_SMOB(Spanner, smob, 1);
211 Grob *yparent = me->get_parent (Y_AXIS);
212 if ((Tie_column::has_interface (yparent)
213 || Semi_tie_column::has_interface (yparent))
214 && unsmob<Grob_array> (yparent->get_object ("ties")))
216 extract_grob_set (yparent, "ties", ties);
217 if (me->original () && ties.size () == 1
218 && !to_dir (me->get_property_data ("direction")))
220 assert (ties[0] == me);
221 set_grob_direction (me, Tie::get_default_dir (me));
223 /* trigger positioning. */
224 (void) yparent->get_property ("positioning-done");
227 SCM cp = me->get_property_data ("control-points");
228 if (!scm_is_pair (cp))
229 cp = get_default_control_points (me);
235 TODO: merge with Slur::print.
237 MAKE_SCHEME_CALLBACK (Tie, print, 1);
239 Tie::print (SCM smob)
241 Grob *me = unsmob<Grob> (smob);
243 SCM cp = me->get_property ("control-points");
245 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
246 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
247 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
251 for (SCM s = cp; scm_is_pair (s); s = scm_cdr (s))
253 b.control_[i] = ly_scm2offset (scm_car (s));
259 SCM dash_definition = me->get_property ("dash-definition");
261 get_grob_direction (me) * base_thick,
265 #if DEBUG_TIE_SCORING
266 SCM annotation = me->get_property ("annotation");
267 if (scm_is_string (annotation))
270 SCM properties = Font_interface::text_font_alist_chain (me);
272 Stencil tm = *unsmob<Stencil> (Text_interface::interpret_markup
273 (me->layout ()->self_scm (), properties,
275 tm.translate (Offset (b.control_[3][X_AXIS] + 0.5,
276 b.control_[0][Y_AXIS] * 2));
277 tm = tm.in_color (1, 0, 0);
280 It would be nice if we could put this in a different layer,
281 but alas, this must be done with a Tie override.
287 return a.smobbed_copy ();
291 "A tie - a horizontal curve connecting two noteheads.\n"
293 "The following properties may be set in the @code{details}"
297 "@item height-limit\n"
298 "The maximum height allowed for this tie.\n"
300 "Parameter for tie shape. The higher this number, the"
301 " quicker the slur attains its height-limit.\n"
302 "@item between-length-limit\n"
303 "This detail is currently unused.\n"
304 "@item wrong-direction-offset-penalty\n"
305 "Demerit for ties that are offset in the wrong"
308 "If the tie is shorter than this amount (in"
309 " staff-spaces) an increasingly large length penalty is"
311 "@item min-length-penalty-factor\n"
312 "Demerit factor for tie lengths shorter than"
313 " @code{min-length}.\n"
314 "@item center-staff-line-clearance\n"
315 "If the center of the tie is closer to a staff line"
316 " than this amount, an increasingly large staff line"
317 " collision penalty is incurred.\n"
318 "@item tip-staff-line-clearance\n"
319 "If the tips of the tie are closer to a staff line"
320 " than this amount, an increasingly large staff line"
321 " collision penalty is incurred.\n"
322 "@item staff-line-collision-penalty\n"
323 "Demerit factor for ties whose tips or center come"
324 " close to staff lines.\n"
325 "@item dot-collision-clearance\n"
326 "If the tie comes closer to a dot than this amount, an"
327 " increasingly large dot collision penalty is incurred.\n"
328 "@item dot-collision-penalty\n"
329 "Demerit factor for ties which come close to dots.\n"
330 "@item note-head-gap\n"
331 "The distance (in staff-spaces) by which the ends of"
332 " the tie are offset horizontally from the center"
333 " line through the note head.\n"
335 "The distance (in staff-spaces) by which the ends of"
336 " the tie are offset horizontally from a stem which"
337 " is on the same side of the note head as the tie.\n"
338 "@item tie-column-monotonicity-penalty\n"
339 "Demerit if the y-position of this tie in the set of"
340 " ties being considered is less than the y-position"
341 " of the previous tie.\n"
342 "@item tie-tie-collision-distance\n"
343 "If this tie is closer than this amount to the previous"
344 " tie in the set being considered, an increasingly"
345 " large tie-tie collision penalty is incurred.\n"
346 "@item tie-tie-collision-penalty\n"
347 "Demerit factor for a tie in the set being considered"
348 " which is close to the previous one.\n"
349 "@item horizontal-distance-penalty-factor\n"
350 "Demerit factor for ties in the set being considered"
351 " which are horizontally distant from the note heads.\n"
352 "@item vertical-distance-penalty-factor\n"
353 "Demerit factor for ties in the set being considered"
354 " which are vertically distant from the note heads.\n"
355 "@item same-dir-as-stem-penalty\n"
356 "Demerit if tie is on the same side as a stem or on the"
357 " opposite side to the one specified.\n"
358 "@item intra-space-threshold\n"
359 "If the tie's height (in half staff-spaces) is less than"
360 " this it is positioned between two adjacent staff"
361 " lines; otherwise it is positioned to straddle a staff"
362 " line further from the note heads.\n"
363 "@item outer-tie-length-symmetry-penalty-factor\n"
364 "Demerit factor for ties horizontally positioned"
365 " unsymmetrically with respect to the two note heads.\n"
366 "@item outer-tie-vertical-distance-symmetry-penalty-factor\n"
367 "Demerit factor for ties vertically positioned"
368 " unsymmetrically with respect to the two note heads.\n"
369 "@item outer-tie-vertical-gap\n"
370 "Amount (in half staff-spaces) by which a tie is moved"
371 " away from the note heads if it is closer to either"
372 " of them than 0.25 half staff-spaces.\n"
373 "@item skyline-padding\n"
374 "Padding of the skylines around note heads in chords.\n"
375 "@item single-tie-region-size\n"
376 "The number of candidate ties to generate when only a"
377 " single tie is required. Successive candidates differ"
378 " in their initial vertical position by half a"
380 "@item multi-tie-region-size\n"
381 "The number of variations that are tried for the"
382 " extremal ties in a chord. Variations differ in their"
383 " initial vertical position by half a staff-space.\n"
389 "avoid-slur " // UGH.