From f138810fbff8abc2da1d96518b1fd7706291fc8b Mon Sep 17 00:00:00 2001
From: hanwen <hanwen>
Date: Tue, 21 May 2002 21:58:59 +0000
Subject: [PATCH] scripts on 2nds

---
 ChangeLog                            |  6 ++++++
 input/bugs/bizarre-beam.ly           |  9 +++++++-
 input/regression/script-collision.ly | 16 ++++++++++++++
 lily/script-column.cc                |  1 -
 lily/script-engraver.cc              | 31 ++++++++++++++++++++++------
 lily/script.cc                       | 17 ++++++++++++---
 6 files changed, 69 insertions(+), 11 deletions(-)
 create mode 100644 input/regression/script-collision.ly

diff --git a/ChangeLog b/ChangeLog
index fc50fac890..b4746929db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-05-22  Han-Wen  <hanwen@cs.uu.nl>
+
+	* lily/script.cc (before_line_breaking): postpone setting the
+	X-parent of vertical scripts. This fixes the case of scripts on
+	chords with seconds 
+
 2002-05-21  Han-Wen  <hanwen@cs.uu.nl>
 
 	* scm/grob-description.scm:  fix alignment of barnumber: make sure
diff --git a/input/bugs/bizarre-beam.ly b/input/bugs/bizarre-beam.ly
index 2a8ecf7465..166376e7b8 100644
--- a/input/bugs/bizarre-beam.ly
+++ b/input/bugs/bizarre-beam.ly
@@ -1,3 +1,10 @@
 
 
-\score{ \notes {[g'' <e'''8 g> g''] }}
+\score{ \notes {g''4 [<e'''8 g> g'']
+\notes\relative c'{
+   \times 2/3{[d16 fis' d,]} \times 2/3{[cis g'' cis,,]}
+  a'16 cis a, g''' % Used to give a nice beam directed upwards.
+  <{\stemUp a,,4:32} \context Voice=lower{\stemDown d,:32}>
+
+}
+	    }}
diff --git a/input/regression/script-collision.ly b/input/regression/script-collision.ly
new file mode 100644
index 0000000000..78645f915c
--- /dev/null
+++ b/input/regression/script-collision.ly
@@ -0,0 +1,16 @@
+
+\header {
+
+    texidoc = "Scripts are put on the utmost head, so they are
+      positioned correctly when there are collisions."
+}
+
+\score  {
+\notes \relative c'' {
+  c4
+  <c d c'-\marcato>
+  < \context Voice = VA { \voiceOne c4^^ }
+    \context Voice = VB { \voiceTwo d4_^} >
+    }
+\paper { linewidth = -1. }
+    }
diff --git a/lily/script-column.cc b/lily/script-column.cc
index 59e28471c7..33aacb3e5e 100644
--- a/lily/script-column.cc
+++ b/lily/script-column.cc
@@ -43,7 +43,6 @@ Script_column::before_line_breaking (SCM smob)
   Link_array<Grob> staff_sided 
     = Pointer_group_interface__extract_grobs (me, (Grob*)0, "scripts");
 				     
-				     
   for (int i=0; i < staff_sided.size (); i++)
     {
       Direction d = Side_position_interface::get_direction (staff_sided[i]);
diff --git a/lily/script-engraver.cc b/lily/script-engraver.cc
index 0466630e3a..10cbfe9d93 100644
--- a/lily/script-engraver.cc
+++ b/lily/script-engraver.cc
@@ -10,6 +10,7 @@
 #include "stem.hh"
 #include "rhythmic-head.hh"
 #include "engraver.hh"
+#include "note-column.hh"
 
 class Script_engraver : public Engraver
 {
@@ -132,10 +133,6 @@ Script_engraver::acknowledge_grob (Grob_info inf)
 	{
 	  Grob *e = script_p_arr_[i];
 	  
-	  if (!e->get_parent (X_AXIS))
-	    {
-	      e->set_parent (inf.grob_l_, X_AXIS);
-	    }
 	  if (Side_position_interface::get_axis (e) == X_AXIS
 	      && !e->get_parent (Y_AXIS))
 	    {
@@ -144,7 +141,29 @@ Script_engraver::acknowledge_grob (Grob_info inf)
 	    }
 	  Side_position_interface::add_support (e,inf.grob_l_);
 	}
-    }  
+    }
+  else if (Note_column::has_interface (inf.grob_l_))
+    {
+
+      /*
+	We make note column the parent of the script. That's not
+	correct, but due to seconds in a chord, noteheads may be
+	swapped around horizontally. We don't know which note head to
+	put it on, so we postpone this decision to
+	Script_interface::before_line_breaking ().
+ 
+       */
+      for (int i=0; i < script_p_arr_.size (); i++)
+	{
+	  Grob *e = script_p_arr_[i];
+	  
+	  if (!e->get_parent (X_AXIS) &&
+	      Side_position_interface::get_axis (e) == Y_AXIS)
+	    {
+	      e->set_parent (inf.grob_l_, X_AXIS);
+	    }
+	}
+    }
 }
 
 void
@@ -180,6 +199,6 @@ ENTER_DESCRIPTION(Script_engraver,
 /* descr */       "    Handles note ornaments generated by @code{\\script}.  
 ",
 /* creats*/       "Script",
-/* acks  */       "stem-interface rhythmic-head-interface",
+/* acks  */       "stem-interface rhythmic-head-interface note-column-interface",
 /* reads */       "scriptDefinitions scriptHorizontal",
 /* write */       "");
diff --git a/lily/script.cc b/lily/script.cc
index 50946ff65d..7483b07a79 100644
--- a/lily/script.cc
+++ b/lily/script.cc
@@ -15,6 +15,8 @@
 #include "item.hh"
 #include "molecule.hh"
 #include "lookup.hh"
+#include "stem.hh"
+#include "note-column.hh"
 
 Molecule
 Script_interface::get_molecule (Grob * me, Direction d)
@@ -48,15 +50,24 @@ Script_interface::before_line_breaking (SCM smob)
 
   if (!d)
     {
-  /*
-    we should not have `arbitrary' directions. 
-   */
+      /*
+	we should not have `arbitrary' directions. 
+      */
       programming_error ("Script direction not yet known!");
       d = DOWN;
     }
   
   Side_position_interface::set_direction (me,d);
 
+  if (Grob * par = me->get_parent (X_AXIS))
+    {
+      Grob * stem = Note_column::stem_l (par);
+      if (stem && Stem::first_head (stem))
+	{
+	  me->set_parent (Stem::first_head (stem), X_AXIS);
+	}
+    }
+  
   return SCM_UNSPECIFIED;
 }
 
-- 
2.39.5