]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
release: 1.5.29
[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 void
38 Note_column::set_interface (Grob* me)
39 {
40   me->set_interface (ly_symbol2scm ("note-column-interface"));
41   
42   Axis_group_interface::set_interface (me);
43   Axis_group_interface::set_axes (me, X_AXIS, Y_AXIS);
44 }
45
46 Item *
47 Note_column::stem_l (Grob*me) 
48 {
49   SCM s = me->get_grob_property ("stem");
50   return  unsmob_item (s);
51 }
52   
53 Slice
54 Note_column::head_positions_interval (Grob *me)
55 {
56   Slice  iv;
57
58   iv.set_empty ();
59
60   SCM h = me->get_grob_property ("note-heads");
61   for (; gh_pair_p (h); h = ly_cdr (h))
62     {
63       Grob *se = unsmob_grob (ly_car (h));
64       
65       int j = int (Staff_symbol_referencer::position_f (se));
66       iv.unite (Slice (j,j));
67     }
68   return iv;
69 }
70
71 Direction
72 Note_column::dir (Grob*  me)
73 {
74   Grob *stem = unsmob_grob (me->get_grob_property ("stem"));
75   if (stem && Stem::has_interface (stem))
76     return Stem::get_direction (stem);
77   else if (gh_pair_p (me->get_grob_property ("note-heads")))
78     return (Direction)sign (head_positions_interval (me).center ());
79
80   programming_error ("Note column without heads and stem!");
81   return CENTER;
82 }
83
84
85 void
86 Note_column::set_stem (Grob*me,Grob * stem_l)
87 {
88   me->set_grob_property ("stem", stem_l->self_scm ());
89   me->add_dependency (stem_l);
90   Axis_group_interface::add_element (me, stem_l);
91 }
92
93 void
94 Note_column::add_head (Grob*me,Grob *h)
95 {
96   if (Rest::has_interface (h))
97     {
98       me->set_grob_property ("rest", h->self_scm ());
99     }
100   else if (Note_head::has_interface (h))
101     {
102       Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"),h);
103     }
104   Axis_group_interface::add_element (me, h);
105 }
106
107 /**
108   translate the rest symbols vertically by amount DY_I.
109  */
110 void
111 Note_column::translate_rests (Grob*me,int dy_i)
112 {
113   Grob * r = unsmob_grob (me->get_grob_property ("rest"));
114   if (r)
115     {
116       r->translate_axis (dy_i * Staff_symbol_referencer::staff_space (r)/2.0, Y_AXIS);
117     }
118 }
119
120
121 void
122 Note_column::set_dotcol (Grob*me,Grob *d)
123 {
124   Axis_group_interface::add_element (me, d);
125 }
126
127
128
129
130 Grob*
131 Note_column::first_head (Grob*me) 
132 {
133   Grob * st = stem_l (me);
134   return st?  Stem::first_head (st): 0; 
135 }
136
137 bool
138 Note_column::has_interface (Grob*me)
139 {
140   return me && me->has_interface (ly_symbol2scm ("note-column-interface"));
141 }
142
143 /*
144   Return the first Accidentals grob that we find in a note-head. 
145  */
146 Grob* 
147 Note_column::accidentals (Grob *me)
148 {
149   SCM heads = me->get_grob_property ("note-heads");
150   for (;gh_pair_p (heads); heads =gh_cdr (heads))
151     {
152       Grob * h = unsmob_grob (gh_car (heads));
153       Grob *a = h ? unsmob_grob(h->get_grob_property ("accidentals")) : 0;
154       if (a)
155         return a;
156     }
157
158   return 0;
159 }