]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/accidental-placement.cc
2003 -> 2004
[lilypond.git] / lily / accidental-placement.cc
index db4d5cb4389712983886033be675d7210b1ea4a0..10ebcbc66d9500ab11fd72fe4ecbb748f42d9bbf 100644 (file)
@@ -3,7 +3,7 @@ accidental-placement.cc --  implement Accidental_placement
 
 source file of the GNU LilyPond music typesetter
 
-(c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+(c) 2002--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
  */
 
@@ -27,9 +27,9 @@ Accidental_placement::alignment_callback(SCM s, SCM )
   Grob * me =unsmob_grob (s);
 
   Grob * par = me->get_parent (X_AXIS);
-  if (!to_boolean (par->get_grob_property ("alignment-done")))
+  if (!to_boolean (par->get_grob_property ("positioning-done")))
     {
-      par->set_grob_property ("alignment-done", SCM_BOOL_T);
+      par->set_grob_property ("positioning-done", SCM_BOOL_T);
       position_accidentals (par);
     }
 
@@ -119,9 +119,9 @@ Accidental_placement::get_relevant_accidental_extent (Grob *me,
       extent.unite (which->elem(i)->extent (item_col, X_AXIS));
     }
 
-  if (!extent.empty_b())
+  if (!extent.is_empty ())
     {
-      Real p = gh_scm2double (me->get_grob_property ("left-padding"));
+      Real p = robust_scm2double (me->get_grob_property ("left-padding"), 0.2);
       extent[LEFT] -= p;
     }
   
@@ -234,6 +234,18 @@ stagger_apes (Link_array<Accidental_placement_entry> *apes)
 
 */
 
+/*
+  TODO: there should be more space in the following situation
+
+
+    Natural + downstem
+
+    |_       
+    | |    X
+    |_|   | 
+      |   |
+      
+ */
 SCM
 Accidental_placement::position_accidentals (Grob * me)
 {
@@ -244,7 +256,7 @@ Accidental_placement::position_accidentals (Grob * me)
 
   /*
     TODO: there is a bug in this code. If two accs are on the same
-    Y-position, they share an Ape, and will be pritned in overstrike.
+    Y-position, they share an Ape, and will be printed in overstrike.
    */
   Link_array<Accidental_placement_entry> apes;
   for (SCM s = accs; gh_pair_p (s); s =gh_cdr (s))
@@ -368,53 +380,32 @@ Accidental_placement::position_accidentals (Grob * me)
   head_ape-> left_skyline_ = head_skyline;
   head_ape->offset_ = 0.0;
 
-  SCM rs = me->get_grob_property ("right-padding");
-  if (gh_number_p (rs))
-    head_ape->offset_ -= gh_scm2double (rs);
+  head_ape->offset_ -= robust_scm2double ( me->get_grob_property ("right-padding"), 0);
 
   
-  Real padding = 0.2;
-  SCM spad = me->get_grob_property ("padding");
-  if (gh_number_p (spad))
-    padding = gh_scm2double (spad);
-
+  Real padding = robust_scm2double (me->get_grob_property ("padding"),0.2);
 
+  Array<Skyline_entry> left_skyline = head_ape->left_skyline_;
   /*
-    TODO:
-
-    There is a bug in this code: the left_skylines should be
-    accumulated, otherwise the b will collide with bb in
-
-      bb
-    b 
-      n 
-    
+    Add accs entries right-to-left.
    */
-  apes.push (head_ape);
-  for (int i= apes.size () -1 ; i-- > 0;)
+  for (int i= apes.size (); i-- > 0;)
     {
-      Accidental_placement_entry *ape = apes[i];
-      Real d = 0.0;
-      int j = i+1;
-      do {
-       d = - skyline_meshing_distance (ape->right_skyline_,
-                                       apes[j]->left_skyline_);
-
-       if (!isinf(d)
-           || j + 1 == apes.size())
-         break;
-       
-       j = j+ 1;
-      } while (1);
-
-      if (isinf(d))
-       d = 0.0;
-      
-      d -= padding;
-      ape->offset_ += apes[j]->offset_ + d;
-    }
+      Real offset =
+       -skyline_meshing_distance (apes[i]->right_skyline_, left_skyline);
+      if (isinf (offset))
+       offset = (i < apes.size () - 1) ? apes[i+1]->offset_ : 0.0;
+      else
+       offset -= padding;
+
+      apes[i]->offset_ = offset;
+
+      Array<Skyline_entry> new_left_skyline = apes[i]->left_skyline_;
+      heighten_skyline (&new_left_skyline, apes[i]->offset_);
+      merge_skyline (&new_left_skyline, left_skyline, LEFT);
+      left_skyline = new_left_skyline;
+    }      
 
-  apes.pop();
   for (int i = apes.size(); i--;)
     {
       Accidental_placement_entry* ape = apes[i];
@@ -435,9 +426,8 @@ Accidental_placement::position_accidentals (Grob * me)
   for (int i = ape->extents_.size(); i--;)
     right_extent.unite (ape->offset_  + ape->extents_[i][X_AXIS]);
 
-  SCM ls = me->get_grob_property ("left-padding");
-  if (gh_number_p (rs))
-    left_extent[LEFT] -= gh_scm2double (ls);
+  
+  left_extent[LEFT] -= robust_scm2double (me->get_grob_property ("left-padding"), 0);
 
   
   Interval width(left_extent[LEFT], right_extent[RIGHT]);
@@ -454,4 +444,4 @@ Accidental_placement::position_accidentals (Grob * me)
 ADD_INTERFACE(Accidental_placement,
              "accidental-placement-interface",
              "Take care of complex accidental collisions.",
-             "left-padding padding right-padding accidental-grobs alignment-done")
+             "left-padding padding right-padding accidental-grobs positioning-done")