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 <math.h> // ceil
13 #include "axis-group-interface.hh"
16 #include "output-def.hh"
17 #include "staff-symbol-referencer.hh"
19 #include "note-head.hh"
20 #include "accidental-placement.hh"
21 #include "pointer-group-interface.hh"
24 TODO: figure out if we can prune this class. This is just an
25 annoying layer between (rest)collision & (note-head + stem)
29 Note_column::has_rests (Grob *me)
31 return unsmob_grob (me->get_object ("rest"));
35 Note_column::shift_compare (Grob *const &p1, Grob *const &p2)
37 SCM s1 = p1->get_property ("horizontal-shift");
38 SCM s2 = p2->get_property ("horizontal-shift");
40 int h1 = (scm_is_number (s1)) ? scm_to_int (s1) : 0;
41 int h2 = (scm_is_number (s2)) ? scm_to_int (s2) : 0;
46 Note_column::get_stem (Grob *me)
48 SCM s = me->get_object ("stem");
49 return unsmob_item (s);
53 Note_column::head_positions_interval (Grob *me)
59 extract_grob_set (me, "note-heads", heads);
60 for (int i = 0; i < heads.size(); i++)
64 int j = Staff_symbol_referencer::get_rounded_position (se);
65 iv.unite (Slice (j, j));
71 Note_column::dir (Grob *me)
73 Grob *stem = unsmob_grob (me->get_object ("stem"));
74 if (stem && Stem::has_interface (stem))
75 return Stem::get_direction (stem);
76 else if (scm_is_pair (me->get_object ("note-heads")))
77 return (Direction)sign (head_positions_interval (me).center ());
79 programming_error ("note column without heads and stem");
84 Note_column::set_stem (Grob *me, Grob *stem)
86 me->set_object ("stem", stem->self_scm ());
87 me->add_dependency (stem);
88 Axis_group_interface::add_element (me, stem);
92 Note_column::get_rest (Grob *me)
94 return unsmob_grob (me->get_object ("rest"));
98 Note_column::add_head (Grob *me, Grob *h)
101 if (Rest::has_interface (h))
103 extract_grob_set (me, "note-heads", heads);
107 me->set_object ("rest", h->self_scm ());
109 else if (Note_head::has_interface (h))
111 if (unsmob_grob (me->get_object ("rest")))
113 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"), h);
117 me->warning (_ ("can't have note heads and rests together on a stem"));
119 Axis_group_interface::add_element (me, h);
123 translate the rest symbols vertically by amount DY, but only if
124 they have no staff-position set.
127 Note_column::translate_rests (Grob *me, int dy)
129 Grob *r = unsmob_grob (me->get_object ("rest"));
130 if (r && !scm_is_number (r->get_property ("staff-position")))
132 r->translate_axis (dy * Staff_symbol_referencer::staff_space (r) / 2.0, Y_AXIS);
133 Grob *p = r->get_parent (Y_AXIS);
134 p->flush_extent_cache (Y_AXIS);
139 Note_column::set_dotcol (Grob *me, Grob *d)
141 Axis_group_interface::add_element (me, d);
145 Note_column::first_head (Grob *me)
147 Grob *st = get_stem (me);
148 return st ? Stem::first_head (st) : 0;
152 Return the first Accidentals grob that we find in a note-head.
155 Note_column::accidentals (Grob *me)
157 extract_grob_set (me, "note-heads", heads);
159 for (int i = 0; i < heads.size(); i++)
162 acc = h ? unsmob_grob (h->get_object ("accidental-grob")) : 0;
170 if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
171 return acc->get_parent (X_AXIS);
177 ADD_INTERFACE (Note_column, "note-column-interface",
178 "Stem and noteheads combined",
179 "arpeggio note-heads rest-collision rest horizontal-shift stem accidentals force-hshift");