]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beaming-pattern.cc
ignore gcov
[lilypond.git] / lily / beaming-pattern.cc
index b6e5a36e516b0b3168ec39f908fb1300d12e0118..092c6b673d39f9509b87d997961796553e82c6fd 100644 (file)
@@ -25,11 +25,21 @@ Beam_rhythmic_element::Beam_rhythmic_element (Moment m, int i)
 }
 
 
+void
+Beam_rhythmic_element::de_grace ()
+{
+  if (start_moment_.grace_part_)
+    {
+      start_moment_.main_part_ = start_moment_.grace_part_; 
+      start_moment_.grace_part_ = 0;
+    }
+}
+
 int
 count_factor_twos (int x)
 {
   int c = 0;
-  while (x && x % 2)
+  while (x && x % 2 == 0)
     {
       x /= 2;
       c ++;
@@ -56,7 +66,7 @@ Beaming_pattern::best_splitpoint_index (bool *at_boundary) const
 
   *at_boundary = false;
   
-  int min_factor_twos = INT_MAX;
+  int min_den = INT_MAX;
   int min_index = -1;
   
   Moment beat_pos;
@@ -72,11 +82,11 @@ Beaming_pattern::best_splitpoint_index (bool *at_boundary) const
        
        */
       
-      int factor_2s =  count_factor_twos (dt.den ());
+      dt /= infos_[i].beat_length_;
       
-      if (factor_2s < min_factor_twos)
+      if (dt.den () < min_den)
        {
-         min_factor_twos = factor_2s;
+         min_den = dt.den ();
          min_index = i;
        }
     }
@@ -96,11 +106,23 @@ Beaming_pattern::beam_extend_count (Direction d) const
   return min (thisbeam.beam_count_drul_[-d], next.beam_count_drul_[d]);
 }
 
+void
+Beaming_pattern::de_grace ()
+{
+  for (vsize i = 0; i < infos_.size (); i ++)
+    {
+      infos_[i].de_grace ();
+    }
+}
+
 void
 Beaming_pattern::beamify (Context *context)
 {
   if (infos_.size () <= 1)
     return;
+
+  if (infos_[0].start_moment_.grace_part_)
+    de_grace ();
   
   bool subdivide_beams = to_boolean (context->get_property ("subdivideBeams"));
   Moment beat_length = robust_scm2moment (context->get_property ("beatLength"), Moment (1, 4));
@@ -142,7 +164,7 @@ Beaming_pattern::beamify (Context *context)
        j++;
 
       infos_[i].group_start_ = group_starts[j];
-
+      infos_[i].beat_length_ = beat_length;  
       while (k < beat_starts.size() - 1
             && beat_starts[k+1] <= infos_[i].start_moment_)
        k++;