]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
release: 1.3.105
[lilypond.git] / lily / beam.cc
index f619e04b9c4fdd4cbc3db45384f3934b3c8d097f..f94c018083f6e3c8617c5649e13a09bca4c45f08 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <math.h> // tanh.
 
-
+#include "molecule.hh" 
 #include "directional-element-interface.hh"
 #include "beaming.hh"
 #include "beam.hh"
@@ -39,8 +39,7 @@
 void
 Beam::add_stem (Score_element*me, Score_element*s)
 {
-  Pointer_group_interface gi (me, "stems");
-  gi.add_element (s);
+  Pointer_group_interface:: add_element(me, "stems", s);
   
   s->add_dependency (me);
 
@@ -72,7 +71,7 @@ Beam::get_multiplicity (Score_element*me)
   [Alternatively, stems could set its own directions, according to
    their beam, during 'final-pre-processing'.]
  */
-MAKE_SCHEME_CALLBACK(Beam,before_line_breaking);
+MAKE_SCHEME_CALLBACK(Beam,before_line_breaking,1);
 SCM
 Beam::before_line_breaking (SCM smob)
 {
@@ -94,9 +93,6 @@ Beam::before_line_breaking (SCM smob)
   return SCM_EOL;
 }
 
-/*
- FIXME
- */
 Direction
 Beam::get_default_dir (Score_element*me) 
 {
@@ -124,14 +120,13 @@ Beam::get_default_dir (Score_element*me)
 
     } while (flip(&d) != DOWN);
   
+  SCM func = me->get_elt_property ("dir-function");
+  SCM s = gh_call2 (func,
+                   gh_cons (gh_int2scm (count[UP]),
+                            gh_int2scm (count[DOWN])),
+                   gh_cons (gh_int2scm (total[UP]),
+                            gh_int2scm (total[DOWN])));
 
-  SCM s = scm_eval2 (gh_list (ly_symbol2scm ("beam-dir-algorithm"),
-                            ly_quote_scm (gh_cons (gh_int2scm (count[UP]),
-                                                   gh_int2scm (count[DOWN]))),
-                            ly_quote_scm (gh_cons (gh_int2scm (total[UP]),
-                                                   gh_int2scm (total[DOWN]))),
-                            SCM_UNDEFINED),
-                    SCM_EOL);
   if (gh_number_p (s) && gh_scm2int (s))
     return to_dir (s);
   
@@ -244,9 +239,7 @@ Beam::set_stem_shorten (Score_element*m)
 
   int multiplicity = get_multiplicity (me);
 
-  // grace stems?
-  SCM shorten = scm_eval2 (ly_symbol2scm ("beamed-stem-shorten"), SCM_EOL);
-
+  SCM shorten = me->get_elt_property ("beamed-stem-shorten");
   if (shorten == SCM_EOL)
     return;
 
@@ -277,7 +270,7 @@ Beam::set_stem_shorten (Score_element*m)
   Set elt properties height and y-position if not set.
   Adjust stem lengths to reach beam.
  */
-MAKE_SCHEME_CALLBACK(Beam,after_line_breaking);
+MAKE_SCHEME_CALLBACK(Beam,after_line_breaking,1);
 SCM
 Beam::after_line_breaking (SCM smob)
 {
@@ -405,8 +398,8 @@ Beam::suspect_slope_b (Score_element*me, Real y, Real dy)
   */
   Real first_ideal = Stem::calc_stem_info (first_visible_stem (me)).idealy_f_;
   Real last_ideal = Stem::calc_stem_info (last_visible_stem (me)).idealy_f_;
-  Real lengthened = me->paper_l ()->get_var ("beam_lengthened");
-  Real steep = me->paper_l ()->get_var ("beam_steep_slope");
+  Real lengthened = gh_scm2double (me->get_elt_property ("outer-stem-length-limit"));
+  Real steep = gh_scm2double (me->get_elt_property ("slope-limit"));
 
   // ugh -> use commonx
   Real dx = last_visible_stem (me)->relative_coordinate (0, X_AXIS) - first_visible_stem (me)->relative_coordinate (0, X_AXIS);
@@ -449,13 +442,11 @@ Beam::calc_stem_y_f (Score_element*me,Item* s, Real y, Real dy)
   int beam_multiplicity = get_multiplicity (me);
   int stem_multiplicity = (Stem::flag_i (s) - 2) >? 0;
 
-  Real staffspace = me->paper_l ()->get_var ("staffspace");
-  
-  SCM space_proc = me->get_elt_property ("beam-space-function");
+  SCM space_proc = me->get_elt_property ("space-function");
   SCM space = gh_call1 (space_proc, gh_int2scm (beam_multiplicity));
 
-  Real thick = gh_scm2double (me->get_elt_property ("beam-thickness")) *staffspace;
-  Real interbeam_f = gh_scm2double (space) * staffspace;
+  Real thick = gh_scm2double (me->get_elt_property ("thickness")) ;
+  Real interbeam_f = gh_scm2double (space) ;
 
   // ugh -> use commonx
   Real x0 = first_visible_stem (me)->relative_coordinate (0, X_AXIS);
@@ -555,8 +546,14 @@ Real
 Beam::quantise_dy_f (Score_element*me,Real dy) 
 {
   Array<Real> a;
-  for (SCM s = scm_eval2 (ly_symbol2scm ("beam-height-quants"), SCM_EOL);
-       s !=SCM_EOL; s = gh_cdr (s))
+
+  SCM proc = me->get_elt_property ("height-quants");
+  SCM quants = gh_call2 (proc, me->self_scm (),
+                        gh_double2scm (me->paper_l ()->get_var ("stafflinethickness")
+                                       / 1.0));
+  
+  
+  for (SCM s = quants; gh_pair_p (s); s = gh_cdr (s))
     a.push (gh_scm2double (gh_car (s)));
   
   if (a.size () <= 1)
@@ -586,15 +583,20 @@ Beam::quantise_y_f (Score_element*me,Real y, Real dy, int quant_dir)
   int multiplicity = get_multiplicity (me);
 
   Real staff_space = Staff_symbol_referencer::staff_space (me);
-  SCM quants = scm_eval2 (gh_list (ly_symbol2scm ("beam-vertical-position-quants"),
-                                 gh_int2scm (multiplicity),
-                                 gh_double2scm (dy/staff_space),
-                                 SCM_UNDEFINED),
-                         SCM_EOL);
+  Real thick = me->paper_l ()->get_var ("stafflinethickness");
+
 
+  SCM proc = me->get_elt_property ("vertical-position-quant-function");
+  SCM quants = scm_apply (proc,
+                         me->self_scm (),
+                         gh_list (gh_int2scm (multiplicity),
+                                  gh_double2scm (dy/staff_space),
+                                  gh_double2scm (thick/staff_space),
+                                  SCM_EOL, SCM_UNDEFINED));
+  
   Array<Real> a;
 
-  for (; quants != SCM_EOL; quants = gh_cdr (quants))
+  for (; gh_pair_p (quants); quants = gh_cdr (quants))
     a.push (gh_scm2double (gh_car (quants)));
 
   if (a.size () <= 1)
@@ -634,8 +636,7 @@ Beam::set_beaming (Score_element*me,Beaming_info_list *beaming)
 /*
   beams to go with one stem.
 
-  BURP
-  clean  me up.
+  FIXME: clean me up.
   */
 Molecule
 Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev) 
@@ -647,13 +648,12 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
 
   Real staffline_f = me->paper_l ()->get_var ("stafflinethickness");
   int multiplicity = get_multiplicity (me);
-  Real staffspace =me->paper_l ()->get_var ("staffspace");
 
-  SCM space_proc = me->get_elt_property ("beam-space-function");
+  SCM space_proc = me->get_elt_property ("space-function");
   SCM space = gh_call1 (space_proc, gh_int2scm (multiplicity));
 
-  Real thick = gh_scm2double (me->get_elt_property ("beam-thickness")) *staffspace;
-  Real interbeam_f = gh_scm2double (space) * staffspace;
+  Real thick = gh_scm2double (me->get_elt_property ("thickness")) ;
+  Real interbeam_f = gh_scm2double (space) ;
     
   Real bdy = interbeam_f;
   Real stemdx = staffline_f;
@@ -668,18 +668,15 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
   Molecule leftbeams;
   Molecule rightbeams;
 
-  /*
-    UGH: make a property of this.
-  */
   Real nw_f;
   if (!Stem::first_head (here))
     nw_f = 0;
   else {
     int t = Stem::type_i (here); 
 
-    SCM proc = me->get_elt_property ("beam-flag-width-function");
+    SCM proc = me->get_elt_property ("flag-width-function");
     SCM result = gh_call1 (proc, gh_int2scm (t));
-    nw_f = gh_scm2double (result) * staffspace;
+    nw_f = gh_scm2double (result);
   }
 
 
@@ -698,7 +695,7 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
       w = w/2 <? nw_f;
       Molecule a;
       if (lhalfs)              // generates warnings if not
-       a =  me->lookup_l ()->beam (dydx, w, thick);
+       a =  Lookup::beam (dydx, w, thick);
       a.translate (Offset (-w, -w * dydx));
       for (int j = 0; j  < lhalfs; j++)
        {
@@ -714,12 +711,12 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
       int rwholebeams= Stem::beam_count (here,RIGHT) <? Stem::beam_count (next,LEFT) ;
 
       Real w = next->relative_coordinate (0, X_AXIS) - here->relative_coordinate (0, X_AXIS);
-      Molecule a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
+      Molecule a = Lookup::beam (dydx, w + stemdx, thick);
       a.translate_axis( - stemdx/2, X_AXIS);
       int j = 0;
       Real gap_f = 0;
 
-      SCM gap = me->get_elt_property ("beam-gap");
+      SCM gap = me->get_elt_property ("gap");
       if (gh_number_p (gap))
        {
          int gap_i = gh_scm2int ( (gap));
@@ -734,7 +731,7 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
          // TODO: notehead widths differ for different types
          gap_f = nw_f / 2;
          w -= 2 * gap_f;
-         a = me->lookup_l ()->beam (dydx, w + stemdx, thick);
+         a = Lookup::beam (dydx, w + stemdx, thick);
        }
 
       for (; j  < rwholebeams; j++)
@@ -746,7 +743,7 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
 
       w = w/2 <? nw_f;
       if (rhalfs)
-       a = me->lookup_l ()->beam (dydx, w, thick);
+       a = Lookup::beam (dydx, w, thick);
 
       for (; j  < rwholebeams + rhalfs; j++)
        {
@@ -765,7 +762,7 @@ Beam::stem_beams (Score_element*me,Item *here, Item *next, Item *prev)
   return leftbeams;
 }
 
-MAKE_SCHEME_CALLBACK(Beam,brew_molecule);
+MAKE_SCHEME_CALLBACK(Beam,brew_molecule,1);
 SCM
 Beam::brew_molecule (SCM smob)
 {
@@ -809,7 +806,7 @@ Beam::brew_molecule (SCM smob)
   mol.translate_axis (x0 
     - dynamic_cast<Spanner*> (me)->get_bound (LEFT)->relative_coordinate (0, X_AXIS), X_AXIS);
 
-  return mol.create_scheme ();
+  return mol.smobbed_copy ();
 }
 
 int
@@ -889,18 +886,22 @@ Beam::last_visible_stem(Score_element*me)
     
     rest -> stem -> beam -> interpolate_y_position ()
 */
-Real
-Beam::rest_collision_callback (Score_element *rest, Axis a )
+MAKE_SCHEME_CALLBACK(Beam,rest_collision_callback,2);
+SCM
+Beam::rest_collision_callback (SCM element_smob, SCM axis)
 {
+  Score_element *rest = unsmob_element (element_smob);
+  Axis a = (Axis) gh_scm2int (axis);
+  
   assert (a == Y_AXIS);
 
   Score_element * st = unsmob_element (rest->get_elt_property ("stem"));
   Score_element * stem = st;
   if (!stem)
-    return 0.0;
+    return gh_double2scm (0.0);
   Score_element * beam = unsmob_element (stem->get_elt_property ("beam"));
   if (!beam || !Beam::has_interface (beam) || !Beam::visible_stem_count (beam))
-    return 0.0;
+    return gh_double2scm (0.0);
 
   // make callback for rest from this.
   Real beam_dy = 0;
@@ -925,7 +926,9 @@ Beam::rest_collision_callback (Score_element *rest, Axis a )
   Real beamy = (stem->relative_coordinate (0, X_AXIS) - x0) * dydx + beam_y;
 
   Real staff_space =   Staff_symbol_referencer::staff_space (rest);
-  Real rest_dim = rest->extent (Y_AXIS)[d]*2.0 / staff_space ;
+
+  
+  Real rest_dim = rest->extent (rest, Y_AXIS)[d]*2.0 / staff_space ; // refp??
 
   Real minimum_dist
     = gh_scm2double (rest->get_elt_property ("minimum-beam-collision-distance"));
@@ -941,7 +944,7 @@ Beam::rest_collision_callback (Score_element *rest, Axis a )
   if (discrete_dist < stafflines+1)
     discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
 
-  return  (-d *  discrete_dist);
+  return gh_double2scm  (-d *  discrete_dist);
 }
 
 
@@ -954,9 +957,6 @@ Beam::has_interface (Score_element*me)
 void
 Beam::set_interface (Score_element*me)
 {
-  Pointer_group_interface g (me, "stems");
-  g.set_interface ();
-
   /*
     why the init? No way to tell difference between default and user
     override.  */