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 mtor << "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 } else if (n->balltype_i_ == 1) {
103 whole_l_arr_.push(n);
111 Stem::invisible_b()const
113 return !head_l_arr_.size();
116 // if dir_i_ is set we return fake values.
119 Stem::get_center_distance_from_top()
122 return (dir_i_ > 0) ? 0 : 1;
124 int staff_center = staff_size_i_ / 2;
125 int max = max_head_i() - staff_center;
129 // if dir_i_ is set we return fake values.
131 Stem::get_center_distance_from_bottom()
134 return (dir_i_ > 0) ? 1 : 0;
136 int staff_center = staff_size_i_ / 2;
137 int min = staff_center - min_head_i();
142 Stem::get_default_dir()
146 return (get_center_distance_from_top() >=
147 get_center_distance_from_bottom()) ? -1 : 1;
152 Stem::set_default_dir()
154 dir_i_ = get_default_dir();
158 Stem::set_default_stemlen()
164 // ugh... how about non 5-line staffs?
165 if ((max_head_i() < -2 && dir_i_ == 1 )
166 ||(min_head_i() > staff_size_i_ && dir_i_ == -1) ){
167 set_stemend( staff_size_i_ /2 -1 );
169 set_stemend( (dir_i_ > 0) ? max_head_i() + STEMLEN :
170 min_head_i() - STEMLEN);
177 Stem::set_default_extents()
179 if (!stem_length_f())
180 set_default_stemlen();
182 set_stemend((dir_i_< 0) ?
183 max_head_i()-stem_length_f(): min_head_i() +stem_length_f());
185 stem_xoffset_f_ = paper()->note_width()-paper()->rule_thickness();
193 move into note_column.cc
197 Stem::set_noteheads()
199 if(!head_l_arr_.size())
201 head_l_arr_.sort(Note_head::compare);
203 head_l_arr_.reverse();
205 head_l_arr_[0]->extremal_i_ = -1;
206 head_l_arr_.top()->extremal_i_ = 1;
208 int lastpos = head_l_arr_[0]->position_i_;
209 for (int i=1; i < head_l_arr_.size(); i ++) {
210 int dy =abs(lastpos- head_l_arr_[i]->position_i_);
214 head_l_arr_[i]->x_dir_i_ = (stem_xoffset_f_>0) ? 1:-1;
218 lastpos = head_l_arr_[i]->position_i_;
223 Stem::do_pre_processing()
225 if (stem_bottom_f_== stem_top_f_)
226 set_default_extents();
228 flag_i_ = dir_i_*abs(flag_i_);
229 transparent_b_ = invisible_b();
230 empty_b_ = invisible_b();
235 Stem::do_width()const
237 if (!print_flag_b_ || abs(flag_i_) <= 4)
238 return Interval(0,0); // TODO!
239 Paper_def*p= paper();
240 Interval r(p->lookup_l()->flag(flag_i_).dim.x());
246 Stem::brew_molecule_p()const
250 Real bot = stem_bottom_f_;
251 Real top = stem_top_f_;
255 Paper_def *p =paper();
257 Real dy = p->internote_f();
258 Symbol ss =p->lookup_l()->stem(bot*dy,top*dy);
260 out = new Molecule(Atom(ss));
262 if (print_flag_b_&&abs(flag_i_) > 4){
263 Symbol fl = p->lookup_l()->flag(flag_i_);
267 } else if (flag_i_ > 4) {
273 out->translate(stem_xoffset_f_, X_AXIS);
280 return Item::hpos_f() + stem_xoffset_f_;
285 Stem::do_substitute_dependency(Score_elem*o,Score_elem*n)
287 Item * o_l = o->item();
288 Item * n_l = n? n->item():0;
289 whole_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);
290 head_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);
291 rest_l_arr_.substitute((Note_head*)o_l, (Note_head*)n_l);