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;
54 IMPLEMENT_STATIC_NAME(Stem);
55 IMPLEMENT_IS_TYPE_B1(Stem,Item);
58 Stem::do_print() const
61 mtor << "flag "<< flag_i_ << " print_flag_b_ " << print_flag_b_;
67 Stem::stem_length_f()const
69 return stem_top_f_-stem_bottom_f_ ;
73 Stem::stem_start_f()const
75 return (dir_i_ < 0)? stem_top_f_ : stem_bottom_f_;
79 Stem::stem_end_f() const
81 return (dir_i_ < 0)? stem_bottom_f_ : stem_top_f_;
86 Stem::set_stemend(Real se)
89 if (! ((dir_i_ > 0 && se >= max_head_i()) ||
90 (se <= min_head_i() && dir_i_ <0)) )
91 warning("Weird stem size; check for narrow beams");
93 stem_top_f_ = (dir_i_ < 0) ? max_head_i() : se;
94 stem_bottom_f_ = (dir_i_ < 0) ? se : min_head_i();
98 Stem::add(Note_head *n)
100 n->add_dependency(this);
103 } else if (n->balltype_i_ == 1) {
104 whole_l_arr_.push(n);
112 Stem::invisible_b()const
114 return !head_l_arr_.size();
117 // if dir_i_ is set we return fake values.
120 Stem::get_center_distance_from_top()
123 return (dir_i_ > 0) ? 0 : 1;
125 int staff_center = staff_size_i_ / 2;
126 int max = max_head_i() - staff_center;
130 // if dir_i_ is set we return fake values.
132 Stem::get_center_distance_from_bottom()
135 return (dir_i_ > 0) ? 1 : 0;
137 int staff_center = staff_size_i_ / 2;
138 int min = staff_center - min_head_i();
143 Stem::get_default_dir()
147 return (get_center_distance_from_top() >=
148 get_center_distance_from_bottom()) ? -1 : 1;
153 Stem::set_default_dir()
155 dir_i_ = get_default_dir();
159 Stem::set_default_stemlen()
165 // ugh... how about non 5-line staffs?
166 if ((max_head_i() < -2 && dir_i_ == 1 )
167 ||(min_head_i() > staff_size_i_ && dir_i_ == -1) ){
168 set_stemend( staff_size_i_ /2 -1 );
170 set_stemend( (dir_i_ > 0) ? max_head_i() + STEMLEN :
171 min_head_i() - STEMLEN);
178 Stem::set_default_extents()
180 if (!stem_length_f())
181 set_default_stemlen();
183 set_stemend((dir_i_< 0) ?
184 max_head_i()-stem_length_f(): min_head_i() +stem_length_f());
186 stem_xoffset_f_ = paper()->note_width()-paper()->rule_thickness();
194 move into note_column.cc
198 Stem::set_noteheads()
200 if(!head_l_arr_.size())
202 head_l_arr_.sort(Note_head::compare);
204 head_l_arr_.reverse();
206 head_l_arr_[0]->extremal_i_ = -1;
207 head_l_arr_.top()->extremal_i_ = 1;
209 int lastpos = head_l_arr_[0]->position_i_;
210 for (int i=1; i < head_l_arr_.size(); i ++) {
211 int dy =abs(lastpos- head_l_arr_[i]->position_i_);
215 head_l_arr_[i]->x_dir_i_ = (stem_xoffset_f_>0) ? 1:-1;
219 lastpos = head_l_arr_[i]->position_i_;
224 Stem::do_pre_processing()
226 if (stem_bottom_f_== stem_top_f_)
227 set_default_extents();
229 flag_i_ = dir_i_*abs(flag_i_);
230 transparent_b_ = invisible_b();
231 empty_b_ = invisible_b();
236 Stem::do_width()const
238 if (!print_flag_b_ || abs(flag_i_) <= 4)
239 return Interval(0,0); // TODO!
240 Paper_def*p= paper();
241 Interval r(p->lookup_l()->flag(flag_i_).dim.x);
247 Stem::brew_molecule_p()const
251 Real bot = stem_bottom_f_;
252 Real top = stem_top_f_;
256 Paper_def *p =paper();
258 Real dy = p->internote_f();
259 Symbol ss =p->lookup_l()->stem(bot*dy,top*dy);
261 out = new Molecule(Atom(ss));
263 if (print_flag_b_&&abs(flag_i_) > 4){
264 Symbol fl = p->lookup_l()->flag(flag_i_);
268 } else if (flag_i_ > 4) {
274 out->translate_x(stem_xoffset_f_);
281 return Item::hpos_f() + stem_xoffset_f_;
286 Stem::do_substitute_dependency(Score_elem*o,Score_elem*n)
288 Item * o_l = o->item();
289 Item * n_l = n? n->item():0;
290 whole_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);
291 head_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);
292 rest_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);