]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam-concave.cc
Doc -- clarification to parenthesize by Jon Kulp, based on James Bailey.
[lilypond.git] / lily / beam-concave.cc
index 2b88e0807ac55a13af98475e17f29028188560e3..48d45c859945eaa87ded018191bb9ab421b7b640 100644 (file)
@@ -1,5 +1,24 @@
+/* 
+  beam-concave.cc -- implement Concaveness for beams.
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2004 Han-Wen Nienhuys <hanwen@lilypond.org>
+  
+*/
+
 /*
   Determine whether a beam is concave.
 /*
   Determine whether a beam is concave.
+
+  A beam is concave when the middle notes get closer to the
+  beam than the left and right edge notes.
+
+  This is determined in two ways: by looking at the positions of the
+  middle notes, or by looking at the deviation of the inside notes
+  compared to the line connecting first and last.
+
+  The tricky thing is what to do with beams with chords. There are no
+  real guidelines in this case.
 */
 
 #include "pointer-group-interface.hh"
 */
 
 #include "pointer-group-interface.hh"
@@ -23,7 +42,7 @@ is_concave_single_notes (vector<int> const &positions, Direction beam_dir)
   /*
     notes above and below the interval covered by 1st and last note.
   */
   /*
     notes above and below the interval covered by 1st and last note.
   */
-  for (vsize i = 1; i < positions.size () - 1; i++)
+  for (vsize i = 1; i + 1 < positions.size (); i++)
     {
       above = above || (positions[i] > covering[UP]);
       below = below || (positions[i] < covering[DOWN]);
     {
       above = above || (positions[i] > covering[UP]);
       below = below || (positions[i] < covering[DOWN]);
@@ -36,7 +55,7 @@ is_concave_single_notes (vector<int> const &positions, Direction beam_dir)
   */
   int dy = positions.back () - positions[0];
   int closest = max (beam_dir * positions.back (), beam_dir * positions[0]);
   */
   int dy = positions.back () - positions[0];
   int closest = max (beam_dir * positions.back (), beam_dir * positions[0]);
-  for (vsize i = 2; !concave && i < positions.size () - 1; i++)
+  for (vsize i = 2; !concave && i + 1 < positions.size (); i++)
     {
       int inner_dy = positions[i] - positions[i - 1];
       if (sign (inner_dy) != sign (dy)
     {
       int inner_dy = positions[i] - positions[i - 1];
       if (sign (inner_dy) != sign (dy)
@@ -46,7 +65,7 @@ is_concave_single_notes (vector<int> const &positions, Direction beam_dir)
     }
 
   bool all_closer = true;
     }
 
   bool all_closer = true;
-  for (vsize i = 1; all_closer && i < positions.size () - 1; i++)
+  for (vsize i = 1; all_closer && i + 1 < positions.size (); i++)
     {
       all_closer = all_closer
        && (beam_dir * positions[i] > closest);
     {
       all_closer = all_closer
        && (beam_dir * positions[i] > closest);
@@ -62,7 +81,7 @@ calc_positions_concaveness (vector<int> const &positions, Direction beam_dir)
   Real dy = positions.back () - positions[0];
   Real slope = dy / Real (positions.size () - 1);
   Real concaveness = 0.0;
   Real dy = positions.back () - positions[0];
   Real slope = dy / Real (positions.size () - 1);
   Real concaveness = 0.0;
-  for (vsize i = 1; i < positions.size () - 1; i++)
+  for (vsize i = 1; i + 1 < positions.size (); i++)
     {
       Real line_y = slope * i + positions[0];
 
     {
       Real line_y = slope * i + positions[0];
 
@@ -118,7 +137,6 @@ Beam::calc_concaveness (SCM smob)
        Hmmm.. wait, for the beams in the last measure of morgenlied,
        this doesn't look so good. Let's try the heads farthest from
        the beam.
        Hmmm.. wait, for the beams in the last measure of morgenlied,
        this doesn't look so good. Let's try the heads farthest from
        the beam.
-
       */
       Interval posns = Stem::head_positions (stems[i]);
 
       */
       Interval posns = Stem::head_positions (stems[i]);
 
@@ -128,7 +146,7 @@ Beam::calc_concaveness (SCM smob)
 
   Real concaveness = 0.0;
 
 
   Real concaveness = 0.0;
 
-  if (is_concave_single_notes (far_positions, beam_dir))
+  if (is_concave_single_notes (beam_dir == UP ? close_positions : far_positions, beam_dir))
     {
       concaveness = 10000;
     }
     {
       concaveness = 10000;
     }