lilypond-1.3.72
[lilypond.git] / lily / note-column.cc
blob473c0146636dbcff21dd5d5e5c27df7ffa40b342
1 /*
2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 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 "debug.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"
20 bool
21 Note_column::rest_b (Score_element*me)
23 return unsmob_element (me->get_elt_property ("rest"));
26 int
27 Note_column::shift_compare (Score_element *const &p1, Score_element *const&p2)
29 SCM s1 = p1->get_elt_property ("horizontal-shift");
30 SCM s2 = p2->get_elt_property ("horizontal-shift");
32 int h1 = (gh_number_p (s1))? gh_scm2int (s1) :0;
33 int h2 = (gh_number_p (s2)) ? gh_scm2int (s2):0;
34 return h1 - h2;
37 void
38 Note_column::set_interface (Score_element* me)
40 me->set_elt_property ("note-heads", SCM_EOL);
41 me->set_interface (ly_symbol2scm ("note-column-interface"));
43 Axis_group_interface::set_interface (me);
44 Axis_group_interface::set_axes (me, X_AXIS, Y_AXIS);
47 Item *
48 Note_column::stem_l (Score_element*me)
50 SCM s = me->get_elt_property ("stem");
51 return dynamic_cast<Item*>(unsmob_element (s));
54 Slice
55 Note_column::head_positions_interval(Score_element *me)
57 Slice iv;
59 iv.set_empty ();
61 SCM h = me->get_elt_property ("note-heads");
62 for (; gh_pair_p (h); h = gh_cdr (h))
64 Score_element *se = unsmob_element (gh_car (h));
66 int j = int (Staff_symbol_referencer::position_f (se));
67 iv.unite (Slice (j,j));
69 return iv;
72 Direction
73 Note_column::dir (Score_element* me)
75 Score_element *stem = unsmob_element (me->get_elt_property ("stem"));
76 if (stem && Stem::has_interface (stem))
77 return Stem::get_direction (stem);
78 else if (gh_pair_p (me->get_elt_property ("note-heads")))
79 return (Direction)sign (head_positions_interval (me).center ());
81 programming_error ("Note column without heads and stem!");
82 return CENTER;
86 void
87 Note_column::set_stem (Score_element*me,Score_element * stem_l)
89 me->set_elt_property ("stem", stem_l->self_scm_);
90 me->add_dependency (stem_l);
91 Axis_group_interface::add_element (me, stem_l);
94 void
95 Note_column::add_head (Score_element*me,Score_element *h)
97 if (Rest::has_interface (h))
99 me->set_elt_property ("rest", h->self_scm_);
101 else if (Note_head::has_interface (h))
103 Pointer_group_interface gi (me, "note-heads");
104 gi.add_element (h);
106 Axis_group_interface::add_element (me, h);
110 translate the rest symbols vertically by amount DY_I.
112 void
113 Note_column::translate_rests (Score_element*me,int dy_i)
115 Score_element * r = unsmob_element (me->get_elt_property ("rest"));
116 if (r)
118 r->translate_axis (dy_i * Staff_symbol_referencer::staff_space (r)/2.0, Y_AXIS);
123 void
124 Note_column::set_dotcol (Score_element*me,Score_element *d)
126 Axis_group_interface::add_element (me, d);
131 Interval
132 Note_column::rest_dim (Score_element*me)
134 Score_element * r = unsmob_element (me->get_elt_property ("rest"));
135 return r->extent (Y_AXIS);
138 Score_element*
139 Note_column::first_head (Score_element*me)
141 Score_element * st = stem_l (me);
142 return st? Stem::first_head (st): 0;
145 bool
146 Note_column::has_interface (Score_element*me)
148 return me && me->has_interface (ly_symbol2scm ("note-column-interface"));