]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / stem.cc
index 8a59a4909cf777997280b98ca6481fc3909e28a1..a25c37f777211d6a77936decee08787fb8cf1016 100644 (file)
@@ -48,8 +48,12 @@ Stem::set_beaming (Grob *me, int beam_count, Direction d)
     }
 
   SCM lst = index_get_cell (pair, d);
-  for (int i = 0; i < beam_count; i++)
-    lst = scm_cons (scm_from_int (i), lst);
+  if (beam_count)
+    for (int i = 0; i < beam_count; i++)
+      lst = scm_cons (scm_from_int (i), lst);
+  else
+    lst = SCM_BOOL_F;
+  
   index_set_cell (pair, d, lst);
 }
 
@@ -335,17 +339,21 @@ Stem::calc_length (SCM smob)
        + 2 * t_flag->extent (t_flag, Y_AXIS).length ()
        / ss;
 
+      /* We don't want to add the whole extent of the flag because the trem
+         and the flag can overlap partly. beam_translation gives a good
+         approximation */
       if (durlog >= 3)
-       {
-         Interval flag_ext = flag (me).extent (Y_AXIS);
-         if (!flag_ext.is_empty ())
-           minlen += 2 * flag_ext.length () / ss;
-
-         /* The clash is smaller for down stems (since the tremolo is
-            angled up.) */
-         if (dir == DOWN)
-           minlen -= 1.0;
-       }
+        {
+          Real beam_trans = Stem_tremolo::get_beam_translation (t_flag);
+          /* the obvious choice is (durlog - 2) here, but we need a bit more space. */
+          minlen += 2 * (durlog - 1.5) * beam_trans;
+
+          /* up-stems need even a little more space to avoid collisions. This
+             needs to be in sync with the tremolo positioning code in
+             Stem_tremolo::print */
+          if (dir == UP)
+            minlen += beam_trans;
+        }
       length = max (length, minlen + 1.0);
     }
   
@@ -798,7 +806,6 @@ Stem::get_stem_info (Grob *me)
   return si;
 }
 
-/* TODO: add extra space for tremolos!  */
 MAKE_SCHEME_CALLBACK(Stem, calc_stem_info, 1);
 SCM
 Stem::calc_stem_info (SCM smob)
@@ -847,6 +854,13 @@ Stem::calc_stem_info (SCM smob)
     * staff_space
     * length_fraction;
 
+  Real height_of_my_trem = 0.0;
+  Grob *trem = unsmob_grob (me->get_object ("tremolo-flag"));
+  if (trem)
+      height_of_my_trem = trem->extent (trem, Y_AXIS).length ()
+        /* hack a bit of space around the trem. */
+        + beam_translation;
+
   /* UGH
      It seems that also for ideal minimum length, we must use
      the maximum beam count (for this direction):
@@ -859,6 +873,7 @@ Stem::calc_stem_info (SCM smob)
 
   Real ideal_minimum_length = ideal_minimum_free
     + height_of_my_beams
+    + height_of_my_trem
     /* stem only extends to center of beam */
     - 0.5 * beam_thickness;
 
@@ -908,18 +923,11 @@ Stem::calc_stem_info (SCM smob)
     * staff_space
     * length_fraction;
 
-  Real minimum_length = minimum_free
+  Real minimum_length = max (minimum_free, height_of_my_trem)
     + height_of_my_beams
     /* stem only extends to center of beam */
     - 0.5 * beam_thickness;
 
-  if (Grob *tremolo = unsmob_grob (me->get_object ("tremolo-flag")))
-    {
-      Interval y_ext = tremolo->extent (tremolo, Y_AXIS);
-      y_ext.widen (0.5);       // FIXME. Should be tunable? 
-      minimum_length = max (minimum_length, y_ext.length ());
-    }
-
   ideal_y *= my_dir;
   Real minimum_y = note_start + minimum_length;
   Real shortest_y = minimum_y * my_dir;
@@ -974,6 +982,7 @@ ADD_INTERFACE (Stem, "stem-interface",
               "french-beaming "
               "length "
               "length-fraction "
+              "max-beam-connect "
               "neutral-direction "
               "no-stem-extend "
               "note-heads "