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) 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);
130 MAKE_SCHEME_CALLBACK(Tie, calc_direction, 1);
132 Tie::calc_direction (SCM smob)
134 Grob *me = unsmob_grob (smob);
135 Grob *yparent = me->get_parent (Y_AXIS);
136 if (Tie_column::has_interface (yparent)
137 && unsmob_grob_array (yparent->get_object ("ties"))
138 && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
140 /* trigger positioning. */
141 (void) yparent->get_property ("positioning-done");
144 set_grob_direction (me, Tie::get_default_dir (me));
146 return SCM_UNSPECIFIED;
151 Tie::set_default_control_points (Grob *me_grob)
153 Spanner *me = dynamic_cast<Spanner*> (me_grob);
155 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
156 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
158 Tie_formatting_problem problem;
159 problem.from_tie (me);
160 Tie_specification spec = problem.get_tie_specification (0);
161 spec.has_manual_dir_ = true;
162 spec.manual_dir_ = get_grob_direction (me);
164 Tie_configuration conf
165 = problem.find_optimal_tie_configuration (spec);
167 set_control_points (me, problem.common_x_refpoint (),
168 conf, problem.details_);
172 Tie::set_control_points (Grob *me,
174 Tie_configuration const &conf,
175 Tie_details const &details
178 Bezier b = conf.get_transformed_bezier (details);
179 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
181 SCM controls = SCM_EOL;
182 for (int i = 4; i--;)
184 if (!b.control_[i].is_sane ())
185 programming_error ("Insane offset");
186 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
188 me->set_property ("control-points", controls);
191 MAKE_SCHEME_CALLBACK(Tie, calc_control_points, 1);
193 Tie::calc_control_points (SCM smob)
195 Grob *me = unsmob_grob (smob);
197 // trigger Tie-column
198 (void) get_grob_direction (me);
200 Grob *yparent = me->get_parent (Y_AXIS);
201 if (Tie_column::has_interface (yparent)
202 && unsmob_grob_array (yparent->get_object ("ties"))
203 && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
205 /* trigger positioning. */
206 (void) yparent->get_property ("positioning-done");
209 if (!scm_is_pair (me->get_property ("control-points")))
211 set_default_control_points (me);
214 return SCM_UNSPECIFIED;
218 TODO: merge witnh Slur::print.
220 MAKE_SCHEME_CALLBACK (Tie, print, 1);
222 Tie::print (SCM smob)
224 Grob *me = unsmob_grob (smob);
226 SCM cp = me->get_property ("control-points");
228 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
229 Real base_thick = staff_thick * robust_scm2double (me->get_property ("thickness"), 1);
230 Real line_thick = staff_thick * robust_scm2double (me->get_property ("line-thickness"), 1);
234 for (SCM s = cp; s != SCM_EOL; s = scm_cdr (s))
236 b.control_[i] = ly_scm2offset (scm_car (s));
242 SCM p = me->get_property ("dash-period");
243 SCM f = me->get_property ("dash-fraction");
244 if (scm_is_number (p) && scm_is_number (f))
245 a = Lookup::dashed_slur (b,
247 robust_scm2double (p, 1.0),
248 robust_scm2double (f, 0));
251 get_grob_direction (me) * base_thick,
254 #if DEBUG_TIE_SCORING
255 SCM quant_score = me->get_property ("quant-score");
257 if (to_boolean (me->layout ()
258 ->lookup_variable (ly_symbol2scm ("debug-tie-scoring")))
259 && scm_is_string (quant_score))
262 SCM properties = Font_interface::text_font_alist_chain (me);
264 Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
265 (me->layout ()->self_scm (), properties,
267 tm.translate_axis (b.control_[0][Y_AXIS]*2, Y_AXIS);
268 a.add_at_edge (X_AXIS, RIGHT, tm, 1.0, 0);
272 return a.smobbed_copy ();
278 "A horizontal curve connecting two noteheads. \n\n"
283 "avoid-slur " // UGH.