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);
129 for (int i = 0; i < boxes.size (); i++)
130 insert_extent_into_skyline (&skyline_drul->elem_ref (d),
131 boxes[i], Y_AXIS, -d);
133 Direction updowndir = DOWN;
136 Box b = boxes.boundary (updowndir, 0);
137 Interval x = b[X_AXIS];
138 x[-d] = b[X_AXIS].linear_combination (-d / 2);
140 && !Stem::is_invisible (stem)
141 && updowndir == get_grob_direction (stem))
142 x.unite (robust_relative_extent (stem, common, X_AXIS));
144 (*skyline_drul)[d].boundary (updowndir, 0).height_ = x[-d];
146 while (flip (&updowndir) != DOWN);
148 for (int i = 0; i < ties.size (); i++)
150 Spanner *tie = dynamic_cast<Spanner*> (ties[i]);
151 Grob *head = Tie::head (tie, d);
155 Grob *dots = unsmob_grob (head->get_object ("dot"));
158 Interval x = dots->extent (common, X_AXIS);
159 Real p = Staff_symbol_referencer::get_position (dots);
162 y *= (staff_space /4);
163 y.translate ( p * staff_space * .5);
165 insert_extent_into_skyline (&skyline_drul->elem_ref (d),
166 Box (x,y), Y_AXIS, -d);
171 while (flip (&d) != LEFT);
176 Tie_column::new_directions (Grob *me)
178 extract_grob_set (me, "ties", ro_ties);
179 Link_array<Grob> ties (ro_ties);
183 if (ties.size() == 1)
185 Tie::set_default_control_points (ties[0]);
189 ties.sort (&Tie::compare);
191 Array<Tie_configuration> tie_configs;
192 for (int i = 0; i < ties.size (); i++)
194 Tie_configuration conf;
195 conf.dir_ = get_grob_direction (ties[i]);
196 conf.position_ = Tie::get_position (ties[i]);
197 tie_configs.push (conf);
200 SCM manual_configs = me->get_property ("tie-configuration");
201 bool manual_override = false;
203 for (SCM s = manual_configs;
204 scm_is_pair (s) && k < tie_configs.size(); s = scm_cdr (s))
206 SCM entry = scm_car (s);
207 if (!scm_is_pair (entry))
210 manual_override = true;
211 tie_configs[k].position_ = robust_scm2double (scm_car (entry), tie_configs[k].position_);
212 tie_configs[k].dir_ = Direction (robust_scm2int (scm_cdr (entry), tie_configs[k].dir_));
216 if (!tie_configs[0].dir_)
217 tie_configs[0].dir_ = DOWN;
218 if (!tie_configs.top().dir_)
219 tie_configs.top().dir_ = UP;
224 for (int i = 1; i < tie_configs.size(); i++)
226 if (fabs (tie_configs[i-1].position_ - tie_configs[i].position_) <= 1)
228 if (!tie_configs[i-1].dir_)
229 tie_configs[i-1].dir_ = DOWN;
230 if (!tie_configs[i].dir_)
231 tie_configs[i].dir_ = UP;
235 for (int i = 1; i < tie_configs.size() - 1; i++)
237 if (tie_configs[i].dir_)
240 tie_configs[i].dir_ = (Direction) sign (tie_configs[i].position_);
244 for (int i = 0; i < ties.size (); i++)
246 common = dynamic_cast<Spanner*> (ties[i])->get_bound (LEFT)->common_refpoint (common, X_AXIS);
247 common = dynamic_cast<Spanner*> (ties[i])->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
250 Drul_array< Array<Skyline_entry> > skylines;
251 set_chord_outlines (&skylines, ties, common);
254 details.init (ties[0]);
257 Let the ties flow out, according to our single-tie formatting.
259 if (!manual_override)
261 Tie::get_configuration (ties[0], common, &tie_configs.elem_ref (0),
265 Tie::get_configuration (ties.top (), common,
266 &tie_configs.elem_ref (tie_configs.size()-1),
273 Calculate final width and shape of the ties.
275 Real staff_space = Staff_symbol_referencer::staff_space (ties[0]);
276 Real gap = robust_scm2double (ties[0]->get_property ("x-gap"), 0.2);
277 for (int i = 0; i < ties.size(); i++)
280 && (i == 0 || i == ties.size () -1))
283 Tie_configuration conf = tie_configs[i];
284 conf = tie_configs[i];
287 bool on_line = Staff_symbol_referencer::on_staffline (ties[0],
288 int (rint (conf.position_)));
290 line_dy = - sign (conf.height (details) - 0.6 * staff_space)
291 * 0.2 * staff_space * conf.dir_;
293 Real y = conf.position_ * staff_space * 0.5
296 = get_skyline_attachment (skylines, y);
297 conf.attachment_x_.intersect (get_skyline_attachment (skylines,
298 y + conf.dir_ * staff_space * .5));
300 conf.delta_y_ += line_dy;
301 conf.attachment_x_.widen (-gap);
303 && Staff_symbol_referencer::staff_radius (ties[0]) * staff_space > y)
304 conf.center_tie_vertically (details);
306 tie_configs[i] = conf;
310 Try to shift small ties into available spaces.
312 if (!manual_override)
314 set<int> positions_taken;
315 for (int i = 0; i < tie_configs.size (); i++)
316 positions_taken.insert (int (rint (tie_configs[i].position_)));
318 for (int i = 0; i < tie_configs.size (); i++)
320 Tie_configuration * conf = &tie_configs.elem_ref (i);
321 if (Staff_symbol_referencer::on_staffline (ties[0], int (rint (conf->position_)))
322 && conf->height (details) < 0.4 * staff_space
323 && (positions_taken.find (int (rint (conf->position_ + conf->dir_)))
324 == positions_taken.end ()))
326 positions_taken.insert (int (rint (conf->position_ + conf->dir_)));
327 conf->delta_y_ += 0.2 * staff_space * conf->dir_;
332 for (int i = 0; i < ties.size(); i++)
334 Tie::set_control_points (ties[i], common, tie_configs[i],
337 set_grob_direction (ties[i], tie_configs[i].dir_);
342 ADD_INTERFACE (Tie_column, "tie-column-interface",
343 "Object that sets directions of multiple ties in a tied chord",