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_;
45 stem_bottom_f_ = stem_top_f_ = 0;
55 IMPLEMENT_IS_TYPE_B1(Stem,Item);
58 Stem::do_print() const
61 DOUT << "flag "<< flag_i_ << " print_flag_b_ " << print_flag_b_;
66 Stem::stem_length_f()const
68 return stem_top_f_-stem_bottom_f_ ;
72 Stem::stem_start_f()const
74 return (dir_i_ < 0)? stem_top_f_ : stem_bottom_f_;
78 Stem::stem_end_f() const
80 return (dir_i_ < 0)? stem_bottom_f_ : stem_top_f_;
85 Stem::set_stemend (Real se)
88 if (! ((dir_i_ > 0 && se >= max_head_i()) ||
89 (se <= min_head_i() && dir_i_ <0)) )
90 warning ("Weird stem size; check for narrow beams");
92 stem_top_f_ = (dir_i_ < 0) ? max_head_i() : se;
93 stem_bottom_f_ = (dir_i_ < 0) ? se : min_head_i();
97 Stem::add (Note_head *n)
99 n->add_dependency (this);
102 rest_l_arr_.push (n);
104 else if (n->balltype_i_ == 0)
106 whole_l_arr_.push (n);
111 head_l_arr_.push (n);
116 Stem::invisible_b()const
118 return !head_l_arr_.size();
121 // if dir_i_ is set we return fake values.
124 Stem::get_center_distance_from_top()
127 return (dir_i_ > 0) ? 0 : 1;
129 int staff_center = staff_size_i_ / 2;
130 int max = max_head_i() - staff_center;
134 // if dir_i_ is set we return fake values.
136 Stem::get_center_distance_from_bottom()
139 return (dir_i_ > 0) ? 1 : 0;
141 int staff_center = staff_size_i_ / 2;
142 int min = staff_center - min_head_i();
147 Stem::get_default_dir()
151 return (get_center_distance_from_top() >=
152 get_center_distance_from_bottom()) ? -1 : 1;
157 Stem::set_default_dir()
159 dir_i_ = get_default_dir();
163 Stem::set_default_stemlen()
169 // ugh... how about non 5-line staffs?
170 if ((max_head_i() < -2 && dir_i_ == 1)
171 ||(min_head_i() > staff_size_i_ && dir_i_ == -1))
173 set_stemend (staff_size_i_ /2 -1);
177 set_stemend ((dir_i_ > 0) ? max_head_i() + STEMLEN :
178 min_head_i() - STEMLEN);
185 Stem::set_default_extents()
187 if (!stem_length_f())
188 set_default_stemlen();
190 set_stemend ((dir_i_< 0) ?
191 max_head_i()-stem_length_f (): min_head_i () +stem_length_f ());
193 stem_xoffset_f_ = paper()->note_width ()-paper ()->rule_thickness ();
202 move into note_column.cc
206 Stem::set_noteheads()
208 if (!head_l_arr_.size())
210 head_l_arr_.sort (Note_head::compare);
212 head_l_arr_.reverse();
214 head_l_arr_[0]->extremal_i_ = -1;
215 head_l_arr_.top()->extremal_i_ = 1;
217 int lastpos = head_l_arr_[0]->position_i_;
218 for (int i=1; i < head_l_arr_.size(); i ++)
220 int dy =abs (lastpos- head_l_arr_[i]->position_i_);
225 head_l_arr_[i]->x_dir_i_ = (stem_xoffset_f_>0) ? 1:-1;
230 lastpos = head_l_arr_[i]->position_i_;
235 Stem::do_pre_processing()
237 if (stem_bottom_f_== stem_top_f_)
238 set_default_extents();
240 flag_i_ = dir_i_*abs (flag_i_);
241 transparent_b_ = invisible_b();
242 empty_b_ = invisible_b();
247 Stem::do_width()const
249 if (!print_flag_b_ || abs (flag_i_) <= 4)
250 return Interval (0,0); // TODO!
251 Paper_def*p= paper();
252 Interval r (p->lookup_l()->flag (flag_i_).dim.x ());
258 Stem::brew_molecule_p()const
262 Real bot = stem_bottom_f_;
263 Real top = stem_top_f_;
267 Paper_def *p =paper();
269 Real dy = p->internote_f();
270 Symbol ss =p->lookup_l()->stem (bot*dy,top*dy);
272 out = new Molecule (Atom (ss));
274 if (print_flag_b_&&abs (flag_i_) > 4)
276 Symbol fl = p->lookup_l()->flag (flag_i_);
281 else if (flag_i_ > 4)
289 out->translate (stem_xoffset_f_, X_AXIS);
296 return Item::hpos_f() + stem_xoffset_f_;
301 Stem::do_substitute_dependency (Score_elem*o,Score_elem*n)
303 Item * o_l = o->item();
304 Item * n_l = n? n->item():0;
305 whole_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
306 head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
307 rest_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);