]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[lilypond.git] / lily / stem.cc
index 4bfac0eb6e75200c6368743e4bea9506c720d3be..fc21f2d6b9597929ee24dd4c888d1a1f7824d027 100644 (file)
@@ -14,6 +14,7 @@
 */
 
 #include "stem.hh"
+#include "spanner.hh"
 
 #include <cmath>               // rint
 using namespace std;
@@ -65,7 +66,9 @@ Stem::get_beaming (Grob *me, Direction d)
     return 0;
 
   SCM lst = index_get_cell (pair, d);
-  return scm_ilength (lst);
+
+  int len = scm_ilength (lst);
+  return max (len, 0);
 }
 
 Interval
@@ -178,12 +181,6 @@ Stem::extremal_heads (Grob *me)
   return exthead;
 }
 
-static int
-integer_compare (int const &a, int const &b)
-{
-  return a - b;
-}
-
 /* The positions, in ascending order.  */
 vector<int>
 Stem::note_head_positions (Grob *me)
@@ -199,7 +196,7 @@ Stem::note_head_positions (Grob *me)
       ps.push_back (p);
     }
 
-  vector_sort (ps, integer_compare);
+  vector_sort (ps, less<int> ());
   return ps;
 }
 
@@ -408,7 +405,7 @@ Stem::calc_positioning_done (SCM smob)
 
   extract_grob_set (me, "note-heads", ro_heads);
   vector<Grob*> heads (ro_heads);
-  vector_sort (heads, compare_position);
+  vector_sort (heads, position_less);
   Direction dir = get_grob_direction (me);
 
   if (dir < 0)
@@ -423,12 +420,25 @@ Stem::calc_positioning_done (SCM smob)
       dir = UP;
       set_grob_direction (me, dir);
     }
-  
+
+  bool is_harmonic_centered = false;
+  for (vsize i = 0; i < heads.size (); i++)
+    is_harmonic_centered = is_harmonic_centered 
+      || heads[i]->get_property ("style") == ly_symbol2scm ("harmonic");
+  is_harmonic_centered = is_harmonic_centered && is_invisible (me);
+
   Real w = hed->extent (hed, X_AXIS)[dir];
   for (vsize i = 0; i < heads.size (); i++)
-    heads[i]->translate_axis (w - heads[i]->extent (heads[i], X_AXIS)[dir],
-                             X_AXIS);
+    {
+      Real amount = w - heads[i]->extent (heads[i], X_AXIS)[dir];
 
+      if (is_harmonic_centered)
+       amount =
+         hed->extent (hed, X_AXIS).linear_combination (CENTER)
+         - heads[i]->extent (heads[i], X_AXIS).linear_combination (CENTER);
+      
+      heads[i]->translate_axis (amount, X_AXIS);
+    }
   bool parity = true;
   Real lastpos = Real (Staff_symbol_referencer::get_position (heads[0]));
   for (vsize i = 1; i < heads.size (); i++)
@@ -979,7 +989,7 @@ Stem::beam_multiplicity (Grob *stem)
 }
 
 /* FIXME:  Too many properties  */
-ADD_INTERFACE (Stem, "stem-interface",
+ADD_INTERFACE (Stem,
               "The stem represent the graphical stem.  "
               "In addition, it internally connects note heads, beams and"
               "tremolos. "