2 note-column.cc -- implement Note_column
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include <math.h> // ceil
10 #include "axis-group-interface.hh"
11 #include "dot-column.hh"
12 #include "note-column.hh"
14 #include "note-head.hh"
18 #include "paper-def.hh"
19 #include "group-interface.hh"
20 #include "staff-symbol-referencer.hh"
23 Note_column::rest_b () const
25 SCM r = get_elt_property ("rests");
31 Note_column::shift_compare (Note_column *const &p1, Note_column*const&p2)
33 SCM s1 = p1->get_elt_property ("horizontal-shift");
34 SCM s2 = p2->get_elt_property ("horizontal-shift");
36 int h1 = (gh_number_p (s1))? gh_scm2int (s1) :0;
37 int h2 = (gh_number_p (s2)) ? gh_scm2int (s2):0;
41 Note_column::Note_column()
43 set_elt_property ("rests", SCM_EOL);
44 set_elt_property ("note-heads", SCM_EOL);
45 Axis_group_interface (this).set_interface ();
46 Axis_group_interface (this).set_axes (X_AXIS, Y_AXIS);
50 Note_column::stem_l () const
52 SCM s = get_elt_property ("stem");
53 return dynamic_cast<Stem*> (unsmob_element (s));
59 Note_column::head_positions_interval() const
65 SCM h = get_elt_property ("note-heads");
66 for (; gh_pair_p (h); h = gh_cdr (h))
68 Score_element *se = unsmob_element (gh_car (h));
69 Staff_symbol_referencer_interface si (se);
71 int j = int (si.position_f ());
72 iv.unite (Slice (j,j));
78 Note_column::dir () const
81 return stem_l ()->get_direction ();
82 else if (gh_pair_p (get_elt_property ("note-heads")))
83 return (Direction)sign (head_positions_interval().center ());
85 programming_error ("Note column without heads and stem!");
91 Note_column::set_stem (Stem * stem_l)
93 set_elt_property ("stem", stem_l->self_scm_);
95 add_dependency (stem_l);
96 Axis_group_interface (this).add_element (stem_l);
102 Note_column::add_head (Rhythmic_head *h)
104 if (Rest*r=dynamic_cast<Rest *> (h))
106 Group_interface gi (this, "rests");
109 if (Note_head *nh=dynamic_cast<Note_head *> (h))
111 Group_interface gi (this, "note-heads");
114 Axis_group_interface (this).add_element (h);
118 translate the rest symbols vertically by amount DY_I.
121 Note_column::translate_rests (int dy_i)
123 SCM s = get_elt_property ("rests");
124 for (; gh_pair_p (s); s = gh_cdr (s))
126 Score_element * se = unsmob_element (gh_car (s));
127 Staff_symbol_referencer_interface si (se);
129 se->translate_axis (dy_i * si.staff_space ()/2.0, Y_AXIS);
135 Note_column::set_dotcol (Dot_column *d)
137 Axis_group_interface (this).add_element (d);
142 handle rest under beam (do_post: beams are calculated now)
143 what about combination of collisions and rest under beam.
147 rest -> stem -> beam -> interpolate_y_position ()
151 Note_column::after_line_breaking ()
153 if (!stem_l () || !rest_b ())
156 Beam * b = stem_l ()->beam_l ();
157 if (!b || !b->visible_stem_count ())
160 /* ugh. Should be done by beam.
161 (what? should be done --jcn)
162 scary too?: height is calculated during post_processing
167 SCM s = b->get_elt_property ("height");
169 beam_dy = gh_scm2double (s);
171 s = b->get_elt_property ("y-position");
173 beam_y = gh_scm2double (s);
176 Real x0 = b->first_visible_stem ()->relative_coordinate (0, X_AXIS);
177 Real dx = b->last_visible_stem ()->relative_coordinate (0, X_AXIS) - x0;
178 Real dydx = beam_dy && dx ? beam_dy/dx : 0;
180 Direction d = stem_l ()->get_direction ();
181 Real beamy = (stem_l ()->relative_coordinate (0, X_AXIS) - x0) * dydx + beam_y;
183 s = get_elt_property ("rests");
184 Score_element * se = unsmob_element (gh_car (s));
185 Staff_symbol_referencer_interface si (se);
187 Real staff_space = si.staff_space ();
188 Real rest_dim = extent (Y_AXIS)[d]*2.0 /staff_space ;
191 = paper_l ()->get_var ("restcollision_minimum_beamdist") ;
193 minimum_dist + -d * (beamy - rest_dim) >? 0;
195 int stafflines = si.line_count ();
197 // move discretely by half spaces.
198 int discrete_dist = int (ceil (dist ));
200 // move by whole spaces inside the staff.
201 if (discrete_dist < stafflines+1)
202 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
204 translate_rests (-d * discrete_dist);
209 Note_column::rest_dim () const
212 SCM s = get_elt_property ("rests");
213 for (; gh_pair_p (s); s = gh_cdr (s))
215 Score_element * sc = unsmob_element ( gh_car (s));
216 restdim.unite (sc->extent (Y_AXIS));
223 Note_column::first_head () const
225 Stem * st = stem_l ();
226 return st? st->first_head (): 0;