lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Better pure heights for slurs (issue 5431065)


From: mtsolo
Subject: Better pure heights for slurs (issue 5431065)
Date: Thu, 24 Nov 2011 09:39:53 +0000

Reviewers: ,

Message:
Hey all,

I'm not sure if this patch will make a big difference, but it should
help the pure height problem a little bit.  Before, pure heights were
calculated using the entire height of the slur.  For slurs with a slope,
this is an overshoot.  I thus use an estimate of the Y portion of this
height by calculating a dummy slope and then tacking on the appropriate
Y value.  In certain cases it could lead to an underestimation of the
pure height, but in general it should still lead to an overestimation
that overshoots less than the original function.

If someone could run a lilypond file with tons of slurs and see if this
makes a difference, I'd be much obliged.

Cheers,
MS

Description:
Better pure heights for slurs

Please review this at http://codereview.appspot.com/5431065/

Affected files:
  M lily/slur.cc


Index: lily/slur.cc
diff --git a/lily/slur.cc b/lily/slur.cc
index bf0fb12361e80298aa5f68a2ad9807dc2a69d692..62683f4e84cb83ef54240d2055756ca9c9ea101b 100644
--- a/lily/slur.cc
+++ b/lily/slur.cc
@@ -73,6 +73,7 @@ Slur::pure_height (SCM smob, SCM start_scm, SCM end_scm)
   Grob *me = unsmob_grob (smob);
   int start = scm_to_int (start_scm);
   int end = scm_to_int (end_scm);
+  Direction dir = get_grob_direction (me);
   Real height = robust_scm2double (me->get_property ("height-limit"), 2.0);

   extract_grob_set (me, "note-columns", encompasses);
@@ -84,17 +85,35 @@ Slur::pure_height (SCM smob, SCM start_scm, SCM end_scm)
        in this case, we want to be ignored */
     return ly_interval2scm (Interval ());

+  vsize no_elts = 0;
   for (vsize i = 0; i < encompasses.size (); i++)
     {
       Interval d = encompasses[i]->pure_height (parent, start, end);
       if (!d.is_empty ())
-        ret.unite (d);
+        {
+          ret.unite (d);
+          no_elts++;
+        }
     }

-  // The +0.5 comes from the fact that we try to place a slur
-  // 0.5 staff spaces from the note-head.
-  // (see Slur_score_state.get_base_attachments ())
-  ret.widen (height * 0.5 + 0.5);
+  if (!no_elts)
+    return ly_interval2scm (Interval ());
+
+  height *= 0.5;
+  /*
+    really poor slope estimation of slope,
+    but better than nothing...
+    2.5 corresponds to guestimation of average spacing
+    between two columns
+  */
+  Real s = ret.length () / (no_elts * 2.5);
+  /*
+    The +0.5 comes from the fact that we try to place a slur
+    0.5 staff spaces from the note-head.
+    (see Slur_score_state.get_base_attachments ())
+  */
+  ret[dir] += dir * (sqrt (height * height / ((s * s) + 1)) + 0.5);
+  ret[-dir] += dir * 0.5;
   return ly_interval2scm (ret);
 }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]