]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
* input/mozart-hrn3-defs.ly (startGraceContext): Customize grace init.
[lilypond.git] / lily / beam.cc
index 16f427bbf3e0fdb0f61a55dcab7cc8e01a8c6f76..8c360baede26e72566579fb2340910e5a642d24a 100644 (file)
@@ -67,24 +67,12 @@ Beam::add_stem (Grob *me, Grob *s)
   add_bound_item (dynamic_cast<Spanner*> (me), dynamic_cast<Item*> (s));
 }
 
-
-/*
-  TODO: fix this for grace notes.
- */
 Real
 Beam::get_interbeam (Grob *me)
 {
-  Real slt = me->paper_l ()->get_var ("stafflinethickness");
-  Real ss = Staff_symbol_referencer::staff_space (me);
-  Real thickness = gh_scm2double (me->get_grob_property ("thickness"))
-    * ss;
-
-  int multiplicity = get_multiplicity (me);
-  Real interbeam = multiplicity < 4
-    ? (2*ss + slt - thickness) / 2.0
-    : (3*ss + slt - thickness) / 3.0;
-  
-  return interbeam;
+  SCM func = me->get_grob_property ("space-function");
+  SCM s = gh_call2 (func, me->self_scm (), gh_int2scm (get_multiplicity (me)));
+  return gh_scm2double (s);
 }
 
 int
@@ -101,6 +89,25 @@ Beam::get_multiplicity (Grob *me)
   return m;
 }
 
+MAKE_SCHEME_CALLBACK (Beam, space_function, 2);
+SCM
+Beam::space_function (SCM smob, SCM multiplicity)
+{
+  Grob *me = unsmob_grob (smob);
+  
+  Real staff_space = Staff_symbol_referencer::staff_space (me);
+  Real line = me->paper_l ()->get_var ("linethickness");
+  Real thickness = gh_scm2double (me->get_grob_property ("thickness"))
+    * staff_space;
+  
+  Real interbeam = gh_scm2int (multiplicity) < 4
+    ? (2*staff_space + line - thickness) / 2.0
+    : (3*staff_space + line - thickness) / 3.0;
+  
+  return gh_double2scm (interbeam);
+}
+
+
 /* After pre-processing all directions should be set.
    Several post-processing routines (stem, slur, script) need stem/beam
    direction.
@@ -170,8 +177,9 @@ Beam::get_default_dir (Grob *me)
     do {
       Grob *s = stems[i];
       Direction sd = Directional_element_interface::get (s);
-      int current = sd ? (1 + d * sd)/2
-       : Stem::get_center_distance (s, (Direction)-d);
+
+      int center_distance = int(- d * Stem::head_positions (s) [-d]) >? 0;
+      int current = sd ? (1 + d * sd)/2 : center_distance;
 
       if (current)
        {
@@ -340,10 +348,12 @@ Beam::after_line_breaking (SCM smob)
   if (ly_car (s) != SCM_BOOL_F)
     return SCM_UNSPECIFIED;
 
+  // one wonders if such genericity is necessary  --hwn.
   SCM callbacks = me->get_grob_property ("position-callbacks");
   for (SCM i = callbacks; gh_pair_p (i); i = ly_cdr (i))
     gh_call1 (ly_car (i), smob);
 
+  set_stem_lengths (me);  
   return SCM_UNSPECIFIED;
 }
 
@@ -378,7 +388,7 @@ Beam::quanting (SCM smob)
 
   Real ss = Staff_symbol_referencer::staff_space (me);
   Real thickness = gh_scm2double (me->get_grob_property ("thickness")) / ss;
-  Real slt = me->paper_l ()->get_var ("stafflinethickness") / ss;
+  Real slt = me->paper_l ()->get_var ("linethickness") / ss;
 
 
   SCM sdy = me->get_grob_property ("least-squares-dy");
@@ -547,7 +557,7 @@ Beam::score_stem_lengths (Link_array<Grob>stems,
       demerit_score += 5 * shrink_extra_weight (d * current_y  - info.ideal_y);
     }
 
-  demerit_score *= 2.0  /stems.size (); 
+  demerit_score *= 2.0 stems.size (); 
 
   return demerit_score;
 }
@@ -875,16 +885,6 @@ Beam::slope_damping (SCM smob)
       
       me->set_grob_property ("positions", ly_interval2scm (pos));
     }
-    return SCM_UNSPECIFIED;
-}
-
-MAKE_SCHEME_CALLBACK (Beam, end_after_line_breaking, 1);
-SCM
-Beam::end_after_line_breaking (SCM smob)
-{
-  Grob *me = unsmob_grob (smob);
-  set_stem_lengths (me);
-  
   return SCM_UNSPECIFIED;
 }
 
@@ -896,7 +896,7 @@ Real
 Beam::calc_stem_y (Grob *me, Grob* s, Interval pos)
 {
   int beam_multiplicity = get_multiplicity (me);
-  int stem_multiplicity = (Stem::flag_i (s) - 2) >? 0;
+  int stem_multiplicity = (Stem::duration_log (s) - 2) >? 0;
 
   Real thick = gh_scm2double (me->get_grob_property ("thickness"));
   Real interbeam = get_interbeam (me);
@@ -1064,7 +1064,7 @@ Beam::stem_beams (Grob *me, Item *here, Item *next, Item *prev, Real dydx)
        - prev->relative_coordinate (0, X_AXIS);
       Real stem_w = gh_scm2double (prev->get_grob_property ("thickness"))
        // URG
-       * me->paper_l ()->get_var ("stafflinethickness");
+       * me->paper_l ()->get_var ("linethickness");
 
       w = w/2 <? nw_f;
       Molecule a;
@@ -1092,7 +1092,7 @@ Beam::stem_beams (Grob *me, Item *here, Item *next, Item *prev, Real dydx)
 
       Real stem_w = gh_scm2double (next->get_grob_property ("thickness"))
        // URG
-       * me->paper_l ()->get_var ("stafflinethickness");
+       * me->paper_l ()->get_var ("linethickness");
 
       Molecule a = Lookup::beam (dydx, w + stem_w, thick);
       a.translate_axis (- stem_w/2, X_AXIS);
@@ -1357,11 +1357,6 @@ Beam::rest_collision_callback (SCM element_smob, SCM axis)
 }
 
 
-bool
-Beam::has_interface (Grob *me)
-{
-  return me->has_interface (ly_symbol2scm ("beam-interface"));
-}
 
 
 ADD_INTERFACE (Beam, "beam-interface",
@@ -1382,5 +1377,5 @@ the ideal slope, how close the result is to the ideal stems, etc.). We
 take the best scoring combination.
 
 ",
-  "concaveness-threshold dir-function quant-score auto-knee-gap gap chord-tremolo beamed-stem-shorten shorten least-squares-dy direction damping flag-width-function neutral-direction positions thickness");
+  "position-callbacks concaveness-gap concaveness-threshold dir-function quant-score auto-knee-gap gap chord-tremolo beamed-stem-shorten shorten least-squares-dy direction damping flag-width-function neutral-direction positions space-function thickness");