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"
23 TODO: figure out if we can prune this class. This is just an
24 annoying layer between (rest)collision & (note-head + stem)
28 Note_column::has_rests (Grob *me)
30 return unsmob_grob (me->get_property ("rest"));
34 Note_column::shift_compare (Grob *const &p1, Grob *const &p2)
36 SCM s1 = p1->get_property ("horizontal-shift");
37 SCM s2 = p2->get_property ("horizontal-shift");
39 int h1 = (scm_is_number (s1))? scm_to_int (s1) :0;
40 int h2 = (scm_is_number (s2)) ? scm_to_int (s2):0;
45 Note_column::get_stem (Grob *me)
47 SCM s = me->get_property ("stem");
48 return unsmob_item (s);
52 Note_column::head_positions_interval (Grob *me)
58 SCM h = me->get_property ("note-heads");
59 for (; scm_is_pair (h); h = scm_cdr (h))
61 Grob *se = unsmob_grob (scm_car (h));
63 int j = Staff_symbol_referencer::get_rounded_position (se);
64 iv.unite (Slice (j, j));
70 Note_column::dir (Grob *me)
72 Grob *stem = unsmob_grob (me->get_property ("stem"));
73 if (stem && Stem::has_interface (stem))
74 return Stem::get_direction (stem);
75 else if (scm_is_pair (me->get_property ("note-heads")))
76 return (Direction)sign (head_positions_interval (me).center ());
78 programming_error ("Note column without heads and stem!");
83 Note_column::set_stem (Grob *me, Grob *stem)
85 me->set_property ("stem", stem->self_scm ());
86 me->add_dependency (stem);
87 Axis_group_interface::add_element (me, stem);
91 Note_column::get_rest (Grob *me)
93 return unsmob_grob (me->get_property ("rest"));
97 Note_column::add_head (Grob *me, Grob *h)
100 if (Rest::has_interface (h))
102 if (scm_is_pair (me->get_property ("note-heads")))
105 me->set_property ("rest", h->self_scm ());
107 else if (Note_head::has_interface (h))
109 if (unsmob_grob (me->get_property ("rest")))
111 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"), h);
115 me->warning ("Can't have rests and note heads together on a stem.");
117 Axis_group_interface::add_element (me, h);
121 translate the rest symbols vertically by amount DY, but only if
122 they have no staff-position set.
125 Note_column::translate_rests (Grob *me, int dy)
127 Grob *r = unsmob_grob (me->get_property ("rest"));
128 if (r && !scm_is_number (r->get_property ("staff-position")))
130 r->translate_axis (dy * Staff_symbol_referencer::staff_space (r) / 2.0, Y_AXIS);
131 Grob *p = r->get_parent (Y_AXIS);
132 p->flush_extent_cache (Y_AXIS);
137 Note_column::set_dotcol (Grob *me, Grob *d)
139 Axis_group_interface::add_element (me, d);
144 Note_column::first_head (Grob *me)
146 Grob *st = get_stem (me);
147 return st? Stem::first_head (st): 0;
151 Return the first Accidentals grob that we find in a note-head.
154 Note_column::accidentals (Grob *me)
156 SCM heads = me->get_property ("note-heads");
158 for (;scm_is_pair (heads); heads = scm_cdr (heads))
160 Grob *h = unsmob_grob (scm_car (heads));
161 acc = h ? unsmob_grob (h->get_property ("accidental-grob")) : 0;
169 if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
170 return acc->get_parent (X_AXIS);
176 ADD_INTERFACE (Note_column, "note-column-interface",
177 "Stem and noteheads combined",
178 "arpeggio note-heads rest-collision rest horizontal-shift stem accidentals force-hshift");