]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/accidental-placement.cc
* lily/spacing-engraver.cc (finalize): robustifications.
[lilypond.git] / lily / accidental-placement.cc
index a184776174a275d30a5b46bb6285fa5d73b65973..bfe0f1b58a368c8e2611e286eea75b20bebac6a5 100644 (file)
@@ -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);
     }
 
@@ -37,7 +37,6 @@ Accidental_placement::alignment_callback(SCM s, SCM )
 }
 
 
-
 void
 Accidental_placement::add_accidental (Grob* me, Grob* a)
 {
@@ -54,7 +53,7 @@ Accidental_placement::add_accidental (Grob* me, Grob* a)
 
   Pitch *p= unsmob_pitch (mcause->get_mus_property ("pitch"));
 
-  int n = p->notename_;
+  int n = p->get_notename ();
 
   SCM accs = me->get_grob_property ("accidental-grobs");
   SCM key = scm_int2num (n);
@@ -120,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;
     }
   
@@ -235,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)
 {
@@ -245,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))
@@ -369,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];
@@ -436,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]);
@@ -455,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")