]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-collision.cc
* lily/grob.cc: edit doc string.
[lilypond.git] / lily / note-collision.cc
index 01364cb838cff207228101158db8f718fbbf922e..0f51668c8a1e38ad0274b690873c96db49478944 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "warn.hh"
@@ -15,6 +15,8 @@
 #include "axis-group-interface.hh"
 #include "item.hh"
 #include "stem.hh"
+#include "side-position-interface.hh"
+#include "dot-column.hh"
 
 MAKE_SCHEME_CALLBACK (Note_collision_interface,force_shift_callback,2);
 
@@ -86,7 +88,8 @@ check_meshing_chords (Grob *me,
       && !to_boolean (me->get_grob_property ("merge-differently-headed")))
     merge_possible = false;
 
-  /* Can never merge quarter and half notes. */
+  /* Should never merge quarter and half notes, as this would make
+     them indistinguishable.  */
   if (merge_possible
       && ((Rhythmic_head::duration_log (nu) == 1
           && Rhythmic_head::duration_log (nd) == 2)
@@ -157,6 +160,9 @@ check_meshing_chords (Grob *me,
       }
   }
 
+  full_collide = full_collide || (close_half_collide
+                                 && distant_half_collide);
+  
   Drul_array<Real> center_note_shifts;
   center_note_shifts[LEFT] = 0.0;
   center_note_shifts[RIGHT] = 0.0;
@@ -164,18 +170,19 @@ check_meshing_chords (Grob *me,
   
   Real shift_amount = 1;
 
-  bool touch = (ups[0] - dps.top () >= 0);
+  bool touch = (ups[0] >= dps.top ());
   if (touch)
     shift_amount *= -1;
 
-  /*
-    for full collisions, the right hand head may obscure dots, so
-    make sure the dotted heads go to the right.
-   */
-  if ((Rhythmic_head::dot_count (nu) > Rhythmic_head::dot_count (nd)
-       && full_collide))
-    shift_amount = 1;
-
+  /* For full collisions, the right hand head may obscure dots, so
+     make sure the dotted heads go to the right.  */
+  bool stem_to_stem = false;
+  if (full_collide)
+    if (Rhythmic_head::dot_count (nu) > Rhythmic_head::dot_count (nd))
+      shift_amount = 1;
+    else if (Rhythmic_head::dot_count (nu) < Rhythmic_head::dot_count (nd))
+      stem_to_stem = true;
+  
   if (merge_possible)
     {
       shift_amount = 0;
@@ -197,7 +204,7 @@ check_meshing_chords (Grob *me,
       if (wipe_ball->live ())
        {
          wipe_ball->set_grob_property ("transparent", SCM_BOOL_T);
-         wipe_ball->set_grob_property ("molecule", SCM_EOL);
+         wipe_ball->set_grob_property ("stencil", SCM_EOL);
 
          if (Grob *d = unsmob_grob (wipe_ball->get_grob_property ("dot")))
            d->suicide ();
@@ -205,6 +212,8 @@ check_meshing_chords (Grob *me,
     }
   /* TODO: these numbers are magic; should devise a set of grob props
      to tune this behavior.  */
+  else if (stem_to_stem)
+    shift_amount *= -0.65; 
   else if (close_half_collide && !touch)
     shift_amount *= 0.52;
   else if (distant_half_collide && !touch)
@@ -218,6 +227,18 @@ check_meshing_chords (Grob *me,
   else
     shift_amount *= 0.25;
 
+  /* For full or close half collisions, the right hand head may
+     obscure dots.  Move dots to the right.  */
+  if (abs (shift_amount) > 1e-6
+      && Rhythmic_head::dot_count (nd) > Rhythmic_head::dot_count (nu)
+      && (full_collide || close_half_collide))
+    {
+      Grob *d = unsmob_grob (nd->get_grob_property ("dot"));
+      Grob *parent = d->get_parent (X_AXIS);
+      if (Dot_column::has_interface (parent))
+       Side_position_interface::add_support (parent, nu);
+    }
+
   Direction d = UP;
   do
     {
@@ -234,8 +255,6 @@ Note_collision_interface::do_shifts (Grob* me)
 
   SCM autos (automatic_shift (me, cg));
   SCM hand (forced_shift (me));
-
-  
   
   Direction d = UP;
   Real wid = 0.0;
@@ -244,12 +263,10 @@ Note_collision_interface::do_shifts (Grob* me)
       if(cg[d].size())
        {
          Grob  *h = cg[d][0];
-         wid = Note_column::first_head(h)->extent(h,X_AXIS).length() ;
+         wid = Note_column::first_head (h)->extent (h,X_AXIS).length() ;
        }
     }
-  
   while (flip (&d) != UP);
-
   
   Link_array<Grob> done;
   for (; gh_pair_p (hand); hand =ly_cdr (hand))
@@ -387,8 +404,9 @@ Note_collision_interface::automatic_shift (Grob *me,
   do
     {
       for (int i=0; i < clash_groups[d].size (); i++)
-       tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm (), gh_double2scm (offsets[d][i])),
-                                tups);
+       tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm (),
+                                gh_double2scm (offsets[d][i])),
+                       tups);
     }
   while (flip (&d) != UP);
   return tups;
@@ -425,8 +443,11 @@ Note_collision_interface::add_column (Grob*me,Grob* ncol)
 
 
 ADD_INTERFACE (Note_collision_interface, "note-collision-interface",
-  "An object that handles collisions between notes with different stem " 
-"directions and horizontal shifts. Most of the interesting properties "
-"are to be set in @ref{note-column-interface}: these are "
-"@code{force-hshift} and @code{horizontal-shift}. ",
-  "merge-differently-dotted merge-differently-headed positioning-done");
+              "An object that handles collisions between notes with different stem " 
+              "directions and horizontal shifts. Most of the interesting properties "
+              "are to be set in @ref{note-column-interface}: these are "
+              "@code{force-hshift} and @code{horizontal-shift}."
+
+              ,
+              
+              "merge-differently-dotted merge-differently-headed positioning-done");