]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/slur.cc
*** empty log message ***
[lilypond.git] / lily / slur.cc
index 7c0580e154520a7aaa8dddefa07f6789ce4ea68b..0f7c8790cf77bee935fa8488ce6b8bd9ba6de0a7 100644 (file)
@@ -87,7 +87,7 @@ Slur::print (SCM smob)
       String str;
       SCM properties = Font_interface::text_font_alist_chain (me);
 
-      Stencil tm = *unsmob_stencil (Text_item::interpret_markup
+      Stencil tm = *unsmob_stencil (Text_interface::interpret_markup
                                    (me->get_paper ()->self_scm (), properties,
                                     quant_score));
       a.add_at_edge (Y_AXIS, get_grob_direction (me), tm, 1.0, 0);
@@ -104,8 +104,8 @@ Slur::get_curve (Grob*me)
   Bezier b;
   int i = 0;
   for (SCM s = me->get_property ("control-points"); s != SCM_EOL;
-       s = ly_cdr (s))
-    b.control_[i++] = ly_scm2offset (ly_car (s));
+       s = scm_cdr (s))
+    b.control_[i++] = ly_scm2offset (scm_car (s));
 
   return b;
 }
@@ -151,32 +151,53 @@ Slur::outside_slur_callback (SCM grob, SCM axis)
   Interval xext = robust_relative_extent (script, cx, X_AXIS);
 
 
-  Real slur_padding = robust_scm2double (me->get_property ("padding"),
-                                        0.2);  // todo: slur property, script property?
+  Real slur_padding = robust_scm2double (script->get_property ("slur-padding"),
+                                        0.0);  // todo: slur property, script property?
   yext.widen (slur_padding);
+  Real EPS = 1e-3;
   
   Interval bezext (curve.control_[0][X_AXIS],
                   curve.control_[3][X_AXIS]);
 
-  Real x = xext.center ();
-  if (bezext.contains (x))
-    ;
-  else if (!bezext.contains (xext[RIGHT]))
-    x = xext[LEFT];
-  else if (!bezext.contains (xext[LEFT]))
-    x = xext[RIGHT];
+  bool consider[] = { false, false, false };
+  Real ys[] = {0, 0, 0};
+  int k = 0;
+  bool do_shift = false;
 
-  
-  if (!bezext.contains (x))
-    return scm_make_real (0);
-
-  Real y = curve.get_other_coordinate (X_AXIS, x);
-  if (yext.contains (y)) 
+  for (Direction d = LEFT ;  d <= RIGHT; d = Direction (d + 1))
     {
-      Direction dir = get_grob_direction (script); 
-      return scm_make_real (y - yext[-dir] + dir * slur_padding);
+      Real x = xext.linear_combination (d);
+      consider[k] = bezext.contains (x);
+
+      if (consider[k])
+       {
+         ys[k] =
+           (fabs(bezext[LEFT] - x) < EPS)
+           ? curve.control_[0][Y_AXIS]
+           : ((fabs(bezext[RIGHT] - x) < EPS)
+              ? curve.control_[3][Y_AXIS]
+              : curve.get_other_coordinate (X_AXIS, x));
+         consider[k] = true;
+
+         if (yext.contains (ys[k]))
+           do_shift = true;
+       }
     }
-  return scm_make_real (0.0);
+  Real offset = 0.0;
+  if (do_shift)
+    {
+      k = 0;
+      Direction dir = get_grob_direction (script);
+      for (Direction d = LEFT ;  d <= RIGHT; d = Direction (d + 1))
+       {
+         offset = 
+           dir * (dir * offset >? dir * (ys[k]
+                                         - yext[-dir] + dir * slur_padding));
+         k++;
+       }
+    }
+  
+  return scm_make_real (offset);
 }