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