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"
18 Note_column::rest_b () const
20 return rest_l_arr_.size ();
24 Note_column::shift_compare (Note_column *const &p1, Note_column*const&p2)
26 SCM s1 = p1->get_elt_property (horizontal_shift_scm_sym);
27 SCM s2 = p2->get_elt_property (horizontal_shift_scm_sym);
29 int h1 = (s1 == SCM_BOOL_F) ? 0 : gh_scm2int (SCM_CDR(s1));
30 int h2 = (s2 == SCM_BOOL_F) ? 0 : gh_scm2int (SCM_CDR(s2));
34 Note_column::Note_column()
36 set_axes (X_AXIS,X_AXIS);
43 head_l_arr_.sort (Note_head::compare);
47 Note_column::head_positions_interval() const
52 for (int i=0; i <head_l_arr_.size ();i ++)
54 int j = head_l_arr_[i]->position_i_;
55 iv.unite (Slice (j,j));
61 Note_column::dir () const
65 else if (head_l_arr_.size ())
66 return (Direction)sign (head_positions_interval().center ());
68 programming_error ("Note column without heads and stem!");
74 Note_column::set_stem (Stem * stem_l)
77 add_dependency (stem_l);
83 Note_column::do_substitute_element_pointer (Score_element*o, Score_element*n)
87 stem_l_ = n ? dynamic_cast<Stem *> (n):0;
89 if (dynamic_cast<Note_head *> (o))
91 head_l_arr_.substitute (dynamic_cast<Note_head *> (o),
92 (n)? dynamic_cast<Note_head *> (n) : 0);
95 if (dynamic_cast<Rest *> (o))
97 rest_l_arr_.substitute (dynamic_cast<Rest *> (o),
98 (n)? dynamic_cast<Rest *> (n) : 0);
103 Note_column::add_head (Rhythmic_head *h)
105 if (Rest*r=dynamic_cast<Rest *> (h))
107 rest_l_arr_.push (r);
109 if (Note_head *nh=dynamic_cast<Note_head *> (h))
111 head_l_arr_.push (nh);
117 translate the rest symbols vertically by amount DY_I.
120 Note_column::translate_rests (int dy_i)
122 invalidate_cache (Y_AXIS);
123 for (int i=0; i < rest_l_arr_.size(); i++)
124 rest_l_arr_[i]->position_i_ += dy_i;
128 Note_column::do_print() const
131 DOUT << "rests: " << rest_l_arr_.size() << ", ";
132 DOUT << "heads: " << head_l_arr_.size();
137 Note_column::set_dotcol (Dot_column *d)
144 handle rest under beam (do_post: beams are calculated now)
145 what about combination of collisions and rest under beam.
149 rest -> stem -> beam -> interpolate_y_position ()
154 Note_column::do_post_processing ()
156 if (!stem_l_ || !rest_b ())
159 Beam * b = stem_l_->beam_l_;
160 if (!b || !b->stems_.size ())
163 /* ugh. Should be done by beam. */
164 Direction d = stem_l_->get_dir ();
165 Real beamy = (stem_l_->hpos_f () - b->stems_[0]->hpos_f ()) * b->slope_f_ + b->left_y_;
167 Real staff_space = rest_l_arr_[0]->staff_line_leading_f ();
168 Real rest_dim = extent (Y_AXIS)[d]*2.0 /staff_space ;
171 = paper_l ()->get_var ("restcollision_minimum_beamdist") ;
173 minimum_dist + -d * (beamy - rest_dim) >? 0;
175 int stafflines = rest_l_arr_[0]->lines_i ();
177 // move discretely by half spaces.
178 int discrete_dist = int (ceil (dist ));
180 // move by whole spaces inside the staff.
181 if (discrete_dist < stafflines+1)
182 discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
184 translate_rests (-d * discrete_dist);