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;
139 Box b = boxes.boundary (updowndir, 0);
141 x[-d] = b[X_AXIS].linear_combination (-d / 2);
145 && !Stem::is_invisible (stem)
146 && updowndir == get_grob_direction (stem))
147 x.unite (robust_relative_extent (stem, common, X_AXIS));
150 (*skyline_drul)[d].boundary (updowndir, 0).height_ = x[-d];
152 while (flip (&updowndir) != DOWN);
154 for (int i = 0; i < ties.size (); i++)
156 Spanner *tie = dynamic_cast<Spanner*> (ties[i]);
157 Grob *head = Tie::head (tie, d);
161 Grob *dots = unsmob_grob (head->get_object ("dot"));
162 if (dots && d == LEFT)
164 Interval x = dots->extent (common, X_AXIS);
165 Real p = Staff_symbol_referencer::get_position (dots);
168 y *= (staff_space /4);
169 y.translate (p * staff_space * .5);
171 insert_extent_into_skyline (&skyline_drul->elem_ref (d),
172 Box (x,y), Y_AXIS, -d);
177 while (flip (&d) != LEFT);
182 Tie_column::new_directions (Grob *me)
184 extract_grob_set (me, "ties", ro_ties);
185 Link_array<Grob> ties (ro_ties);
189 if (ties.size() == 1)
191 Tie::set_default_control_points (ties[0]);
195 ties.sort (&Tie::compare);
197 Array<Tie_configuration> tie_configs;
198 for (int i = 0; i < ties.size (); i++)
200 Tie_configuration conf;
201 conf.dir_ = get_grob_direction (ties[i]);
202 conf.position_ = Tie::get_position (ties[i]);
203 tie_configs.push (conf);
206 SCM manual_configs = me->get_property ("tie-configuration");
207 bool manual_override = false;
209 for (SCM s = manual_configs;
210 scm_is_pair (s) && k < tie_configs.size(); s = scm_cdr (s))
212 SCM entry = scm_car (s);
213 if (!scm_is_pair (entry))
216 manual_override = true;
217 tie_configs[k].position_ = robust_scm2double (scm_car (entry), tie_configs[k].position_);
218 tie_configs[k].dir_ = Direction (robust_scm2int (scm_cdr (entry), tie_configs[k].dir_));
222 if (!tie_configs[0].dir_)
223 tie_configs[0].dir_ = DOWN;
224 if (!tie_configs.top().dir_)
225 tie_configs.top().dir_ = UP;
230 for (int i = 1; i < tie_configs.size(); i++)
232 if (fabs (tie_configs[i-1].position_ - tie_configs[i].position_) <= 1)
234 if (!tie_configs[i-1].dir_)
235 tie_configs[i-1].dir_ = DOWN;
236 if (!tie_configs[i].dir_)
237 tie_configs[i].dir_ = UP;
241 for (int i = 1; i < tie_configs.size() - 1; i++)
243 if (tie_configs[i].dir_)
246 tie_configs[i].dir_ = (Direction) sign (tie_configs[i].position_);
250 for (int i = 0; i < ties.size (); i++)
252 common = dynamic_cast<Spanner*> (ties[i])->get_bound (LEFT)->common_refpoint (common, X_AXIS);
253 common = dynamic_cast<Spanner*> (ties[i])->get_bound (RIGHT)->common_refpoint (common, X_AXIS);
256 Drul_array< Array<Skyline_entry> > skylines;
257 set_chord_outlines (&skylines, ties, common);
260 details.init (ties[0]);
263 Let the ties flow out, according to our single-tie formatting.
265 if (!manual_override)
267 Tie::get_configuration (ties[0], common, &tie_configs.elem_ref (0),
271 Tie::get_configuration (ties.top (), common,
272 &tie_configs.elem_ref (tie_configs.size()-1),
279 Calculate final width and shape of the ties.
281 Real staff_space = Staff_symbol_referencer::staff_space (ties[0]);
282 Real gap = robust_scm2double (ties[0]->get_property ("x-gap"), 0.2);
283 for (int i = 0; i < ties.size(); i++)
286 && (i == 0 || i == ties.size () -1))
289 Tie_configuration conf = tie_configs[i];
290 conf = tie_configs[i];
293 bool on_line = Staff_symbol_referencer::on_staffline (ties[0],
294 int (rint (conf.position_)));
296 line_dy = - sign (conf.height (details) - 0.6 * staff_space)
297 * 0.2 * staff_space * conf.dir_;
299 Real y = conf.position_ * staff_space * 0.5
302 = get_skyline_attachment (skylines, y);
303 conf.attachment_x_.intersect (get_skyline_attachment (skylines,
304 y + conf.dir_ * staff_space * .5));
306 conf.delta_y_ += line_dy;
307 conf.attachment_x_.widen (-gap);
309 && Staff_symbol_referencer::staff_radius (ties[0]) * staff_space > y)
310 conf.center_tie_vertically (details);
312 tie_configs[i] = conf;
316 Try to shift small ties into available spaces.
318 if (!manual_override)
320 set<int> positions_taken;
321 for (int i = 0; i < tie_configs.size (); i++)
322 positions_taken.insert (int (rint (tie_configs[i].position_)));
324 for (int i = 0; i < tie_configs.size (); i++)
326 Tie_configuration * conf = &tie_configs.elem_ref (i);
327 if (Staff_symbol_referencer::on_staffline (ties[0], int (rint (conf->position_)))
328 && conf->height (details) < 0.4 * staff_space
329 && (positions_taken.find (int (rint (conf->position_ + conf->dir_)))
330 == positions_taken.end ()))
332 positions_taken.insert (int (rint (conf->position_ + conf->dir_)));
333 conf->delta_y_ += 0.2 * staff_space * conf->dir_;
338 for (int i = 0; i < ties.size(); i++)
340 Tie::set_control_points (ties[i], common, tie_configs[i],
343 set_grob_direction (ties[i], tie_configs[i].dir_);
348 ADD_INTERFACE (Tie_column, "tie-column-interface",
349 "Object that sets directions of multiple ties in a tied chord",