2 stem.cc -- implement Stem
4 source file of the GNU LilyPond music typesetter
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
12 #include "paper-def.hh"
13 #include "note-head.hh"
15 #include "molecule.hh"
23 IMPLEMENT_IS_TYPE_B1 (Stem,Item);
35 stem_bottom_f_ = stem_top_f_ = 0;
45 Stem::min_head_i () const
48 for (int i =0; i < head_l_arr_.size (); i++)
49 m = m <? head_l_arr_[i]->position_i_;
54 Stem::max_head_i () const
57 for (int i =0; i < head_l_arr_.size (); i++)
58 m = m >? head_l_arr_[i]->position_i_;
64 Stem::do_print () const
67 DOUT << "flag "<< flag_i_ << " print_flag? " << !(bool)beam_l_ << "abbrev_flag_i_" << abbrev_flag_i_;
72 Stem::stem_length_f () const
74 return stem_top_f_-stem_bottom_f_ ;
78 Stem::stem_start_f () const
80 return (dir_ < 0)? stem_top_f_ : stem_bottom_f_;
84 Stem::stem_end_f () const
86 return (dir_ < 0)? stem_bottom_f_ : stem_top_f_;
91 Stem::set_stemend (Real se)
94 if (! ((dir_ > 0 && se >= max_head_i ()) ||
95 (se <= min_head_i () && dir_ <0)))
96 warning ("Weird stem size; check for narrow beams");
98 stem_top_f_ = (dir_ < 0) ? max_head_i () : se;
99 stem_bottom_f_ = (dir_ < 0) ? se : min_head_i ();
103 Stem::type_i () const
105 return head_l_arr_[0]->balltype_i_;
109 Stem::add (Note_head *n)
111 n->add_dependency (this);
112 head_l_arr_.push (n);
118 rest_l_arr_.push (r);
119 r->add_dependency (this); // ?
123 Stem::invisible_b () const
126 return !head_l_arr_.size () ||
127 head_l_arr_[0]->balltype_i_ <= 0;
131 // if dir_ is set we return fake values.
134 Stem::get_center_distance_from_top ()
137 return (dir_ > 0) ? 0 : 1;
139 int staff_center = staff_size_i_ / 2;
140 int max = max_head_i () - staff_center;
144 // if dir_ is set we return fake values.
146 Stem::get_center_distance_from_bottom ()
149 return (dir_ > 0) ? 1 : 0;
151 int staff_center = staff_size_i_ / 2;
152 int min = staff_center - min_head_i ();
157 Stem::get_default_dir ()
161 return (get_center_distance_from_top () >=
162 get_center_distance_from_bottom ()) ?
163 (Direction)-1 : (Direction)1;
168 Stem::set_default_dir ()
170 dir_ = get_default_dir ();
174 Stem::set_default_stemlen ()
179 // ugh... how about non 5-line staffs?
180 bool on_ledger_line_b = ((max_head_i () < -2 && dir_ == 1)
181 // || (min_head_i () > staff_size_i_ && dir_ == -1));
182 || (min_head_i () > staff_size_i_ + 3 && dir_ == -1));
183 if (on_ledger_line_b)
185 set_stemend (staff_size_i_ / 2 - 1);
189 Real dy = paper ()->interbeam_f ();
191 // ugh, should get nice *rule* for this
192 if (abbrev_flag_i_ > 1)
193 len += (abbrev_flag_i_ - 1)* dy / 2;
194 set_stemend ((dir_ > 0) ? max_head_i () + len :
195 min_head_i () - len);
200 Stem::set_default_extents ()
202 if (!stem_length_f ())
203 set_default_stemlen ();
205 set_stemend ((dir_< 0) ?
206 max_head_i ()-stem_length_f (): min_head_i () + stem_length_f ());
207 // ugh, a whole ball is wider
208 if (head_l_arr_[0]->balltype_i_ <= 0)
209 stem_xoffset_f_ = paper ()->note_width () / 2;
211 stem_xoffset_f_ = paper ()->note_width () - paper ()->rule_thickness ();
219 move into note_column.cc
223 Stem::set_noteheads ()
225 if (!head_l_arr_.size ())
227 head_l_arr_.sort (Note_head::compare);
229 head_l_arr_.reverse ();
231 head_l_arr_[0]->extremal_i_ = -1;
232 head_l_arr_.top ()->extremal_i_ = 1;
234 int lastpos = head_l_arr_[0]->position_i_;
235 for (int i=1; i < head_l_arr_.size (); i ++)
237 int dy =abs (lastpos- head_l_arr_[i]->position_i_);
242 head_l_arr_[i]->x_dir_ = (stem_xoffset_f_>0) ? UP:DOWN;
247 lastpos = head_l_arr_[i]->position_i_;
252 Stem::do_pre_processing ()
254 if (stem_bottom_f_== stem_top_f_)
255 set_default_extents ();
257 flag_i_ = dir_ * abs (flag_i_);
258 transparent_b_ = invisible_b ();
259 empty_b_ = invisible_b ();
265 Stem::do_width () const
270 r = abbrev_mol ().extent ().x ();
272 else if (beam_l_ || abs (flag_i_) <= 4)
276 Paper_def*p= paper ();
277 r = p->lookup_l ()->flag (flag_i_).dim.x ();
286 Stem::abbrev_mol () const
288 Real dy = paper ()->interbeam_f ();
289 Real w = 1.5 * paper ()->lookup_l ()->ball (2).dim.x ().length ();
290 Real beamdy = paper ()->interline_f () / 2;
293 Real slope = paper ()->internote_f () / 4;
297 slope = 2 * beam_l_->slope;
298 // ugh, rather calc from Abbreviation_req
299 beams_i = beams_right_i_ >? beams_left_i_;
301 paper ()->lookup_l ()->beam (slope, 20 PT);
304 Atom a (paper ()->lookup_l ()->beam (slope, w));
305 a.translate (Offset(- w / 2, stem_end_f () - (w / 2 * slope)));
308 a.translate (dy + beamdy - dir_ * dy, Y_AXIS);
310 a.translate (2 * beamdy - dir_ * (beamdy - dy), Y_AXIS);
312 for (int i = 0; i < abbrev_flag_i_; i++)
315 b.translate (-dir_ * dy * (beams_i + i), Y_AXIS);
323 Stem::brew_molecule_p () const
325 Molecule *mol_p =new Molecule;
327 Real bot = stem_bottom_f_;
328 Real top = stem_top_f_;
332 Paper_def *p =paper ();
334 Real dy = p->internote_f ();
337 Symbol ss =p->lookup_l ()->stem (bot*dy,top*dy);
338 mol_p->add (Atom (ss));
341 if (!beam_l_ &&abs (flag_i_) > 4)
343 Symbol fl = p->lookup_l ()->flag (flag_i_);
347 mol_p->add_at_edge (Y_AXIS, DOWN, m);
349 else if (flag_i_ > 4)
351 mol_p->add_at_edge (Y_AXIS, UP, m);
355 assert (!abbrev_flag_i_);
359 mol_p->add (abbrev_mol ());
361 mol_p->translate (stem_xoffset_f_, X_AXIS);
366 Stem::hpos_f () const
368 return Item::hpos_f () + stem_xoffset_f_;
373 Stem::do_substitute_dependency (Score_elem*o,Score_elem*n)
375 Item * o_l = o->item ();
376 Item * n_l = n? n->item () : 0;
377 head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
378 rest_l_arr_.substitute ((Rest*)o_l, (Rest*)n_l);