2 tie.cc -- implement Tie
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
13 #include "directional-element-interface.hh"
14 #include "font-interface.hh"
15 #include "grob-array.hh"
17 #include "note-head.hh"
18 #include "output-def.hh"
19 #include "paper-column.hh"
20 #include "rhythmic-head.hh"
22 #include "staff-symbol-referencer.hh"
24 #include "text-interface.hh"
25 #include "tie-column.hh"
26 #include "tie-configuration.hh"
27 #include "tie-formatting-problem.hh"
29 #include "semi-tie-column.hh"
33 Tie::less (Grob *const &s1,
36 return Tie::get_position (s1) < Tie::get_position (s2);
40 Tie::set_head (Grob *me, Direction d, Grob *h)
42 dynamic_cast<Spanner *> (me)->set_bound (d, h);
46 Tie::head (Grob *me, Direction d)
48 if (is_direction (me->get_property ("head-direction")))
50 Direction hd = to_dir (me->get_property ("head-direction"));
53 ? unsmob_grob (me->get_object ("note-head"))
57 Item *it = dynamic_cast<Spanner*> (me)->get_bound (d);
58 if (Note_head::has_interface (it))
65 Tie::get_column_rank (Grob *me, Direction d)
67 Spanner *span = dynamic_cast<Spanner *> (me);
68 Grob *h = head (me, d);
70 h = span->get_bound (d);
72 Grob *col = dynamic_cast<Item *> (h)->get_column ();
73 return Paper_column::get_rank (col);
77 Tie::get_position (Grob *me)
82 Grob *h = head (me, d);
84 return (int) rint (Staff_symbol_referencer::get_position (h));
86 while (flip (&d) != LEFT);
90 TODO: this is theoretically possible for ties across more than 2
91 systems.. We should look at the first broken copy.
94 programming_error ("Tie without heads. Suicide");
100 Default: Put the tie oppositie of the stem [Wanske p231]
102 In case of chords: Tie_column takes over
104 The direction of the Tie is more complicated (See [Ross] p136 and
107 (what about linebreaks? )
110 Tie::get_default_dir (Grob *me)
112 Drul_array<Grob*> stems;
116 Grob *stem = head (me, d) ? Rhythmic_head::get_stem (head (me, d)) : 0;
118 stem = Stem::is_invisible (stem) ? 0 : stem;
122 while (flip (&d)!= LEFT);
124 if (stems[LEFT] && stems[RIGHT])
126 if (get_grob_direction (stems[LEFT]) == UP
127 && get_grob_direction (stems[RIGHT]) == UP)
130 else if (stems[LEFT] || stems[RIGHT])
132 Grob *s = stems[LEFT] ? stems[LEFT] : stems[RIGHT];
133 return -get_grob_direction (s);
135 else if (int p = get_position (me))
136 return Direction (sign (p));
142 MAKE_SCHEME_CALLBACK (Tie, calc_direction, 1);
144 Tie::calc_direction (SCM smob)
146 Grob *me = unsmob_grob (smob);
147 Grob *yparent = me->get_parent (Y_AXIS);
148 if ((Tie_column::has_interface (yparent)
149 || Semi_tie_column::has_interface (yparent))
150 && unsmob_grob_array (yparent->get_object ("ties"))
151 // && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1
154 /* trigger positioning. */
155 (void) yparent->get_property ("positioning-done");
157 return me->get_property_data ("direction");
160 return scm_from_int (Tie::get_default_dir (me));
165 Tie::get_default_control_points (Grob *me_grob)
167 Spanner *me = dynamic_cast<Spanner*> (me_grob);
169 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
170 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
172 Tie_formatting_problem problem;
173 problem.from_tie (me);
175 Tie_specification spec = problem.get_tie_specification (0);
180 Ties_configuration conf
181 = problem.generate_optimal_configuration ();
183 return get_control_points (me, problem.common_x_refpoint (),
184 conf[0], problem.details_);
188 Tie::get_control_points (Grob *me,
190 Tie_configuration const &conf,
191 Tie_details const &details
194 Bezier b = conf.get_transformed_bezier (details);
195 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
197 SCM controls = SCM_EOL;
198 for (int i = 4; i--;)
200 if (!b.control_[i].is_sane ())
201 programming_error ("Insane offset");
202 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
208 MAKE_SCHEME_CALLBACK (Tie, calc_control_points, 1);
210 Tie::calc_control_points (SCM smob)
212 Grob *me = unsmob_grob (smob);
214 Grob *yparent = me->get_parent (Y_AXIS);
215 if ((Tie_column::has_interface (yparent)
216 || Semi_tie_column::has_interface (yparent))
217 && unsmob_grob_array (yparent->get_object ("ties"))
218 // && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1
221 /* trigger positioning. */
222 (void) yparent->get_property ("positioning-done");
225 SCM cp = me->get_property_data ("control-points");
226 if (!scm_is_pair (cp))
228 cp = get_default_control_points (me);
235 TODO: merge with Slur::print.
237 MAKE_SCHEME_CALLBACK (Tie, print, 1);
239 Tie::print (SCM smob)
241 Grob *me = unsmob_grob (smob);
243 SCM cp = me->get_property ("control-points");
245 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
246 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
247 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
251 for (SCM s = cp; scm_is_pair (s); s = scm_cdr (s))
253 b.control_[i] = ly_scm2offset (scm_car (s));
259 SCM p = me->get_property ("dash-period");
260 SCM f = me->get_property ("dash-fraction");
261 if (scm_is_number (p) && scm_is_number (f))
262 a = Lookup::dashed_slur (b,
264 robust_scm2double (p, 1.0),
265 robust_scm2double (f, 0));
268 get_grob_direction (me) * base_thick,
271 #if DEBUG_TIE_SCORING
272 SCM quant_score = me->get_property ("quant-score");
274 if (to_boolean (me->layout ()
275 ->lookup_variable (ly_symbol2scm ("debug-tie-scoring")))
276 && scm_is_string (quant_score))
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 horizontal curve connecting two noteheads. \n\n"
305 "avoid-slur " // UGH.