]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
make implementation for Class::has_interface automatically. Junk all
[lilypond.git] / lily / note-column.cc
1 /*
2   note-column.cc -- implement Note_column
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <math.h>               // ceil
9
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"
19
20 bool
21 Note_column::rest_b (Grob*me) 
22 {
23   return unsmob_grob (me->get_grob_property ("rest"));
24 }
25
26 int
27 Note_column::shift_compare (Grob *const &p1, Grob *const&p2)
28 {
29   SCM s1 = p1->get_grob_property ("horizontal-shift");
30   SCM s2 = p2->get_grob_property ("horizontal-shift");
31
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;
35 }
36
37 Item *
38 Note_column::stem_l (Grob*me) 
39 {
40   SCM s = me->get_grob_property ("stem");
41   return  unsmob_item (s);
42 }
43   
44 Slice
45 Note_column::head_positions_interval (Grob *me)
46 {
47   Slice  iv;
48
49   iv.set_empty ();
50
51   SCM h = me->get_grob_property ("note-heads");
52   for (; gh_pair_p (h); h = ly_cdr (h))
53     {
54       Grob *se = unsmob_grob (ly_car (h));
55       
56       int j = int (Staff_symbol_referencer::position_f (se));
57       iv.unite (Slice (j,j));
58     }
59   return iv;
60 }
61
62 Direction
63 Note_column::dir (Grob*  me)
64 {
65   Grob *stem = unsmob_grob (me->get_grob_property ("stem"));
66   if (stem && Stem::has_interface (stem))
67     return Stem::get_direction (stem);
68   else if (gh_pair_p (me->get_grob_property ("note-heads")))
69     return (Direction)sign (head_positions_interval (me).center ());
70
71   programming_error ("Note column without heads and stem!");
72   return CENTER;
73 }
74
75
76 void
77 Note_column::set_stem (Grob*me,Grob * stem_l)
78 {
79   me->set_grob_property ("stem", stem_l->self_scm ());
80   me->add_dependency (stem_l);
81   Axis_group_interface::add_element (me, stem_l);
82 }
83
84 void
85 Note_column::add_head (Grob*me,Grob *h)
86 {
87   if (Rest::has_interface (h))
88     {
89       me->set_grob_property ("rest", h->self_scm ());
90     }
91   else if (Note_head::has_interface (h))
92     {
93       Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"),h);
94     }
95   Axis_group_interface::add_element (me, h);
96 }
97
98 /**
99   translate the rest symbols vertically by amount DY_I, but only if
100   they have no staff-position set.
101 */
102 void
103 Note_column::translate_rests (Grob*me,int dy_i)
104 {
105   Grob * r = unsmob_grob (me->get_grob_property ("rest"));
106   if (r && !gh_number_p (r->get_grob_property ("staff-position")))
107     {
108       r->translate_axis (dy_i * Staff_symbol_referencer::staff_space (r)/2.0, Y_AXIS);
109     }
110 }
111
112
113 void
114 Note_column::set_dotcol (Grob*me,Grob *d)
115 {
116   Axis_group_interface::add_element (me, d);
117 }
118
119
120
121
122 Grob*
123 Note_column::first_head (Grob*me) 
124 {
125   Grob * st = stem_l (me);
126   return st?  Stem::first_head (st): 0; 
127 }
128
129
130 /*
131   Return the first Accidentals grob that we find in a note-head. 
132  */
133 Grob* 
134 Note_column::accidentals (Grob *me)
135 {
136   SCM heads = me->get_grob_property ("note-heads");
137   for (;gh_pair_p (heads); heads =gh_cdr (heads))
138     {
139       Grob * h = unsmob_grob (gh_car (heads));
140       Grob *a = h ? unsmob_grob(h->get_grob_property ("accidentals-grob")) : 0;
141       if (a)
142         return a;
143     }
144
145   return 0;
146 }
147
148
149
150 ADD_INTERFACE (Note_column,"note-column-interface",
151   "Stem and noteheads combined",
152   "arpeggio note-heads rest-collision rest horizontal-shift stem accidentals force-hshift");
153