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"
22 Stem::min_head_i() const
25 for (int i =0; i < head_l_arr_.size(); i++)
26 m = m <? head_l_arr_[i]->position_i_;
31 Stem::max_head_i() const
34 for (int i =0; i < head_l_arr_.size(); i++)
35 m = m >? head_l_arr_[i]->position_i_;
47 stem_bottom_f_ = stem_top_f_ = 0;
57 IMPLEMENT_IS_TYPE_B1(Stem,Item);
60 Stem::do_print() const
63 DOUT << "flag "<< flag_i_ << " print_flag_b_ " << print_flag_b_;
68 Stem::stem_length_f() const
70 return stem_top_f_-stem_bottom_f_ ;
74 Stem::stem_start_f() const
76 return (dir_ < 0)? stem_top_f_ : stem_bottom_f_;
80 Stem::stem_end_f() const
82 return (dir_ < 0)? stem_bottom_f_ : stem_top_f_;
87 Stem::set_stemend (Real se)
90 if (! ((dir_ > 0 && se >= max_head_i()) ||
91 (se <= min_head_i() && dir_ <0)))
92 warning ("Weird stem size; check for narrow beams");
94 stem_top_f_ = (dir_ < 0) ? max_head_i() : se;
95 stem_bottom_f_ = (dir_ < 0) ? se : min_head_i();
99 Stem::add (Note_head *n)
101 n->add_dependency (this);
104 rest_l_arr_.push (n);
106 else if (n->balltype_i_ == 0)
108 whole_l_arr_.push (n);
113 head_l_arr_.push (n);
118 Stem::invisible_b() const
120 return !head_l_arr_.size();
123 // if dir_ is set we return fake values.
126 Stem::get_center_distance_from_top()
129 return (dir_ > 0) ? 0 : 1;
131 int staff_center = staff_size_i_ / 2;
132 int max = max_head_i() - staff_center;
136 // if dir_ is set we return fake values.
138 Stem::get_center_distance_from_bottom()
141 return (dir_ > 0) ? 1 : 0;
143 int staff_center = staff_size_i_ / 2;
144 int min = staff_center - min_head_i();
149 Stem::get_default_dir()
153 return (get_center_distance_from_top() >=
154 get_center_distance_from_bottom()) ? -1 : 1;
159 Stem::set_default_dir()
161 dir_ = get_default_dir();
165 Stem::set_default_stemlen()
171 // ugh... how about non 5-line staffs?
172 if ((max_head_i() < -2 && dir_ == 1)
173 ||(min_head_i() > staff_size_i_ && dir_ == -1))
175 set_stemend (staff_size_i_ /2 -1);
179 set_stemend ((dir_ > 0) ? max_head_i() + STEMLEN :
180 min_head_i() - STEMLEN);
187 Stem::set_default_extents()
189 if (!stem_length_f())
190 set_default_stemlen();
192 set_stemend ((dir_< 0) ?
193 max_head_i()-stem_length_f (): min_head_i () +stem_length_f ());
195 stem_xoffset_f_ = paper()->note_width ()-paper ()->rule_thickness ();
204 move into note_column.cc
208 Stem::set_noteheads()
210 if (!head_l_arr_.size())
212 head_l_arr_.sort (Note_head::compare);
214 head_l_arr_.reverse();
216 head_l_arr_[0]->extremal_i_ = -1;
217 head_l_arr_.top()->extremal_i_ = 1;
219 int lastpos = head_l_arr_[0]->position_i_;
220 for (int i=1; i < head_l_arr_.size(); i ++)
222 int dy =abs (lastpos- head_l_arr_[i]->position_i_);
227 head_l_arr_[i]->x_dir_ = (stem_xoffset_f_>0) ? UP:DOWN;
232 lastpos = head_l_arr_[i]->position_i_;
237 Stem::do_pre_processing()
239 if (stem_bottom_f_== stem_top_f_)
240 set_default_extents();
242 flag_i_ = dir_*abs (flag_i_);
243 transparent_b_ = invisible_b();
244 empty_b_ = invisible_b();
249 Stem::do_width() const
251 if (!print_flag_b_ || abs (flag_i_) <= 4)
252 return Interval (0,0); // TODO!
253 Paper_def*p= paper();
254 Interval r (p->lookup_l()->flag (flag_i_).dim.x ());
260 Stem::brew_molecule_p() const
264 Real bot = stem_bottom_f_;
265 Real top = stem_top_f_;
269 Paper_def *p =paper();
271 Real dy = p->internote_f();
272 Symbol ss =p->lookup_l()->stem (bot*dy,top*dy);
274 out = new Molecule (Atom (ss));
276 if (print_flag_b_&&abs (flag_i_) > 4)
278 Symbol fl = p->lookup_l()->flag (flag_i_);
283 else if (flag_i_ > 4)
291 out->translate (stem_xoffset_f_, X_AXIS);
298 return Item::hpos_f() + stem_xoffset_f_;
303 Stem::do_substitute_dependency (Score_elem*o,Score_elem*n)
305 Item * o_l = o->item();
306 Item * n_l = n? n->item():0;
307 whole_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
308 head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
309 rest_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);