]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur.cc
* lily/slur.cc (outside_slur_callback): make offset_scm optional.
[lilypond.git] / lily / slur.cc
index 16b63bef8dd9d51014a74e2eea969b74b620326e..d8c81f7836337258a4d1a09e9344d1a8f1f24070 100644 (file)
@@ -24,6 +24,7 @@
 #include "staff-symbol.hh"
 #include "stem.hh"
 #include "text-interface.hh"
+#include "tie.hh"
 #include "warn.hh"
 #include "slur-scoring.hh"
 
@@ -56,6 +57,35 @@ Slur::calc_direction (SCM smob)
   return scm_from_int (d);
 }
 
+MAKE_SCHEME_CALLBACK (Slur, pure_height, 3);
+SCM
+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);
+  Real height = robust_scm2double (me->get_property ("height-limit"), 2.0);
+
+  extract_grob_set (me, "note-columns", encompasses);
+  Interval ret;
+
+  Grob *parent = me->get_parent (Y_AXIS);
+  if (common_refpoint_of_array (encompasses, me, Y_AXIS) != parent)
+    /* this could happen if, for example, we are a cross-staff slur.
+       in this case, we want to be ignored */
+    return ly_interval2scm (Interval ());
+
+  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.widen (height * 0.5);
+  return ly_interval2scm (ret);
+}
+
 MAKE_SCHEME_CALLBACK (Slur, height, 1);
 SCM
 Slur::height (SCM smob)
@@ -135,7 +165,7 @@ Slur::get_curve (Grob *me)
 {
   Bezier b;
   int i = 0;
-  for (SCM s = me->get_property ("control-points"); s != SCM_EOL;
+  for (SCM s = me->get_property ("control-points"); scm_is_pair (s);
        s = scm_cdr (s))
     b.control_[i++] = ly_scm2offset (scm_car (s));
 
@@ -156,7 +186,7 @@ Slur::add_extra_encompass (Grob *me, Grob *n)
 }
 
 
-MAKE_SCHEME_CALLBACK (Slur, outside_slur_callback, 2);
+MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Slur, outside_slur_callback, 2, 1);
 SCM
 Slur::outside_slur_callback (SCM grob, SCM offset_scm)
 {
@@ -186,8 +216,8 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm)
   Interval yext = robust_relative_extent (script, cy, Y_AXIS);
   Interval xext = robust_relative_extent (script, cx, X_AXIS);
 
-  yext.translate (robust_scm2double (offset_scm, 0));
-  
+  Real offset = robust_scm2double (offset_scm, 0);
+  yext.translate (offset);
   
   /* FIXME: slur property, script property?  */
   Real slur_padding = robust_scm2double (script->get_property ("slur-padding"),
@@ -228,9 +258,48 @@ Slur::outside_slur_callback (SCM grob, SCM offset_scm)
       avoidance_offset = dir * (max (dir * avoidance_offset,
                                     dir * (ys[k] - yext[-dir] + dir * slur_padding)));
   
-  return scm_from_double (scm_to_double (offset_scm) + avoidance_offset);
+  return scm_from_double (offset + avoidance_offset);
 }
 
+/*
+ * Used by Slur_engraver:: and Phrasing_slur_engraver::
+ */
+void
+Slur::auxiliary_acknowledge_extra_object (Grob_info info,
+                                         vector<Grob*> &slurs,
+                                         vector<Grob*> &end_slurs)
+{
+  if (slurs.empty () && end_slurs.empty ())
+    return;
+  
+  Grob *e = info.grob ();
+  SCM avoid = e->get_property ("avoid-slur");
+  if (Tie::has_interface (e)
+      || avoid == ly_symbol2scm ("inside"))
+    {
+      for (vsize i = slurs.size (); i--;)
+       add_extra_encompass (slurs[i], e);
+      for (vsize i = end_slurs.size (); i--;)
+       add_extra_encompass (end_slurs[i], e);
+    }
+  else if (avoid == ly_symbol2scm ("outside")
+          || avoid == ly_symbol2scm ("around"))
+    {
+      Grob *slur;
+      if (end_slurs.size () && !slurs.size ())
+       slur = end_slurs[0];
+      else
+       slur = slurs[0];
+
+      if (slur)
+       {
+         chain_offset_callback (e, outside_slur_callback_proc, Y_AXIS);
+         e->set_object ("slur", slur->self_scm ());
+       }
+    }
+  else
+    e->warning ("Ignoring grob for slur. avoid-slur not set?");
+}
 
 
 ADD_INTERFACE (Slur, "slur-interface",
@@ -247,12 +316,13 @@ ADD_INTERFACE (Slur, "slur-interface",
               "eccentricity "
               "encompass-objects "
               "height-limit "
+              "inspect-quants "
+              "inspect-index "
               "line-thickness "
               "note-columns "
               "positions "
               "quant-score "
               "ratio "
               "thickness "
-
               );