]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beaming-pattern.cc
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / beaming-pattern.cc
index 092c6b673d39f9509b87d997961796553e82c6fd..0f6f1e1b8fa46ef192f263494ef9bdbdadd5d734 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "beaming-pattern.hh"
@@ -116,29 +116,25 @@ Beaming_pattern::de_grace ()
 }
 
 void
-Beaming_pattern::beamify (Context *context)
+Beaming_pattern::beamify (Beaming_options const &options)
 {
   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));
-  Moment measure_length = robust_scm2moment (context->get_property ("measureLength"), Moment (1, 4));
 
   if (infos_[0].start_moment_ < Moment (0))
-    for (vsize i = 0; i < infos_.size(); i++)
-      infos_[i].start_moment_ += measure_length;
+    for (vsize i = 0; i < infos_.size (); i++)
+      infos_[i].start_moment_ += options.measure_length_;
   
-  SCM grouping = context->get_property ("beatGrouping");
   Moment measure_pos (0);
   
   vector<Moment> group_starts;
   vector<Moment> beat_starts;
-  
-  while (measure_pos <= infos_.back().start_moment_)
+
+  SCM grouping = options.grouping_;
+  while (measure_pos <= infos_.back ().start_moment_)
     {
       int count = 2;
       if (scm_is_pair (grouping))
@@ -150,29 +146,32 @@ Beaming_pattern::beamify (Context *context)
       group_starts.push_back (measure_pos);
       for (int i = 0; i < count; i++)
        {
-         beat_starts.push_back (measure_pos + beat_length * i);
+         beat_starts.push_back (measure_pos + options.beat_length_ * i);
        }
-      measure_pos += beat_length * count;
+      measure_pos += options.beat_length_ * count;
     }
    
   vsize j = 0;
   vsize k = 0;
-  for (vsize i = 0; i  < infos_.size(); i++)
+  for (vsize i = 0; i  < infos_.size (); i++)
     {
-      while (j < group_starts.size() - 1
+      while (j + 1 < group_starts.size ()
             && group_starts[j+1] <= infos_[i].start_moment_)
        j++;
 
-      infos_[i].group_start_ = group_starts[j];
-      infos_[i].beat_length_ = beat_length;  
-      while (k < beat_starts.size() - 1
+      if (j < group_starts.size ())
+       infos_[i].group_start_ = group_starts[j];
+      
+      infos_[i].beat_length_ = options.beat_length_;  
+      while (k + 1 < beat_starts.size () 
             && beat_starts[k+1] <= infos_[i].start_moment_)
        k++;
 
-      infos_[i].beat_start_ = beat_starts[k];
+      if (k < beat_starts.size ())
+       infos_[i].beat_start_ = beat_starts[k];
     }
   
-  beamify (subdivide_beams);
+  beamify (options.subdivide_beams_);
 }
 
 
@@ -234,3 +233,18 @@ Beaming_pattern::beamlet_count (int i, Direction d) const
 {
   return infos_.at (i).beam_count_drul_[d];
 }
+
+void
+Beaming_options::from_context (Context *context)
+{
+  grouping_ = context->get_property ("beatGrouping");
+  subdivide_beams_ = to_boolean (context->get_property ("subdivideBeams"));
+  beat_length_ = robust_scm2moment (context->get_property ("beatLength"), Moment (1, 4));
+  measure_length_ = robust_scm2moment (context->get_property ("measureLength"), Moment (1, 4));
+}
+
+Beaming_options::Beaming_options ()
+{
+  grouping_ = SCM_EOL;
+  subdivide_beams_ = false;
+}