*** empty log message ***
[lilypond.git] / lily / note-column.cc
blob5f523ea26b13fdcebfc6f7cf4cccb2d3ae671a7d
1 /*
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>
7 */
8 #include <math.h> // ceil
10 #include "axis-group-interface.hh"
11 #include "note-column.hh"
12 #include "stem.hh"
13 #include "warn.hh"
14 #include "paper-def.hh"
15 #include "group-interface.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "rest.hh"
18 #include "note-head.hh"
19 #include "accidental-placement.hh"
21 bool
22 Note_column::rest_b (Grob*me)
24 return unsmob_grob (me->get_grob_property ("rest"));
27 int
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;
35 return h1 - h2;
38 Item *
39 Note_column::get_stem (Grob*me)
41 SCM s = me->get_grob_property ("stem");
42 return unsmob_item (s);
45 Slice
46 Note_column::head_positions_interval (Grob *me)
48 Slice iv;
50 iv.set_empty ();
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));
60 return iv;
63 Direction
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!");
73 return CENTER;
77 void
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);
85 void
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);
99 /**
100 translate the rest symbols vertically by amount DY_I, but only if
101 they have no staff-position set.
103 void
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);
114 void
115 Note_column::set_dotcol (Grob*me,Grob *d)
117 Axis_group_interface::add_element (me, d);
123 Grob*
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.
134 Grob*
135 Note_column::accidentals (Grob *me)
137 SCM heads = me->get_grob_property ("note-heads");
138 Grob * acc = 0;
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;
143 if (acc)
144 break;
147 if (!acc)
148 return 0;
150 if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
151 return acc->get_parent (X_AXIS);
153 /* compatibility. */
154 return acc;
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");