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 *const &s1, Grob *const &s2)
47 return get_position_generic (s1) < get_position_generic (s2);
51 Tie::set_head (Spanner *me, Direction d, Grob *h)
57 Tie::head (Spanner *me, Direction d)
59 Item *it = me->get_bound (d);
60 return Note_head::has_interface (it) ? it : 0;
64 Tie::get_column_rank (Spanner *me, Direction d)
66 return Paper_column::get_rank (me->get_bound (d)->get_column ());
70 Tie::get_position (Spanner *me)
72 for (LEFT_and_RIGHT (d))
74 Grob *h = head (me, d);
76 return (int) rint (Staff_symbol_referencer::get_position (h));
80 TODO: this is theoretically possible for ties across more than 2
81 systems.. We should look at the first broken copy.
84 programming_error ("Tie without heads. Suicide");
90 Tie::get_position_generic (Grob *me) // TODO: do away with this
92 Spanner *spanner = dynamic_cast<Spanner *> (me);
94 return get_position (spanner);
96 Item *item = dynamic_cast<Item *> (me);
98 return Semi_tie::get_position (item);
100 programming_error ("grob is neither a tie nor a semi-tie");
105 Default: Put the tie oppositie of the stem [Wanske p231]
107 In case of chords: Tie_column takes over
109 The direction of the Tie is more complicated (See [Ross] p136 and
112 (what about linebreaks? )
115 Tie::get_default_dir (Grob *me)
117 Drul_array<Grob *> stems;
118 for (LEFT_and_RIGHT (d))
121 if (Spanner *spanner = dynamic_cast<Spanner *> (me))
123 one_head = head (spanner, d);
125 one_head = head (spanner->broken_neighbor (d), d);
127 else if (Item *item = dynamic_cast<Item *> (me))
128 one_head = Semi_tie::head (item);
130 Grob *stem = one_head ? Rhythmic_head::get_stem (one_head) : 0;
131 stems[d] = (stem && !Stem::is_invisible (stem)) ? stem : 0;
134 if (stems[LEFT] && stems[RIGHT])
136 if (get_grob_direction (stems[LEFT]) == UP
137 && get_grob_direction (stems[RIGHT]) == UP)
140 // And why not return UP if both stems are DOWN?
142 // And when stems conflict, why fall directly through to using
143 // neutral-direction without considering get_position (me)?
145 else if (stems[LEFT])
146 return -get_grob_direction (stems[LEFT]);
147 else if (stems[RIGHT])
148 return -get_grob_direction (stems[RIGHT]);
149 else if (int p = get_position_generic (me))
150 return Direction (sign (p));
152 return to_dir (me->get_property ("neutral-direction"));
155 MAKE_SCHEME_CALLBACK (Tie, calc_direction, 1);
157 Tie::calc_direction (SCM smob)
159 Grob *me = unsmob<Grob> (smob);
160 Grob *yparent = me->get_parent (Y_AXIS);
161 if ((Tie_column::has_interface (yparent)
162 || Semi_tie_column::has_interface (yparent))
163 && unsmob<Grob_array> (yparent->get_object ("ties"))
164 // && unsmob<Grob_array> (yparent->get_object ("ties"))->size () > 1
167 /* trigger positioning. */
168 (void) yparent->get_property ("positioning-done");
170 return me->get_property_data ("direction");
173 return scm_from_int (Tie::get_default_dir (me));
177 Tie::get_default_control_points (Spanner *me)
180 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
181 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
183 Tie_formatting_problem problem;
184 problem.from_tie (me);
189 Ties_configuration conf
190 = problem.generate_optimal_configuration ();
192 return get_control_points (me, problem.common_x_refpoint (),
193 conf[0], problem.details_);
197 Tie::get_control_points (Grob *me,
199 Tie_configuration const &conf,
200 Tie_details const &details)
202 Bezier b = conf.get_transformed_bezier (details);
203 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
205 SCM controls = SCM_EOL;
206 for (int i = 4; i--;)
208 if (!b.control_[i].is_sane ())
209 programming_error ("Insane offset");
210 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
215 MAKE_SCHEME_CALLBACK (Tie, calc_control_points, 1);
217 Tie::calc_control_points (SCM smob)
219 Spanner *me = LY_ASSERT_SMOB(Spanner, smob, 1);
221 Grob *yparent = me->get_parent (Y_AXIS);
222 if ((Tie_column::has_interface (yparent)
223 || Semi_tie_column::has_interface (yparent))
224 && unsmob<Grob_array> (yparent->get_object ("ties")))
226 extract_grob_set (yparent, "ties", ties);
227 if (me->original () && ties.size () == 1
228 && !to_dir (me->get_property_data ("direction")))
230 assert (ties[0] == me);
231 set_grob_direction (me, Tie::get_default_dir (me));
233 /* trigger positioning. */
234 (void) yparent->get_property ("positioning-done");
237 SCM cp = me->get_property_data ("control-points");
238 if (!scm_is_pair (cp))
239 cp = get_default_control_points (me);
245 TODO: merge with Slur::print.
247 MAKE_SCHEME_CALLBACK (Tie, print, 1);
249 Tie::print (SCM smob)
251 Grob *me = unsmob<Grob> (smob);
253 SCM cp = me->get_property ("control-points");
255 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
256 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
257 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
261 for (SCM s = cp; scm_is_pair (s); s = scm_cdr (s))
263 b.control_[i] = ly_scm2offset (scm_car (s));
269 SCM dash_definition = me->get_property ("dash-definition");
271 get_grob_direction (me) * base_thick,
275 #if DEBUG_TIE_SCORING
276 SCM annotation = me->get_property ("annotation");
277 if (scm_is_string (annotation))
280 SCM properties = Font_interface::text_font_alist_chain (me);
282 Stencil tm = *unsmob<Stencil> (Text_interface::interpret_markup
283 (me->layout ()->self_scm (), properties,
285 tm.translate (Offset (b.control_[3][X_AXIS] + 0.5,
286 b.control_[0][Y_AXIS] * 2));
287 tm = tm.in_color (1, 0, 0);
290 It would be nice if we could put this in a different layer,
291 but alas, this must be done with a Tie override.
297 return a.smobbed_copy ();
301 "A tie - a horizontal curve connecting two noteheads.\n"
303 "The following properties may be set in the @code{details}"
307 "@item height-limit\n"
308 "The maximum height allowed for this tie.\n"
310 "Parameter for tie shape. The higher this number, the"
311 " quicker the slur attains its height-limit.\n"
312 "@item between-length-limit\n"
313 "This detail is currently unused.\n"
314 "@item wrong-direction-offset-penalty\n"
315 "Demerit for ties that are offset in the wrong"
318 "If the tie is shorter than this amount (in"
319 " staff-spaces) an increasingly large length penalty is"
321 "@item min-length-penalty-factor\n"
322 "Demerit factor for tie lengths shorter than"
323 " @code{min-length}.\n"
324 "@item center-staff-line-clearance\n"
325 "If the center of the tie is closer to a staff line"
326 " than this amount, an increasingly large staff line"
327 " collision penalty is incurred.\n"
328 "@item tip-staff-line-clearance\n"
329 "If the tips of the tie are closer to a staff line"
330 " than this amount, an increasingly large staff line"
331 " collision penalty is incurred.\n"
332 "@item staff-line-collision-penalty\n"
333 "Demerit factor for ties whose tips or center come"
334 " close to staff lines.\n"
335 "@item dot-collision-clearance\n"
336 "If the tie comes closer to a dot than this amount, an"
337 " increasingly large dot collision penalty is incurred.\n"
338 "@item dot-collision-penalty\n"
339 "Demerit factor for ties which come close to dots.\n"
340 "@item note-head-gap\n"
341 "The distance (in staff-spaces) by which the ends of"
342 " the tie are offset horizontally from the center"
343 " line through the note head.\n"
345 "The distance (in staff-spaces) by which the ends of"
346 " the tie are offset horizontally from a stem which"
347 " is on the same side of the note head as the tie.\n"
348 "@item tie-column-monotonicity-penalty\n"
349 "Demerit if the y-position of this tie in the set of"
350 " ties being considered is less than the y-position"
351 " of the previous tie.\n"
352 "@item tie-tie-collision-distance\n"
353 "If this tie is closer than this amount to the previous"
354 " tie in the set being considered, an increasingly"
355 " large tie-tie collision penalty is incurred.\n"
356 "@item tie-tie-collision-penalty\n"
357 "Demerit factor for a tie in the set being considered"
358 " which is close to the previous one.\n"
359 "@item horizontal-distance-penalty-factor\n"
360 "Demerit factor for ties in the set being considered"
361 " which are horizontally distant from the note heads.\n"
362 "@item vertical-distance-penalty-factor\n"
363 "Demerit factor for ties in the set being considered"
364 " which are vertically distant from the note heads.\n"
365 "@item same-dir-as-stem-penalty\n"
366 "Demerit if tie is on the same side as a stem or on the"
367 " opposite side to the one specified.\n"
368 "@item intra-space-threshold\n"
369 "If the tie's height (in half staff-spaces) is less than"
370 " this it is positioned between two adjacent staff"
371 " lines; otherwise it is positioned to straddle a staff"
372 " line further from the note heads.\n"
373 "@item outer-tie-length-symmetry-penalty-factor\n"
374 "Demerit factor for ties horizontally positioned"
375 " unsymmetrically with respect to the two note heads.\n"
376 "@item outer-tie-vertical-distance-symmetry-penalty-factor\n"
377 "Demerit factor for ties vertically positioned"
378 " unsymmetrically with respect to the two note heads.\n"
379 "@item outer-tie-vertical-gap\n"
380 "Amount (in half staff-spaces) by which a tie is moved"
381 " away from the note heads if it is closer to either"
382 " of them than 0.25 half staff-spaces.\n"
383 "@item skyline-padding\n"
384 "Padding of the skylines around note heads in chords.\n"
385 "@item single-tie-region-size\n"
386 "The number of candidate ties to generate when only a"
387 " single tie is required. Successive candidates differ"
388 " in their initial vertical position by half a"
390 "@item multi-tie-region-size\n"
391 "The number of variations that are tried for the"
392 " extremal ties in a chord. Variations differ in their"
393 " initial vertical position by half a staff-space.\n"
399 "avoid-slur " // UGH.