]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
patch::: 1.3.57.jcn2
[lilypond.git] / lily / beam.cc
index 23a62f4a5c4bc9f4a065c371b0554a28bbc0bd26..e131cbc17c176f47794847a9f7f1af67b28e4dd4 100644 (file)
     * less hairy code
     * move paper vars to scm
 
+    remove *-hs variables.
 */
 
 
-#include <math.h>              // tanh.
-
+#include <math.h> // tanh.
 #include "directional-element-interface.hh"
 #include "beaming.hh"
 #include "dimensions.hh"
 #include "group-interface.hh"
 #include "staff-symbol-referencer.hh"
 #include "cross-staff.hh"
-#include "lily-guile.icc"
 
-Beam::Beam ()
+Beam::Beam (SCM s)
+  : Spanner (s)
 {
-  Group_interface g (this, "stems");
+  Pointer_group_interface g (this, "stems");
   g.set_interface ();
+
+  set_elt_property ("height", gh_int2scm (0)); // ugh.
+  set_elt_property ("y-position" ,gh_int2scm (0));
 }
 
 void
 Beam::add_stem (Stem*s)
 {
-  Group_interface gi (this, "stems");
+  Pointer_group_interface gi (this, "stems");
   gi.add_element (s);
   
   s->add_dependency (this);
 
   assert (!s->beam_l ());
-  s->set_elt_property ("beam", self_scm_);
+  s->set_elt_pointer ("beam", self_scm_);
 
   if (!get_bound (LEFT))
     set_bound (LEFT,s);
@@ -60,7 +63,7 @@ int
 Beam::get_multiplicity () const
 {
   int m = 0;
-  for (SCM s = get_elt_property ("stems"); gh_pair_p (s); s = gh_cdr (s))
+  for (SCM s = get_elt_pointer ("stems"); gh_pair_p (s); s = gh_cdr (s))
     {
       Score_element * sc = unsmob_element (gh_car (s));
 
@@ -85,7 +88,7 @@ Beam::before_line_breaking ()
   if (visible_stem_count () < 2)
     {
       warning (_ ("beam has less than two stems"));
-      //      set_elt_property ("transparent", SCM_BOOL_T);
+
     }
 
   if (!directional_element (this).get ())
@@ -232,17 +235,19 @@ Beam::set_stem_shorten ()
     return;
 
   int multiplicity = get_multiplicity ();
+
   // grace stems?
-  SCM shorten = ly_eval_str ("beamed-stem-shorten");
+  SCM shorten = scm_eval (ly_symbol2scm ("beamed-stem-shorten"));
 
-  Array<Real> a;
-  scm_to_array (shorten, &a);
-  if (!a.size ())
+  if (shorten == SCM_EOL)
     return;
 
+  int sz = scm_ilength (shorten);
+  
   Staff_symbol_referencer_interface st (this);
   Real staff_space = st.staff_space ();
-  Real shorten_f = a[multiplicity <? (a.size () - 1)] * staff_space;
+  SCM shorten_elt = scm_list_ref (shorten, gh_int2scm (multiplicity <? (sz - 1)));
+  Real shorten_f = gh_scm2double (shorten_elt) * staff_space;
 
   /* cute, but who invented this -- how to customise ? */
   if (forced_fraction < 1)
@@ -267,7 +272,7 @@ Beam::after_line_breaking ()
 {
   /* first, calculate y, dy */
   Real y, dy;
-  calc_position_and_height (&y, &dy);
+  calc_default_position_and_height (&y, &dy);
   if (visible_stem_count ())
     {
       if (suspect_slope_b (y, dy))
@@ -335,9 +340,10 @@ Beam::after_line_breaking ()
   See Documentation/tex/fonts.doc
  */
 void
-Beam::calc_position_and_height (Real* y, Real* dy) const
+Beam::calc_default_position_and_height (Real* y, Real* dy) const
 {
-  *y = *dy = 0;
+  *y = 0;
+  *dy = 0;  
   if (visible_stem_count () <= 1)
     return;
 
@@ -417,6 +423,8 @@ Real
 Beam::calc_stem_y_f (Stem* s, Real y, Real dy) const
 {
   Real thick = gh_scm2double (get_elt_property ("beam-thickness"));
+  thick *= paper_l ()->get_var ("staffspace");
+  
   int beam_multiplicity = get_multiplicity ();
   int stem_multiplicity = (s->flag_i () - 2) >? 0;
 
@@ -511,10 +519,10 @@ Beam::set_stem_length (Real y, Real dy)
 Real
 Beam::quantise_dy_f (Real dy) const
 {
-  SCM quants = ly_eval_str ("beam-height-quants");
-
   Array<Real> a;
-  scm_to_array (quants, &a);
+  for (SCM s = scm_eval (ly_symbol2scm ("beam-height-quants")); s !=SCM_EOL; s = gh_cdr (s))
+    a.push (gh_scm2double (gh_car (s)));
+  
   if (a.size () <= 1)
     return dy;
 
@@ -543,13 +551,16 @@ Beam::quantise_y_f (Real y, Real dy, int quant_dir)
   int multiplicity = get_multiplicity ();
   Staff_symbol_referencer_interface st (this);
   Real staff_space = st.staff_space ();
-  SCM quants = scm_eval (gh_list (
-                                 ly_symbol2scm ("beam-vertical-position-quants"),
+  SCM quants = scm_eval (gh_list (ly_symbol2scm ("beam-vertical-position-quants"),
                                  gh_int2scm (multiplicity),
                                  gh_double2scm (dy/staff_space),
                                  SCM_UNDEFINED));
+
   Array<Real> a;
-  scm_to_array (quants, &a);
+
+  for (; quants != SCM_EOL; quants = gh_cdr (quants))
+    a.push (gh_scm2double (gh_car (quants)));
+
   if (a.size () <= 1)
     return y;
 
@@ -595,12 +606,13 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
       programming_error ("Beams are not left-to-right");
 
   Real staffline_f = paper_l ()->get_var ("stafflinethickness");
-  int   multiplicity = get_multiplicity ();
+  int multiplicity = get_multiplicity ();
 
 
   Real interbeam_f = paper_l ()->interbeam_f (multiplicity);
   Real thick = gh_scm2double (get_elt_property ("beam-thickness"));
-
+  thick *= paper_l ()->get_var ("staffspace");
+    
   Real bdy = interbeam_f;
   Real stemdx = staffline_f;
 
@@ -707,6 +719,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
   return leftbeams;
 }
 
+MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS (Beam);
 
 Molecule 
 Beam::do_brew_molecule () const
@@ -765,8 +778,6 @@ Beam::forced_stem_count () const
   return f;
 }
 
-
-
 /*
   TODO: Fix this class. This is wildly inefficient.
   And it sux.  Yet another array/list 'interface'.
@@ -774,24 +785,22 @@ Beam::forced_stem_count () const
 Stem *
 Beam::stem (int i) const
 {
-  return Group_interface__extract_elements ((Beam*) this, (Stem*) 0, "stems")[i];
+  return Pointer_group_interface__extract_elements ((Beam*) this, (Stem*) 0, "stems")[i];
 }
 
 int
 Beam::stem_count () const
 {
-  Group_interface gi (this, "stems");
+  Pointer_group_interface gi (this, "stems");
   return gi.count ();
 }
 
 Stem*
 Beam::stem_top () const
 {
-  SCM s = get_elt_property ("stems");
+  SCM s = get_elt_pointer ("stems");
   
   return gh_pair_p (s) ? dynamic_cast<Stem*> (unsmob_element (gh_car (s))) : 0;
-    
-  //Group_interface__extract_elements ((Beam*) this, (Stem*) 0, "stems")[stem_count () - 1];
 }
 
 /* burp */