From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Tue, 14 Sep 2004 22:29:54 +0000 (+0000)
Subject: (score_edges): add exp(slope*dir*leftright)
X-Git-Tag: release/2.3.17~32
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=694a96d90805c2361fe5f8bbb9aba90fd9ed42dd;p=lilypond.git

(score_edges): add exp(slope*dir*leftright)
factor in edge attraction. This reflects that the left edge may
have a larger gap for an ascending up-slur.
---

diff --git a/ChangeLog b/ChangeLog
index e6bb67ec28..4b464ba74c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-09-15  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+	* lily/slur-scoring.cc (score_edges): add exp(slope*dir*leftright)
+	factor in edge attraction. This reflects that the left edge may
+	have a larger gap for an ascending up-slur.
+
 2004-09-14  Jan Nieuwenhuizen  <janneke@gnu.org>
 
 	* buildscripts/guile-gnome.sh: Update with tarball [pre]releases.
@@ -12,6 +18,8 @@
 
 2004-09-13  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+	* lily/slur-scoring.cc (score_edges): don't be so picky for
+
 	* ly/property-init.ly (hideStaffSwitch): remove turnOff.
 
 	* scripts/convert-ly.py (conv): change Both to Neutral in property
diff --git a/input/regression/new-slur.ly b/input/regression/new-slur.ly
index 2908984fcf..0127e66fdf 100644
--- a/input/regression/new-slur.ly
+++ b/input/regression/new-slur.ly
@@ -57,9 +57,11 @@
     \clef bass a=8[ e16(f] g[ a bes d,)]  s4 | \break
     
     \clef treble
-    \relative c'' {
+    \new Voice \relative c'' {
 	\slurDown f2( d4 f | g c a f | d c f2 | f1) |
     }
 
+%    \override Slur #'excentricity = #-2
+    c=''8 ( d[ b f d] a'[ c])
 }
 
diff --git a/input/regression/spacing-clef-first-note.ly b/input/regression/spacing-clef-first-note.ly
index 71928b6184..fe19a6362f 100644
--- a/input/regression/spacing-clef-first-note.ly
+++ b/input/regression/spacing-clef-first-note.ly
@@ -6,20 +6,23 @@ than clef changes halfway the line."
 
 }
 
-\score  {  {
-    << \new Staff {
-	c'2
-	\clef bass e16 f a
-	\clef treble b
+\score  {  
+    <<
+	\new Staff {
+	    c'2
+	    \clef bass e16 f a
+	    \clef treble b
+	}
+	\new Staff  {
+	    c'4 c'4 c'4 
+	}
+    >>
+    \paper {
+	raggedright = ##t
+	\context {
+	    \Staff
+	    \remove Time_signature_engraver
 	}
-      \new Staff  {
-	  c'4 c'4 c'4 
-      }>>
     }
-    \paper { raggedright = ##t
-\context { \Staff
-	      TimeSignature = \turnOff
-	 }
-
-     }}
+}
 
diff --git a/lily/slur-scoring.cc b/lily/slur-scoring.cc
index 3cef50cb1a..bb7904e9c3 100644
--- a/lily/slur-scoring.cc
+++ b/lily/slur-scoring.cc
@@ -83,7 +83,7 @@ struct Slur_score_parameters
   Real free_slur_distance_;
   Real free_head_distance_;
   Real extra_encompass_free_distance_;
-
+  Real edge_slope_exponent_;  
   Real head_slur_distance_max_ratio_;
   Real head_slur_distance_factor_;
 
@@ -125,7 +125,7 @@ struct Bound_info
   Interval slur_head_extent_;
   Real neighbor_y_;
   Real staff_space_;
-
+  
   Bound_info ()
   {
     stem_ = 0;
@@ -250,6 +250,8 @@ init_score_param (Grob *me,
     = get_detail (details, ly_symbol2scm ("head-slur-distance-max-ratio"));
   score_param->free_slur_distance_
     = get_detail (details, ly_symbol2scm ("free-slur-distance"));
+  score_param->edge_slope_exponent_
+    = get_detail (details, ly_symbol2scm ("edge-slope-exponent"));
 }
 
 
@@ -928,13 +930,18 @@ score_encompass (Grob *me, Grob *common[],
 						configuration.attachment_[RIGHT][Y_AXIS],
 						configuration.attachment_[LEFT][Y_AXIS]);
 
-	      if (dir * (infos[j].get_point (dir) - line_y) > 0)
+	      if ( 1 ) // dir * infos[j].get_point (dir) > dir *line_y )
 		{
-		  Real d = fabs (infos[j].get_point (dir) - y);
+		  
+		  Real closest =
+		    dir * (dir * infos[j].get_point (dir)
+			   >? dir *line_y
+			   );
+		  Real d = fabs(closest - y);
+	      
 		  convex_head_distances.push (d);
-		}	      
+		}
 	    }
-
 	  
 	
 
@@ -981,11 +988,13 @@ score_encompass (Grob *me, Grob *common[],
 	  int n =  convex_head_distances.size();
 	  if (convex_head_distances.size() <= 2)
 	    {
+	      //	      Real min_edge_dist = 1e6;
 	      for (int j = 0; j < edge_distances.size(); j++)
 		{
 		  avg_distance += edge_distances[j];
 		  n++;
 		}
+
 	    }
 
 	  /*
@@ -1185,6 +1194,10 @@ score_extra_encompass (Grob *me, Grob *common[],
     }
 }
 
+/*
+  TODO: should make edge penalties dependent on the direction that the
+  slur-end is pointing.
+ */
 void
 score_edges (Grob *me, Grob *common[],
 	     Slur_score_parameters * score_param,
@@ -1198,9 +1211,12 @@ score_edges (Grob *me, Grob *common[],
   for (int i = 0; i < scores->size (); i++)
     {
       Direction d = LEFT;
+      Slur_score &config = scores->elem_ref (i);
+      Offset dz = config.attachment_[RIGHT] - config.attachment_[LEFT];
+      Real slope = dz[Y_AXIS] / dz[X_AXIS];
       do
 	{
-	  Real y = scores->elem (i).attachment_[d][Y_AXIS];
+	  Real y = config.attachment_[d][Y_AXIS];
 	  Real dy = fabs (y - base_attach[d][Y_AXIS]);
 	
 	  Real factor = score_param->edge_attraction_factor_;
@@ -1210,7 +1226,10 @@ score_edges (Grob *me, Grob *common[],
 	      && !Stem::get_beaming (extremes[d].stem_, -d)
 	      )
 	    demerit /= 5;
-	
+
+	  demerit *= exp (dir * d * slope
+			  * score_param->edge_slope_exponent_ );
+	  
 	  (*scores)[i].score_ += demerit;
 #if DEBUG_SLUR_QUANTING
 	  (*scores)[i].score_card_ += to_string ("E%.2f", demerit);
diff --git a/scm/script.scm b/scm/script.scm
index d08c26a4e2..0165f27c90 100644
--- a/scm/script.scm
+++ b/scm/script.scm
@@ -9,7 +9,7 @@
        '(("thumb" .
 	  ((script-stencil . (feta . ("thumb"  . "thumb")))
 	   (direction . 1)))
-	 ("accent" .
+         ("accent" .
 	  ((inside-slur . #f)
 	   (follow-into-staff . #t)
 	   (script-stencil . (feta . ("sforzato" .  "sforzato")))
diff --git a/scm/slur.scm b/scm/slur.scm
index 0213fdf738..5b1e9c1028 100644
--- a/scm/slur.scm
+++ b/scm/slur.scm
@@ -25,4 +25,5 @@
     (extra-encompass-free-distance . 0.3)
     (head-slur-distance-max-ratio . 3)
     (head-slur-distance-factor . 10)
+    (edge-slope-exponent . 2)
     ))