]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
release: 1.1.1
[lilypond.git] / lily / stem.cc
index 41175bdb5fd83ca2b9e6e529ed2662d25e5de19e..09193e06471d17d6488f5b52ccae5c01f70f27b2 100644 (file)
@@ -3,13 +3,12 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1996, 1997--1998 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 ()
 {
   /*
@@ -32,10 +33,13 @@ Stem::Stem ()
   beam_l_ = 0;
   beams_left_i_ = 0;
   beams_right_i_ = 0;
+  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;
 
@@ -59,7 +63,7 @@ void
 Stem::do_print () const
 {
 #ifndef NPRINT
-  DOUT << "flag "<< flag_i_ ;
+  DOUT << "flag "<< flag_i_;
   if (beam_l_)
     DOUT << "beamed";
 #endif
@@ -94,7 +98,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;
@@ -108,14 +112,14 @@ 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 (dynamic_cast<Note_head *> (n))
     {
       head_l_arr_.push ((Note_head*)n);
     }
-  else if (n->is_type_b (Rest::static_name ()))
+  else if (dynamic_cast<Rest *> (n))
     {
       rest_l_arr_.push ((Rest*)n);
     }
@@ -129,7 +133,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);
@@ -137,7 +141,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)) 
@@ -146,7 +150,7 @@ Stem::get_default_dir ()
 }
 
 Direction
-Stem::get_dir ()
+Stem::get_dir () const
 {
   return dir_;
 }
@@ -160,18 +164,27 @@ Stem::set_default_dir ()
 void
 Stem::set_default_stemlen ()
 {
-  Real len = STEMLEN;
-  Real dy = paper ()->interbeam_f ();
+  /*
+   TODO
+   urg; this should be handled by Stem_info
+   */
+
+  Real length_f = paper ()->get_var ("stem_length");
+  Real shorten_f = paper ()->get_var ("forced_stem_shorten");
+
+  Real internote_f = paper ()->internote_f ();
+  length_f /= internote_f;
+  shorten_f /= internote_f;
 
+  Real len = length_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.
-     */
+  /* 
+    stems in unnatural (forced) direction should be shortened, 
+    accoding to [Roush & Gourlay]
+   */
   else if (dir_ != get_default_dir ())
-    len  -= 1.0;
+    len -= shorten_f / internote_f;
 
   if (flag_i_ >= 5)
     len += 2.0;
@@ -181,13 +194,12 @@ Stem::set_default_stemlen ()
   set_stemend ((dir_ > 0) ? head_positions()[BIGGER] + len :
               head_positions()[SMALLER] - len);
 
-
   if (dir_ * stem_end_f () < 0)
     {
       set_stemend (0);
     }
 }
-
+//xxx
 void
 Stem::set_default_extents ()
 {
@@ -256,8 +268,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;
@@ -272,9 +283,8 @@ Molecule*
 Stem::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;
@@ -284,16 +294,16 @@ Stem::brew_molecule_p () const
   
   if (!invisible_b ())
     {
-      Atom ss =p->lookup_l ()->stem (stem_y[DOWN]*dy,
+      Atom ss =lookup_l ()->stem (stem_y[DOWN]*dy,
                                     stem_y[UP]*dy);
-      mol_p->add (Atom (ss));
+      mol_p->add_atom (ss);
     }
 
-  if (!beam_l_ &&abs (flag_i_) > 2)
+  if (!beam_l_ && abs (flag_i_) > 2)
     {
-      Atom fl = p->lookup_l ()->flag (flag_i_, dir_);
+      Atom fl = lookup_l ()->flag (flag_i_, dir_);
       fl.translate_axis(stem_y[dir_]*dy, Y_AXIS);
-      mol_p->add(fl);
+      mol_p->add_atom (fl);
     }
 
   if (head_l_arr_.size())
@@ -307,29 +317,38 @@ Real
 Stem::note_delta_f () const
 {
   Real r=0;
-  if (head_l_arr_.size() && stem_xdir_ != CENTER)
+  if (head_l_arr_.size())
     {
       Interval head_wid(0,  head_l_arr_[0]->width ().length ());
       Real rule_thick(paper ()->rule_thickness ());
       Interval stem_wid(-rule_thick/2, rule_thick/2);
-      r = head_wid[stem_xdir_] - stem_wid[stem_xdir_];
+      if (stem_xdir_ == CENTER)
+#define EGCS_ICE
+#ifndef EGCS_ICE
+       r = head_wid.center ();
+#else
+       r = (head_wid.min () + head_wid.max ()) / 2;
+#endif
+      else
+       r = head_wid[stem_xdir_] - stem_wid[stem_xdir_];
     }
   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;
+  Item * o_l = dynamic_cast <Item *> (o);
+  Item * n_l = n? dynamic_cast <Item *> (n) : 0;
   head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
   rest_l_arr_.substitute ((Rest*)o_l, (Rest*)n_l);
 }