]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
Fretboards: markup strings in dot positions
[lilypond.git] / lily / stem.cc
index 0a72fcf01953b1d276c57a64c9782e82a6844d6a..0c2625b9e4c454b9bd108001801b6d3e3b63098d 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1996--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
   Jan Nieuwenhuizen <janneke@gnu.org>
 
   TODO: This is way too hairy
@@ -110,10 +110,10 @@ Stem::head_positions (Grob *me)
 Real
 Stem::chord_start_y (Grob *me)
 {
-  Interval hp = head_positions (me);
-  if (!hp.is_empty ())
-    return hp[get_grob_direction (me)] * Staff_symbol_referencer::staff_space (me)
-           * 0.5;
+  if (head_count (me))
+    return Staff_symbol_referencer::get_position (last_head (me))
+      * Staff_symbol_referencer::staff_space (me) * 0.5;
+
   return 0;
 }
 
@@ -456,7 +456,7 @@ Stem::internal_calc_stem_end_position (Grob *me, bool calc_beam)
 
   /* Tremolo stuff.  */
   Grob *t_flag = Grob::unsmob (me->get_object ("tremolo-flag"));
-  if (t_flag && (!Grob::unsmob (me->get_object ("beam")) || !calc_beam))
+  if (t_flag && (!Grob::is_smob (me->get_object ("beam")) || !calc_beam))
     {
       /* Crude hack: add extra space if tremolo flag is there.
 
@@ -533,7 +533,8 @@ Stem::calc_positioning_done (SCM smob)
   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");
+                           || scm_is_eq (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];
@@ -575,14 +576,32 @@ Stem::calc_positioning_done (SCM smob)
                 stem 100% whereas reversed heads only overlaps the
                 stem 50%
               */
-
               Real reverse_overlap = 0.5;
-              heads[i]->translate_axis ((ell - thick * reverse_overlap) * d,
-                                        X_AXIS);
+
+              /*
+                However, the first reverse head has to be shifted even
+                more than the full reverse overlap if it is the same
+                height as the first head or there will be a gap
+                because of the head slant (issue 346).
+              */
+
+              if (i == 1 && dy < 0.1)
+                reverse_overlap = 1.1;
 
               if (is_invisible (me))
-                heads[i]->translate_axis (-thick * (2 - reverse_overlap) * d,
-                                          X_AXIS);
+                {
+                  // Semibreves and longer are tucked in considerably
+                  // to be recognizable as chorded rather than
+                  // parallel voices.  During the course of issue 346
+                  // there was a discussion to change this for unisons
+                  // (dy < 0.1) to reduce overlap but without reaching
+                  // agreement and with Gould being rather on the
+                  // overlapping front.
+                  reverse_overlap = 2;
+                }
+
+              heads[i]->translate_axis ((ell - thick * reverse_overlap) * d,
+                                        X_AXIS);
 
               /* TODO:
 
@@ -640,9 +659,9 @@ Stem::calc_default_direction (SCM smob)
 
   Direction dir = CENTER;
   int staff_center = 0;
-  Interval hp = head_positions (me);
-  if (!hp.is_empty ())
+  if (head_count (me))
     {
+      Interval hp = head_positions (me);
       int udistance = (int) (UP * hp[UP] - staff_center);
       int ddistance = (int) (DOWN * hp[DOWN] - staff_center);
 
@@ -706,7 +725,7 @@ Stem::internal_height (Grob *me, bool calc_beam)
     If there is a beam but no stem, slope calculations depend on this
     routine to return where the stem end /would/ be.
   */
-  if (calc_beam && !beam && !Stencil::unsmob (me->get_property ("stencil")))
+  if (calc_beam && !beam && !Stencil::is_smob (me->get_property ("stencil")))
     return Interval ();
 
   Real y1 = robust_scm2double ((calc_beam
@@ -819,7 +838,7 @@ SCM
 Stem::calc_length (SCM smob)
 {
   Grob *me = Grob::unsmob (smob);
-  if (Grob::unsmob (me->get_object ("beam")))
+  if (Grob::is_smob (me->get_object ("beam")))
     {
       me->programming_error ("ly:stem::calc-length called but will not be used for beamed stem.");
       return scm_from_double (0.0);
@@ -835,6 +854,8 @@ Stem::is_valid_stem (Grob *me)
 {
   /* TODO: make the stem start a direction ?
      This is required to avoid stems passing in tablature chords.  */
+  if (!me)
+    return false;
   Grob *lh = get_reference_head (me);
   Grob *beam = Grob::unsmob (me->get_object ("beam"));
 
@@ -931,7 +952,7 @@ Spanner *
 Stem::get_beam (Grob *me)
 {
   SCM b = me->get_object ("beam");
-  return dynamic_cast<Spanner *> (Grob::unsmob (b));
+  return Spanner::unsmob (b);
 }
 
 Stem_info