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"
47 Tie::less (Grob *g1, Grob *g2)
49 Spanner *s1 = dynamic_cast<Spanner *> (g1);
52 g1->programming_error ("grob is not a tie");
56 Spanner *s2 = dynamic_cast<Spanner *> (g2);
59 g2->programming_error ("grob is not a tie");
63 return get_position (s1) < get_position (s2);
67 Tie::set_head (Spanner *me, Direction d, Grob *h)
73 Tie::head (Spanner *me, Direction d)
75 Item *it = me->get_bound (d);
76 return has_interface<Note_head> (it) ? it : 0;
80 Tie::get_column_rank (Spanner *me, Direction d)
82 return Paper_column::get_rank (me->get_bound (d)->get_column ());
86 Tie::get_position (Spanner *me)
88 for (LEFT_and_RIGHT (d))
90 Grob *h = head (me, d);
92 return (int) rint (Staff_symbol_referencer::get_position (h));
96 TODO: this is theoretically possible for ties across more than 2
97 systems.. We should look at the first broken copy.
100 programming_error ("Tie without heads. Suicide");
106 Default: Put the tie oppositie of the stem [Wanske p231]
108 In case of chords: Tie_column takes over
110 The direction of the Tie is more complicated (See [Ross] p136 and
113 (what about linebreaks? )
116 Tie::get_default_dir (Spanner *me)
118 Drul_array<Grob *> stems;
119 for (LEFT_and_RIGHT (d))
121 Grob *one_head = head (me, d);
123 one_head = head (me->broken_neighbor (d), d);
125 Grob *stem = one_head ? Rhythmic_head::get_stem (one_head) : 0;
126 stems[d] = (stem && !Stem::is_invisible (stem)) ? stem : 0;
129 if (stems[LEFT] && stems[RIGHT])
131 if (get_grob_direction (stems[LEFT]) == UP
132 && get_grob_direction (stems[RIGHT]) == UP)
135 // And why not return UP if both stems are DOWN?
137 // And when stems conflict, why fall directly through to using
138 // neutral-direction without considering get_position (me)?
140 else if (stems[LEFT])
141 return -get_grob_direction (stems[LEFT]);
142 else if (stems[RIGHT])
143 return -get_grob_direction (stems[RIGHT]);
144 else if (int p = get_position (me))
145 return Direction (sign (p));
147 return to_dir (me->get_property ("neutral-direction"));
150 MAKE_SCHEME_CALLBACK (Tie, calc_direction, 1);
152 Tie::calc_direction (SCM smob)
154 // In this method, Tie and Semi_tie require the same logic with different
155 // types. It might be clearer to use a template.
156 Grob *me = unsmob<Grob> (smob);
157 Grob *yparent = me->get_parent (Y_AXIS);
158 if ((has_interface<Tie_column> (yparent)
159 || has_interface<Semi_tie_column> (yparent))
160 && unsmob<Grob_array> (yparent->get_object ("ties"))
161 // && unsmob<Grob_array> (yparent->get_object ("ties"))->size () > 1
164 /* trigger positioning. */
165 (void) yparent->get_property ("positioning-done");
167 return me->get_property_data ("direction");
170 programming_error ("no Tie_column or Semi_tie_column. Killing grob.");
172 return scm_from_int (CENTER);
176 Tie::get_default_control_points (Spanner *me)
179 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
180 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
182 Tie_formatting_problem problem;
183 problem.from_tie (me);
188 Ties_configuration conf
189 = problem.generate_optimal_configuration ();
191 return get_control_points (me, problem.common_x_refpoint (),
192 conf[0], problem.details_);
196 Tie::get_control_points (Grob *me,
198 Tie_configuration const &conf,
199 Tie_details const &details)
201 Bezier b = conf.get_transformed_bezier (details);
202 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
204 SCM controls = SCM_EOL;
205 for (int i = 4; i--;)
207 if (!b.control_[i].is_sane ())
208 programming_error ("Insane offset");
209 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
214 MAKE_SCHEME_CALLBACK (Tie, calc_control_points, 1);
216 Tie::calc_control_points (SCM smob)
218 Spanner *me = LY_ASSERT_SMOB(Spanner, smob, 1);
220 Grob *yparent = me->get_parent (Y_AXIS);
221 if ((has_interface<Tie_column> (yparent)
222 || has_interface<Semi_tie_column> (yparent))
223 && unsmob<Grob_array> (yparent->get_object ("ties")))
225 extract_grob_set (yparent, "ties", ties);
226 if (me->original () && ties.size () == 1
227 && !to_dir (me->get_property_data ("direction")))
229 assert (ties[0] == me);
230 set_grob_direction (me, Tie::get_default_dir (me));
232 /* trigger positioning. */
233 (void) yparent->get_property ("positioning-done");
236 SCM cp = me->get_property_data ("control-points");
237 if (!scm_is_pair (cp))
238 cp = get_default_control_points (me);
244 TODO: merge with Slur::print.
246 MAKE_SCHEME_CALLBACK (Tie, print, 1);
248 Tie::print (SCM smob)
250 Grob *me = unsmob<Grob> (smob);
252 SCM cp = me->get_property ("control-points");
254 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
255 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
256 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
260 for (SCM s = cp; scm_is_pair (s); s = scm_cdr (s))
262 b.control_[i] = ly_scm2offset (scm_car (s));
268 SCM dash_definition = me->get_property ("dash-definition");
270 get_grob_direction (me) * base_thick,
274 #if DEBUG_TIE_SCORING
275 SCM annotation = me->get_property ("annotation");
276 if (scm_is_string (annotation))
279 SCM properties = Font_interface::text_font_alist_chain (me);
281 Stencil tm = *unsmob<Stencil> (Text_interface::interpret_markup
282 (me->layout ()->self_scm (), properties,
284 tm.translate (Offset (b.control_[3][X_AXIS] + 0.5,
285 b.control_[0][Y_AXIS] * 2));
286 tm = tm.in_color (1, 0, 0);
289 It would be nice if we could put this in a different layer,
290 but alas, this must be done with a Tie override.
296 return a.smobbed_copy ();
300 "A tie - a horizontal curve connecting two noteheads.\n"
302 "The following properties may be set in the @code{details}"
306 "@item height-limit\n"
307 "The maximum height allowed for this tie.\n"
309 "Parameter for tie shape. The higher this number, the"
310 " quicker the slur attains its height-limit.\n"
311 "@item between-length-limit\n"
312 "This detail is currently unused.\n"
313 "@item wrong-direction-offset-penalty\n"
314 "Demerit for ties that are offset in the wrong"
317 "If the tie is shorter than this amount (in"
318 " staff-spaces) an increasingly large length penalty is"
320 "@item min-length-penalty-factor\n"
321 "Demerit factor for tie lengths shorter than"
322 " @code{min-length}.\n"
323 "@item center-staff-line-clearance\n"
324 "If the center of the tie is closer to a staff line"
325 " than this amount, an increasingly large staff line"
326 " collision penalty is incurred.\n"
327 "@item tip-staff-line-clearance\n"
328 "If the tips of the tie are closer to a staff line"
329 " than this amount, an increasingly large staff line"
330 " collision penalty is incurred.\n"
331 "@item staff-line-collision-penalty\n"
332 "Demerit factor for ties whose tips or center come"
333 " close to staff lines.\n"
334 "@item dot-collision-clearance\n"
335 "If the tie comes closer to a dot than this amount, an"
336 " increasingly large dot collision penalty is incurred.\n"
337 "@item dot-collision-penalty\n"
338 "Demerit factor for ties which come close to dots.\n"
339 "@item note-head-gap\n"
340 "The distance (in staff-spaces) by which the ends of"
341 " the tie are offset horizontally from the center"
342 " line through the note head.\n"
344 "The distance (in staff-spaces) by which the ends of"
345 " the tie are offset horizontally from a stem which"
346 " is on the same side of the note head as the tie.\n"
347 "@item tie-column-monotonicity-penalty\n"
348 "Demerit if the y-position of this tie in the set of"
349 " ties being considered is less than the y-position"
350 " of the previous tie.\n"
351 "@item tie-tie-collision-distance\n"
352 "If this tie is closer than this amount to the previous"
353 " tie in the set being considered, an increasingly"
354 " large tie-tie collision penalty is incurred.\n"
355 "@item tie-tie-collision-penalty\n"
356 "Demerit factor for a tie in the set being considered"
357 " which is close to the previous one.\n"
358 "@item horizontal-distance-penalty-factor\n"
359 "Demerit factor for ties in the set being considered"
360 " which are horizontally distant from the note heads.\n"
361 "@item vertical-distance-penalty-factor\n"
362 "Demerit factor for ties in the set being considered"
363 " which are vertically distant from the note heads.\n"
364 "@item same-dir-as-stem-penalty\n"
365 "Demerit if tie is on the same side as a stem or on the"
366 " opposite side to the one specified.\n"
367 "@item intra-space-threshold\n"
368 "If the tie's height (in half staff-spaces) is less than"
369 " this it is positioned between two adjacent staff"
370 " lines; otherwise it is positioned to straddle a staff"
371 " line further from the note heads.\n"
372 "@item outer-tie-length-symmetry-penalty-factor\n"
373 "Demerit factor for ties horizontally positioned"
374 " unsymmetrically with respect to the two note heads.\n"
375 "@item outer-tie-vertical-distance-symmetry-penalty-factor\n"
376 "Demerit factor for ties vertically positioned"
377 " unsymmetrically with respect to the two note heads.\n"
378 "@item outer-tie-vertical-gap\n"
379 "Amount (in half staff-spaces) by which a tie is moved"
380 " away from the note heads if it is closer to either"
381 " of them than 0.25 half staff-spaces.\n"
382 "@item skyline-padding\n"
383 "Padding of the skylines around note heads in chords.\n"
384 "@item single-tie-region-size\n"
385 "The number of candidate ties to generate when only a"
386 " single tie is required. Successive candidates differ"
387 " in their initial vertical position by half a"
389 "@item multi-tie-region-size\n"
390 "The number of variations that are tried for the"
391 " extremal ties in a chord. Variations differ in their"
392 " initial vertical position by half a staff-space.\n"
398 "avoid-slur " // UGH.