2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include <math.h> // ceil
10 #include "axis-group-interface.hh"
11 #include "note-column.hh"
14 #include "paper-def.hh"
15 #include "group-interface.hh"
16 #include "staff-symbol-referencer.hh"
18 #include "note-head.hh"
19 #include "accidental-placement.hh"
22 Note_column::rest_b (Grob
*me
)
24 return unsmob_grob (me
->get_grob_property ("rest"));
28 Note_column::shift_compare (Grob
*const &p1
, Grob
*const&p2
)
30 SCM s1
= p1
->get_grob_property ("horizontal-shift");
31 SCM s2
= p2
->get_grob_property ("horizontal-shift");
33 int h1
= (gh_number_p (s1
))? gh_scm2int (s1
) :0;
34 int h2
= (gh_number_p (s2
)) ? gh_scm2int (s2
):0;
39 Note_column::get_stem (Grob
*me
)
41 SCM s
= me
->get_grob_property ("stem");
42 return unsmob_item (s
);
46 Note_column::head_positions_interval (Grob
*me
)
52 SCM h
= me
->get_grob_property ("note-heads");
53 for (; gh_pair_p (h
); h
= ly_cdr (h
))
55 Grob
*se
= unsmob_grob (ly_car (h
));
57 int j
= int (Staff_symbol_referencer::get_position (se
));
58 iv
.unite (Slice (j
,j
));
64 Note_column::dir (Grob
* me
)
66 Grob
*stem
= unsmob_grob (me
->get_grob_property ("stem"));
67 if (stem
&& Stem::has_interface (stem
))
68 return Stem::get_direction (stem
);
69 else if (gh_pair_p (me
->get_grob_property ("note-heads")))
70 return (Direction
)sign (head_positions_interval (me
).center ());
72 programming_error ("Note column without heads and stem!");
78 Note_column::set_stem (Grob
*me
,Grob
* stem
)
80 me
->set_grob_property ("stem", stem
->self_scm ());
81 me
->add_dependency (stem
);
82 Axis_group_interface::add_element (me
, stem
);
86 Note_column::add_head (Grob
*me
,Grob
*h
)
88 if (Rest::has_interface (h
))
90 me
->set_grob_property ("rest", h
->self_scm ());
92 else if (Note_head::has_interface (h
))
94 Pointer_group_interface::add_grob (me
, ly_symbol2scm ("note-heads"),h
);
96 Axis_group_interface::add_element (me
, h
);
100 translate the rest symbols vertically by amount DY_I, but only if
101 they have no staff-position set.
104 Note_column::translate_rests (Grob
*me
,int dy_i
)
106 Grob
* r
= unsmob_grob (me
->get_grob_property ("rest"));
107 if (r
&& !gh_number_p (r
->get_grob_property ("staff-position")))
109 r
->translate_axis (dy_i
* Staff_symbol_referencer::staff_space (r
)/2.0, Y_AXIS
);
115 Note_column::set_dotcol (Grob
*me
,Grob
*d
)
117 Axis_group_interface::add_element (me
, d
);
124 Note_column::first_head (Grob
*me
)
126 Grob
* st
= get_stem (me
);
127 return st
? Stem::first_head (st
): 0;
132 Return the first Accidentals grob that we find in a note-head.
135 Note_column::accidentals (Grob
*me
)
137 SCM heads
= me
->get_grob_property ("note-heads");
139 for (;gh_pair_p (heads
); heads
=gh_cdr (heads
))
141 Grob
* h
= unsmob_grob (gh_car (heads
));
142 acc
= h
? unsmob_grob (h
->get_grob_property ("accidental-grob")) : 0;
150 if (Accidental_placement::has_interface (acc
->get_parent (X_AXIS
)))
151 return acc
->get_parent (X_AXIS
);
159 ADD_INTERFACE (Note_column
,"note-column-interface",
160 "Stem and noteheads combined",
161 "arpeggio note-heads rest-collision rest horizontal-shift stem accidentals force-hshift");