2 dot-column.cc -- implement Dot_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "dot-column.hh"
19 #include "dot-column.hh"
20 #include "rhythmic-head.hh"
21 #include "staff-symbol-referencer.hh"
22 #include "directional-element-interface.hh"
23 #include "side-position-interface.hh"
24 #include "axis-group-interface.hh"
27 #include "pointer-group-interface.hh"
28 #include "dot-configuration.hh"
29 #include "note-head.hh"
31 #include "dot-formatting-problem.hh"
33 MAKE_SCHEME_CALLBACK (Dot_column, calc_positioning_done, 1);
35 Dot_column::calc_positioning_done (SCM smob)
37 Grob *me = unsmob_grob (smob);
39 me->set_property ("positioning-done", SCM_BOOL_T);
42 = extract_grob_array (me, "dots");
44 vector<Grob*> main_heads;
49 Trigger note collision resolution first, since that may kill off
52 for (vsize i = 0; i < dots.size (); i++)
54 Grob *n = dots[i]->get_parent (Y_AXIS);
55 commonx = n->common_refpoint (commonx, X_AXIS);
57 if (Grob *stem = unsmob_grob (n->get_object("stem")))
59 commonx = stem->common_refpoint (commonx, X_AXIS);
61 if (Stem::first_head (stem) == n)
62 main_heads.push_back (n);
70 extract_grob_set(me, "side-support-elements", support);
73 for (vsize i = 0; i < main_heads.size (); i++)
74 base_x.unite (main_heads[i]->extent (commonx, X_AXIS));
76 for (vsize i = 0; i < support.size (); i++)
79 ss = Staff_symbol_referencer::staff_space (support[i]);
81 Interval y (support[i]->extent (support[i], Y_AXIS));
84 y += Staff_symbol_referencer::get_position (support[i]);
86 Box b (support[i]->extent (commonx, X_AXIS), y);
89 if (Grob *s = unsmob_grob (support[i]->get_object ("stem")))
93 for (set<Grob*>::const_iterator i(stems.begin());
94 i != stems.end (); i++)
97 Stencil flag = Stem::flag (stem);
98 if (!flag.is_empty ())
100 Interval y = flag.extent (Y_AXIS)
102 + Stem::stem_end_position (stem);
104 Interval x = stem->relative_coordinate (commonx, X_AXIS)
105 + flag.extent (X_AXIS);
107 boxes.push_back (Box (x,y));
111 vector_sort (dots, position_less);
112 for (vsize i = dots.size (); i--;)
113 if (!dots[i]->is_live ())
114 dots.erase (dots.begin () + i);
116 Dot_formatting_problem problem (boxes, base_x);
118 Dot_configuration cfg (problem);
119 for (vsize i = 0; i < dots.size (); i++)
124 Grob *note = dots[i]->get_parent (Y_AXIS);
127 Grob *stem = unsmob_grob (note->get_object ("stem"));
129 dp.extremal_head_ = Stem::first_head (stem) == note;
131 dp.x_extent_ = note->extent (commonx, X_AXIS);
134 int p = Staff_symbol_referencer::get_rounded_position (dp.dot_);
136 /* icky, since this should go via a Staff_symbol_referencer
137 offset callback but adding a dot overwrites Y-offset. */
138 p += (int) robust_scm2double (dp.dot_->get_property ("staff-position"), 0.0);
140 if (dp.extremal_head_)
141 dp.dir_ = to_dir (dp.dot_->get_property ("direction"));
143 cfg.remove_collision (p);
145 if (Staff_symbol_referencer::on_line (dp.dot_, p))
146 cfg.remove_collision (p);
149 problem.register_configuration (cfg);
151 for (Dot_configuration::const_iterator i (cfg.begin ());
152 i != cfg.end (); i++)
157 Staff_symbol_referencer::set_position (i->second.dot_, i->first);
161 me->translate_axis (cfg.x_offset () - me->relative_coordinate (commonx, X_AXIS),
167 Dot_column::add_head (Grob *me, Grob *rh)
169 Grob *d = unsmob_grob (rh->get_object ("dot"));
172 Side_position_interface::add_support (me, rh);
174 Pointer_group_interface::add_grob (me, ly_symbol2scm ("dots"), d);
175 d->set_property ("Y-offset", Grob::x_parent_positioning_proc);
176 d->set_property ("X-offset", Grob::x_parent_positioning_proc);
177 Axis_group_interface::add_element (me, d);
181 ADD_INTERFACE (Dot_column,
183 "Groups dot objects so they form a column, and position dots so they do not "
184 "clash with staff lines. ",