]> git.donarmstrong.com Git - lilypond.git/commitdiff
4704: Improve beam subdivision beaming count
authorUrs Liska <ul@openlilylib.org>
Wed, 23 Dec 2015 21:07:22 +0000 (22:07 +0100)
committerUrs Liska <ul@openlilylib.org>
Mon, 28 Dec 2015 16:08:34 +0000 (17:08 +0100)
Calculates the remaining length of a beam.
If this is shorter than the regular value at the
subdivision point more beams are used.
(Example: subdivision at 1/8 -> one beam left.
Remaing notes on the beam: 3/32 -> two beams left.)

However, if only one stem is left after the subdivision
this isn't applied in order to have a visual separation.
In this case the default subdivision beam count is used.

lily/beaming-pattern.cc
lily/include/beaming-pattern.hh

index 135438e063c91673825a33326dd630e90be1ea94..a8899905252317ec33db0e5bccde330fec7ee7c4 100644 (file)
@@ -166,15 +166,26 @@ Beaming_pattern::beamify (Beaming_options const &options)
         Direction non_flag_dir = -flag_directions[i];
         if (non_flag_dir)
           {
-            int importance = infos_[i + 1].rhythmic_importance_;
-            int start_dur = intlog2(infos_[i+1].start_moment_.main_part_.den());
-            int count = (importance < 0 && options.subdivide_beams_) 
-                        ? max(start_dur,3)-2 // 1/8 note has one beam
-                        : min (min (infos_[i].count (non_flag_dir),
-                                        infos_[i + non_flag_dir].count (-non_flag_dir)),
-                                   infos_[i - non_flag_dir].count (non_flag_dir));
-
-            infos_[i].beam_count_drul_[non_flag_dir] = max(count, 1);
+            int count = 
+                (infos_[i + 1].rhythmic_importance_ < 0 && 
+                 options.subdivide_beams_)
+                        // we're left of a subdivision 
+                ?  (i != infos_.size () - 2)
+                   // respect the beam count for shortened beams ...   
+                   ? max (beam_count_for_rhythmic_position (i + 1),
+                          beam_count_for_length (remaining_length (i + 1)))
+                   // ... except if there's only one trailing stem
+                   : beam_count_for_rhythmic_position (i + 1)
+                
+                // we're at any other stem
+                : min (min (infos_[i].count (non_flag_dir),
+                            infos_[i + non_flag_dir].count (-non_flag_dir)),
+                       infos_[i - non_flag_dir].count (non_flag_dir));
+
+            // Ensure at least one beam is left, even for groups longer than 1/8
+            count = max (count, 1);
+            
+            infos_[i].beam_count_drul_[non_flag_dir] = count;
           }
       }
 }
@@ -362,6 +373,25 @@ Beaming_pattern::end_moment (int i) const
          + infos_.at (i).factor_ * dur.get_length ();
 }
 
+Moment
+Beaming_pattern::remaining_length (int i) const
+{
+    return end_moment (infos_.size () - 1) - infos_[i].start_moment_;
+}
+
+int
+Beaming_pattern::beam_count_for_rhythmic_position (int idx) const
+{
+    // Calculate number of beams representing the rhythmic position of given stem
+    return intlog2(infos_[idx].start_moment_.main_part_.den()) - 2;
+}
+
+int 
+Beaming_pattern::beam_count_for_length (Moment len) const
+{
+    return intlog2(len.main_part_.den()) - 2 - intlog2(len.main_part_.num());
+}
+
 bool
 Beaming_pattern::invisibility (int i) const
 {
index 217af19088a4268ce8cfc88cb1a970dbfe6c3a31..089bb31abdcdc21912091cd5f71bc7ff0b434aa2 100644 (file)
@@ -80,6 +80,9 @@ private:
   Direction flag_direction (Beaming_options const &, vsize) const;
   void find_rhythmic_importance (Beaming_options const &);
   void unbeam_invisible_stems ();
+  Moment remaining_length (int idx) const;
+  int beam_count_for_rhythmic_position (int idx) const;
+  int beam_count_for_length (Moment len) const;
 };
 
 #endif /* BEAMING_PATTERN_HH */