2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "note-column.hh"
11 #include <cmath> // ceil
14 #include "accidental-placement.hh"
15 #include "axis-group-interface.hh"
16 #include "directional-element-interface.hh"
17 #include "international.hh"
18 #include "note-head.hh"
19 #include "output-def.hh"
20 #include "pointer-group-interface.hh"
22 #include "staff-symbol-referencer.hh"
27 TODO: figure out if we can prune this class. This is just an
28 annoying layer between (rest)collision & (note-head + stem)
32 Note_column::has_rests (Grob *me)
34 return unsmob_grob (me->get_object ("rest"));
38 Note_column::shift_less (Grob *const &p1, Grob *const &p2)
40 SCM s1 = p1->get_property ("horizontal-shift");
41 SCM s2 = p2->get_property ("horizontal-shift");
43 int h1 = (scm_is_number (s1)) ? scm_to_int (s1) : 0;
44 int h2 = (scm_is_number (s2)) ? scm_to_int (s2) : 0;
49 Note_column::get_stem (Grob *me)
51 SCM s = me->get_object ("stem");
52 return unsmob_item (s);
56 Note_column::head_positions_interval (Grob *me)
62 extract_grob_set (me, "note-heads", heads);
63 for (vsize i = 0; i < heads.size (); i++)
67 int j = Staff_symbol_referencer::get_rounded_position (se);
68 iv.unite (Slice (j, j));
74 Note_column::dir (Grob *me)
76 Grob *stem = unsmob_grob (me->get_object ("stem"));
77 if (stem && Stem::has_interface (stem))
78 return get_grob_direction (stem);
81 extract_grob_set (me, "note-heads", heads);
83 return (Direction)sign (head_positions_interval (me).center ());
86 programming_error ("note column without heads and stem");
91 Note_column::set_stem (Grob *me, Grob *stem)
93 me->set_object ("stem", stem->self_scm ());
94 Axis_group_interface::add_element (me, stem);
98 Note_column::get_rest (Grob *me)
100 return unsmob_grob (me->get_object ("rest"));
104 Note_column::add_head (Grob *me, Grob *h)
107 if (Rest::has_interface (h))
109 extract_grob_set (me, "note-heads", heads);
113 me->set_object ("rest", h->self_scm ());
115 else if (Note_head::has_interface (h))
117 if (unsmob_grob (me->get_object ("rest")))
119 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"), h);
123 me->warning (_ ("can't have note heads and rests together on a stem"));
125 Axis_group_interface::add_element (me, h);
129 translate the rest symbols vertically by amount DY, but only if
130 they have no staff-position set.
133 Note_column::translate_rests (Grob *me, int dy)
135 Grob *r = unsmob_grob (me->get_object ("rest"));
136 if (r && !scm_is_number (r->get_property ("staff-position")))
138 r->translate_axis (dy * Staff_symbol_referencer::staff_space (r) / 2.0, Y_AXIS);
139 Grob *p = r->get_parent (Y_AXIS);
140 p->flush_extent_cache (Y_AXIS);
145 Note_column::set_dotcol (Grob *me, Grob *d)
147 Axis_group_interface::add_element (me, d);
151 Note_column::first_head (Grob *me)
153 Grob *st = get_stem (me);
154 return st ? Stem::first_head (st) : 0;
158 Return the first Accidentals grob that we find in a note-head.
161 Note_column::accidentals (Grob *me)
163 extract_grob_set (me, "note-heads", heads);
165 for (vsize i = 0; i < heads.size (); i++)
168 acc = h ? unsmob_grob (h->get_object ("accidental-grob")) : 0;
176 if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
177 return acc->get_parent (X_AXIS);
184 Note_column::arpeggio (Grob *me)
186 return unsmob_grob (me->get_object ("arpeggio"));
189 ADD_INTERFACE (Note_column, "note-column-interface",
190 "Stem and noteheads combined",