]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-collision.cc
* lily/relocate.cc (setup_paths): only check path for non-absolute
[lilypond.git] / lily / note-collision.cc
index 333970b187aac2dce624d3043f88ef4f1dad1a6f..31c9d41cc369bacf3daaae472a2dfcbe00af3a05 100644 (file)
@@ -3,12 +3,11 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "note-collision.hh"
 
-#include <math.h>
 
 #include "warn.hh"
 #include "note-column.hh"
 #include "stem.hh"
 #include "side-position-interface.hh"
 #include "dot-column.hh"
+#include "pointer-group-interface.hh"
 
-MAKE_SCHEME_CALLBACK (Note_collision_interface, force_shift_callback, 2);
 
-SCM
-Note_collision_interface::force_shift_callback (SCM element_smob, SCM axis)
-{
-  Grob *me = unsmob_grob (element_smob);
-  Axis a = (Axis) scm_to_int (axis);
-  assert (a == X_AXIS);
-
-  me = me->get_parent (a);
-
-  if (! to_boolean (me->get_property ("positioning-done")))
-    {
-      me->set_property ("positioning-done", SCM_BOOL_T);
-      do_shifts (me);
-    }
-
-  return scm_make_real (0.0);
-}
 
 void
 check_meshing_chords (Grob *me,
@@ -71,8 +53,8 @@ check_meshing_chords (Grob *me,
   bool merge_possible = (ups[0] >= dps[0]) && (ups.top () >= dps.top ());
 
   /* Do not merge notes typeset in different style. */
-  if (!ly_c_equal_p (nu->get_property ("style"),
-                    nd->get_property ("style")))
+  if (!ly_is_equal (nu->get_property ("style"),
+                   nd->get_property ("style")))
     merge_possible = false;
 
   int upball_type = Note_head::get_balltype (nu);
@@ -94,6 +76,11 @@ check_meshing_chords (Grob *me,
       && !to_boolean (me->get_property ("merge-differently-headed")))
     merge_possible = false;
 
+  merge_possible = merge_possible &&
+    !(nu->get_property ("style") == ly_symbol2scm ("fa")
+      && nd->get_property ("style") == ly_symbol2scm ("fa"));
+  
+  
   /* Should never merge quarter and half notes, as this would make
      them indistinguishable.  */
   if (merge_possible
@@ -210,9 +197,7 @@ check_meshing_chords (Grob *me,
              wipe_ball = nu;
            }
          else
-           {
-             dot_wipe_head = nu;
-           }
+           dot_wipe_head = nu;
        }
       else if (dnball_type > upball_type)
        {
@@ -227,14 +212,13 @@ check_meshing_chords (Grob *me,
 
       if (dot_wipe_head)
        {
-         if (Grob *d = unsmob_grob (dot_wipe_head->get_property ("dot")))
+         if (Grob *d = unsmob_grob (dot_wipe_head->get_object ("dot")))
            d->suicide ();
        }
 
       if (wipe_ball && wipe_ball->is_live ())
        {
          wipe_ball->set_property ("transparent", SCM_BOOL_T);
-         wipe_ball->set_property ("stencil", SCM_EOL);
        }
     }
   /* TODO: these numbers are magic; should devise a set of grob props
@@ -260,7 +244,7 @@ check_meshing_chords (Grob *me,
       && Rhythmic_head::dot_count (nd) > Rhythmic_head::dot_count (nu)
       && (full_collide || close_half_collide))
     {
-      Grob *d = unsmob_grob (nd->get_property ("dot"));
+      Grob *d = unsmob_grob (nd->get_object ("dot"));
       Grob *parent = d->get_parent (X_AXIS);
 
       /*
@@ -287,15 +271,30 @@ check_meshing_chords (Grob *me,
   while ((flip (&d)) != UP);
 }
 
-void
-Note_collision_interface::do_shifts (Grob *me)
+
+MAKE_SCHEME_CALLBACK(Note_collision_interface, calc_positioning_done, 1) 
+SCM
+Note_collision_interface::calc_positioning_done (SCM smob)
 {
+  Grob *me = unsmob_grob (smob);  
   Drul_array<Link_array<Grob> > cg = get_clash_groups (me);
 
+  Direction d = UP;
+  do
+    {
+      for (int i = cg[d].size(); i--; )
+       {
+         /*
+           Trigger positioning
+          */
+         cg[d][i]->extent (me, X_AXIS);
+       }
+    }
+  while (flip (&d) != UP);
+
   SCM autos (automatic_shift (me, cg));
   SCM hand (forced_shift (me));
 
-  Direction d = UP;
   Real wid = 0.0;
   do
     {
@@ -336,22 +335,20 @@ Note_collision_interface::do_shifts (Grob *me)
     }
 
   for (int i = 0; i < amounts.size (); i++)
-    {
-      done[i]->translate_axis (amounts[i] - left_most, X_AXIS);
-    }
+    done[i]->translate_axis (amounts[i] - left_most, X_AXIS);
+
+  return SCM_BOOL_T;
 }
 
-Drul_array < Link_array<Grob>
-Note_collision_interface::get_clash_groups (Grob *me)
+Drul_array < Link_array<Grob> >
+Note_collision_interface::get_clash_groups (Grob *me)
 {
   Drul_array<Link_array<Grob> > clash_groups;
 
-  SCM s = me->get_property ("elements");
-  for (; scm_is_pair (s); s = scm_cdr (s))
+  extract_grob_set (me, "elements", elements);
+  for (int i = 0; i < elements.size (); i++)
     {
-      SCM car = scm_car (s);
-
-      Grob *se = unsmob_grob (car);
+      Grob *se = elements[i];
       if (Note_column::has_interface (se))
        clash_groups[Note_column::dir (se)].push (se);
     }
@@ -457,7 +454,7 @@ Note_collision_interface::automatic_shift (Grob *me,
     {
       for (int i = 0; i < clash_groups[d].size (); i++)
        tups = scm_cons (scm_cons (clash_groups[d][i]->self_scm (),
-                                  scm_make_real (offsets[d][i])),
+                                  scm_from_double (offsets[d][i])),
                         tups);
     }
   while (flip (&d) != UP);
@@ -470,10 +467,10 @@ Note_collision_interface::forced_shift (Grob *me)
 {
   SCM tups = SCM_EOL;
 
-  SCM s = me->get_property ("elements");
-  for (; scm_is_pair (s); s = scm_cdr (s))
+  extract_grob_set (me, "elements", elements);
+  for (int i = 0; i < elements.size (); i++)
     {
-      Grob *se = unsmob_grob (scm_car (s));
+      Grob *se = elements[i];
 
       SCM force = se->get_property ("force-hshift");
       if (scm_is_number (force))
@@ -488,9 +485,8 @@ Note_collision_interface::forced_shift (Grob *me)
 void
 Note_collision_interface::add_column (Grob *me, Grob *ncol)
 {
-  ncol->add_offset_callback (Note_collision_interface::force_shift_callback_proc, X_AXIS);
+  ncol->set_property ("X-offset", Grob::x_parent_positioning_proc);
   Axis_group_interface::add_element (me, ncol);
-  me->add_dependency (ncol);
 }
 
 ADD_INTERFACE (Note_collision_interface, "note-collision-interface",
@@ -499,4 +495,7 @@ ADD_INTERFACE (Note_collision_interface, "note-collision-interface",
               "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");
+              /* properties */
+              "merge-differently-dotted "
+              "merge-differently-headed "
+              "positioning-done");