2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "note-column.hh"
22 #include <cmath> // ceil
25 #include "accidental-placement.hh"
26 #include "axis-group-interface.hh"
27 #include "directional-element-interface.hh"
28 #include "international.hh"
30 #include "note-head.hh"
31 #include "output-def.hh"
32 #include "pointer-group-interface.hh"
34 #include "staff-symbol-referencer.hh"
39 TODO: figure out if we can prune this class. This is just an
40 annoying layer between (rest)collision & (note-head + stem)
44 Note_column::has_rests (Grob *me)
46 return Grob::unsmob (me->get_object ("rest"));
50 Note_column::shift_less (Grob *const &p1, Grob *const &p2)
52 SCM s1 = p1->get_property ("horizontal-shift");
53 SCM s2 = p2->get_property ("horizontal-shift");
55 int h1 = (scm_is_number (s1)) ? scm_to_int (s1) : 0;
56 int h2 = (scm_is_number (s2)) ? scm_to_int (s2) : 0;
61 Note_column::get_stem (Grob *me)
63 SCM s = me->get_object ("stem");
64 return Item::unsmob (s);
68 Note_column::get_flag (Grob *me)
70 Item *stem = get_stem (me);
73 SCM s = stem->get_object ("flag");
74 return Item::unsmob (s);
80 Note_column::head_positions_interval (Grob *me)
86 extract_grob_set (me, "note-heads", heads);
87 for (vsize i = 0; i < heads.size (); i++)
91 int j = Staff_symbol_referencer::get_rounded_position (se);
92 iv.unite (Slice (j, j));
98 Note_column::dir (Grob *me)
100 Grob *stem = Grob::unsmob (me->get_object ("stem"));
101 if (stem && Stem::has_interface (stem))
102 return get_grob_direction (stem);
105 extract_grob_set (me, "note-heads", heads);
107 return (Direction)sign (head_positions_interval (me).center ());
110 programming_error ("note column without heads and stem");
115 Note_column::set_stem (Grob *me, Grob *stem)
117 me->set_object ("stem", stem->self_scm ());
118 Axis_group_interface::add_element (me, stem);
122 Note_column::get_rest (Grob *me)
124 return Grob::unsmob (me->get_object ("rest"));
128 Note_column::add_head (Grob *me, Grob *h)
131 if (Rest::has_interface (h))
133 extract_grob_set (me, "note-heads", heads);
137 me->set_object ("rest", h->self_scm ());
139 else if (Note_head::has_interface (h))
141 if (Grob::unsmob (me->get_object ("rest")))
143 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"), h);
147 me->warning (_ ("cannot have note heads and rests together on a stem"));
149 Axis_group_interface::add_element (me, h);
153 Note_column::first_head (Grob *me)
155 Grob *st = get_stem (me);
156 return st ? Stem::first_head (st) : 0;
160 Return extent of the noteheads in the "main column",
161 i.e. excluding any suspended noteheads.
164 Note_column::calc_main_heads_extent (Grob *me)
167 return first_head (me)->extent (me, X_AXIS);
170 // no stems => no suspended noteheads.
171 extract_grob_set (me, "note-heads", heads);
173 return heads[0]->extent (me, X_AXIS);
175 return Interval (0, 0);
180 Return the first AccidentalPlacement grob that we find in a note-head.
183 Note_column::accidentals (Grob *me)
185 extract_grob_set (me, "note-heads", heads);
187 for (vsize i = 0; i < heads.size (); i++)
190 acc = h ? Grob::unsmob (h->get_object ("accidental-grob")) : 0;
198 if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
199 return acc->get_parent (X_AXIS);
206 Note_column::dot_column (Grob *me)
208 extract_grob_set (me, "note-heads", heads);
209 for (vsize i = 0; i < heads.size (); i++)
211 Grob *dots = Grob::unsmob (heads[i]->get_object ("dot"));
213 return dots->get_parent (X_AXIS);
219 /* If a note-column contains a cross-staff stem then
220 nc->extent (Y_AXIS, refp) will not consider the extent of the stem.
221 If you want the extent of the stem to be included (and you are safe
222 from any cross-staff issues) then call this function instead. */
224 Note_column::cross_staff_extent (Grob *me, Grob *refp)
226 Interval iv = me->extent (refp, Y_AXIS);
227 if (Grob *s = get_stem (me))
228 iv.unite (s->extent (refp, Y_AXIS));
233 ADD_INTERFACE (Note_column,
234 "Stem and noteheads combined.",