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"
19 Note_column::rest_b () const
21 SCM r = get_elt_property ("rests");
27 Note_column::shift_compare (Note_column *const &p1, Note_column*const&p2)
29 SCM s1 = p1->get_elt_property ("horizontal-shift");
30 SCM s2 = p2->get_elt_property ("horizontal-shift");
32 int h1 = (s1 == SCM_UNDEFINED) ? 0 : gh_scm2int (s1);
33 int h2 = (s2 == SCM_UNDEFINED) ? 0 : gh_scm2int (s2);
37 Note_column::Note_column()
39 set_elt_property ("rests", SCM_EOL);
40 set_elt_property ("note-heads", SCM_EOL);
41 set_axes (X_AXIS, Y_AXIS);
45 Note_column::stem_l () const
47 SCM s = get_elt_property ("stem");
48 return dynamic_cast<Stem*> (unsmob_element (s));
54 Note_column::head_positions_interval() const
60 SCM h = get_elt_property ("note-heads");
61 for (; gh_pair_p (h); h = gh_cdr (h))
63 Score_element *se = unsmob_element (gh_car (h));
65 int j = int (dynamic_cast<Staff_symbol_referencer*> (se)->position_f ());
66 iv.unite (Slice (j,j));
72 Note_column::dir () const
75 return stem_l ()->get_direction ();
76 else if (gh_pair_p (get_elt_property ("note-heads")))
77 return (Direction)sign (head_positions_interval().center ());
79 programming_error ("Note column without heads and stem!");
85 Note_column::set_stem (Stem * stem_l)
87 set_elt_property ("stem", stem_l->self_scm_);
89 add_dependency (stem_l);
96 Note_column::add_head (Rhythmic_head *h)
98 if (Rest*r=dynamic_cast<Rest *> (h))
100 Group_interface gi (this, "rests");
103 if (Note_head *nh=dynamic_cast<Note_head *> (h))
105 Group_interface gi (this, "note-heads");
112 translate the rest symbols vertically by amount DY_I.
115 Note_column::translate_rests (int dy_i)
117 invalidate_cache (Y_AXIS);
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 *str = dynamic_cast<Staff_symbol_referencer*> (se);
124 se->translate_axis (dy_i * str->staff_line_leading_f ()/2.0, Y_AXIS);
130 Note_column::set_dotcol (Dot_column *d)
137 handle rest under beam (do_post: beams are calculated now)
138 what about combination of collisions and rest under beam.
142 rest -> stem -> beam -> interpolate_y_position ()
147 Note_column::do_post_processing ()
149 if (!stem_l () || !rest_b ())
152 Beam * b = stem_l ()->beam_l ();
153 if (!b || !b->stem_count ())
156 /* ugh. Should be done by beam. */
157 Direction d = stem_l ()->get_direction ();
158 Real beamy = (stem_l ()->hpos_f () - b->stem(0)->hpos_f ()) * b->slope_f_ + b->left_y_;
160 SCM s = get_elt_property ("rests");
161 Score_element * se = unsmob_element (gh_car (s));
162 Staff_symbol_referencer *str = dynamic_cast<Staff_symbol_referencer*> (se);
164 Real staff_space = str->staff_line_leading_f ();
165 Real rest_dim = extent (Y_AXIS)[d]*2.0 /staff_space ;
168 = paper_l ()->get_var ("restcollision_minimum_beamdist") ;
170 minimum_dist + -d * (beamy - rest_dim) >? 0;
172 int stafflines = str->lines_i ();
174 // move discretely by half spaces.
175 int discrete_dist = int (ceil (dist ));
177 // move by whole spaces inside the staff.
178 if (discrete_dist < stafflines+1)
179 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
181 translate_rests (-d * discrete_dist);
186 Note_column::rest_dim () const
189 SCM s = get_elt_property ("rests");
190 for (; gh_pair_p (s); s = gh_cdr (s))
192 Score_element * sc = unsmob_element ( gh_car (s));
193 restdim.unite (sc->extent (Y_AXIS));
200 Note_column::first_head () const
202 Stem * st = stem_l ();
203 return st? st->first_head (): 0;