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);
50 g1->programming_error ("grob is not a tie");
54 Spanner *s2 = dynamic_cast<Spanner *> (g2);
57 g2->programming_error ("grob is not a tie");
61 return get_position (s1) < get_position (s2);
65 Tie::set_head (Spanner *me, Direction d, Grob *h)
71 Tie::head (Spanner *me, Direction d)
73 Item *it = me->get_bound (d);
74 return has_interface<Note_head> (it) ? it : 0;
78 Tie::get_column_rank (Spanner *me, Direction d)
80 return Paper_column::get_rank (me->get_bound (d)->get_column ());
84 Tie::get_position (Spanner *me)
86 for (LEFT_and_RIGHT (d))
88 Grob *h = head (me, d);
90 return (int) rint (Staff_symbol_referencer::get_position (h));
94 TODO: this is theoretically possible for ties across more than 2
95 systems.. We should look at the first broken copy.
98 programming_error ("Tie without heads. Suicide");
104 Default: Put the tie oppositie of the stem [Wanske p231]
106 In case of chords: Tie_column takes over
108 The direction of the Tie is more complicated (See [Ross] p136 and
111 (what about linebreaks? )
114 Tie::get_default_dir (Spanner *me)
116 Drul_array<Grob *> stems;
117 for (LEFT_and_RIGHT (d))
119 Grob *one_head = head (me, d);
121 one_head = head (me->broken_neighbor (d), d);
123 Grob *stem = one_head ? Rhythmic_head::get_stem (one_head) : 0;
124 stems[d] = (stem && !Stem::is_invisible (stem)) ? stem : 0;
127 if (stems[LEFT] && stems[RIGHT])
129 if (get_grob_direction (stems[LEFT]) == UP
130 && get_grob_direction (stems[RIGHT]) == UP)
133 // And why not return UP if both stems are DOWN?
135 // And when stems conflict, why fall directly through to using
136 // neutral-direction without considering get_position (me)?
138 else if (stems[LEFT])
139 return -get_grob_direction (stems[LEFT]);
140 else if (stems[RIGHT])
141 return -get_grob_direction (stems[RIGHT]);
142 else if (int p = get_position (me))
143 return Direction (sign (p));
145 return to_dir (me->get_property ("neutral-direction"));
148 MAKE_SCHEME_CALLBACK (Tie, calc_direction, 1);
150 Tie::calc_direction (SCM smob)
152 // In this method, Tie and Semi_tie require the same logic with different
153 // types. It might be clearer to use a template.
154 Grob *me = unsmob<Grob> (smob);
155 Grob *yparent = me->get_parent (Y_AXIS);
156 if ((has_interface<Tie_column> (yparent)
157 || has_interface<Semi_tie_column> (yparent))
158 && unsmob<Grob_array> (yparent->get_object ("ties"))
159 // && unsmob<Grob_array> (yparent->get_object ("ties"))->size () > 1
162 /* trigger positioning. */
163 (void) yparent->get_property ("positioning-done");
165 return me->get_property_data ("direction");
168 programming_error ("no Tie_column or Semi_tie_column. Killing grob.");
170 return scm_from_int (CENTER);
174 Tie::get_default_control_points (Spanner *me)
177 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
178 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
180 Tie_formatting_problem problem;
181 problem.from_tie (me);
186 Ties_configuration conf
187 = problem.generate_optimal_configuration ();
189 return get_control_points (me, problem.common_x_refpoint (),
190 conf[0], problem.details_);
194 Tie::get_control_points (Grob *me,
196 Tie_configuration const &conf,
197 Tie_details const &details)
199 Bezier b = conf.get_transformed_bezier (details);
200 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
202 SCM controls = SCM_EOL;
203 for (int i = 4; i--;)
205 if (!b.control_[i].is_sane ())
206 programming_error ("Insane offset");
207 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
212 MAKE_SCHEME_CALLBACK (Tie, calc_control_points, 1);
214 Tie::calc_control_points (SCM smob)
216 Spanner *me = LY_ASSERT_SMOB(Spanner, smob, 1);
218 Grob *yparent = me->get_parent (Y_AXIS);
219 if ((has_interface<Tie_column> (yparent)
220 || has_interface<Semi_tie_column> (yparent))
221 && unsmob<Grob_array> (yparent->get_object ("ties")))
223 extract_grob_set (yparent, "ties", ties);
224 if (me->original () && ties.size () == 1
225 && !to_dir (me->get_property_data ("direction")))
227 assert (ties[0] == me);
228 set_grob_direction (me, Tie::get_default_dir (me));
230 /* trigger positioning. */
231 (void) yparent->get_property ("positioning-done");
234 SCM cp = me->get_property_data ("control-points");
235 if (!scm_is_pair (cp))
236 cp = get_default_control_points (me);
242 TODO: merge with Slur::print.
244 MAKE_SCHEME_CALLBACK (Tie, print, 1);
246 Tie::print (SCM smob)
248 Grob *me = unsmob<Grob> (smob);
250 SCM cp = me->get_property ("control-points");
252 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
253 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
254 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
258 for (SCM s = cp; scm_is_pair (s); s = scm_cdr (s))
260 b.control_[i] = ly_scm2offset (scm_car (s));
266 SCM dash_definition = me->get_property ("dash-definition");
268 get_grob_direction (me) * base_thick,
272 #if DEBUG_TIE_SCORING
273 SCM annotation = me->get_property ("annotation");
274 if (scm_is_string (annotation))
277 SCM properties = Font_interface::text_font_alist_chain (me);
279 Stencil tm = *unsmob<Stencil> (Text_interface::interpret_markup
280 (me->layout ()->self_scm (), properties,
282 tm.translate (Offset (b.control_[3][X_AXIS] + 0.5,
283 b.control_[0][Y_AXIS] * 2));
284 tm = tm.in_color (1, 0, 0);
287 It would be nice if we could put this in a different layer,
288 but alas, this must be done with a Tie override.
294 return a.smobbed_copy ();
298 "A tie - a horizontal curve connecting two noteheads.\n"
300 "The following properties may be set in the @code{details}"
304 "@item height-limit\n"
305 "The maximum height allowed for this tie.\n"
307 "Parameter for tie shape. The higher this number, the"
308 " quicker the slur attains its height-limit.\n"
309 "@item between-length-limit\n"
310 "This detail is currently unused.\n"
311 "@item wrong-direction-offset-penalty\n"
312 "Demerit for ties that are offset in the wrong"
315 "If the tie is shorter than this amount (in"
316 " staff-spaces) an increasingly large length penalty is"
318 "@item min-length-penalty-factor\n"
319 "Demerit factor for tie lengths shorter than"
320 " @code{min-length}.\n"
321 "@item center-staff-line-clearance\n"
322 "If the center of the tie is closer to a staff line"
323 " than this amount, an increasingly large staff line"
324 " collision penalty is incurred.\n"
325 "@item tip-staff-line-clearance\n"
326 "If the tips of the tie are closer to a staff line"
327 " than this amount, an increasingly large staff line"
328 " collision penalty is incurred.\n"
329 "@item staff-line-collision-penalty\n"
330 "Demerit factor for ties whose tips or center come"
331 " close to staff lines.\n"
332 "@item dot-collision-clearance\n"
333 "If the tie comes closer to a dot than this amount, an"
334 " increasingly large dot collision penalty is incurred.\n"
335 "@item dot-collision-penalty\n"
336 "Demerit factor for ties which come close to dots.\n"
337 "@item note-head-gap\n"
338 "The distance (in staff-spaces) by which the ends of"
339 " the tie are offset horizontally from the center"
340 " line through the note head.\n"
342 "The distance (in staff-spaces) by which the ends of"
343 " the tie are offset horizontally from a stem which"
344 " is on the same side of the note head as the tie.\n"
345 "@item tie-column-monotonicity-penalty\n"
346 "Demerit if the y-position of this tie in the set of"
347 " ties being considered is less than the y-position"
348 " of the previous tie.\n"
349 "@item tie-tie-collision-distance\n"
350 "If this tie is closer than this amount to the previous"
351 " tie in the set being considered, an increasingly"
352 " large tie-tie collision penalty is incurred.\n"
353 "@item tie-tie-collision-penalty\n"
354 "Demerit factor for a tie in the set being considered"
355 " which is close to the previous one.\n"
356 "@item horizontal-distance-penalty-factor\n"
357 "Demerit factor for ties in the set being considered"
358 " which are horizontally distant from the note heads.\n"
359 "@item vertical-distance-penalty-factor\n"
360 "Demerit factor for ties in the set being considered"
361 " which are vertically distant from the note heads.\n"
362 "@item same-dir-as-stem-penalty\n"
363 "Demerit if tie is on the same side as a stem or on the"
364 " opposite side to the one specified.\n"
365 "@item intra-space-threshold\n"
366 "If the tie's height (in half staff-spaces) is less than"
367 " this it is positioned between two adjacent staff"
368 " lines; otherwise it is positioned to straddle a staff"
369 " line further from the note heads.\n"
370 "@item outer-tie-length-symmetry-penalty-factor\n"
371 "Demerit factor for ties horizontally positioned"
372 " unsymmetrically with respect to the two note heads.\n"
373 "@item outer-tie-vertical-distance-symmetry-penalty-factor\n"
374 "Demerit factor for ties vertically positioned"
375 " unsymmetrically with respect to the two note heads.\n"
376 "@item outer-tie-vertical-gap\n"
377 "Amount (in half staff-spaces) by which a tie is moved"
378 " away from the note heads if it is closer to either"
379 " of them than 0.25 half staff-spaces.\n"
380 "@item skyline-padding\n"
381 "Padding of the skylines around note heads in chords.\n"
382 "@item single-tie-region-size\n"
383 "The number of candidate ties to generate when only a"
384 " single tie is required. Successive candidates differ"
385 " in their initial vertical position by half a"
387 "@item multi-tie-region-size\n"
388 "The number of variations that are tried for the"
389 " extremal ties in a chord. Variations differ in their"
390 " initial vertical position by half a staff-space.\n"
396 "avoid-slur " // UGH.