]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
release: 1.2.14
[lilypond.git] / lily / stem.cc
index 55b2036269b12ddfb95110d1d3709e0cef11c521..aef8245546d93d250159dbe1348ccacd8d54e6b2 100644 (file)
@@ -14,7 +14,7 @@
 #include "note-head.hh"
 #include "lookup.hh"
 #include "molecule.hh"
-#include "p-col.hh"
+#include "paper-column.hh"
 #include "misc.hh"
 #include "beam.hh"
 #include "rest.hh"
@@ -23,7 +23,7 @@ void
 Stem::set_direction (Direction d)
 {
   if  (!dir_)
-    warning ("Stem direction set already!");
+    warning (_ ("stem direction set already!"));
 
   dir_ = d;
 
@@ -57,7 +57,7 @@ Stem::head_positions () const
   Interval_t<int> r;
   for (int i =0; i < head_l_arr_.size (); i++)
     {
-      int p = head_l_arr_[i]->position_i_;
+      int p = (int)head_l_arr_[i]->position_f ();
       r[BIGGER] = r[BIGGER] >? p;
       r[SMALLER] = r[SMALLER] <? p;
     }
@@ -68,9 +68,9 @@ void
 Stem::do_print () const
 {
 #ifndef NPRINT
-  DOUT << "flag "<< flag_i_;
+  DEBUG_OUT << "flag "<< flag_i_;
   if (beam_l_)
-    DOUT << "beamed";
+    DEBUG_OUT << "beamed";
 #endif
 }
 
@@ -103,7 +103,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;
@@ -119,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))
     {
@@ -148,10 +149,13 @@ Stem::get_center_distance (Direction d) const
 Direction
 Stem::get_default_dir () const
 {
-  return (get_center_distance (UP) >
-         get_center_distance (DOWN)) 
-    ? DOWN 
-    : UP;
+  int du = get_center_distance (UP);
+  int dd = get_center_distance (DOWN);
+
+  if (sign (dd - du))
+    return Direction (sign (dd -du));
+
+  return Direction (int(paper_l ()->get_var ("stem_default_neutral_direction")));
 }
 
 Direction
@@ -164,9 +168,19 @@ Stem::get_dir () const
 void
 Stem::set_default_stemlen ()
 {
-  Real internote_f = staff_line_leading_f ()/2.0;
-  Real length_f = paper_l ()->get_var ("stem_length0") / internote_f;
-  Real shorten_f = paper_l ()->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_)
     dir_ = get_default_dir ();
@@ -187,7 +201,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);
 }
 
@@ -215,10 +229,10 @@ Stem::set_noteheads ()
     head_l_arr_.top ()->set_elt_property (extremal_scm_sym, SCM_BOOL_T);
   
   int parity=1;
-  int lastpos = beginhead->position_i_;
+  int lastpos = int (beginhead->position_f ());
   for (int i=1; i < head_l_arr_.size (); i ++)
     {
-      int dy =abs (lastpos- head_l_arr_[i]->position_i_);
+      int dy =abs (lastpos- (int)head_l_arr_[i]->position_f ());
 
       if (dy <= 1)
        {
@@ -228,7 +242,7 @@ Stem::set_noteheads ()
        }
       else
        parity = 1;
-      lastpos = head_l_arr_[i]->position_i_;
+      lastpos = int (head_l_arr_[i]->position_f ());
     }
 }
 
@@ -243,9 +257,58 @@ Stem::do_pre_processing ()
     {
       set_elt_property (transparent_scm_sym, SCM_BOOL_T);
     }
-  set_empty (invisible_b ());
+  set_empty (invisible_b (), X_AXIS, Y_AXIS);
+  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
@@ -255,7 +318,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;
@@ -280,14 +343,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);
     }