2 tie.cc -- implement Tie
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "output-def.hh"
13 #include "rhythmic-head.hh"
15 #include "paper-column.hh"
17 #include "staff-symbol-referencer.hh"
18 #include "directional-element-interface.hh"
21 #include "note-head.hh"
22 #include "tie-column.hh"
23 #include "grob-array.hh"
24 #include "tie-formatting-problem.hh"
25 #include "tie-configuration.hh"
29 Tie::compare (Grob *const &s1,
32 return sign (Tie::get_position (s1) - Tie::get_position (s2));
36 Tie::set_head (Grob *me, Direction d, Grob *h)
38 dynamic_cast<Spanner *> (me)->set_bound (d, h);
42 Tie::head (Grob *me, Direction d)
44 Item *it = dynamic_cast<Spanner*> (me)->get_bound (d);
45 if (Note_head::has_interface (it))
52 Tie::get_column_rank (Grob *me, Direction d)
54 Spanner *span = dynamic_cast<Spanner *> (me);
55 Grob *h = head (me, d);
57 h = span->get_bound (d);
59 Grob *col = dynamic_cast<Item *> (h)->get_column ();
60 return Paper_column::get_rank (col);
64 Tie::get_position (Grob *me)
69 Grob *h = head (me, d);
71 return (int) Staff_symbol_referencer::get_position (h);
73 while (flip (&d) != LEFT);
77 TODO: this is theoretically possible for ties across more than 2
78 systems.. We should look at the first broken copy.
81 programming_error ("Tie without heads. Suicide");
87 Default: Put the tie oppositie of the stem [Wanske p231]
89 In case of chords: Tie_column takes over
91 The direction of the Tie is more complicated (See [Ross] p136 and
94 (what about linebreaks? )
97 Tie::get_default_dir (Grob *me)
99 Item *sl = head (me, LEFT) ? Rhythmic_head::get_stem (head (me, LEFT)) : 0;
100 Item *sr = head (me, RIGHT) ? Rhythmic_head::get_stem (head (me, RIGHT)) : 0;
103 if (get_grob_direction (sl) == UP
104 && get_grob_direction (sr) == UP)
109 Item *s = sl ? sl : sr;
110 return -get_grob_direction (s);
117 MAKE_SCHEME_CALLBACK(Tie, calc_direction, 1);
119 Tie::calc_direction (SCM smob)
121 Grob *me = unsmob_grob (smob);
122 Grob *yparent = me->get_parent (Y_AXIS);
123 if (Tie_column::has_interface (yparent)
124 && unsmob_grob_array (yparent->get_object ("ties"))
125 && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
127 /* trigger positioning. */
128 (void) yparent->get_property ("positioning-done");
131 set_grob_direction (me, Tie::get_default_dir (me));
133 return SCM_UNSPECIFIED;
138 Tie::set_default_control_points (Grob *me_grob)
140 Spanner *me = dynamic_cast<Spanner*> (me_grob);
142 common = me->get_bound (LEFT)->common_refpoint (common, X_AXIS);
143 common = me->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
145 Tie_formatting_problem problem;
146 problem.from_tie (me);
148 // get_configuration (me, &conf, problem);
149 int tie_position = (int) Tie::get_position (me);
150 Tie_configuration conf
151 = problem.find_optimal_tie_configuration (tie_position, get_grob_direction (me));
152 set_control_points (me, problem.common_x_refpoint (),
153 conf, problem.details_);
157 Tie::set_control_points (Grob *me,
159 Tie_configuration const &conf,
160 Tie_details const &details
163 Bezier b = conf.get_transformed_bezier (details);
164 b.translate (Offset (- me->relative_coordinate (common, X_AXIS), 0));
166 SCM controls = SCM_EOL;
167 for (int i = 4; i--;)
169 if (!b.control_[i].is_sane ())
170 programming_error ("Insane offset");
171 controls = scm_cons (ly_offset2scm (b.control_[i]), controls);
173 me->set_property ("control-points", controls);
176 MAKE_SCHEME_CALLBACK(Tie, calc_control_points, 1);
178 Tie::calc_control_points (SCM smob)
180 Grob *me = unsmob_grob (smob);
182 // trigger Tie-column
183 (void) get_grob_direction (me);
185 Grob *yparent = me->get_parent (Y_AXIS);
186 if (Tie_column::has_interface (yparent)
187 && unsmob_grob_array (yparent->get_object ("ties"))
188 && unsmob_grob_array (yparent->get_object ("ties"))->size () > 1)
190 /* trigger positioning. */
191 (void) yparent->get_property ("positioning-done");
194 if (!scm_is_pair (me->get_property ("control-points")))
196 set_default_control_points (me);
199 return SCM_UNSPECIFIED;
203 MAKE_SCHEME_CALLBACK (Tie, print, 1);
205 Tie::print (SCM smob)
207 Grob *me = unsmob_grob (smob);
209 SCM cp = me->get_property ("control-points");
211 Real staff_thick = Staff_symbol_referencer::line_thickness (me);
212 Real base_thick = robust_scm2double (me->get_property ("thickness"), 1);
213 Real thick = base_thick * staff_thick;
217 for (SCM s = cp; s != SCM_EOL; s = scm_cdr (s))
219 b.control_[i] = ly_scm2offset (scm_car (s));
225 SCM p = me->get_property ("dash-period");
226 SCM f = me->get_property ("dash-fraction");
227 if (scm_is_number (p) && scm_is_number (f))
228 a = Lookup::dashed_slur (b,
230 robust_scm2double (p, 1.0),
231 robust_scm2double (f, 0));
234 get_grob_direction (me) * staff_thick,
237 return a.smobbed_copy ();
243 "A tie connecting two noteheads. \n\n"