2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "note-column.hh"
11 #include <cmath> // ceil
14 #include "axis-group-interface.hh"
17 #include "output-def.hh"
18 #include "staff-symbol-referencer.hh"
20 #include "note-head.hh"
21 #include "accidental-placement.hh"
22 #include "pointer-group-interface.hh"
25 TODO: figure out if we can prune this class. This is just an
26 annoying layer between (rest)collision & (note-head + stem)
30 Note_column::has_rests (Grob *me)
32 return unsmob_grob (me->get_object ("rest"));
36 Note_column::shift_compare (Grob *const &p1, Grob *const &p2)
38 SCM s1 = p1->get_property ("horizontal-shift");
39 SCM s2 = p2->get_property ("horizontal-shift");
41 int h1 = (scm_is_number (s1)) ? scm_to_int (s1) : 0;
42 int h2 = (scm_is_number (s2)) ? scm_to_int (s2) : 0;
47 Note_column::get_stem (Grob *me)
49 SCM s = me->get_object ("stem");
50 return unsmob_item (s);
54 Note_column::head_positions_interval (Grob *me)
60 extract_grob_set (me, "note-heads", heads);
61 for (int i = 0; i < heads.size (); i++)
65 int j = Staff_symbol_referencer::get_rounded_position (se);
66 iv.unite (Slice (j, j));
72 Note_column::dir (Grob *me)
74 Grob *stem = unsmob_grob (me->get_object ("stem"));
75 if (stem && Stem::has_interface (stem))
76 return Stem::get_direction (stem);
79 extract_grob_set (me, "note-heads", heads);
81 return (Direction)sign (head_positions_interval (me).center ());
84 programming_error ("note column without heads and stem");
89 Note_column::set_stem (Grob *me, Grob *stem)
91 me->set_object ("stem", stem->self_scm ());
92 me->add_dependency (stem);
93 Axis_group_interface::add_element (me, stem);
97 Note_column::get_rest (Grob *me)
99 return unsmob_grob (me->get_object ("rest"));
103 Note_column::add_head (Grob *me, Grob *h)
106 if (Rest::has_interface (h))
108 extract_grob_set (me, "note-heads", heads);
112 me->set_object ("rest", h->self_scm ());
114 else if (Note_head::has_interface (h))
116 if (unsmob_grob (me->get_object ("rest")))
118 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"), h);
122 me->warning (_ ("can't have note heads and rests together on a stem"));
124 Axis_group_interface::add_element (me, h);
128 translate the rest symbols vertically by amount DY, but only if
129 they have no staff-position set.
132 Note_column::translate_rests (Grob *me, int dy)
134 Grob *r = unsmob_grob (me->get_object ("rest"));
135 if (r && !scm_is_number (r->get_property ("staff-position")))
137 r->translate_axis (dy * Staff_symbol_referencer::staff_space (r) / 2.0, Y_AXIS);
138 Grob *p = r->get_parent (Y_AXIS);
139 p->flush_extent_cache (Y_AXIS);
144 Note_column::set_dotcol (Grob *me, Grob *d)
146 Axis_group_interface::add_element (me, d);
150 Note_column::first_head (Grob *me)
152 Grob *st = get_stem (me);
153 return st ? Stem::first_head (st) : 0;
157 Return the first Accidentals grob that we find in a note-head.
160 Note_column::accidentals (Grob *me)
162 extract_grob_set (me, "note-heads", heads);
164 for (int i = 0; i < heads.size (); i++)
167 acc = h ? unsmob_grob (h->get_object ("accidental-grob")) : 0;
175 if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
176 return acc->get_parent (X_AXIS);
183 Note_column::arpeggio (Grob *me)
185 return unsmob_grob (me->get_object ("arpeggio"));
188 ADD_INTERFACE (Note_column, "note-column-interface",
189 "Stem and noteheads combined",
190 "arpeggio note-heads rest-collision rest horizontal-shift stem accidentals force-hshift");