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;
48 Trigger note collision resolution first, since that may kill off
51 for (vsize i = 0; i < dots.size (); i++)
53 Grob *n = dots[i]->get_parent (Y_AXIS);
54 commonx = n->common_refpoint (commonx, X_AXIS);
56 if (Grob *stem = unsmob_grob (n->get_object("stem")))
58 commonx = stem->common_refpoint (commonx, X_AXIS);
60 if (Stem::first_head (stem) == n)
61 main_heads.push_back (n);
69 extract_grob_set(me, "side-support-elements", support);
72 for (vsize i = 0; i < main_heads.size (); i++)
73 base_x.unite (main_heads[i]->extent (commonx, X_AXIS));
75 for (vsize i = 0; i < support.size (); i++)
77 if (Note_head::has_interface (support[i]))
80 y += Staff_symbol_referencer::get_position (support[i]);
82 Box b (support[i]->extent (commonx, X_AXIS), y);
85 if (Grob *s = unsmob_grob (support[i]->get_object ("stem")))
89 programming_error ("unknown grob in dot col support");
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)
101 * (2 / Staff_symbol_referencer::staff_space (stem))
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"));
130 dp.extremal_head_ = Stem::first_head (stem) == note;
135 dp.x_extent_ = note->extent (commonx, X_AXIS);
138 int p = Staff_symbol_referencer::get_rounded_position (dp.dot_);
140 /* icky, since this should go via a Staff_symbol_referencer
141 offset callback but adding a dot overwrites Y-offset. */
142 p += (int) robust_scm2double (dp.dot_->get_property ("staff-position"), 0.0);
144 if (dp.extremal_head_)
145 dp.dir_ = to_dir (dp.dot_->get_property ("direction"));
147 cfg.remove_collision (p);
149 if (Staff_symbol_referencer::on_line (dp.dot_, p))
150 cfg.remove_collision (p);
153 problem.register_configuration (cfg);
155 for (Dot_configuration::const_iterator i (cfg.begin ());
156 i != cfg.end (); i++)
161 Staff_symbol_referencer::set_position (i->second.dot_, i->first);
165 me->translate_axis (cfg.x_offset () - me->relative_coordinate (commonx, X_AXIS),
171 Dot_column::add_head (Grob *me, Grob *rh)
173 Grob *d = unsmob_grob (rh->get_object ("dot"));
176 Side_position_interface::add_support (me, rh);
178 Pointer_group_interface::add_grob (me, ly_symbol2scm ("dots"), d);
179 d->set_property ("Y-offset", Grob::x_parent_positioning_proc);
180 d->set_property ("X-offset", Grob::x_parent_positioning_proc);
181 Axis_group_interface::add_element (me, d);
185 ADD_INTERFACE (Dot_column,
187 "Groups dot objects so they form a column, and position dots so they do not "
188 "clash with staff lines. ",