]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
patch::: 1.1.30.mb1: Re: LilyPond 1.1.30
[lilypond.git] / lily / stem.cc
index a2361b4fe8a295e77fb14e8b3d0ea11051b771d8..7b387d8d6d5452dca97139e034750aaef23a7fe2 100644 (file)
@@ -3,13 +3,12 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1996, 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
   TODO: This is way too hairy
 */
 
 #include "stem.hh"
-#include "dimen.hh"
 #include "debug.hh"
 #include "paper-def.hh"
 #include "note-head.hh"
 #include "beam.hh"
 #include "rest.hh"
 
-const int STEMLEN = 7;
 
-IMPLEMENT_IS_TYPE_B1 (Stem,Item);
+
+
+Stem::~Stem ()
+{
+}
 
 Stem::Stem ()
 {
   /*
     TODO: staff-size
     */
-  beam_l_ = 0;
-  beams_left_i_ = 0;
-  beams_right_i_ = 0;
+  beams_i_drul_[LEFT] = beams_i_drul_[RIGHT] = -1;
   mult_i_ = 0;
 
   yextent_drul_[DOWN] = yextent_drul_[UP] = 0;
   flag_i_ = 2;
   dir_ = CENTER;
+  beam_dir_ = CENTER;
+  dir_forced_b_ = false;
   stem_xdir_ = LEFT;
   staff_size_i_ = 8;
 
   beam_gap_i_ = 0;
+  beam_l_ = 0;
 }
 
 Interval_t<int>
 Stem::head_positions () const
 {
+  /* 
+    Mysterious FreeBSD fix by John Galbraith.  Somehow, the empty intervals 
+    trigger FP exceptions on FreeBSD.  Fix: do not return infinity 
+
+   */
+  if (!head_l_arr_.size ())
+    {
+      return Interval_t<int> (100,-100);       
+    }
+
   Interval_t<int> r;
   for (int i =0; i < head_l_arr_.size (); i++)
     {
@@ -60,7 +73,7 @@ void
 Stem::do_print () const
 {
 #ifndef NPRINT
-  DOUT << "flag "<< flag_i_ ;
+  DOUT << "flag "<< flag_i_;
   if (beam_l_)
     DOUT << "beamed";
 #endif
@@ -95,7 +108,7 @@ Stem::set_stemend (Real se)
 {
   // todo: margins
   if (dir_ && dir_ * head_positions()[dir_] >= se*dir_)
-    warning (_("Weird stem size; check for narrow beams"));
+    warning (_ ("weird stem size; check for narrow beams"));
 
   
   yextent_drul_[dir_]  =  se;
@@ -109,16 +122,16 @@ Stem::type_i () const
 }
 
 void
-Stem::add (Rhythmic_head *n)
+Stem::add_head (Rhythmic_head *n)
 {
   n->add_dependency (this);    // ?
-  if (n->is_type_b (Note_head::static_name ()))
+  if (Note_head *nh = dynamic_cast<Note_head *> (n))
     {
-      head_l_arr_.push ((Note_head*)n);
+      head_l_arr_.push (nh);
     }
-  else if (n->is_type_b (Rest::static_name ()))
+  else if (Rest *r = dynamic_cast<Rest *> (n))
     {
-      rest_l_arr_.push ((Rest*)n);
+      rest_l_arr_.push (r);
     }
 }
 
@@ -130,7 +143,7 @@ Stem::invisible_b () const
 }
 
 int
-Stem::get_center_distance (Direction d)
+Stem::get_center_distance (Direction d) const
 {
   int staff_center = 0;
   int distance = d*(head_positions()[d] - staff_center);
@@ -138,7 +151,7 @@ Stem::get_center_distance (Direction d)
 }
 
 Direction
-Stem::get_default_dir ()
+Stem::get_default_dir () const
 {
   return (get_center_distance (UP) >
          get_center_distance (DOWN)) 
@@ -147,7 +160,7 @@ Stem::get_default_dir ()
 }
 
 Direction
-Stem::get_dir ()
+Stem::get_dir () const
 {
   return dir_;
 }
@@ -161,34 +174,33 @@ Stem::set_default_dir ()
 void
 Stem::set_default_stemlen ()
 {
-  Real len = STEMLEN;
-  Real dy = paper ()->interbeam_f ();
+  Real internote_f = paper ()->internote_f ();
+  Real length_f = paper ()->get_var ("stem_length0") / internote_f;
+  Real shorten_f = paper ()->get_var ("forced_stem_shorten0") / internote_f;
 
   if (!dir_)
     set_default_dir ();
-
-  /* If the stem points in the "wrong" direction, it should be
-     shortened, according to [Roush & Gourlay].  Their suggestion to knock off
-     a whole staffspace is a bit drastical though.
-     */
-  else if (dir_ != get_default_dir ())
-    len  -= 1.0;
+  /* 
+    stems in unnatural (forced) direction should be shortened, 
+    accoding to [Roush & Gourlay]
+   */
+  if (((int)chord_start_f ())
+      && (dir_ != get_default_dir ()))
+    length_f -= shorten_f;
 
   if (flag_i_ >= 5)
-    len += 2.0;
+    length_f += 2.0;
   if (flag_i_ >= 6)
-    len += 1.0;
+    length_f += 1.0;
   
-  set_stemend ((dir_ > 0) ? head_positions()[BIGGER] + len :
-              head_positions()[SMALLER] - len);
-
+  set_stemend ((dir_ > 0) ? head_positions()[BIGGER] + length_f:
+              head_positions()[SMALLER] - length_f);
 
   if (dir_ * stem_end_f () < 0)
-    {
-      set_stemend (0);
-    }
+    set_stemend (0);
 }
 
+//xxx
 void
 Stem::set_default_extents ()
 {
@@ -257,8 +269,7 @@ Stem::do_width () const
     ;  // TODO!
   else
     {
-      Paper_def*p= paper ();
-      r = p->lookup_l ()->flag (flag_i_, dir_).dim_.x ();
+      r = lookup_l ()->flag (flag_i_, dir_).dim_.x ();
       r += note_delta_f ();
     }
   return r;
@@ -270,31 +281,29 @@ Stem::do_width () const
 const Real ANGLE = 20* (2.0*M_PI/360.0); // ugh!
 
 Molecule*
-Stem::brew_molecule_p () const
+Stem::do_brew_molecule_p () const
 {
   Molecule *mol_p =new Molecule;
-  Paper_def *p =paper ();
   Drul_array<Real> stem_y = yextent_drul_;
-  Real dy = p->internote_f ();
-  
+  Real dy = paper ()->internote_f ();
 
   Real head_wid = 0;
   if (head_l_arr_.size ())
-    head_wid = head_l_arr_[0]->width ().length ();
+    head_wid = head_l_arr_[0]->extent (X_AXIS).length ();
   stem_y[Direction(-dir_)] += dir_ * head_wid * tan(ANGLE)/(2*dy);
   
   if (!invisible_b ())
     {
-      Atom ss =p->lookup_l ()->stem (stem_y[DOWN]*dy,
+      Molecule ss =lookup_l ()->stem (stem_y[DOWN]*dy,
                                     stem_y[UP]*dy);
-      mol_p->add (Atom (ss));
+      mol_p->add_molecule (ss);
     }
 
-  if (!beam_l_ &&abs (flag_i_) > 2)
+  if (!beam_l_ && abs (flag_i_) > 2)
     {
-      Atom fl = p->lookup_l ()->flag (flag_i_, dir_);
+      Molecule fl = lookup_l ()->flag (flag_i_, dir_);
       fl.translate_axis(stem_y[dir_]*dy, Y_AXIS);
-      mol_p->add(fl);
+      mol_p->add_molecule (fl);
     }
 
   if (head_l_arr_.size())
@@ -310,7 +319,7 @@ Stem::note_delta_f () const
   Real r=0;
   if (head_l_arr_.size())
     {
-      Interval head_wid(0,  head_l_arr_[0]->width ().length ());
+      Interval head_wid(0,  head_l_arr_[0]->extent (X_AXIS).length ());
       Real rule_thick(paper ()->rule_thickness ());
       Interval stem_wid(-rule_thick/2, rule_thick/2);
       if (stem_xdir_ == CENTER)
@@ -320,20 +329,21 @@ Stem::note_delta_f () const
     }
   return r;
 }
+
 Real
 Stem::hpos_f () const
 {
-  return note_delta_f () +Item::hpos_f ();
+  return note_delta_f () + Item::hpos_f ();
 }
 
 /*
   TODO:  head_l_arr_/rest_l_arr_ in  do_substitute_dependent ()
  */
 void
- Stem::do_substitute_dependency (Score_elem*o,Score_elem*n)
+Stem::do_substitute_dependency (Score_element*o,Score_element*n)
 {
-  Item * o_l = o->item ();
-  Item * n_l = n? n->item () : 0;
-  head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
-  rest_l_arr_.substitute ((Rest*)o_l, (Rest*)n_l);
+  if (Note_head*h=dynamic_cast<Note_head*> (o))
+  head_l_arr_.substitute (h, dynamic_cast<Note_head*>(n));
+  if (Rest *r=dynamic_cast<Rest*> (o))
+    rest_l_arr_.substitute (r, dynamic_cast<Rest*>(n));
 }