From 7f9d755e4c19f5603e1e9b608c1bfff1eda5ab16 Mon Sep 17 00:00:00 2001
From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Sat, 12 Oct 2002 21:42:45 +0000
Subject: [PATCH] * input/regression/spacing-to-grace.ly: new file.

* input/regression/spacing-end-of-line.ly: new file.

* lily/note-spacing.cc (get_spacing): take into account breakable
stuff sticking out at the left (time sig change at line break).

* lily/spacing-spanner.cc (breakable_column_spacing): junk weird
raggedright code.

* scm/music-functions.scm (make-voice-props-set): add
staff-position for mm rests.

* lily/spacing-spanner.cc (musical_column_spacing): shrink space
before grace notes a little.
---
 ChangeLog                               | 16 ++++++
 input/regression/spacing-end-of-line.ly | 16 ++++++
 input/regression/spacing-to-grace.ly    | 19 +++++++
 lily/note-spacing.cc                    | 69 +++++++++++++++----------
 lily/spacing-spanner.cc                 | 59 +++++++++++++++------
 lily/staff-spacing.cc                   | 13 +++--
 ly/grace-init.ly                        |  2 +-
 scm/music-functions.scm                 |  8 ++-
 8 files changed, 152 insertions(+), 50 deletions(-)
 create mode 100644 input/regression/spacing-end-of-line.ly
 create mode 100644 input/regression/spacing-to-grace.ly

diff --git a/ChangeLog b/ChangeLog
index 43ce953973..00d3f72e80 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2002-10-12  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+	* input/regression/spacing-to-grace.ly: new file.
+
+	* input/regression/spacing-end-of-line.ly: new file.
+
+	* lily/note-spacing.cc (get_spacing): take into account breakable
+	stuff sticking out at the left (time sig change at line break).
+
+	* lily/spacing-spanner.cc (breakable_column_spacing): junk weird
+	raggedright code.
+
+	* scm/music-functions.scm (make-voice-props-set): add
+	staff-position for mm rests.
+ 
+	* lily/spacing-spanner.cc (musical_column_spacing): shrink space
+	before grace notes a little.
+
 	* lily/parser.yy (sup_quotes): use '\'' for sup_quotes.
 
 	* lily/break-align-interface.cc (do_alignment): right-edge spacing
diff --git a/input/regression/spacing-end-of-line.ly b/input/regression/spacing-end-of-line.ly
new file mode 100644
index 0000000000..5b5f7650fa
--- /dev/null
+++ b/input/regression/spacing-end-of-line.ly
@@ -0,0 +1,16 @@
+\header {
+    
+    texidoc ="Broken matter at the end of line does not upset the
+    space following rests and notes."  }
+
+\score
+{
+\notes \relative c' {
+    c2.. r8
+    c2.. r8
+    \time 3/4 \break
+    e2 e4 | e2 e4 \time 4/4 \break
+}
+\paper {
+    raggedright = ##t }  
+}
diff --git a/input/regression/spacing-to-grace.ly b/input/regression/spacing-to-grace.ly
new file mode 100644
index 0000000000..c6106d4125
--- /dev/null
+++ b/input/regression/spacing-to-grace.ly
@@ -0,0 +1,19 @@
+\header {
+
+    texidoc ="space from a normal note /barline to a grace note is
+    smaller than to a normal note."
+    
+}
+
+\score {
+    \context Voice \notes
+    { \time 2/4
+      \relative c'' {
+	  e8 e \grace d8 e e \grace f8 e es, d' d
+	  e8 e e e \grace { \stemDown f8 \stemBoth } e es, d'
+
+		  }  
+
+    }
+    \paper { linewidth =  -1.0 }
+    }
diff --git a/lily/note-spacing.cc b/lily/note-spacing.cc
index 7964a2966e..9c4c236c63 100644
--- a/lily/note-spacing.cc
+++ b/lily/note-spacing.cc
@@ -108,9 +108,20 @@ Note_spacing::get_spacing (Grob *me, Item* right_col,
   *space = (base_space - increment) + *fixed +
     (extents[LEFT][RIGHT]
      - (left_head_wid.empty_b () ? 0.0 : left_head_wid[RIGHT]))/ 2;
-    ;
 
-  if (*space - *fixed < 2 * ((- extents[RIGHT][LEFT]) >? 0))
+  if (Item::breakable_b (right_col)
+      || right_col->original_)
+    {
+      /*
+	This is for the situation
+
+	rest | 3/4 (eol)
+	
+       */
+      *space += -extents[RIGHT][LEFT];
+      *fixed += -extents[RIGHT][LEFT];
+    }
+  else if (*space - *fixed < 2 * ((- extents[RIGHT][LEFT]) >? 0))
     {
       /*
     
@@ -216,14 +227,13 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 			me->get_grob_property ("right-items"));
 
   Drul_array<Grob*> beams_drul(0,0);
-  Real correction = 0.0;
   
   stem_dirs[LEFT] = stem_dirs[RIGHT] = CENTER;
   Interval intersect;
   Interval bar_xextent;
   Interval bar_yextent;  
   
-  bool correct = true;
+  bool correct_stem_dirs = true;
   Direction d = LEFT;
   bool acc_right = false;
   
@@ -260,7 +270,8 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 	  
 	  if(Stem::invisible_b (stem))
 	    {
-	      return ;
+	      correct_stem_dirs = false;
+	      continue;
 	    }
 
 	  beams_drul[d] = Stem::get_beam (stem);
@@ -269,7 +280,8 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 	  Direction sd = Stem::get_direction (stem);
 	  if (stem_dirs[d] && stem_dirs[d] != sd)
 	    {
-	      return ; 
+	      correct_stem_dirs = false;
+	      continue;
 	    }
 	  stem_dirs[d] = sd;
 
@@ -280,8 +292,7 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 	  if (d == LEFT
 	      && Stem::duration_log (stem) > 2  && !Stem::get_beam (stem))
 	    {
-
-	      return;
+	      correct_stem_dirs = false;
 	    }
 	  
 
@@ -299,18 +310,19 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 
   /*
     don't correct if accidentals are sticking out of the right side.
-
   */
   if (acc_right)
     return ;
 
+  Real correction = 0.0;
+
   if (!bar_yextent.empty_b())
     {
       stem_dirs[RIGHT] = - stem_dirs[LEFT];
       stem_posns[RIGHT] = bar_yextent;
     }
   
-  if (correct &&stem_dirs[LEFT] *stem_dirs[RIGHT] == -1)
+  if (correct_stem_dirs && stem_dirs[LEFT] *stem_dirs[RIGHT] == -1)
     {
       if (beams_drul[LEFT] && beams_drul[LEFT] == beams_drul[RIGHT])
 	{
@@ -326,28 +338,29 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
 	{
 	  intersect = stem_posns[LEFT];  
 	  intersect.intersect(stem_posns[RIGHT]);
-	  correct = correct && !intersect.empty_b ();
+	  correct_stem_dirs = correct_stem_dirs && !intersect.empty_b ();
 
-	  if (!correct)
-	    return;
-	  
-	  correction = abs (intersect.length ());	  
+	  if (correct_stem_dirs)
+	    {
+	      correction =abs (intersect.length ());
 
       
-	  /*
-	    Ugh. 7 is hardcoded.
-	  */
-	  correction = (correction/7) <? 1.0;
-	  correction *= stem_dirs[LEFT] ;
-	  correction *= gh_scm2double (me->get_grob_property ("stem-spacing-correction"));
-
+	      /*
+		Ugh. 7 is hardcoded.
+	      */
+	      correction = (correction/7) <? 1.0;
+	      correction *= stem_dirs[LEFT] ;
+	      correction *=
+		gh_scm2double (me->get_grob_property ("stem-spacing-correction"));
+	    }
+	  
 	  if (!bar_yextent.empty_b())
 	    {
 	      correction *= 0.5;
 	    }
 	}
     }
-  else if (correct && stem_dirs[LEFT] *stem_dirs[RIGHT] == UP)
+  else if (correct_stem_dirs && stem_dirs[LEFT] *stem_dirs[RIGHT] == UP)
     {
       /*
 	Correct for the following situation:
@@ -384,10 +397,14 @@ Note_spacing::stem_dir_correction (Grob*me, Item * rcolumn,
       correction=  -lowest * corr ;
     }
 
-  if (!bar_xextent.empty_b())
-    correction += - bar_xextent[LEFT];
-
   *space += correction;
+
+#if 0
+  /* there used to be a correction for bar_xextent() here, but
+     it's unclear what that was good for ?
+  */
+#endif
+
 }
  
 
diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc
index 4cd183f9e4..2add89b86b 100644
--- a/lily/spacing-spanner.cc
+++ b/lily/spacing-spanner.cc
@@ -586,6 +586,15 @@ Spacing_spanner::musical_column_spacing (Grob *me, Item * lc, Item *rc, Real inc
 	}
     }
 
+  if (Paper_column::when_mom (rc).grace_part_ &&
+      !Paper_column::when_mom (lc).grace_part_)
+    {
+      /*
+	Ugh. 0.8 is arbitrary.
+       */
+      max_note_space *= 0.8; 
+    }
+  
   if (max_note_space < 0)
     {
       max_note_space = base_note_space;
@@ -602,6 +611,8 @@ Spacing_spanner::musical_column_spacing (Grob *me, Item * lc, Item *rc, Real inc
     Maybe it should be continuous?
   */
   max_fixed_note_space = max_fixed_note_space <?  max_note_space;
+
+
 #if 0
   /*
     This doesn't make sense. For ragged right we want to have the same
@@ -707,7 +718,17 @@ Spacing_spanner::breakable_column_spacing (Grob*me, Item* l, Item *r,Moment shor
       assert (spacing_grob-> get_column () == l);
 
       Staff_spacing::get_spacing_params (spacing_grob,
-					 &space, &fixed_space);  
+					 &space, &fixed_space);
+
+      if (Paper_column::when_mom (r).grace_part_)
+	{
+	  /*
+	    Correct for grace notes.
+
+	    Ugh. The 0.8 is arbitrary.
+	   */
+	  space *= 0.8;
+	}
       if (space > max_space)
 	{
 	  max_space = space;
@@ -748,10 +769,16 @@ Spacing_spanner::breakable_column_spacing (Grob*me, Item* l, Item *r,Moment shor
     Hmm.  we do 1/0 in the next thing. Perhaps we should check if this
     works on all architectures.
    */
-  
-  bool ragged = to_boolean (me->get_paper ()->get_scmvar ("raggedright"));
-  Real strength = (ragged) ? 1.0 : 1 / (max_space - max_fixed);
-  Real distance = (ragged) ? max_fixed : max_space;
+
+  /*
+    There used to be code that changed spacing depending on
+    raggedright setting.  Ugh.
+
+    Do it more cleanly, or rename the property. 
+    
+   */
+  Real strength = 1 / (max_space - max_fixed);
+  Real distance =  max_space;
   Spaceable_grob::add_spring (l, r, distance, strength, false);
 }
 
@@ -863,18 +890,16 @@ Spacing_spanner::note_spacing (Grob*me, Grob *lc, Grob *rc,
 
 
 ADD_INTERFACE (Spacing_spanner,"spacing-spanner-interface",
-  "
-The space taken by a note is dependent on its duration. Doubling a
-duration adds spacing-increment to the space. The most common shortest
-note gets shortest-duration-space. Notes that are even shorter are
-spaced proportonial to their duration.
-
-Typically, the increment is the width of a black note head.  In a
-piece with lots of 8th notes, and some 16th notes, the eighth note
-gets 2 note heads width (i.e. the space following a note is 1 note
-head width) A 16th note is followed by 0.5 note head width. The
-quarter note is followed by  3 NHW, the half by 4 NHW, etc.
-",
+"The space taken by a note is dependent on its duration. Doubling a\n"
+"duration adds spacing-increment to the space. The most common shortest\n"
+"note gets shortest-duration-space. Notes that are even shorter are\n"
+"spaced proportonial to their duration.\n"
+"\n"
+"Typically, the increment is the width of a black note head.  In a\n"
+"piece with lots of 8th notes, and some 16th notes, the eighth note\n"
+"gets 2 note heads width (i.e. the space following a note is 1 note\n"
+"head width) A 16th note is followed by 0.5 note head width. The\n"
+"quarter note is followed by  3 NHW, the half by 4 NHW, etc.\n",
   "grace-space-factor spacing-increment base-shortest-duration shortest-duration-space common-shortest-duration");
 
 
diff --git a/lily/staff-spacing.cc b/lily/staff-spacing.cc
index 33d2a037f8..b6102d660c 100644
--- a/lily/staff-spacing.cc
+++ b/lily/staff-spacing.cc
@@ -126,16 +126,19 @@ Staff_spacing::next_notes_correction (Grob *me, Grob * last_grob)
 {
   Interval bar_size = bar_y_positions (last_grob);
   Real max_corr =0.0;
+
   for (SCM s = me->get_grob_property ("right-items");
        gh_pair_p (s);  s = gh_cdr (s))
     {
       Grob * g = unsmob_grob (gh_car (s));
+
       max_corr = max_corr >?  next_note_correction (me, g,  bar_size);
       for (SCM t = g->get_grob_property ("elements");
 	   gh_pair_p (t); t  = gh_cdr (t))
 	max_corr = max_corr >? next_note_correction (me, unsmob_grob (gh_car (t)), bar_size);
       
     }
+  
   return max_corr;
 }
 
@@ -145,9 +148,9 @@ Staff_spacing::next_notes_correction (Grob *me, Grob * last_grob)
 */
 Grob*
 Staff_spacing::extremal_break_aligned_grob (Grob *separation_item, Direction d,
-				   Interval * last_ext)
+					    Interval * last_ext)
 {
-  Grob *left_col = dynamic_cast<Item*> (separation_item)->get_column ();
+  Grob *col = dynamic_cast<Item*> (separation_item)->get_column ();
   last_ext->set_empty ();
   Grob *last_grob = 0;
   for (SCM s = separation_item->get_grob_property ("elements");
@@ -158,7 +161,7 @@ Staff_spacing::extremal_break_aligned_grob (Grob *separation_item, Direction d,
       if (!gh_symbol_p (break_item->get_grob_property ("break-align-symbol")))
 	continue;
 
-      Interval ext = break_item->extent (left_col, X_AXIS);
+      Interval ext = break_item->extent (col, X_AXIS);
 
       if (ext.empty_b ())
 	continue;
@@ -231,7 +234,8 @@ Staff_spacing::get_spacing_params (Grob *me, Real * space, Real * fixed)
       if (gh_pair_p (nndef ))
 	space_def = nndef;
     }
-
+  
+  
   if (!gh_pair_p (space_def))
     {
       programming_error ("Unknown prefatory spacing. "); 
@@ -248,7 +252,6 @@ Staff_spacing::get_spacing_params (Grob *me, Real * space, Real * fixed)
   else if (type == ly_symbol2scm("minimum-space"))
     *space = last_ext[LEFT] + (last_ext.length () >? distance);
 
-
   *space += next_notes_correction (me, last_grob);
 }
 
diff --git a/ly/grace-init.ly b/ly/grace-init.ly
index e357e50242..ac54002b05 100644
--- a/ly/grace-init.ly
+++ b/ly/grace-init.ly
@@ -15,7 +15,7 @@ startGraceMusic = {
     \property Voice.Stem \override #'no-stem-extend = ##t
     \property Voice.Stem \override #'stroke-style  = #"grace"
     \property Voice.Beam \override #'thickness = #0.384
-
+    
     %% Instead of calling Beam::space_function, we should invoke
     %% the previously active beam function...
     \property Voice.Beam \override #'space-function =
diff --git a/scm/music-functions.scm b/scm/music-functions.scm
index 3469888450..eb536e3750 100644
--- a/scm/music-functions.scm
+++ b/scm/music-functions.scm
@@ -157,7 +157,13 @@ this is not an override
       (map (lambda (x) (make-grob-property-set x 'direction
 					       (if (odd? n) -1 1)))
 	   '(Tie Slur Stem Dots))
-      (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
+      (list
+       (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2))
+       (make-grob-property-set 'MultiMeasureRest 'staff-position
+			       (if (odd? n) -4 4)
+			       )
+       
+       )
    )
   ))
 
-- 
2.39.5