]> git.donarmstrong.com Git - lilypond.git/commitdiff
Restores stem length and stem-begin-position.
authorMike Solomon <mike@apollinemike.com>
Thu, 1 Sep 2011 08:32:23 +0000 (10:32 +0200)
committerMike Solomon <mike@apollinemike.com>
Thu, 1 Sep 2011 08:32:23 +0000 (10:32 +0200)
These two properties are used by the stencil and by the Y-extent
(unpure) callbacks to generate the stem.  This allows users to:

* Use length like they did prior to 2.15.9.
* Override Y-extent without there being an effect on the stencil.

This patch also makes minor fixes in the pure height estimations of
certain beamed notes.

input/regression/stem-length-override.ly [deleted file]
input/regression/stem-length.ly [new file with mode: 0644]
lily/grob-scheme.cc
lily/stem.cc
scm/define-grob-properties.scm
scm/define-grobs.scm
scm/output-lib.scm

diff --git a/input/regression/stem-length-override.ly b/input/regression/stem-length-override.ly
deleted file mode 100644 (file)
index 7d0bc2d..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-
-\version "2.15.9"
-
-\header {
-  texidoc = "Stem length can be overridden via the function
-stem::length
-"
-}
-
-\relative c' {
-  \override Stem #'Y-extent = #(stem::length 8)
-  e4 f'4
-}
diff --git a/input/regression/stem-length.ly b/input/regression/stem-length.ly
new file mode 100644 (file)
index 0000000..1b98289
--- /dev/null
@@ -0,0 +1,20 @@
+
+\version "2.15.9"
+
+\header {
+  texidoc = "Stem length and stem-begin-position can be set manually.
+"
+}
+
+\relative c' {
+  \autoBeamOff
+  \stemUp
+  a8 aes''8
+  \override Stem #'length = #20
+  a,,8
+  \revert Stem #'length
+  aes''!8
+  \stemNeutral
+  \override Stem #'stem-begin-position = #-2
+  c,8
+}
index 1709cb7e926c215d59100acb695897fe1d8454ea..92f755d7a77e3eb098d84f1c3fa031c13a558d0a 100644 (file)
@@ -78,6 +78,28 @@ LY_DEFINE (ly_grob_set_nested_property_x, "ly:grob-set-nested-property!",
   return SCM_UNSPECIFIED;
 }
 
+LY_DEFINE (ly_grob_pure_property, "ly:grob-pure-property",
+           4, 1, 0, (SCM grob, SCM sym, SCM beg, SCM end, SCM val),
+           "Return the pure value for property @var{sym} of @var{grob}."
+           "  If no value is found, return @var{val} or @code{'()}"
+           " if @var{val} is not specified.")
+{
+  Grob *sc = unsmob_grob (grob);
+
+  LY_ASSERT_SMOB (Grob, grob, 1);
+  LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
+  LY_ASSERT_TYPE (scm_is_integer, beg, 3);
+  LY_ASSERT_TYPE (scm_is_integer, end, 4);
+  if (val == SCM_UNDEFINED)
+    val = SCM_EOL;
+
+  SCM retval = sc->internal_get_pure_property (sym, scm_to_int (beg), scm_to_int (end));
+  if (retval == SCM_EOL)
+    retval = val;
+
+  return retval;
+}
+
 LY_DEFINE (ly_grob_property, "ly:grob-property",
            2, 1, 0, (SCM grob, SCM sym, SCM val),
            "Return the value for property @var{sym} of @var{grob}."
index 7245e3c07fae7053aa0d4d9e0edf4378d42281d9..8a755afaa5aec63946003a19017be335f0c39b80 100644 (file)
@@ -128,7 +128,8 @@ Stem::set_stem_positions (Grob *me, Real se)
     me->warning (_ ("weird stem size, check for narrow beams"));
 
   Interval height = me->pure_height (me, 0, INT_MAX);
-  Real half_space = Staff_symbol_referencer::staff_space (me) * 0.5;
+  Real staff_space = Staff_symbol_referencer::staff_space (me);
+  Real half_space =  staff_space * 0.5;
 
   height[d] = se * half_space + beam_end_corrective (me);
 
@@ -157,7 +158,9 @@ Stem::set_stem_positions (Grob *me, Real se)
         me->programming_error ("Can't have a stemlet without a beam.");
     }
 
-  me->set_property ("Y-extent", ly_interval2scm (height));
+  me->set_property ("stem-begin-position", scm_from_double (height[-d] * 2 / staff_space));
+  me->set_property ("length", scm_from_double (height.length () * 2 / staff_space));
+  (void) me->extent (me, Y_AXIS);
 }
 
 /* Note head that determines hshift for upstems
@@ -367,10 +370,13 @@ Stem::internal_calc_stem_end_position (Grob *me, bool calc_beam)
 
   Grob *beam = get_beam (me);
   Real ss = Staff_symbol_referencer::staff_space (me);
+  Direction dir = get_grob_direction (me);
+
   if (beam && calc_beam)
     {
       (void) beam->get_property ("quantized-positions");
-      return me->extent (me, Y_AXIS)[get_grob_direction (me)] * ss * 2;
+      return robust_scm2double (me->get_property ("length"), 0.0)
+             + dir * robust_scm2double (me->get_property ("stem-begin-position"), 0.0);
     }
 
   vector<Real> a;
@@ -385,7 +391,6 @@ Stem::internal_calc_stem_end_position (Grob *me, bool calc_beam)
   if (scm_is_pair (s))
     length = 2 * scm_to_double (robust_list_ref (durlog - 2, s));
 
-  Direction dir = get_grob_direction (me);
 
   /* Stems in unnatural (forced) direction should be shortened,
      according to [Roush & Gourlay] */
@@ -655,26 +660,32 @@ Stem::beam_end_corrective (Grob *me)
 Interval
 Stem::internal_height (Grob *me, bool calc_beam)
 {
-  if (!is_valid_stem (me))
+  Grob *beam = get_beam (me);
+  if (!is_valid_stem (me) && ! beam)
     return Interval ();
 
   Direction dir = get_grob_direction (me);
 
-  Grob *beam = get_beam (me);
   if (beam && calc_beam)
     {
       /* trigger set-stem-lengths. */
       (void) beam->get_property ("quantized-positions");
-      return me->extent (me, Y_AXIS);
     }
 
-  Real y2 = internal_calc_stem_end_position (me, calc_beam);
-  Real y1 = internal_calc_stem_begin_position (me, calc_beam);
+  Real y1 = robust_scm2double ((calc_beam
+                                ? me->get_property ("stem-begin-position")
+                                : me->get_pure_property ("stem-begin-position", 0, INT_MAX)),
+                               0.0);
+
+  Real y2 = dir * robust_scm2double ((calc_beam
+                                     ? me->get_property ("length")
+                                     : me->get_pure_property ("length", 0, INT_MAX)),
+                                      0.0)
+                + y1;
 
   Real half_space = Staff_symbol_referencer::staff_space (me) * 0.5;
 
   Interval stem_y  = Interval (min (y1, y2), max (y2, y1)) * half_space;
-  stem_y[dir] += beam_end_corrective (me);
 
   return stem_y;
 }
@@ -731,12 +742,15 @@ Stem::internal_calc_stem_begin_position (Grob *me, bool calc_beam)
   if (beam && calc_beam)
     {
       (void) beam->get_property ("quantized-positions");
-      return me->extent (me, Y_AXIS)[-get_grob_direction (me)] * ss * 2;
+      return robust_scm2double (me->get_property ("stem-begin-position"), 0.0);
     }
 
   Direction d = get_grob_direction (me);
   Grob *lh = get_reference_head (me);
 
+  if (!lh)
+    return 0.0;
+
   Real pos = Staff_symbol_referencer::get_position (lh);
 
   if (Grob *head = support_head (me))
@@ -756,17 +770,10 @@ Stem::is_valid_stem (Grob *me)
 {
   /* TODO: make the stem start a direction ?
      This is required to avoid stems passing in tablature chords.  */
-  Real stemlet_length = robust_scm2double (me->get_property ("stemlet-length"),
-                                           0.0);
-  bool stemlet = stemlet_length > 0.0;
-
   Grob *lh = get_reference_head (me);
   Grob *beam = unsmob_grob (me->get_object ("beam"));
 
-  if (!lh && !stemlet)
-    return false;
-
-  if (!lh && stemlet && !beam)
+  if (!lh && !beam)
     return false;
 
   if (lh && robust_scm2int (lh->get_property ("duration-log"), 0) < 1)
@@ -786,8 +793,13 @@ Stem::print (SCM smob)
   if (!is_valid_stem (me))
     return SCM_EOL;
 
-  Interval stem_y = me->extent (me, Y_AXIS);
   Direction dir = get_grob_direction (me);
+  Real y1 = robust_scm2double (me->get_property ("stem-begin-position"), 0.0);
+  Real y2 = dir * robust_scm2double (me->get_property ("length"), 0.0) + y1;
+
+  Real half_space = Staff_symbol_referencer::staff_space (me) * 0.5;
+
+  Interval stem_y  = Interval (min (y1, y2), max (y2, y1)) * half_space;
 
   stem_y[dir] -= beam_end_corrective (me);
 
@@ -1078,6 +1090,7 @@ ADD_INTERFACE (Stem,
                "duration-log "
                "flag "
                "french-beaming "
+               "length "
                "length-fraction "
                "max-beam-connect "
                "neutral-direction "
@@ -1085,6 +1098,7 @@ ADD_INTERFACE (Stem,
                "note-heads "
                "positioning-done "
                "rests "
+               "stem-begin-position "
                "stem-info "
                "stemlet-length "
                "thickness "
index cd3fd6ec979b2e4dde93ec2fb59aec8d1d19ef78..d9a38bfd5ff7ddf7954a0c961676122daaaa97de 100644 (file)
@@ -838,6 +838,8 @@ the @code{staff-staff-spacing} property of the staff's
 structure.")
      (stem-attachment ,number-pair? "An @code{(@var{x} . @var{y})}
 pair where the stem attaches to the notehead.")
+     (stem-begin-position ,ly:dimension? "User override for the
+begin position of a stem.")
      ;;[TODO: doco]
      (stem-spacing-correction ,number? "Optical correction amount for
 stems that are placed in tight configurations.  For opposite
index b5f56e036e6cd862951dd09dd47360990b68e5b8..b5315cfd93511301382f67f1f3e5138c0896a9b1 100644 (file)
 
        (direction . ,ly:stem::calc-direction)
        (duration-log . ,stem::calc-duration-log)
+        (length . ,stem::length)
        (neutral-direction . ,DOWN)
        (positioning-done . ,ly:stem::calc-positioning-done)
        (stem-info . ,ly:stem::calc-stem-info)
+       (stem-begin-position . ,ly:stem::calc-stem-begin-position)
        (stencil . ,ly:stem::print)
        (thickness . 1.3)
        (X-extent . ,ly:stem::width)
     (,ly:slur::outside-slur-callback . ,ly:slur::pure-outside-slur-callback)
     (,ly:stem::calc-stem-begin-position . ,ly:stem::pure-calc-stem-begin-position)
     (,ly:stem::calc-stem-end-position . ,ly:stem::pure-calc-stem-end-position)
+    (,stem::length . ,stem::pure-length)
     (,ly:stem::height . ,ly:stem::pure-height)
     (,ly:stem-tremolo::calc-y-offset . ,ly:stem-tremolo::pure-calc-y-offset)
     (,ly:system::height . ,ly:system::calc-pure-height)))
index 5f257844542297c5924a0f8e12804310c3a6756f..70e3ba3eeb07885ff46475ec6f20b2a841dd01f8 100644 (file)
   (ly:duration-log
    (ly:event-property (event-cause grob) 'duration)))
 
-(define-public (stem::length val)
-  (lambda (grob)
-    (let* ((d (ly:grob-property grob 'direction))
-           (ss (ly:staff-symbol-staff-space grob))
-           (beg (ly:stem::calc-stem-begin-position grob))
-           (y1 (* beg (* 0.5 ss)))
-           (y2 (* ((if (eqv? d DOWN) - +) beg val) (* 0.5 ss))))
-      (if (eqv? d DOWN)
-          (cons y2 y1)
-          (cons y1 y2)))))
+(define-public (stem::length grob)
+  (let* ((d (ly:grob-property grob 'direction))
+         (ss (ly:staff-symbol-staff-space grob))
+         (beg (ly:grob-property grob 'stem-begin-position))
+         (beam (ly:grob-object grob 'beam)))
+    (if (null? beam)
+        (abs (- (ly:stem::calc-stem-end-position grob) beg))
+        (ly:grob-property grob 'length))))
+
+(define-public (stem::pure-length grob beg end)
+  (let* ((d (ly:grob-property grob 'direction))
+         (ss (ly:staff-symbol-staff-space grob))
+         (beg (ly:grob-pure-property grob 'stem-begin-position 0 1000)))
+    (abs (- (ly:stem::pure-calc-stem-end-position grob 0 2147483646) beg))))
 
 (define-public (note-head::calc-duration-log grob)
   (min 2