]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / lily / beam.cc
index dc7cd4ccedd538c955bc698169f25ae578544c84..3b76c373b96178950c25993a77d275764ecdc75f 100644 (file)
@@ -11,9 +11,6 @@
 /*
 TODO:
 
-
-  * Junk stem_info.
-
   * Use Number_pair i.s.o Interval to represent (yl, yr).
   
   - Determine auto knees based on positions if it's set by the user.
@@ -70,9 +67,17 @@ Beam::add_stem (Grob *me, Grob *s)
 }
 
 
-/*
-  this returns the translation between 2 adjoining beams.
- */
+Real
+Beam::get_thickness (Grob * me)
+{
+  SCM th = me->get_grob_property ("thickness");
+  if (gh_number_p (th))
+    return gh_scm2double (th)* Staff_symbol_referencer::staff_space (me);
+  else
+    return 0.0;
+}
+
+/* Return the translation between 2 adjoining beams. */
 Real
 Beam::get_beam_translation (Grob *me)
 {
@@ -81,18 +86,15 @@ Beam::get_beam_translation (Grob *me)
   return gh_scm2double (s);
 }
 
-/*
-  Maximum beam_count.
- */
+/* Maximum beam_count. */
 int
 Beam::get_beam_count (Grob *me) 
 {
   int m = 0;
   for (SCM s = me->get_grob_property ("stems"); gh_pair_p (s); s = ly_cdr (s))
     {
-      Grob *sc = unsmob_grob (ly_car (s));
-      
-      m = m >? (Stem::beam_multiplicity (sc).length () + 1);
+      Grob *stem = unsmob_grob (ly_car (s));
+      m = m >? (Stem::beam_multiplicity (stem).length () + 1);
     }
   return m;
 }
@@ -105,8 +107,7 @@ Beam::space_function (SCM smob, SCM beam_count)
   
   Real staff_space = Staff_symbol_referencer::staff_space (me);
   Real line = me->get_paper ()->get_var ("linethickness");
-  Real thickness = gh_scm2double (me->get_grob_property ("thickness"))
-    * staff_space;
+  Real thickness = get_thickness (me);
   
   Real beam_translation = gh_scm2int (beam_count) < 4
     ? (2*staff_space + line - thickness) / 2.0
@@ -324,7 +325,7 @@ Beam::brew_molecule (SCM grob)
   Real dy = pos.delta ();
   Real dydx = dy && dx ? dy/dx : 0;
   
-  Real thick = gh_scm2double (me->get_grob_property ("thickness"));
+  Real thick = get_thickness (me);
   Real bdy = get_beam_translation (me);
 
   SCM last_beaming = SCM_EOL;;
@@ -727,7 +728,8 @@ Beam::set_stem_shorten (Grob *me)
   if (knee_b(me))
     return ;
   
-  Real forced_fraction = forced_stem_count (me) / visible_stem_count (me);
+  Real forced_fraction = 1.0 * forced_stem_count (me)
+    / visible_stem_count (me);
 
   int beam_count = get_beam_count (me);
 
@@ -802,9 +804,9 @@ Beam::least_squares (SCM smob)
   Grob *fvs  = first_visible_stem (me);
   Grob *lvs  = last_visible_stem (me);
   
-  Interval ideal (Stem::calc_stem_info (fvs).ideal_y_
+  Interval ideal (Stem::get_stem_info (fvs).ideal_y_
                  + fvs->relative_coordinate (commony, Y_AXIS) -my_y,
-                 Stem::calc_stem_info (lvs).ideal_y_
+                 Stem::get_stem_info (lvs).ideal_y_
                  + lvs->relative_coordinate (commony, Y_AXIS) - my_y);
   
   Real x0 = first_visible_stem (me)->relative_coordinate (commonx, X_AXIS);
@@ -826,23 +828,18 @@ Beam::least_squares (SCM smob)
       Interval chord (Stem::chord_start_y (first_visible_stem (me)),
                      Stem::chord_start_y (last_visible_stem (me)));
 
+      /* Simple beams (2 stems) on middle line should be allowed to be
+        slightly sloped.
+        
+        However, if both stems reach middle line,
+        ideal[LEFT] == ideal[RIGHT] and ideal.delta () == 0.
 
-      /*
-       TODO -- use scoring for this.
-
-       complicated, because we take stem-info.ideal for determining
-       beam slopes.
-       */
-      /* Make simple beam on middle line have small tilt */
+        For that case, we apply artificial slope */
       if (!ideal[LEFT] && chord.delta () && count == 2)
        {
-
-         /*
-           FIXME. -> UP
-         */
+         /* FIXME. -> UP */
          Direction d = (Direction) (sign (chord.delta ()) * UP);
          pos[d] = gh_scm2double (me->get_grob_property ("thickness")) / 2;
-         //                * dir;
          pos[-d] = - pos[d];
        }
       else
@@ -863,7 +860,7 @@ Beam::least_squares (SCM smob)
          if (Stem::invisible_b (s))
            continue;
          ideals.push (Offset (x_posns[i],
-                              Stem::calc_stem_info (s).ideal_y_
+                              Stem::get_stem_info (s).ideal_y_
                               + s->relative_coordinate (commony, Y_AXIS)
                               - my_y));
        }
@@ -939,7 +936,7 @@ Beam::shift_region_to_valid (SCM grob)
       Direction d = Stem::get_direction (s);
 
       Real left_y =
-       Stem::calc_stem_info (s).shortest_y_
+       Stem::get_stem_info (s).shortest_y_
        - dydx * x_posns [i];
 
       /*
@@ -1156,10 +1153,8 @@ where_are_the_whole_beams(SCM beaming)
   return l;
 }
 
-/*
-  Calculate the Y position of the stem-end, given the Y-left, Y-right
-  in POS for stem S. This Y position is relative to S.
- */
+/* Return the Y position of the stem-end, given the Y-left, Y-right
+   in POS for stem S.  This Y position is relative to S. */
 Real
 Beam::calc_stem_y (Grob *me, Grob* s, Grob ** common,
                   Real xl, Real xr,
@@ -1228,8 +1223,7 @@ Beam::set_stem_lengths (Grob *me)
       &&gh_scm2double (me->get_grob_property ("gap")))
   {
     gap = true;
-    thick = gh_scm2double (me->get_grob_property ("thickness"))
-      * Staff_symbol_referencer::staff_space(me);
+    thick = get_thickness(me);
   }
       
   // ugh -> use commonx
@@ -1306,7 +1300,9 @@ Beam::forced_stem_count (Grob *me)
       if (Stem::invisible_b (s))
        continue;
 
-      if (((int)Stem::chord_start_y (s)) 
+      /* I can imagine counting those boundaries as a half forced stem,
+        but let's count them full for now. */
+      if (abs (Stem::chord_start_y (s)) > 0.1
         && (Stem::get_direction (s) != Stem::get_default_dir (s)))
         f++;
     }
@@ -1491,6 +1487,6 @@ the ideal slope, how close the result is to the ideal stems, etc.). We
 take the best scoring combination.
 
 ",
-  "french-beaming position-callbacks concaveness-gap concaveness-threshold dir-function quant-score auto-knee-gap gap chord-tremolo beamed-stem-shorten shorten least-squares-dy damping flag-width-function neutral-direction positions space-function thickness");
+  "knee french-beaming position-callbacks concaveness-gap concaveness-threshold dir-function quant-score auto-knee-gap gap chord-tremolo beamed-stem-shorten shorten least-squares-dy damping flag-width-function neutral-direction positions space-function thickness");