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 Tie::get_position_generic (Grob *me) // TODO: do away with this
99 Spanner *spanner = dynamic_cast<Spanner *> (me);
101 return get_position (spanner);
103 Item *item = dynamic_cast<Item *> (me);
105 return Semi_tie::get_position (item);
107 programming_error ("grob is neither a tie nor a semi-tie");
112 Default: Put the tie oppositie of the stem [Wanske p231]
114 In case of chords: Tie_column takes over
116 The direction of the Tie is more complicated (See [Ross] p136 and
119 (what about linebreaks? )
122 Tie::get_default_dir (Grob *me)
124 Drul_array<Grob *> stems;
125 for (LEFT_and_RIGHT (d))
128 if (Spanner *spanner = dynamic_cast<Spanner *> (me))
130 one_head = head (spanner, d);
132 one_head = head (spanner->broken_neighbor (d), d);
134 else if (Item *item = dynamic_cast<Item *> (me))
135 one_head = Semi_tie::head (item);
137 Grob *stem = one_head ? Rhythmic_head::get_stem (one_head) : 0;
138 stems[d] = (stem && !Stem::is_invisible (stem)) ? stem : 0;
141 if (stems[LEFT] && stems[RIGHT])
143 if (get_grob_direction (stems[LEFT]) == UP
144 && get_grob_direction (stems[RIGHT]) == UP)
147 // And why not return UP if both stems are DOWN?
149 // And when stems conflict, why fall directly through to using
150 // neutral-direction without considering get_position (me)?
152 else if (stems[LEFT])
153 return -get_grob_direction (stems[LEFT]);
154 else if (stems[RIGHT])
155 return -get_grob_direction (stems[RIGHT]);
156 else if (int p = get_position_generic (me))
157 return Direction (sign (p));
159 return to_dir (me->get_property ("neutral-direction"));
162 MAKE_SCHEME_CALLBACK (Tie, calc_direction, 1);
164 Tie::calc_direction (SCM smob)
166 Grob *me = unsmob<Grob> (smob);
167 Grob *yparent = me->get_parent (Y_AXIS);
168 if ((Tie_column::has_interface (yparent)
169 || Semi_tie_column::has_interface (yparent))
170 && unsmob<Grob_array> (yparent->get_object ("ties"))
171 // && unsmob<Grob_array> (yparent->get_object ("ties"))->size () > 1
174 /* trigger positioning. */
175 (void) yparent->get_property ("positioning-done");
177 return me->get_property_data ("direction");
180 return scm_from_int (Tie::get_default_dir (me));
184 Tie::get_default_control_points (Spanner *me)
187 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
188 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
190 Tie_formatting_problem problem;
191 problem.from_tie (me);
196 Ties_configuration conf
197 = problem.generate_optimal_configuration ();
199 return get_control_points (me, problem.common_x_refpoint (),
200 conf[0], problem.details_);
204 Tie::get_control_points (Grob *me,
206 Tie_configuration const &conf,
207 Tie_details const &details)
209 Bezier b = conf.get_transformed_bezier (details);
210 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
212 SCM controls = SCM_EOL;
213 for (int i = 4; i--;)
215 if (!b.control_[i].is_sane ())
216 programming_error ("Insane offset");
217 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
222 MAKE_SCHEME_CALLBACK (Tie, calc_control_points, 1);
224 Tie::calc_control_points (SCM smob)
226 Spanner *me = LY_ASSERT_SMOB(Spanner, smob, 1);
228 Grob *yparent = me->get_parent (Y_AXIS);
229 if ((Tie_column::has_interface (yparent)
230 || Semi_tie_column::has_interface (yparent))
231 && unsmob<Grob_array> (yparent->get_object ("ties")))
233 extract_grob_set (yparent, "ties", ties);
234 if (me->original () && ties.size () == 1
235 && !to_dir (me->get_property_data ("direction")))
237 assert (ties[0] == me);
238 set_grob_direction (me, Tie::get_default_dir (me));
240 /* trigger positioning. */
241 (void) yparent->get_property ("positioning-done");
244 SCM cp = me->get_property_data ("control-points");
245 if (!scm_is_pair (cp))
246 cp = get_default_control_points (me);
252 TODO: merge with Slur::print.
254 MAKE_SCHEME_CALLBACK (Tie, print, 1);
256 Tie::print (SCM smob)
258 Grob *me = unsmob<Grob> (smob);
260 SCM cp = me->get_property ("control-points");
262 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
263 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
264 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
268 for (SCM s = cp; scm_is_pair (s); s = scm_cdr (s))
270 b.control_[i] = ly_scm2offset (scm_car (s));
276 SCM dash_definition = me->get_property ("dash-definition");
278 get_grob_direction (me) * base_thick,
282 #if DEBUG_TIE_SCORING
283 SCM annotation = me->get_property ("annotation");
284 if (scm_is_string (annotation))
287 SCM properties = Font_interface::text_font_alist_chain (me);
289 Stencil tm = *unsmob<Stencil> (Text_interface::interpret_markup
290 (me->layout ()->self_scm (), properties,
292 tm.translate (Offset (b.control_[3][X_AXIS] + 0.5,
293 b.control_[0][Y_AXIS] * 2));
294 tm = tm.in_color (1, 0, 0);
297 It would be nice if we could put this in a different layer,
298 but alas, this must be done with a Tie override.
304 return a.smobbed_copy ();
308 "A tie - a horizontal curve connecting two noteheads.\n"
310 "The following properties may be set in the @code{details}"
314 "@item height-limit\n"
315 "The maximum height allowed for this tie.\n"
317 "Parameter for tie shape. The higher this number, the"
318 " quicker the slur attains its height-limit.\n"
319 "@item between-length-limit\n"
320 "This detail is currently unused.\n"
321 "@item wrong-direction-offset-penalty\n"
322 "Demerit for ties that are offset in the wrong"
325 "If the tie is shorter than this amount (in"
326 " staff-spaces) an increasingly large length penalty is"
328 "@item min-length-penalty-factor\n"
329 "Demerit factor for tie lengths shorter than"
330 " @code{min-length}.\n"
331 "@item center-staff-line-clearance\n"
332 "If the center of the tie is closer to a staff line"
333 " than this amount, an increasingly large staff line"
334 " collision penalty is incurred.\n"
335 "@item tip-staff-line-clearance\n"
336 "If the tips of the tie are closer to a staff line"
337 " than this amount, an increasingly large staff line"
338 " collision penalty is incurred.\n"
339 "@item staff-line-collision-penalty\n"
340 "Demerit factor for ties whose tips or center come"
341 " close to staff lines.\n"
342 "@item dot-collision-clearance\n"
343 "If the tie comes closer to a dot than this amount, an"
344 " increasingly large dot collision penalty is incurred.\n"
345 "@item dot-collision-penalty\n"
346 "Demerit factor for ties which come close to dots.\n"
347 "@item note-head-gap\n"
348 "The distance (in staff-spaces) by which the ends of"
349 " the tie are offset horizontally from the center"
350 " line through the note head.\n"
352 "The distance (in staff-spaces) by which the ends of"
353 " the tie are offset horizontally from a stem which"
354 " is on the same side of the note head as the tie.\n"
355 "@item tie-column-monotonicity-penalty\n"
356 "Demerit if the y-position of this tie in the set of"
357 " ties being considered is less than the y-position"
358 " of the previous tie.\n"
359 "@item tie-tie-collision-distance\n"
360 "If this tie is closer than this amount to the previous"
361 " tie in the set being considered, an increasingly"
362 " large tie-tie collision penalty is incurred.\n"
363 "@item tie-tie-collision-penalty\n"
364 "Demerit factor for a tie in the set being considered"
365 " which is close to the previous one.\n"
366 "@item horizontal-distance-penalty-factor\n"
367 "Demerit factor for ties in the set being considered"
368 " which are horizontally distant from the note heads.\n"
369 "@item vertical-distance-penalty-factor\n"
370 "Demerit factor for ties in the set being considered"
371 " which are vertically distant from the note heads.\n"
372 "@item same-dir-as-stem-penalty\n"
373 "Demerit if tie is on the same side as a stem or on the"
374 " opposite side to the one specified.\n"
375 "@item intra-space-threshold\n"
376 "If the tie's height (in half staff-spaces) is less than"
377 " this it is positioned between two adjacent staff"
378 " lines; otherwise it is positioned to straddle a staff"
379 " line further from the note heads.\n"
380 "@item outer-tie-length-symmetry-penalty-factor\n"
381 "Demerit factor for ties horizontally positioned"
382 " unsymmetrically with respect to the two note heads.\n"
383 "@item outer-tie-vertical-distance-symmetry-penalty-factor\n"
384 "Demerit factor for ties vertically positioned"
385 " unsymmetrically with respect to the two note heads.\n"
386 "@item outer-tie-vertical-gap\n"
387 "Amount (in half staff-spaces) by which a tie is moved"
388 " away from the note heads if it is closer to either"
389 " of them than 0.25 half staff-spaces.\n"
390 "@item skyline-padding\n"
391 "Padding of the skylines around note heads in chords.\n"
392 "@item single-tie-region-size\n"
393 "The number of candidate ties to generate when only a"
394 " single tie is required. Successive candidates differ"
395 " in their initial vertical position by half a"
397 "@item multi-tie-region-size\n"
398 "The number of variations that are tried for the"
399 " extremal ties in a chord. Variations differ in their"
400 " initial vertical position by half a staff-space.\n"
406 "avoid-slur " // UGH.