]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
release: 1.1.56
[lilypond.git] / lily / stem.cc
index a0600e8636a1bef5f01c004660ebf67ad29989db..0fd640c795e997a67a9eafed7764cb8941e9f893 100644 (file)
 #include "beam.hh"
 #include "rest.hh"
 
+void
+Stem::set_direction (Direction d)
+{
+  if  (!dir_)
+    warning ("Stem direction set already!");
 
+  dir_ = d;
 
-
-Stem::~Stem ()
-{
+  /*
+    todo
+  */
 }
 
 Stem::Stem ()
 {
-  /*
-    TODO: staff-size
-    */
   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;
 }
 
@@ -94,7 +89,7 @@ Stem::stem_begin_f () const
 Real
 Stem::chord_start_f () const
 {
-  return head_positions()[dir_] * paper ()->internote_f ();
+  return head_positions()[dir_] * staff_line_leading_f ()/2.0;
 }
 
 Real
@@ -124,6 +119,7 @@ Stem::type_i () const
 void
 Stem::add_head (Rhythmic_head *n)
 {
+  n->stem_l_ = this;
   n->add_dependency (this);    // ?
   if (Note_head *nh = dynamic_cast<Note_head *> (n))
     {
@@ -165,24 +161,30 @@ Stem::get_dir () const
   return dir_;
 }
 
-void
-Stem::set_default_dir ()
-{
-  dir_ = get_default_dir ();
-}
 
 void
 Stem::set_default_stemlen ()
 {
-  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;
+  Real length_f = 0.;
+  SCM scm_len = get_elt_property(length_scm_sym);
+  if (scm_len != SCM_BOOL_F)
+    {
+      length_f = gh_scm2double (SCM_CDR(scm_len));
+    }
+  else
+    length_f = paper_l ()->get_var ("stem_length0");
+
+  bool grace_b = get_elt_property (grace_scm_sym) != SCM_BOOL_F;
+  String type_str = grace_b ? "grace_" : "";
+
+  Real shorten_f = paper_l ()->get_var (type_str + "forced_stem_shorten0");
 
   if (!dir_)
-    set_default_dir ();
+    dir_ = get_default_dir ();
+
   /* 
     stems in unnatural (forced) direction should be shortened, 
-    accoding to [Roush & Gourlay]
+    according to [Roush & Gourlay]
    */
   if (((int)chord_start_f ())
       && (dir_ != get_default_dir ()))
@@ -196,7 +198,7 @@ Stem::set_default_stemlen ()
   set_stemend ((dir_ > 0) ? head_positions()[BIGGER] + length_f:
               head_positions()[SMALLER] - length_f);
 
-  if (dir_ * stem_end_f () < 0)
+  if (!grace_b && (dir_ * stem_end_f () < 0))
     set_stemend (0);
 }
 
@@ -207,19 +209,8 @@ Stem::set_default_extents ()
   if (!stem_length_f ())
     set_default_stemlen ();
 
-
-  if (dir_ == UP)
-    stem_xdir_ = RIGHT;
-  if (invisible_b ())
-    stem_xdir_ = CENTER;
 }
 
-/*
-  TODO
-
-  move into note_column.cc
-
-  */
 void
 Stem::set_noteheads ()
 {
@@ -229,10 +220,13 @@ Stem::set_noteheads ()
   if (dir_ < 0)
     head_l_arr_.reverse ();
 
-  head_l_arr_[0]->extremal_i_ = -1;
-  head_l_arr_.top ()->extremal_i_ = 1;
+  Note_head * beginhead =   head_l_arr_[0];
+  beginhead->set_elt_property (extremal_scm_sym, SCM_BOOL_T);
+  if  (beginhead !=   head_l_arr_.top ())
+    head_l_arr_.top ()->set_elt_property (extremal_scm_sym, SCM_BOOL_T);
+  
   int parity=1;
-  int lastpos = head_l_arr_[0]->position_i_;
+  int lastpos = beginhead->position_i_;
   for (int i=1; i < head_l_arr_.size (); i ++)
     {
       int dy =abs (lastpos- head_l_arr_[i]->position_i_);
@@ -240,7 +234,7 @@ Stem::set_noteheads ()
       if (dy <= 1)
        {
          if (parity)
-           head_l_arr_[i]->x_dir_ = (stem_xdir_ == LEFT) ? LEFT : RIGHT;
+           head_l_arr_[i]->flip_around_stem (dir_);
          parity = !parity;
        }
       else
@@ -255,12 +249,63 @@ Stem::do_pre_processing ()
   if (yextent_drul_[DOWN]== yextent_drul_[UP])
     set_default_extents ();
   set_noteheads ();
-  flag_i_ = flag_i_;
-  transparent_b_ = invisible_b ();
+
+  if (invisible_b ())
+    {
+      set_elt_property (transparent_scm_sym, SCM_BOOL_T);
+    }
   set_empty (invisible_b ());
+  set_spacing_hints ();
 }
 
 
+
+/**
+   set stem directions for hinting the optical spacing correction.
+
+   Modifies DIR_LIST property of the Stem's Score_column
+
+   TODO: more advanced: supply height of noteheads as well, for more advanced spacing possibilities
+ */
+void
+Stem::set_spacing_hints () 
+{
+  if (!invisible_b ())
+    {
+      SCM scmdir  = gh_int2scm (dir_);
+      SCM dirlist = column_l ()->get_elt_property (dir_list_scm_sym);
+      if (dirlist == SCM_BOOL_F)
+       dirlist = SCM_EOL;
+      else
+       dirlist = SCM_CDR (dirlist);
+
+      if (scm_sloppy_memq (scmdir, dirlist) == SCM_EOL)
+       {
+         dirlist = gh_cons (scmdir, dirlist);
+         column_l ()->set_elt_property (dir_list_scm_sym, dirlist);
+       }
+    }
+}
+
+Molecule
+Stem::flag () const
+{
+  String style;
+  SCM st = get_elt_property (style_scm_sym);
+  if ( st != SCM_BOOL_F)
+    {
+      st = SCM_CDR(st);
+      style = ly_scm2string (st);
+    }
+
+  char c = (dir_ == UP) ? 'u' : 'd';
+  Molecule m = lookup_l ()->afm_find (String ("flags-") + to_str (c) + 
+                                     to_str (flag_i_));
+  if (!style.empty_b ())
+    m.add_molecule(lookup_l ()->afm_find (String ("flags-") + to_str (c) + style));
+  return m;
+}
+
 Interval
 Stem::do_width () const
 {
@@ -269,7 +314,7 @@ Stem::do_width () const
     ;  // TODO!
   else
     {
-      r = lookup_l ()->flag (flag_i_, dir_).dim_.x ();
+      r = flag ().dim_.x ();
       r += note_delta_f ();
     }
   return r;
@@ -285,7 +330,7 @@ Stem::do_brew_molecule_p () const
 {
   Molecule *mol_p =new Molecule;
   Drul_array<Real> stem_y = yextent_drul_;
-  Real dy = paper ()->internote_f ();
+  Real dy = staff_line_leading_f ()/2.0;
 
   Real head_wid = 0;
   if (head_l_arr_.size ())
@@ -294,14 +339,15 @@ Stem::do_brew_molecule_p () const
   
   if (!invisible_b ())
     {
-      Molecule ss =lookup_l ()->stem (stem_y[DOWN]*dy,
-                                    stem_y[UP]*dy);
+      Real stem_width = paper_l ()->get_var ("stemthickness");
+      Molecule ss =lookup_l ()->filledbox (Box (Interval (-stem_width/2, stem_width/2),
+                                                Interval (stem_y[DOWN]*dy, stem_y[UP]*dy)));
       mol_p->add_molecule (ss);
     }
 
   if (!beam_l_ && abs (flag_i_) > 2)
     {
-      Molecule fl = lookup_l ()->flag (flag_i_, dir_);
+      Molecule fl = flag ();
       fl.translate_axis(stem_y[dir_]*dy, Y_AXIS);
       mol_p->add_molecule (fl);
     }
@@ -320,12 +366,12 @@ Stem::note_delta_f () const
   if (head_l_arr_.size())
     {
       Interval head_wid(0,  head_l_arr_[0]->extent (X_AXIS).length ());
-      Real rule_thick(paper ()->rule_thickness ());
+      Real rule_thick(paper_l ()->rule_thickness ());
       Interval stem_wid(-rule_thick/2, rule_thick/2);
-      if (stem_xdir_ == CENTER)
+      if (dir_ == CENTER)
        r = head_wid.center ();
       else
-       r = head_wid[stem_xdir_] - stem_wid[stem_xdir_];
+       r = head_wid[dir_] - stem_wid[dir_];
     }
   return r;
 }
@@ -336,27 +382,17 @@ Stem::hpos_f () const
   return note_delta_f () + Item::hpos_f ();
 }
 
-/*
-  TODO:  head_l_arr_/rest_l_arr_ in  
- */
 void
 Stem::do_substitute_element_pointer (Score_element*o,Score_element*n)
 {
   if (Note_head*h=dynamic_cast<Note_head*> (o))
-  head_l_arr_.substitute (h, dynamic_cast<Note_head*>(n));
+    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));
   if (Beam* b = dynamic_cast<Beam*> (o))
     {
       if (b == beam_l_) 
-       {
-         beam_l_ = dynamic_cast<Beam*> (n);
-         if (!beam_l_)
-           {
-             beams_i_drul_[LEFT] = 0;
-             beams_i_drul_[RIGHT] = 0;
-             mult_i_ = 0;
-           }
-       }
+       beam_l_ = dynamic_cast<Beam*> (n);
     }
+  Staff_symbol_referencer::do_substitute_element_pointer (o,n);
 }