Use `transform'.
[lilypond.git] / lily / note-column.cc
blob3f57d3e63c888b09fb564849aa3809b4307366b3
1 /*
2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "note-column.hh"
11 #include <cmath> // ceil
12 using namespace std;
14 #include "accidental-placement.hh"
15 #include "axis-group-interface.hh"
16 #include "directional-element-interface.hh"
17 #include "international.hh"
18 #include "item.hh"
19 #include "note-head.hh"
20 #include "output-def.hh"
21 #include "pointer-group-interface.hh"
22 #include "rest.hh"
23 #include "staff-symbol-referencer.hh"
24 #include "stem.hh"
25 #include "warn.hh"
28 TODO: figure out if we can prune this class. This is just an
29 annoying layer between (rest)collision & (note-head + stem)
32 bool
33 Note_column::has_rests (Grob *me)
35 return unsmob_grob (me->get_object ("rest"));
38 bool
39 Note_column::shift_less (Grob *const &p1, Grob *const &p2)
41 SCM s1 = p1->get_property ("horizontal-shift");
42 SCM s2 = p2->get_property ("horizontal-shift");
44 int h1 = (scm_is_number (s1)) ? scm_to_int (s1) : 0;
45 int h2 = (scm_is_number (s2)) ? scm_to_int (s2) : 0;
46 return h1 < h2;
49 Item *
50 Note_column::get_stem (Grob *me)
52 SCM s = me->get_object ("stem");
53 return unsmob_item (s);
56 Slice
57 Note_column::head_positions_interval (Grob *me)
59 Slice iv;
61 iv.set_empty ();
63 extract_grob_set (me, "note-heads", heads);
64 for (vsize i = 0; i < heads.size (); i++)
66 Grob *se = heads[i];
68 int j = Staff_symbol_referencer::get_rounded_position (se);
69 iv.unite (Slice (j, j));
71 return iv;
74 Direction
75 Note_column::dir (Grob *me)
77 Grob *stem = unsmob_grob (me->get_object ("stem"));
78 if (stem && Stem::has_interface (stem))
79 return get_grob_direction (stem);
80 else
82 extract_grob_set (me, "note-heads", heads);
83 if (heads.size ())
84 return (Direction)sign (head_positions_interval (me).center ());
87 programming_error ("note column without heads and stem");
88 return CENTER;
91 void
92 Note_column::set_stem (Grob *me, Grob *stem)
94 me->set_object ("stem", stem->self_scm ());
95 Axis_group_interface::add_element (me, stem);
98 Grob *
99 Note_column::get_rest (Grob *me)
101 return unsmob_grob (me->get_object ("rest"));
104 void
105 Note_column::add_head (Grob *me, Grob *h)
107 bool both = false;
108 if (Rest::has_interface (h))
110 extract_grob_set (me, "note-heads", heads);
111 if (heads.size ())
112 both = true;
113 else
114 me->set_object ("rest", h->self_scm ());
116 else if (Note_head::has_interface (h))
118 if (unsmob_grob (me->get_object ("rest")))
119 both = true;
120 Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"), h);
123 if (both)
124 me->warning (_ ("cannot have note heads and rests together on a stem"));
125 else
126 Axis_group_interface::add_element (me, h);
130 translate the rest symbols vertically by amount DY, but only if
131 they have no staff-position set.
133 void
134 Note_column::translate_rests (Grob *me, int dy)
136 Grob *r = unsmob_grob (me->get_object ("rest"));
137 if (r && !scm_is_number (r->get_property ("staff-position")))
139 r->translate_axis (dy * Staff_symbol_referencer::staff_space (r) / 2.0, Y_AXIS);
140 Grob *p = r->get_parent (Y_AXIS);
141 p->flush_extent_cache (Y_AXIS);
145 void
146 Note_column::set_dotcol (Grob *me, Grob *d)
148 Axis_group_interface::add_element (me, d);
151 Grob *
152 Note_column::first_head (Grob *me)
154 Grob *st = get_stem (me);
155 return st ? Stem::first_head (st) : 0;
159 Return the first Accidentals grob that we find in a note-head.
161 Grob *
162 Note_column::accidentals (Grob *me)
164 extract_grob_set (me, "note-heads", heads);
165 Grob *acc = 0;
166 for (vsize i = 0; i < heads.size (); i++)
168 Grob *h = heads[i];
169 acc = h ? unsmob_grob (h->get_object ("accidental-grob")) : 0;
170 if (acc)
171 break;
174 if (!acc)
175 return 0;
177 if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
178 return acc->get_parent (X_AXIS);
180 /* compatibility. */
181 return acc;
184 Grob *
185 Note_column::dot_column (Grob *me)
187 extract_grob_set (me, "note-heads", heads);
188 for (vsize i = 0; i < heads.size (); i++)
190 Grob *dots = unsmob_grob (heads[i]->get_object ("dot"));
191 if (dots)
192 return dots->get_parent (X_AXIS);
195 return 0;
198 Grob *
199 Note_column::arpeggio (Grob *me)
201 return unsmob_grob (me->get_object ("arpeggio"));
204 ADD_INTERFACE (Note_column,
205 "Stem and noteheads combined",
207 /* properties */
208 "arpeggio "
209 "force-hshift "
210 "horizontal-shift "
211 "note-heads "
212 "rest "
213 "rest-collision "
214 "stem "