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