]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-column.cc
2003 -> 2004
[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--2004 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 "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"
20
21 bool
22 Note_column::rest_b (Grob*me) 
23 {
24   return unsmob_grob (me->get_grob_property ("rest"));
25 }
26
27 int
28 Note_column::shift_compare (Grob *const &p1, Grob *const&p2)
29 {
30   SCM s1 = p1->get_grob_property ("horizontal-shift");
31   SCM s2 = p2->get_grob_property ("horizontal-shift");
32
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;
36 }
37
38 Item *
39 Note_column::get_stem (Grob*me) 
40 {
41   SCM s = me->get_grob_property ("stem");
42   return  unsmob_item (s);
43 }
44   
45 Slice
46 Note_column::head_positions_interval (Grob *me)
47 {
48   Slice  iv;
49
50   iv.set_empty ();
51
52   SCM h = me->get_grob_property ("note-heads");
53   for (; gh_pair_p (h); h = ly_cdr (h))
54     {
55       Grob *se = unsmob_grob (ly_car (h));
56       
57       int j = int (Staff_symbol_referencer::get_position (se));
58       iv.unite (Slice (j,j));
59     }
60   return iv;
61 }
62
63 Direction
64 Note_column::dir (Grob*  me)
65 {
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 ());
71
72   programming_error ("Note column without heads and stem!");
73   return CENTER;
74 }
75
76
77 void
78 Note_column::set_stem (Grob*me,Grob * stem)
79 {
80   me->set_grob_property ("stem", stem->self_scm ());
81   me->add_dependency (stem);
82   Axis_group_interface::add_element (me, stem);
83 }
84
85 void
86 Note_column::add_head (Grob*me,Grob *h)
87 {
88   if (Rest::has_interface (h))
89     {
90       me->set_grob_property ("rest", h->self_scm ());
91     }
92   else if (Note_head::has_interface (h))
93     {
94       Pointer_group_interface::add_grob (me, ly_symbol2scm ("note-heads"),h);
95     }
96   Axis_group_interface::add_element (me, h);
97 }
98
99 /**
100   translate the rest symbols vertically by amount DY_I, but only if
101   they have no staff-position set.
102 */
103 void
104 Note_column::translate_rests (Grob*me,int dy_i)
105 {
106   Grob * r = unsmob_grob (me->get_grob_property ("rest"));
107   if (r && !gh_number_p (r->get_grob_property ("staff-position")))
108     {
109       r->translate_axis (dy_i * Staff_symbol_referencer::staff_space (r)/2.0, Y_AXIS);
110     }
111 }
112
113
114 void
115 Note_column::set_dotcol (Grob*me,Grob *d)
116 {
117   Axis_group_interface::add_element (me, d);
118 }
119
120
121
122
123 Grob*
124 Note_column::first_head (Grob*me) 
125 {
126   Grob * st = get_stem (me);
127   return st?  Stem::first_head (st): 0; 
128 }
129
130
131 /*
132   Return the first Accidentals grob that we find in a note-head. 
133  */
134 Grob* 
135 Note_column::accidentals (Grob *me)
136 {
137   SCM heads = me->get_grob_property ("note-heads");
138   Grob * acc = 0;
139   for (;gh_pair_p (heads); heads =gh_cdr (heads))
140     {
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;
145     }
146
147   if (!acc)
148     return 0;
149   
150   if (Accidental_placement::has_interface (acc->get_parent (X_AXIS)))
151     return acc->get_parent (X_AXIS);
152
153   /* compatibility. */
154   return  acc;
155 }
156
157
158
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");
162