2 tie-column.cc -- implement Tie_column
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
16 #include "staff-symbol-referencer.hh"
18 #include "tie-column.hh"
19 #include "paper-column.hh"
21 #include "pointer-group-interface.hh"
23 #include "directional-element-interface.hh"
24 #include "rhythmic-head.hh"
27 Tie_column::add_tie (Grob *me, Grob *tie)
29 if (tie->get_parent (Y_AXIS)
30 && Tie_column::has_interface (tie->get_parent (Y_AXIS)))
33 if (!Pointer_group_interface::count (me, ly_symbol2scm ("ties")))
35 dynamic_cast<Spanner *> (me)->set_bound (LEFT, Tie::head (tie, LEFT));
36 dynamic_cast<Spanner *> (me)->set_bound (RIGHT, Tie::head (tie, RIGHT));
39 tie->set_parent (me, Y_AXIS);
40 Pointer_group_interface::add_grob (me, ly_symbol2scm ("ties"), tie);
41 tie->add_dependency (me);
45 Tie_column::set_directions (Grob *me)
47 if (!to_boolean (me->get_property ("positioning-done")))
49 me->set_property ("positioning-done", SCM_BOOL_T);
55 Tie::compare (Grob *const &s1,
58 return sign (Tie::get_position (s1) - Tie::get_position (s2));
61 MAKE_SCHEME_CALLBACK (Tie_column, after_line_breaking, 1);
63 Tie_column::after_line_breaking (SCM smob)
65 set_directions (unsmob_grob (smob));
66 return SCM_UNSPECIFIED;
70 Extend the spanner over its Tie constituents.
72 MAKE_SCHEME_CALLBACK (Tie_column, before_line_breaking, 1);
74 Tie_column::before_line_breaking (SCM smob)
76 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
77 for (SCM s = me->get_property ("ties"); scm_is_pair (s); s = scm_cdr (s))
79 Spanner *tie = dynamic_cast<Spanner *> (unsmob_grob (scm_car (s)));
83 if (dir * tie->get_bound (dir)->get_column ()->get_rank ()
84 > dir * me->get_bound (dir)->get_column ()->get_rank ())
85 me->set_bound (dir, Tie::head (tie, dir));
87 while (flip (&dir) != LEFT);
89 return SCM_UNSPECIFIED;
95 set_chord_outlines (Drul_array< Array<Skyline_entry> > *skyline_drul,
96 Link_array<Grob> ties,
101 Real staff_space = Staff_symbol_referencer::staff_space (ties[0]);
108 for (int i = 0; i < ties.size (); i++)
110 Spanner *tie = dynamic_cast<Spanner*> (ties[i]);
112 Grob *head = Tie::head (tie, d);
117 stem = unsmob_grob (head->get_object ("stem"));
119 Real p = Tie::get_position (tie);
120 Interval y ((p-1) * 0.5 * staff_space,
121 (p+1) * 0.5 * staff_space);
123 Interval x = head->extent (common, X_AXIS);
124 boxes.push (Box (x, y));
128 (*skyline_drul)[d] = empty_skyline (-d);
130 Spanner *tie = dynamic_cast<Spanner*> (ties[0]);
131 if (tie->get_bound (d)->break_status_dir ())
133 Real x = robust_relative_extent (tie->get_bound (d),
137 (*skyline_drul)[d].elem_ref (0).height_ = x;
140 for (int i = 0; i < boxes.size (); i++)
141 insert_extent_into_skyline (&skyline_drul->elem_ref (d),
142 boxes[i], Y_AXIS, -d);
144 Direction updowndir = DOWN;
150 Box b = boxes.boundary (updowndir, 0);
152 x[-d] = b[X_AXIS].linear_combination (-d / 2);
156 && !Stem::is_invisible (stem)
157 && updowndir == get_grob_direction (stem))
158 x.unite (robust_relative_extent (stem, common, X_AXIS));
161 (*skyline_drul)[d].boundary (updowndir, 0).height_ = x[-d];
163 while (flip (&updowndir) != DOWN);
165 for (int i = 0; i < ties.size (); i++)
167 Spanner *tie = dynamic_cast<Spanner*> (ties[i]);
168 Grob *head = Tie::head (tie, d);
172 Grob *dots = unsmob_grob (head->get_object ("dot"));
173 if (dots && d == LEFT)
175 Interval x = dots->extent (common, X_AXIS);
176 Real p = Staff_symbol_referencer::get_position (dots);
179 y *= (staff_space /4);
180 y.translate (p * staff_space * .5);
182 insert_extent_into_skyline (&skyline_drul->elem_ref (d),
183 Box (x,y), Y_AXIS, -d);
188 while (flip (&d) != LEFT);
193 Tie_column::new_directions (Grob *me)
195 extract_grob_set (me, "ties", ro_ties);
196 Link_array<Grob> ties (ro_ties);
200 if (ties.size() == 1)
202 Tie::set_default_control_points (ties[0]);
206 ties.sort (&Tie::compare);
208 Array<Tie_configuration> tie_configs;
209 for (int i = 0; i < ties.size (); i++)
211 Tie_configuration conf;
212 conf.dir_ = get_grob_direction (ties[i]);
213 conf.position_ = Tie::get_position (ties[i]);
214 tie_configs.push (conf);
217 SCM manual_configs = me->get_property ("tie-configuration");
218 bool manual_override = false;
220 for (SCM s = manual_configs;
221 scm_is_pair (s) && k < tie_configs.size(); s = scm_cdr (s))
223 SCM entry = scm_car (s);
224 if (!scm_is_pair (entry))
227 manual_override = true;
228 tie_configs[k].position_ = robust_scm2double (scm_car (entry), tie_configs[k].position_);
229 tie_configs[k].dir_ = Direction (robust_scm2int (scm_cdr (entry), tie_configs[k].dir_));
233 if (!tie_configs[0].dir_)
234 tie_configs[0].dir_ = DOWN;
235 if (!tie_configs.top().dir_)
236 tie_configs.top().dir_ = UP;
241 for (int i = 1; i < tie_configs.size(); i++)
243 if (fabs (tie_configs[i-1].position_ - tie_configs[i].position_) <= 1)
245 if (!tie_configs[i-1].dir_)
246 tie_configs[i-1].dir_ = DOWN;
247 if (!tie_configs[i].dir_)
248 tie_configs[i].dir_ = UP;
252 for (int i = 1; i < tie_configs.size() - 1; i++)
254 if (tie_configs[i].dir_)
257 tie_configs[i].dir_ = (Direction) sign (tie_configs[i].position_);
261 for (int i = 0; i < ties.size (); i++)
263 common = dynamic_cast<Spanner*> (ties[i])->get_bound (LEFT)->common_refpoint (common, X_AXIS);
264 common = dynamic_cast<Spanner*> (ties[i])->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
267 Drul_array< Array<Skyline_entry> > skylines;
268 set_chord_outlines (&skylines, ties, common);
271 details.init (ties[0]);
274 Let the ties flow out, according to our single-tie formatting.
276 if (!manual_override)
278 Tie::get_configuration (ties[0], common, &tie_configs.elem_ref (0),
282 Tie::get_configuration (ties.top (), common,
283 &tie_configs.elem_ref (tie_configs.size()-1),
290 Calculate final width and shape of the ties.
292 Real staff_space = Staff_symbol_referencer::staff_space (ties[0]);
293 Real gap = robust_scm2double (ties[0]->get_property ("x-gap"), 0.2);
294 for (int i = 0; i < ties.size(); i++)
297 && (i == 0 || i == ties.size () -1))
300 Tie_configuration conf = tie_configs[i];
301 conf = tie_configs[i];
304 bool on_line = Staff_symbol_referencer::on_staffline (ties[0],
305 int (rint (conf.position_)));
307 line_dy = - sign (conf.height (details) - 0.6 * staff_space)
308 * 0.2 * staff_space * conf.dir_;
310 Real y = conf.position_ * staff_space * 0.5
313 = get_skyline_attachment (skylines, y);
314 conf.attachment_x_.intersect (get_skyline_attachment (skylines,
315 y + conf.dir_ * staff_space * .5));
317 conf.delta_y_ += line_dy;
318 conf.attachment_x_.widen (-gap);
320 && Staff_symbol_referencer::staff_radius (ties[0]) * staff_space > y)
321 conf.center_tie_vertically (details);
323 tie_configs[i] = conf;
327 Try to shift small ties into available spaces.
329 if (!manual_override)
331 set<int> positions_taken;
332 for (int i = 0; i < tie_configs.size (); i++)
333 positions_taken.insert (int (rint (tie_configs[i].position_)));
335 for (int i = 0; i < tie_configs.size (); i++)
337 Tie_configuration * conf = &tie_configs.elem_ref (i);
338 if (Staff_symbol_referencer::on_staffline (ties[0], int (rint (conf->position_)))
339 && conf->height (details) < 0.4 * staff_space
340 && (positions_taken.find (int (rint (conf->position_ + conf->dir_)))
341 == positions_taken.end ()))
343 positions_taken.insert (int (rint (conf->position_ + conf->dir_)));
344 conf->delta_y_ += 0.2 * staff_space * conf->dir_;
349 for (int i = 0; i < ties.size(); i++)
351 Tie::set_control_points (ties[i], common, tie_configs[i],
354 set_grob_direction (ties[i], tie_configs[i].dir_);
359 ADD_INTERFACE (Tie_column, "tie-column-interface",
360 "Object that sets directions of multiple ties in a tied chord",