2 tie.cc -- implement Tie
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 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"
32 Tie::compare (Grob *const &s1,
35 return sign (Tie::get_position (s1) - Tie::get_position (s2));
39 Tie::set_head (Grob *me, Direction d, Grob *h)
41 dynamic_cast<Spanner *> (me)->set_bound (d, h);
45 Tie::head (Grob *me, Direction d)
47 Item *it = dynamic_cast<Spanner*> (me)->get_bound (d);
48 if (Note_head::has_interface (it))
55 Tie::get_column_rank (Grob *me, Direction d)
57 Spanner *span = dynamic_cast<Spanner *> (me);
58 Grob *h = head (me, d);
60 h = span->get_bound (d);
62 Grob *col = dynamic_cast<Item *> (h)->get_column ();
63 return Paper_column::get_rank (col);
67 Tie::get_position (Grob *me)
72 Grob *h = head (me, d);
74 return (int) rint (Staff_symbol_referencer::get_position (h));
76 while (flip (&d) != LEFT);
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 Default: Put the tie oppositie of the stem [Wanske p231]
92 In case of chords: Tie_column takes over
94 The direction of the Tie is more complicated (See [Ross] p136 and
97 (what about linebreaks? )
100 Tie::get_default_dir (Grob *me)
102 Drul_array<Grob*> stems;
106 Grob *stem = head (me, d) ? Rhythmic_head::get_stem (head (me, d)) : 0;
108 stem = Stem::is_invisible (stem) ? 0 : stem;
112 while (flip (&d)!= LEFT);
114 if (stems[LEFT] && stems[RIGHT])
116 if (get_grob_direction (stems[LEFT]) == UP
117 && get_grob_direction (stems[RIGHT]) == UP)
120 else if (stems[LEFT] || stems[RIGHT])
122 Grob *s = stems[LEFT] ? stems[LEFT] : stems[RIGHT];
123 return -get_grob_direction (s);
125 else if (int p = get_position (me))
126 return Direction (sign (p));
132 MAKE_SCHEME_CALLBACK(Tie, calc_direction, 1);
134 Tie::calc_direction (SCM smob)
136 Grob *me = unsmob_grob (smob);
137 Grob *yparent = me->get_parent (Y_AXIS);
138 if (Tie_column::has_interface (yparent)
139 && unsmob_grob_array (yparent->get_object ("ties"))
140 && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
142 /* trigger positioning. */
143 (void) yparent->get_property ("positioning-done");
146 set_grob_direction (me, Tie::get_default_dir (me));
148 return SCM_UNSPECIFIED;
153 Tie::set_default_control_points (Grob *me_grob)
155 Spanner *me = dynamic_cast<Spanner*> (me_grob);
157 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
158 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
160 Tie_formatting_problem problem;
161 problem.from_tie (me);
162 Tie_specification spec = problem.get_tie_specification (0);
163 spec.has_manual_dir_ = true;
164 spec.manual_dir_ = get_grob_direction (me);
168 Tie_configuration conf
169 = problem.find_optimal_tie_configuration (spec);
171 set_control_points (me, problem.common_x_refpoint (),
172 conf, problem.details_);
176 Tie::set_control_points (Grob *me,
178 Tie_configuration const &conf,
179 Tie_details const &details
182 Bezier b = conf.get_transformed_bezier (details);
183 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
185 SCM controls = SCM_EOL;
186 for (int i = 4; i--;)
188 if (!b.control_[i].is_sane ())
189 programming_error ("Insane offset");
190 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
192 me->set_property ("control-points", controls);
195 MAKE_SCHEME_CALLBACK(Tie, calc_control_points, 1);
197 Tie::calc_control_points (SCM smob)
199 Grob *me = unsmob_grob (smob);
201 // trigger Tie-column
202 (void) get_grob_direction (me);
204 Grob *yparent = me->get_parent (Y_AXIS);
205 if (Tie_column::has_interface (yparent)
206 && unsmob_grob_array (yparent->get_object ("ties"))
207 && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
209 /* trigger positioning. */
210 (void) yparent->get_property ("positioning-done");
213 if (!scm_is_pair (me->get_property_data (ly_symbol2scm ("control-points"))))
215 set_default_control_points (me);
218 return SCM_UNSPECIFIED;
222 TODO: merge witnh Slur::print.
224 MAKE_SCHEME_CALLBACK (Tie, print, 1);
226 Tie::print (SCM smob)
228 Grob *me = unsmob_grob (smob);
230 SCM cp = me->get_property ("control-points");
232 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
233 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
234 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
238 for (SCM s = cp; s != SCM_EOL; s = scm_cdr (s))
240 b.control_[i] = ly_scm2offset (scm_car (s));
246 SCM p = me->get_property ("dash-period");
247 SCM f = me->get_property ("dash-fraction");
248 if (scm_is_number (p) && scm_is_number (f))
249 a = Lookup::dashed_slur (b,
251 robust_scm2double (p, 1.0),
252 robust_scm2double (f, 0));
255 get_grob_direction (me) * base_thick,
258 #if DEBUG_TIE_SCORING
259 SCM quant_score = me->get_property ("quant-score");
261 if (to_boolean (me->layout ()
262 ->lookup_variable (ly_symbol2scm ("debug-tie-scoring")))
263 && scm_is_string (quant_score))
266 SCM properties = Font_interface::text_font_alist_chain (me);
268 Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
269 (me->layout ()->self_scm (), properties,
271 tm.translate_axis (b.control_[0][Y_AXIS]*2, Y_AXIS);
272 a.add_at_edge (X_AXIS, RIGHT, tm, 1.0, 0);
276 return a.smobbed_copy ();
282 "A horizontal curve connecting two noteheads. \n\n"
287 "avoid-slur " // UGH.