2 stem.cc -- implement Stem
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 TODO: This is way too hairy
13 #include "paper-def.hh"
14 #include "note-head.hh"
16 #include "molecule.hh"
38 yextent_drul_[DOWN] = yextent_drul_[UP] = 0;
42 dir_forced_b_ = false;
50 Stem::head_positions () const
53 for (int i =0; i < head_l_arr_.size (); i++)
55 int p = head_l_arr_[i]->position_i_;
56 r[BIGGER] = r[BIGGER] >? p;
57 r[SMALLER] = r[SMALLER] <? p;
63 Stem::do_print () const
66 DOUT << "flag "<< flag_i_;
73 Stem::stem_length_f () const
75 return yextent_drul_[UP]-yextent_drul_[DOWN] ;
79 Stem::stem_begin_f () const
81 return yextent_drul_[Direction(-dir_)];
85 Stem::chord_start_f () const
87 return head_positions()[dir_] * paper ()->internote_f ();
91 Stem::stem_end_f () const
93 return yextent_drul_[dir_];
97 Stem::set_stemend (Real se)
100 if (dir_ && dir_ * head_positions()[dir_] >= se*dir_)
101 warning (_ ("weird stem size; check for narrow beams"));
104 yextent_drul_[dir_] = se;
105 yextent_drul_[Direction(-dir_)] = head_positions()[-dir_];
109 Stem::type_i () const
111 return head_l_arr_[0]->balltype_i_;
115 Stem::add_head (Rhythmic_head *n)
117 n->add_dependency (this); // ?
118 if (dynamic_cast<Note_head *> (n))
120 head_l_arr_.push ((Note_head*)n);
122 else if (dynamic_cast<Rest *> (n))
124 rest_l_arr_.push ((Rest*)n);
129 Stem::invisible_b () const
131 return (!head_l_arr_.size () ||
132 head_l_arr_[0]->balltype_i_ <= 0);
136 Stem::get_center_distance (Direction d) const
138 int staff_center = 0;
139 int distance = d*(head_positions()[d] - staff_center);
140 return distance >? 0;
144 Stem::get_default_dir () const
146 return (get_center_distance (UP) >
147 get_center_distance (DOWN))
153 Stem::get_dir () const
159 Stem::set_default_dir ()
161 dir_ = get_default_dir ();
165 Stem::set_default_stemlen ()
169 urg; this should be handled by Stem_info
172 Real length_f = paper ()->get_var ("stem_length");
173 Real shorten_f = paper ()->get_var ("forced_stem_shorten");
175 Real internote_f = paper ()->internote_f ();
176 length_f /= internote_f;
177 shorten_f /= internote_f;
183 stems in unnatural (forced) direction should be shortened,
184 accoding to [Roush & Gourlay]
186 else if (dir_ != get_default_dir ())
187 len -= shorten_f / internote_f;
194 set_stemend ((dir_ > 0) ? head_positions()[BIGGER] + len :
195 head_positions()[SMALLER] - len);
197 if (dir_ * stem_end_f () < 0)
204 Stem::set_default_extents ()
206 if (!stem_length_f ())
207 set_default_stemlen ();
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_xdir_ == LEFT) ? LEFT : RIGHT;
247 lastpos = head_l_arr_[i]->position_i_;
252 Stem::do_pre_processing ()
254 if (yextent_drul_[DOWN]== yextent_drul_[UP])
255 set_default_extents ();
258 transparent_b_ = invisible_b ();
259 set_empty (invisible_b ());
264 Stem::do_width () const
267 if (beam_l_ || abs (flag_i_) <= 2)
271 r = lookup_l ()->flag (flag_i_, dir_).dim_.x ();
272 r += note_delta_f ();
280 const Real ANGLE = 20* (2.0*M_PI/360.0); // ugh!
283 Stem::brew_molecule_p () const
285 Molecule *mol_p =new Molecule;
286 Drul_array<Real> stem_y = yextent_drul_;
287 Real dy = paper ()->internote_f ();
291 if (head_l_arr_.size ())
292 head_wid = head_l_arr_[0]->width ().length ();
293 stem_y[Direction(-dir_)] += dir_ * head_wid * tan(ANGLE)/(2*dy);
297 Atom ss =lookup_l ()->stem (stem_y[DOWN]*dy,
299 mol_p->add_atom (ss);
302 if (!beam_l_ && abs (flag_i_) > 2)
304 Atom fl = lookup_l ()->flag (flag_i_, dir_);
305 fl.translate_axis(stem_y[dir_]*dy, Y_AXIS);
306 mol_p->add_atom (fl);
309 if (head_l_arr_.size())
311 mol_p->translate_axis (note_delta_f (), X_AXIS);
317 Stem::note_delta_f () const
320 if (head_l_arr_.size())
322 Interval head_wid(0, head_l_arr_[0]->width ().length ());
323 Real rule_thick(paper ()->rule_thickness ());
324 Interval stem_wid(-rule_thick/2, rule_thick/2);
325 if (stem_xdir_ == CENTER)
328 r = head_wid.center ();
330 r = (head_wid.min () + head_wid.max ()) / 2;
333 r = head_wid[stem_xdir_] - stem_wid[stem_xdir_];
339 Stem::hpos_f () const
341 return note_delta_f () + Item::hpos_f ();
345 TODO: head_l_arr_/rest_l_arr_ in do_substitute_dependent ()
348 Stem::do_substitute_dependency (Score_element*o,Score_element*n)
350 Item * o_l = dynamic_cast <Item *> (o);
351 Item * n_l = n? dynamic_cast <Item *> (n) : 0;
352 head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
353 rest_l_arr_.substitute ((Rest*)o_l, (Rest*)n_l);