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 dx = b->last_visible_stem ()->hpos_f () - x0;
174 Real dydx = beam_dy && dx ? beam_dy/dx : 0;
176 Direction d = stem_l ()->get_direction ();
177 Real beamy = (stem_l ()->hpos_f () - x0) * dydx + beam_y;
179 s = get_elt_property ("rests");
180 Score_element * se = unsmob_element (gh_car (s));
181 Staff_symbol_referencer_interface si (se);
183 Real staff_space = si.staff_space ();
184 Real rest_dim = extent (Y_AXIS)[d]*2.0 /staff_space ;
187 = paper_l ()->get_var ("restcollision_minimum_beamdist") ;
189 minimum_dist + -d * (beamy - rest_dim) >? 0;
191 int stafflines = si.line_count ();
193 // move discretely by half spaces.
194 int discrete_dist = int (ceil (dist ));
196 // move by whole spaces inside the staff.
197 if (discrete_dist < stafflines+1)
198 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
200 translate_rests (-d * discrete_dist);
205 Note_column::rest_dim () const
208 SCM s = get_elt_property ("rests");
209 for (; gh_pair_p (s); s = gh_cdr (s))
211 Score_element * sc = unsmob_element ( gh_car (s));
212 restdim.unite (sc->extent (Y_AXIS));
219 Note_column::first_head () const
221 Stem * st = stem_l ();
222 return st? st->first_head (): 0;