]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem-info.cc
release: 1.2.4
[lilypond.git] / lily / stem-info.cc
index 708c6b4f450da3f0e803a758e5d8cabbd3c4a122..930130da2bb0f96ec120d147d5088e5dab5886fc 100644 (file)
@@ -10,6 +10,7 @@
 #include "proto.hh"
 #include "misc.hh"
 #include "debug.hh"
+#include "dimension-cache.hh"
 
 #include "align-element.hh"
 #include "stem.hh"
@@ -22,6 +23,9 @@
 Stem_info::Stem_info ()
 {
 }
+/*
+  FIXME: y dims should not be in internote.
+ */
 
 Stem_info::Stem_info (Stem*s, int mult)
 {
@@ -30,6 +34,7 @@ Stem_info::Stem_info (Stem*s, int mult)
   x_ = stem_l_->hpos_f ();
   dir_ = stem_l_->dir_;
   SCM bd = stem_l_->remove_elt_property (beam_dir_scm_sym);
+  
   beam_dir_ = gh_scm2int (SCM_CDR(bd));
   interstaff_f_ = 0;
 
@@ -53,12 +58,15 @@ Stem_info::Stem_info (Stem*s, int mult)
 
   // for simplicity, we calculate as if dir == UP
   idealy_f_ *= beam_dir_;
-  
+
+  bool grace_b = stem_l_->get_elt_property (grace_scm_sym) != SCM_BOOL_F;
+
   int stem_max = (int)rint(paper_l->get_var ("stem_max"));
-  Real min_stem_f = paper_l->get_var (String ("minimum_stem_length")
-                                    + to_str (mult_i_ <? stem_max));
-  Real stem_f = paper_l->get_var (String ("stem_length")
-                                + to_str (mult_i_ <? stem_max));
+  String type_str = grace_b ? "grace_" : "";
+  Real min_stem_f = paper_l->get_var (type_str + "minimum_stem_length"
+                                     + to_str (mult_i_ <? stem_max)) * internote_f;
+  Real stem_f = paper_l->get_var (type_str + "stem_length"
+                                 + to_str (mult_i_ <? stem_max))* internote_f;
 
   if (!beam_dir_ || (beam_dir_ == dir_))
     /* normal beamed stem */
@@ -74,9 +82,24 @@ Stem_info::Stem_info (Stem*s, int mult)
       idealy_f_ += stem_f;
       miny_f_ += min_stem_f;
 
-      // lowest beam of (UP) beam must never be lower than second staffline
-      miny_f_ = miny_f_ >? (- 2 * internote_f - beam_f
-       + (mult_i_ > 0) * beam_f + interbeam_f * (mult_i_ - 1));
+      /*
+       lowest beam of (UP) beam must never be lower than second staffline
+
+       Hmm, reference (Wanske?)
+
+       Although this (additional) rule is probably correct,
+       I expect that highest beam (UP) should also never be lower
+       than middle staffline, just as normal stems.
+       
+      */
+      if (!grace_b)
+       {
+         //highest beam of (UP) beam must never be lower than middle staffline
+         miny_f_ = miny_f_ >? 0;
+         //lowest beam of (UP) beam must never be lower than second staffline
+         miny_f_ = miny_f_ >? (- 2 * internote_f - beam_f
+                               + (mult_i_ > 0) * beam_f + interbeam_f * (mult_i_ - 1));
+       }
     }
   else
     /* knee */
@@ -107,8 +130,9 @@ Stem_info::Stem_info (Stem*s, int mult)
 
   // interstaff beam
   Beam* beam_l = stem_l_->beam_l_;
-  Dimension_cache *common = stem_l_->common_group (beam_l, Y_AXIS);
-  Align_element * align = dynamic_cast<Align_element*> (common->element_l ());
+  
+  Graphical_element *common = stem_l_->common_refpoint (beam_l, Y_AXIS);
+  Align_element * align = dynamic_cast<Align_element*> (common);
   if (align && align->axis() == Y_AXIS)
     {
       if (align->threshold_interval_[MIN] != 
@@ -117,19 +141,19 @@ Stem_info::Stem_info (Stem*s, int mult)
 
       interstaff_f_ = align->threshold_interval_[MIN] / internote_f;
 
-      Dimension_cache * beam_refpoint = &beam_l->dim_cache_[Y_AXIS];
-      Dimension_cache * stem_refpoint = &stem_l_->dim_cache_[Y_AXIS];
+      Graphical_element * beam_refpoint = beam_l;
+      Graphical_element * stem_refpoint = stem_l_;
 
-      while (beam_refpoint->parent_l_ != common)
-       beam_refpoint = beam_refpoint->parent_l_;
-      while (stem_refpoint->parent_l_ != common)
-       stem_refpoint = stem_refpoint->parent_l_;
+      while (beam_refpoint->parent_l (Y_AXIS) != common)
+       beam_refpoint = beam_refpoint->parent_l (Y_AXIS);
+      while (stem_refpoint->parent_l (Y_AXIS) != common)
+       stem_refpoint = stem_refpoint->parent_l (Y_AXIS);
 
 
       int beam_prio =
-       align->get_priority (dynamic_cast<Score_element*> (beam_refpoint->element_l ()));
+       align->get_priority (dynamic_cast<Score_element*> (beam_refpoint));
       int stem_prio =
-       align->get_priority (dynamic_cast<Score_element*> (stem_refpoint->element_l ()));
+       align->get_priority (dynamic_cast<Score_element*> (stem_refpoint));
 
       /*
        our staff is lower -> interstaff_f_ *= -1