]> git.donarmstrong.com Git - lilypond.git/commitdiff
(set_stem_lengths): force direction callback.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 4 Nov 2005 00:20:58 +0000 (00:20 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 4 Nov 2005 00:20:58 +0000 (00:20 +0000)
(print): read quantized-positions, so we can force
Beam::set_stem_lengths to occur.
(rest_collision_callback): use common X parent.

ChangeLog
lily/beam.cc
lily/include/beam.hh
lily/stem.cc
scm/define-grobs.scm

index 16e8e3293bf12ac2d89a33118a4b043f01ccf661..5d7b6a9b42f2fb22f59153990d290128fa235a1c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-11-04  Han-Wen Nienhuys  <hanwen@xs4all.nl>
+
+       * lily/beam.cc (set_stem_lengths): force direction callback.
+       (print): read quantized-positions, so we can force
+       Beam::set_stem_lengths to occur.
+       (rest_collision_callback): use common X parent. 
+
 2005-11-03  Jan Nieuwenhuizen  <janneke@gnu.org>
 
        * flower/file-path.cc (find): Bugfix: Return name of file found.
index 8c88457dfca49e01166ccb40d5a26dc066a16177..71930f2e07e5636c4480ba2f9f6da3b062305310 100644 (file)
@@ -217,7 +217,6 @@ Beam::connect_beams (Grob *me)
   Slice last_int;
   last_int.set_empty ();
   
-  //  SCM last_beaming = SCM_EOL;
   SCM last_beaming = scm_cons (SCM_EOL, scm_list_1 (scm_from_int (0)));
   Direction last_dir = CENTER;
   for (int i = 0; i < stems.size (); i++)
@@ -303,7 +302,7 @@ Beam::print (SCM grob)
       dx = stems.top ()->relative_coordinate (xcommon, X_AXIS) - x0;
     }
 
-  SCM posns = me->get_property ("positions");
+  SCM posns = me->get_property ("quantized-positions");
   Drul_array<Real> pos;
   if (!is_number_pair (posns))
     {
@@ -1073,11 +1072,16 @@ Beam::calc_stem_y (Grob *me, Grob *s, Grob ** common,
   Hmm.  At this time, beam position and slope are determined.  Maybe,
   stem directions and length should set to relative to the chord's
   position of the beam.  */
-MAKE_SCHEME_CALLBACK(Beam, set_stem_lengths, 2); 
+MAKE_SCHEME_CALLBACK(Beam, set_stem_lengths, 1); 
 SCM
-Beam::set_stem_lengths (SCM smob,  SCM posns)
+Beam::set_stem_lengths (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
+
+  /* trigger callback. */
+  (void) me->get_property ("direction");
+
+  SCM posns = me->get_property ("positions");
   
   extract_grob_set (me, "stems", stems);
   if (!stems.size ())
@@ -1094,13 +1098,12 @@ Beam::set_stem_lengths (SCM smob,  SCM posns)
   bool gap = false;
   Real thick = 0.0;
   if (scm_is_number (me->get_property ("gap-count"))
-      &&scm_to_int (me->get_property ("gap-count")))
+      && scm_to_int (me->get_property ("gap-count")))
     {
       gap = true;
       thick = get_thickness (me);
     }
 
-  // ugh -> use commonx
   Grob *fvs = first_visible_stem (me);
   Grob *lvs = last_visible_stem (me);
 
@@ -1142,7 +1145,6 @@ Beam::set_beaming (Grob *me, Beaming_info_list const *beaming)
       /*
        Don't overwrite user settings.
       */
-
       do
        {
          Grob *stem = stems[i];
@@ -1267,13 +1269,19 @@ Beam::rest_collision_callback (SCM smob, SCM prev_offset)
 
   Real dy = pos[RIGHT] - pos[LEFT];
 
-  // ugh -> use commonx
-  Real x0 = first_visible_stem (beam)->relative_coordinate (0, X_AXIS);
-  Real dx = last_visible_stem (beam)->relative_coordinate (0, X_AXIS) - x0;
+  Drul_array<Grob*> visible_stems (first_visible_stem (beam),
+                                  last_visible_stem (beam));
+                                   
+  Grob *common = visible_stems[RIGHT]
+    ->common_refpoint (visible_stems[LEFT], X_AXIS);
+  
+  Real x0 = visible_stems[LEFT]->relative_coordinate (common, X_AXIS);
+  Real dx = visible_stems[RIGHT]->relative_coordinate (common, X_AXIS) - x0;
   Real slope = dy && dx ? dy / dx : 0;
 
   Direction d = get_grob_direction (stem);
-  Real stem_y = pos[LEFT] + (stem->relative_coordinate (0, X_AXIS) - x0) * slope;
+  Real stem_y = pos[LEFT]
+    + (stem->relative_coordinate (common, X_AXIS) - x0) * slope;
 
   Real beam_translation = get_beam_translation (beam);
   Real beam_thickness = Beam::get_thickness (beam);
index e26dc1fff4ce094d75c3c8ca50e1dd6bcb787d26..a044a1fd8cc8723ce9d149af97d7a238c1a76a82 100644 (file)
@@ -61,12 +61,12 @@ public:
   DECLARE_SCHEME_CALLBACK (calc_positions, (SCM));
   DECLARE_SCHEME_CALLBACK (calc_least_squares_positions, (SCM, SCM));
   DECLARE_SCHEME_CALLBACK (calc_concaveness, (SCM));
+  DECLARE_SCHEME_CALLBACK (set_stem_lengths, (SCM));
 
   /* position callbacks */
   DECLARE_SCHEME_CALLBACK (shift_region_to_valid, (SCM, SCM));
   DECLARE_SCHEME_CALLBACK (slope_damping, (SCM, SCM));
   DECLARE_SCHEME_CALLBACK (quanting, (SCM, SCM));
-  DECLARE_SCHEME_CALLBACK (set_stem_lengths, (SCM,SCM));
   
 static Real score_slopes_dy (Real, Real, Real, Real, Real, bool, Beam_quant_parameters const *);
 
index e6183a63b7de47cbd72a7c6cdb53fdebe2edf600..9cdaaa2568073c274aeaa903c57a15e23087e8e5 100644 (file)
@@ -229,7 +229,7 @@ Stem::calc_stem_end_position (SCM smob)
   if (!head_count (me))
     return scm_from_double (0.0);
 
-
+  
   Real ss = Staff_symbol_referencer::staff_space (me);
   int durlog = duration_log (me);
   Array<Real> a;
@@ -239,13 +239,14 @@ Stem::calc_stem_end_position (SCM smob)
 
   Direction dir = get_grob_direction (me);
   Interval hp = head_positions (me);
-  Real st = dir ? hp[dir] + dir * length : 0;
+  Real stem_end = dir ? hp[dir] + dir * length : 0;
 
   /* TODO: change name  to extend-stems to staff/center/'()  */
   bool no_extend_b = to_boolean (me->get_property ("no-stem-extend"));
-  if (!no_extend_b && dir * st < 0)
-    st = 0.0;
+  if (!no_extend_b && dir * stem_end < 0)
+    stem_end = 0.0;
 
+  
   /* Make a little room if we have a upflag and there is a dot.
      previous approach was to lengthen the stem. This is not
      good typesetting practice.  */
@@ -263,7 +264,7 @@ Stem::calc_stem_end_position (SCM smob)
 
          /* Very gory: add myself to the X-support of the parent,
             which should be a dot-column. */
-         if (dir * (st + flagy - dp) < 0.5)
+         if (dir * (stem_end + flagy - dp) < 0.5)
            {
              Grob *par = dots->get_parent (X_AXIS);
 
@@ -279,7 +280,7 @@ Stem::calc_stem_end_position (SCM smob)
        }
     }
 
-  return scm_from_double (st);
+  return scm_from_double (stem_end);
 }
 
 
@@ -507,8 +508,12 @@ Stem::height (SCM smob)
       beam->get_property ("positions");
     }
 
-  /* FIXME uncached? */
-  Interval iv = me->get_stencil () ? me->get_stencil ()->extent (Y_AXIS) : Interval();
+  /*
+    Can't get_stencil(), since that would cache stencils too early.
+    This causes problems with beams.
+   */
+  Stencil *stencil = unsmob_stencil (print (smob));
+  Interval iv = stencil ? stencil->extent (Y_AXIS) : Interval();
   if (beam)
     {
       if (dir == CENTER)
@@ -679,13 +684,13 @@ Stem::print (SCM smob)
 
   Interval stem_y (min (y1, y2), max (y2, y1));
 
-  if (Grob *hed = support_head (me))
+  if (Grob *head = support_head (me))
     {
       /*
        must not take ledgers into account.
       */
-      Interval head_height = hed->extent (hed, Y_AXIS);
-      Real y_attach = Note_head::stem_attachment_coordinate (hed, Y_AXIS);
+      Interval head_height = head->extent (head, Y_AXIS);
+      Real y_attach = Note_head::stem_attachment_coordinate (head, Y_AXIS);
 
       y_attach = head_height.linear_combination (y_attach);
       stem_y[Direction (-d)] += d * y_attach / half_space;
@@ -942,11 +947,9 @@ ADD_INTERFACE (Stem, "stem-interface",
               "should be shortened. The list gives an amount depending on the number "
               "of flags/beams."
               "@end table\n"
-
               ,
 
               /* properties */
-              
               "avoid-note-head "
               "beam "
               "beaming "
index afbd73bf7e5091583e03a46ffc8560e8eb4f800b..27123ad246806db0ff3447bb118e6c168192f019 100644 (file)
                           Beam::slope_damping
                           Beam::shift_region_to_valid
                           Beam::quanting
-                          Beam::set_stem_lengths
                           ))))
-       
+
+       ;; this is a hack to set stem lengths, if positions is set.
+       (quantized-positions . ,Beam::set_stem_lengths)
        (concaveness . ,Beam::calc_concaveness)
        (direction . ,Beam::calc_direction)
        (stencil . ,Beam::print)