]> 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 0e8bf56f3458302935d8cdfc10562738f5851688..8c360baede26e72566579fb2340910e5a642d24a 100644 (file)
@@ -67,33 +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)
 {
-  int multiplicity = get_multiplicity (me);
-  Real ss = Staff_symbol_referencer::staff_space (me);
-  
-  SCM s = me->get_grob_property ("beam-space");
-  if (gh_number_p (s))
-    return gh_scm2double (s) * ss;
-  else if (s != SCM_EOL && gh_list_p (s))
-    return gh_scm2double (scm_list_ref (s,
-                                       gh_int2scm (multiplicity - 1
-                                                   <? scm_ilength (s) - 1)))
-      * ss;
-  
-  Real slt = me->paper_l ()->get_var ("linethickness");
-  Real thickness = gh_scm2double (me->get_grob_property ("thickness")) * ss;
-
-  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
@@ -110,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.
@@ -179,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)
        {
@@ -349,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;
 }
 
@@ -556,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;
 }
@@ -884,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;
 }
 
@@ -1366,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",
@@ -1391,5 +1377,5 @@ the ideal slope, how close the result is to the ideal stems, etc.). We
 take the best scoring combination.
 
 ",
-  "beam-space 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 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");