2 tie.cc -- implement Tie
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 #include "output-def.hh"
16 #include "rhythmic-head.hh"
18 #include "paper-column.hh"
20 #include "staff-symbol-referencer.hh"
21 #include "directional-element-interface.hh"
24 #include "note-head.hh"
25 #include "tie-column.hh"
28 tie: Connect two noteheads.
32 c4 ~ \clef bass ; c4 or
36 do we have non-horizontal ties then?
40 Tie::set_head (Grob *me, Direction d, Grob *h)
42 assert (!head (me, d));
43 index_set_cell (me->get_property ("head-pair"), d, h->self_scm ());
45 dynamic_cast<Spanner *> (me)->set_bound (d, h);
46 me->add_dependency (h);
50 Tie::set_interface (Grob *me)
52 me->set_property ("head-pair", scm_cons (SCM_EOL, SCM_EOL));
56 Tie::head (Grob *me, Direction d)
58 SCM c = me->get_property ("head-pair");
61 return unsmob_grob (index_get_cell (c, d));
67 Tie::get_column_rank (Grob *me, Direction d)
69 Spanner *span = dynamic_cast<Spanner *> (me);
70 Grob *h = head (me, d);
72 h = span->get_bound (d);
74 Grob *col = dynamic_cast<Item *> (h)->get_column ();
75 return Paper_column::get_rank (col);
79 Tie::get_position (Grob *me)
81 Direction d = head (me, LEFT) ? LEFT : RIGHT;
82 return Staff_symbol_referencer::get_position (head (me, d));
86 Default: Put the tie oppositie of the stem [Wanske p231]
88 In case of chords: Tie_column takes over
90 The direction of the Tie is more complicated (See [Ross] p136 and
93 (what about linebreaks? )
96 Tie::get_default_dir (Grob *me)
98 Item *sl = head (me, LEFT) ? Rhythmic_head::get_stem (head (me, LEFT)) : 0;
99 Item *sr = head (me, RIGHT) ? Rhythmic_head::get_stem (head (me, RIGHT)) : 0;
102 if (get_grob_direction (sl) == UP
103 && get_grob_direction (sr) == UP)
108 Item *s = sl ? sl : sr;
109 return -get_grob_direction (s);
116 Tie::set_direction (Grob *me)
118 if (!get_grob_direction (me))
120 if (Tie_column::has_interface (me->get_parent (Y_AXIS)))
121 Tie_column::set_directions (me->get_parent (Y_AXIS));
123 set_grob_direction (me, Tie::get_default_dir (me));
129 Tie::get_control_points (SCM smob)
131 Spanner *me = unsmob_spanner (smob);
132 if (!head (me, LEFT) && !head (me, RIGHT))
134 programming_error ("tie without heads");
140 int tie_position = (int) Tie::get_position (me);
142 Direction dir = get_grob_direction (me);
144 Real staff_space = Staff_symbol_referencer::staff_space (me);
145 Real staff_position = tie_position;
147 Grob *common[NO_AXES];
148 for (int a = X_AXIS; a < NO_AXES; a++)
151 common[ax] = me->get_bound (LEFT)->common_refpoint (me, ax);
152 common[ax] = me->get_bound (RIGHT)->common_refpoint (common[a], ax);
155 Interval attachments;
158 Real gap = robust_scm2double (me->get_property ("x-gap"), 0.2);
162 = robust_relative_extent (me->get_bound (d),
167 while (flip (&d) != LEFT);
169 bool in_between = true;
170 if (attachments.length () < 0.6 * staff_space)
173 Let short ties start over note heads, instead of between.
175 Drul_array<bool> allow (true, true);
179 if (Note_head::has_interface (me->get_bound (d)))
181 Grob *stem = unsmob_grob (me->get_bound (d)->get_object ("stem"));
182 if (get_grob_direction (stem) == dir
186 } while (flip (&d) != LEFT);
188 if (allow[LEFT] && allow[RIGHT])
190 staff_position += dir;
193 if (Note_head::has_interface (me->get_bound (d)))
196 = robust_relative_extent (me->get_bound (d),
197 common[X_AXIS], X_AXIS);
199 attachments[d] = extent.linear_combination (- 0.5 * d);
203 while (flip (&d) != LEFT);
207 SCM details = me->get_property ("details");
210 = scm_assq (ly_symbol2scm ("height-limit"), details);
212 Real h_inf = robust_scm2double (scm_cdr (limit), 0.75) * staff_space;
213 Real r_0 = robust_scm2double (scm_cdr (scm_assq (ly_symbol2scm ("ratio"), details)),
216 Bezier b = slur_shape (attachments.length(),
220 Offset middle = b.curve_point (0.5);
221 Offset edge = b.curve_point (0.0);
223 staff_position = rint (staff_position);
225 Real dy = fabs (middle[Y_AXIS] - edge[Y_AXIS]);
226 bool in_space = !(Staff_symbol_referencer::on_staffline (me, (int) staff_position));
228 (dy < 0.6 * staff_space);
233 Grob *left_dot = unsmob_grob (me->get_bound (LEFT)->get_object ("dot"));
234 if (left_dot && in_space)
236 if (staff_position == Staff_symbol_referencer::get_position (left_dot))
238 staff_position += dir;
246 Grob *left_stem = unsmob_grob (me->get_bound (LEFT)->get_object ("stem"));
249 Stencil flag = Stem::get_translated_flag (left_stem);
250 Real y = staff_position * staff_space * 0.5;
251 if (flag.extent (Y_AXIS).contains (y))
253 staff_position += dir;
254 in_space = !in_space;
259 Putting larger in-space ties next to the notes forces
260 the edges to be opposite (Y-wise) to the tie direction.
262 if (staff_position == tie_position
264 && dy > 0.3 * staff_space)
266 staff_position += 2 * dir;
269 if (in_space != fits_in_space)
273 staff_position += dir;
278 staff_position += dir;
284 && fabs (staff_position - tie_position) <= 1)
285 staff_position += 2*dir;
290 if (fabs (dy) < 0.4 * staff_space)
293 vertically center in space.
295 Offset middle = b.curve_point (0.5);
296 Offset edge = b.curve_point (0.0);
298 Real center = (edge[Y_AXIS] + middle[Y_AXIS])/2.0;
299 b.translate (Offset (0,
300 staff_position * staff_space * 0.5
305 b.translate (Offset (0,
306 (staff_position - dir) * staff_space * 0.5
307 + dir * 0.2 * staff_space));
312 Real where = 0.5 * dir;
314 Real rounding_dy = (where - middle[Y_AXIS]);
315 b.translate (Offset (0,
316 0.5 * staff_position * staff_space + rounding_dy));
318 if (dir * b.curve_point (0.0)[Y_AXIS] <
319 dir * tie_position * 0.5 * staff_space)
320 b.translate (Offset (0, staff_space * dir));
323 b.translate (Offset (attachments[LEFT]
324 - me->relative_coordinate (common[X_AXIS], X_AXIS), 0));
326 SCM controls = SCM_EOL;
327 for (int i = 4; i--;)
328 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
334 MAKE_SCHEME_CALLBACK (Tie, print, 1);
336 Tie::print (SCM smob)
338 Grob *me = unsmob_grob (smob);
340 SCM cp = me->get_property ("control-points");
341 if (!scm_is_pair (cp)) // list is more accurate
343 cp = get_control_points (smob);
344 me->set_property ("control-points", cp);
347 if (!scm_is_pair (cp))
348 return Stencil ().smobbed_copy ();
350 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
351 Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
352 Real thick = base_thick * staff_thick;
356 for (SCM s = cp; s != SCM_EOL; s = scm_cdr (s))
358 b.control_[i] = ly_scm2offset (scm_car (s));
364 SCM p = me->get_property ("dash-period");
365 SCM f = me->get_property ("dash-fraction");
366 if (scm_is_number (p) && scm_is_number (f))
367 a = Lookup::dashed_slur (b,
369 robust_scm2double (p, 1.0),
370 robust_scm2double (f, 0));
373 get_grob_direction (me) * staff_thick,
376 return a.smobbed_copy ();
381 "A tie connecting two noteheads.\n",