2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "dot-column.hh"
9 #include "note-column.hh"
11 #include "note-head.hh"
15 #include "paper-def.hh"
16 #include "group-interface.hh"
17 #include "staff-symbol-referencer.hh"
20 Note_column::rest_b () const
22 SCM r
= get_elt_property ("rests");
28 Note_column::shift_compare (Note_column
*const &p1
, Note_column
*const&p2
)
30 SCM s1
= p1
->get_elt_property ("horizontal-shift");
31 SCM s2
= p2
->get_elt_property ("horizontal-shift");
33 int h1
= (gh_number_p (s1
))? gh_scm2int (s1
) :0;
34 int h2
= (gh_number_p (s2
)) ? gh_scm2int (s2
):0;
38 Note_column::Note_column()
40 set_elt_property ("rests", SCM_EOL
);
41 set_elt_property ("note-heads", SCM_EOL
);
42 set_axes (X_AXIS
, Y_AXIS
);
46 Note_column::stem_l () const
48 SCM s
= get_elt_property ("stem");
49 return dynamic_cast<Stem
*> (unsmob_element (s
));
55 Note_column::head_positions_interval() const
61 SCM h
= get_elt_property ("note-heads");
62 for (; gh_pair_p (h
); h
= gh_cdr (h
))
64 Score_element
*se
= unsmob_element (gh_car (h
));
65 Staff_symbol_referencer_interface
si (se
);
67 int j
= int (si
.position_f ());
68 iv
.unite (Slice (j
,j
));
74 Note_column::dir () const
77 return stem_l ()->get_direction ();
78 else if (gh_pair_p (get_elt_property ("note-heads")))
79 return (Direction
)sign (head_positions_interval().center ());
81 programming_error ("Note column without heads and stem!");
87 Note_column::set_stem (Stem
* stem_l
)
89 set_elt_property ("stem", stem_l
->self_scm_
);
91 add_dependency (stem_l
);
98 Note_column::add_head (Rhythmic_head
*h
)
100 if (Rest
*r
=dynamic_cast<Rest
*> (h
))
102 Group_interface
gi (this, "rests");
105 if (Note_head
*nh
=dynamic_cast<Note_head
*> (h
))
107 Group_interface
gi (this, "note-heads");
114 translate the rest symbols vertically by amount DY_I.
117 Note_column::translate_rests (int dy_i
)
119 SCM s
= get_elt_property ("rests");
120 for (; gh_pair_p (s
); s
= gh_cdr (s
))
122 Score_element
* se
= unsmob_element (gh_car (s
));
123 Staff_symbol_referencer_interface
si (se
);
125 se
->translate_axis (dy_i
* si
.staff_space ()/2.0, Y_AXIS
);
131 Note_column::set_dotcol (Dot_column
*d
)
138 handle rest under beam (do_post: beams are calculated now)
139 what about combination of collisions and rest under beam.
143 rest -> stem -> beam -> interpolate_y_position ()
148 Note_column::do_post_processing ()
150 if (!stem_l () || !rest_b ())
153 Beam
* b
= stem_l ()->beam_l ();
154 if (!b
|| !b
->stem_count ())
157 /* ugh. Should be done by beam.
158 (what? should be done --jcn)
159 scary too?: height is calculated during post_processing
164 SCM s
= b
->get_elt_property ("height");
166 beam_dy
= gh_scm2double (s
);
168 s
= b
->get_elt_property ("y-position");
170 beam_y
= gh_scm2double (s
);
172 Real x0
= b
->first_visible_stem ()->hpos_f ();
173 Real dydx
= beam_dy
/(b
->last_visible_stem ()->hpos_f () - x0
);
175 Direction d
= stem_l ()->get_direction ();
176 Real beamy
= (stem_l ()->hpos_f () - x0
) * dydx
+ beam_y
;
178 s
= get_elt_property ("rests");
179 Score_element
* se
= unsmob_element (gh_car (s
));
180 Staff_symbol_referencer_interface
si (se
);
182 Real staff_space
= si
.staff_space ();
183 Real rest_dim
= extent (Y_AXIS
)[d
]*2.0 /staff_space
;
186 = paper_l ()->get_var ("restcollision_minimum_beamdist") ;
188 minimum_dist
+ -d
* (beamy
- rest_dim
) >? 0;
190 int stafflines
= si
.lines_i ();
192 // move discretely by half spaces.
193 int discrete_dist
= int (ceil (dist
));
195 // move by whole spaces inside the staff.
196 if (discrete_dist
< stafflines
+1)
197 discrete_dist
= int (ceil (discrete_dist
/ 2.0)* 2.0);
199 translate_rests (-d
* discrete_dist
);
204 Note_column::rest_dim () const
207 SCM s
= get_elt_property ("rests");
208 for (; gh_pair_p (s
); s
= gh_cdr (s
))
210 Score_element
* sc
= unsmob_element ( gh_car (s
));
211 restdim
.unite (sc
->extent (Y_AXIS
));
218 Note_column::first_head () const
220 Stem
* st
= stem_l ();
221 return st
? st
->first_head (): 0;