]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/accidental-placement.cc
* lily/include/scm-hash.hh (class Scheme_hash_table): idem.
[lilypond.git] / lily / accidental-placement.cc
index 03d7ac60c6ab159e79aac66ffb22e9991ed35af9..d8bd7aaeb84ba75434f9580b6ea41249d4c5c709 100644 (file)
@@ -3,7 +3,7 @@ accidental-placement.cc --  implement Accidental_placement
 
 source file of the GNU LilyPond music typesetter
 
-(c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+(c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
  */
 
@@ -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,7 +119,7 @@ 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"));
       extent[LEFT] -= p;
@@ -245,7 +244,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))
@@ -379,43 +378,27 @@ Accidental_placement::position_accidentals (Grob * me)
   if (gh_number_p (spad))
     padding = gh_scm2double (spad);
 
-
+  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];