]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
release: 1.3.3
[lilypond.git] / lily / beam.cc
index 92a92050a2fc019dcc24bce56191e284d71070c3..0d7b93157f654be423184360cc1270220cad7835 100644 (file)
@@ -24,7 +24,6 @@ needs what, and what information should be available when.
 
 #include <math.h>
 
-#include "chord-tremolo.hh"
 #include "beaming.hh"
 #include "proto.hh"
 #include "dimensions.hh"
@@ -41,7 +40,6 @@ Beam::Beam ()
 {
   slope_f_ = 0;
   left_y_ = 0;
-  quantisation_ = NORMAL;
   multiple_i_ = 0;
 }
 
@@ -130,9 +128,9 @@ Beam::auto_knee (SCM gap, bool interstaff_b)
   bool knee = false;
   int knee_y = 0;
   Real internote_f = stems_[0]->staff_line_leading_f ()/2;
-  if (gap != SCM_BOOL_F)
+  if (gap != SCM_UNDEFINED)
     {
-      int auto_gap_i = gh_scm2int (SCM_CDR (gap));
+      int auto_gap_i = gh_scm2int (gap);
       for (int i=1; i < stems_.size (); i++)
         {
          bool is_b = (bool)(sinfo_[i].interstaff_f_ - sinfo_[i-1].interstaff_f_);
@@ -160,8 +158,8 @@ Beam::auto_knee (SCM gap, bool interstaff_b)
         {
          int y = (int)(stems_[i]->chord_start_f () / internote_f)
            + (int)sinfo_[i].interstaff_f_;
-         stems_[i]->dir_ = y < knee_y ? UP : DOWN;
-         stems_[i]->set_elt_property (dir_forced_scm_sym, SCM_BOOL_T);
+         stems_[i]->set_direction ( y < knee_y ? UP : DOWN);
+         stems_[i]->set_elt_property ("dir-forced", SCM_BOOL_T);
        }
     }
   return knee;
@@ -170,10 +168,10 @@ Beam::auto_knee (SCM gap, bool interstaff_b)
 bool
 Beam::auto_knees ()
 {
-  if (auto_knee (get_elt_property (auto_interstaff_knee_gap_scm_sym), true))
+  if (auto_knee (get_elt_property ("auto-interstaff-knee-gap"), true))
     return true;
   
-  return auto_knee (get_elt_property (auto_knee_gap_scm_sym), false);
+  return auto_knee (get_elt_property ("auto-knee-gap"), false);
 }
 
 
@@ -184,10 +182,10 @@ Beam::do_pre_processing ()
     urg: it seems that info on whether beam (voice) dir was forced
          is being junked here?
   */
-  if (!dir_)
-    dir_ = get_default_dir ();
+  if (!get_direction ())
+    set_direction ( get_default_dir ());
   
-  set_direction (dir_);
+  set_direction (get_direction ());
 }
 
 void
@@ -205,7 +203,7 @@ Beam::do_post_processing ()
   if (stems_.size () < 2)
     {
       warning (_ ("beam with less than two stems"));
-      set_elt_property (transparent_scm_sym, SCM_BOOL_T);
+      set_elt_property ("transparent", SCM_BOOL_T);
       return;
     }
   set_steminfo ();
@@ -215,12 +213,12 @@ Beam::do_post_processing ()
        if auto-knee did its work, most probably stem directions
        have changed, so we must recalculate all.
        */
-      dir_ = get_default_dir ();
-      set_direction (dir_);
+      set_direction ( get_default_dir ());
+      set_direction (get_direction ());
 
       /* auto-knees used to only work for slope = 0
         anyway, should be able to set slope per beam
-         set_elt_property (damping_scm_sym, gh_int2scm(1000));
+         set_elt_property ("damping", gh_int2scm(1000));
       */
 
       sinfo_.clear ();
@@ -257,8 +255,8 @@ Beam::get_default_dir () const
   for (int i=0; i <stems_.size (); i++)
     do {
       Stem *s = stems_[i];
-      int current = s->dir_ 
-       ? (1 + d * s->dir_)/2
+      int current = s->get_direction () 
+       ? (1 + d * s->get_direction ())/2
        : s->get_center_distance ((Direction)-d);
 
       if (current)
@@ -273,60 +271,56 @@ Beam::get_default_dir () const
      [Ross] states that the majority of the notes dictates the
      direction (and not the mean of "center distance")
 
-     But is that because it really looks better, or because he
-     wants to provide some real simple hands-on rules.
+     But is that because it really looks better, or because he wants
+     to provide some real simple hands-on rules?
      
      We have our doubts, so we simply provide all sensible alternatives.
 
-     If dir is not determined: up (see stem::get_default_dir ())
-  */
+     If dir is not determined: up (see stem::get_default_dir ()) */
 
-  Direction beam_dir;
+  Direction beam_dir = CENTER;
   Direction neutral_dir = (Direction)(int)paper_l ()->get_var ("stem_default_neutral_direction");
 
-  Dir_algorithm a = (Dir_algorithm)rint(paper_l ()->get_var ("beam_dir_algorithm"));
-  switch (a)
+  SCM a = get_elt_property ("beam-dir-algorithm");
+  
+  if (a == gh_symbol2scm ("majority")) // should get default from paper.
+    beam_dir = (count[UP] == count[DOWN]) ? neutral_dir 
+      : (count[UP] > count[DOWN]) ? UP : DOWN;
+  else if (a == gh_symbol2scm ("mean"))
+    // mean center distance
+    beam_dir = (total[UP] == total[DOWN]) ? neutral_dir
+      : (total[UP] > total[DOWN]) ? UP : DOWN;
+  else if (a == gh_symbol2scm ("median"))
     {
-    case MAJORITY:
-      beam_dir = (count[UP] == count[DOWN]) ? neutral_dir 
-        : (count[UP] > count[DOWN]) ? UP : DOWN;
-      break;
-    case MEAN:
-      // mean center distance
-      beam_dir = (total[UP] == total[DOWN]) ? neutral_dir
-        : (total[UP] > total[DOWN]) ? UP : DOWN;
-      break;
-    default:
-    case MEDIAN:
       // median center distance
-      if (!count[DOWN] || !count[UP])
-        {
-         beam_dir = (count[UP] == count[DOWN]) ? neutral_dir 
-           : (count[UP] > count[DOWN]) ? UP : DOWN;
-       }
-      else
-        {
+      if (count[DOWN] && count[UP])
+       {
          beam_dir = (total[UP] / count[UP] == total[DOWN] / count[DOWN]) 
            ? neutral_dir 
-             : (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+           : (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+       }
+      else
+       {
+         beam_dir = (count[UP] == count[DOWN]) ? neutral_dir 
+           : (count[UP] > count[DOWN]) ? UP : DOWN;
        }
-      break;
     }
+  
   return beam_dir;
 }
 
 void
 Beam::set_direction (Direction d)
 {
-  dir_ = d;
+  set_direction ( d);
   for (int i=0; i <stems_.size (); i++)
     {
       Stem *s = stems_[i];
-      s->set_elt_property (beam_dir_scm_sym, gh_int2scm (d));
+      s->set_elt_property ("beam-dir", gh_int2scm (d));
 
-      SCM force = s->remove_elt_property (dir_forced_scm_sym);
-      if (force == SCM_BOOL_F)
-       s->dir_ = d;
+      SCM force = s->remove_elt_property ("dir-forced");
+      if (force == SCM_UNDEFINED)
+       s->set_direction ( d);
     }
 }
 
@@ -338,7 +332,6 @@ void
 Beam::solve_slope ()
 {
   assert (sinfo_.size () > 1);
-  DEBUG_OUT << "Beam::solve_slope: \n";
 
   Least_squares l;
   for (int i=0; i < sinfo_.size (); i++)
@@ -357,8 +350,8 @@ Beam::check_stemlengths_f (bool set_b)
 {
   Real interbeam_f = paper_l ()->interbeam_f (multiple_i_);
 
-  Real beam_f = paper_l ()->beam_thickness_f ();
-  Real staffline_f = paper_l ()->rule_thickness ();
+  Real beam_f = paper_l ()->get_var ("beam_thickness");;
+  Real staffline_f = paper_l ()-> get_var ("stafflinethickness");
   Real epsilon_f = staffline_f / 8;
   Real dy_f = 0.0;
   for (int i=0; i < sinfo_.size (); i++)
@@ -366,21 +359,21 @@ Beam::check_stemlengths_f (bool set_b)
       Real y = sinfo_[i].x_ * slope_f_ + left_y_;
 
       // correct for knee
-      if (dir_ != sinfo_[i].dir_)
+      if (get_direction () != sinfo_[i].get_direction ())
        {
          Real internote_f = sinfo_[i].stem_l_->staff_line_leading_f ()/2;
-         y -= dir_ * (beam_f / 2
+         y -= get_direction () * (beam_f / 2
                       + (sinfo_[i].mult_i_ - 1) * interbeam_f) / internote_f;
          if (!i && sinfo_[i].stem_l_->staff_symbol_l () !=
              sinfo_.top ().stem_l_->staff_symbol_l ())
-           y += dir_ * (multiple_i_ - (sinfo_[i].stem_l_->flag_i_ - 2) >? 0)
+           y += get_direction () * (multiple_i_ - (sinfo_[i].stem_l_->flag_i_ - 2) >? 0)
              * interbeam_f / internote_f;
        }
 
       if (set_b)
        sinfo_[i].stem_l_->set_stemend (y - sinfo_[i].interstaff_f_);
        
-      y *= dir_;
+      y *= get_direction ();
       if (y > sinfo_[i].maxy_f_)
        dy_f = dy_f <? sinfo_[i].maxy_f_ - y;
       if (y < sinfo_[i].miny_f_)
@@ -411,12 +404,12 @@ Beam::set_steminfo ()
       s->set_default_extents ();
       if (s->invisible_b ())
        continue;
-      if (((int)s->chord_start_f ()) && (s->dir_ != s->get_default_dir ()))
+      if (((int)s->chord_start_f ()) && (s->get_direction () != s->get_default_dir ()))
         forced_count_i++;
       total_count_i++;
     }
 
-  bool grace_b = get_elt_property (grace_scm_sym) != SCM_BOOL_F;
+  bool grace_b = get_elt_property ("grace") == SCM_BOOL_T;
   String type_str = grace_b ? "grace_" : "";
   int stem_max = (int)rint(paper_l ()->get_var ("stem_max"));
   Real shorten_f = paper_l ()->get_var (type_str + "forced_stem_shorten"
@@ -429,7 +422,8 @@ Beam::set_steminfo ()
       /*
        Chord tremolo needs to beam over invisible stems of wholes
       */
-      if (!dynamic_cast<Chord_tremolo*> (this))
+      SCM trem = get_elt_property ("chord-tremolo");
+      if (gh_boolean_p (trem) && gh_scm2bool (trem))
        {
          if (s->invisible_b ())
            continue;
@@ -439,7 +433,7 @@ Beam::set_steminfo ()
       if (leftx == 0)
        leftx = info.x_;
       info.x_ -= leftx;
-      if (info.dir_ == dir_)
+      if (info.get_direction () == get_direction ())
         {
          if (forced_count_i == total_count_i)
            info.idealy_f_ -= shorten_f;
@@ -459,7 +453,7 @@ Beam::calculate_slope ()
     {
       slope_f_ = 0;
       left_y_ = sinfo_[0].idealy_f_;
-      left_y_ *= dir_;
+      left_y_ *= get_direction ();
     }
   else
     {
@@ -489,10 +483,10 @@ Beam::calculate_slope ()
        damped = tanh (slope_f_)
        corresponds with some tables in [Wanske]
       */
-      SCM damp = remove_elt_property (damping_scm_sym);
+      SCM damp = remove_elt_property ("damping");
       int damping = 1;         // ugh.
-      if (damp!= SCM_BOOL_F)
-       damping = gh_int2scm (SCM_CDR(damp));
+      if (damp!= SCM_UNDEFINED)
+       damping = gh_int2scm (damp);
 
       if (damping)
        slope_f_ = 0.6 * tanh (slope_f_) / damping;
@@ -502,8 +496,8 @@ Beam::calculate_slope ()
       Real damped_slope_dy_f = (solved_slope_f - slope_f_) * dx_f / 2;
       left_y_ += damped_slope_dy_f;
 
-      left_y_ *= dir_;
-      slope_f_ *= dir_;
+      left_y_ *= get_direction ();
+      slope_f_ *= get_direction ();
     }
 }
 
@@ -519,13 +513,15 @@ Beam::quantise_dy ()
     + n * interline
     */
 
-  if (quantisation_ <= NONE)
+  SCM q = get_elt_property ("slope-quantisation");
+  
+  if (q == gh_symbol2scm ("none"))
     return;
 
   Real interline_f = stems_[0]->staff_line_leading_f ();
   Real internote_f = interline_f / 2;
-  Real staffline_f = paper_l ()->rule_thickness ();
-  Real beam_f = paper_l ()->beam_thickness_f ();
+  Real staffline_f = paper_l ()->get_var ("stafflinethickness");
+  Real beam_f = paper_l ()->get_var ("beam_thickness");;
 
   Real dx_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
 
@@ -534,7 +530,6 @@ Beam::quantise_dy ()
   
   Real quanty_f = 0.0;
 
-  /* UGR.   ICE in 2.8.1; bugreport filed. */
   Array<Real> allowed_fraction (3);
   allowed_fraction[0] = 0;
   allowed_fraction[1] = (beam_f / 2 + staffline_f / 2);
@@ -550,9 +545,6 @@ Beam::quantise_dy ()
   slope_f_ = (quanty_f / dx_f) / internote_f * sign (slope_f_);
 }
 
-static int test_pos = 0;
-
-
 /*
   
   Prevent interference from stafflines and beams.  See Documentation/tex/fonts.doc
@@ -565,9 +557,8 @@ Beam::quantise_left_y (bool extend_b)
     we only need to quantise the start of the beam as dy is quantised too
    if extend_b then stems must *not* get shorter
    */
+  SCM q = get_elt_property ("slope-quantisation");
 
-  if (quantisation_ <= NONE)
-    return;
 
   /*
     ----------------------------------------------------------
@@ -582,8 +573,8 @@ Beam::quantise_left_y (bool extend_b)
 
   Real space = stems_[0]->staff_line_leading_f ();
   Real internote_f = space /2;
-  Real staffline_f = paper_l ()->rule_thickness ();
-  Real beam_f = paper_l ()->beam_thickness_f ();
+  Real staffline_f = paper_l ()->get_var ("stafflinethickness");
+  Real beam_f = paper_l ()->get_var ("beam_thickness");;
 
   /*
     [TODO]
@@ -593,7 +584,6 @@ Beam::quantise_left_y (bool extend_b)
 
   Real straddle = 0;
   Real sit = beam_f / 2 - staffline_f / 2;
-  Real inter = space / 2;
   Real hang = space - beam_f / 2 + staffline_f / 2;
 
   /*
@@ -604,59 +594,35 @@ Beam::quantise_left_y (bool extend_b)
     For simplicity, we'll assume dir = UP and correct if 
     dir = DOWN afterwards.
    */
-
+  // isn't this asymmetric ? --hwn
+  
   // dim(left_y_) = internote
-  Real dy_f = dir_ * left_y_ * internote_f;
+  Real dy_f = get_direction () * left_y_ * internote_f;
 
   Real beamdx_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
   Real beamdy_f = beamdx_f * slope_f_ * internote_f;
 
   Array<Real> allowed_position;
-  if (quantisation_ != TEST)
+  if (q == gh_symbol2scm ("normal"))
     {
-      if (quantisation_ <= NORMAL) 
-       {
-         if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
-           allowed_position.push (straddle);
-         if ((multiple_i_ <= 1) || (abs (beamdy_f) >= staffline_f / 2))
-           allowed_position.push (sit);
-         allowed_position.push (hang);
-       }
-      else
-        // TODO: check and fix TRADITIONAL
-       {
-         if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
-           allowed_position.push (straddle);
-         if ((multiple_i_ <= 1) && (beamdy_f <= staffline_f / 2))
-           allowed_position.push (sit);
-         if (beamdy_f >= -staffline_f / 2)
-           allowed_position.push (hang);
-       }
+      if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
+       allowed_position.push (straddle);
+      if ((multiple_i_ <= 1) || (abs (beamdy_f) >= staffline_f / 2))
+       allowed_position.push (sit);
+      allowed_position.push (hang);
     }
-  else
+  else if (q == gh_symbol2scm ("traditional"))
     {
-      if (test_pos == 0)
-        {
-       allowed_position.push (hang);
-       cout << "hang" << hang << "\n";
-       }
-      else if (test_pos==1)
-        {
+      // TODO: check and fix TRADITIONAL
+      if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
        allowed_position.push (straddle);
-       cout << "straddle" << straddle << endl;
-       }
-      else if (test_pos==2)
-        {
+      if ((multiple_i_ <= 1) && (beamdy_f <= staffline_f / 2))
        allowed_position.push (sit);
-       cout << "sit" << sit << endl;
-       }
-      else if (test_pos==3)
-        {
-       allowed_position.push (inter);
-       cout << "inter" << inter << endl;
-       }
+      if (beamdy_f >= -staffline_f / 2)
+       allowed_position.push (hang);
     }
 
+
   Interval iv = quantise_iv (allowed_position, space, dy_f);
 
   Real quanty_f = dy_f - iv[SMALLER] <= iv[BIGGER] - dy_f ? iv[SMALLER] : iv[BIGGER];
@@ -664,22 +630,22 @@ Beam::quantise_left_y (bool extend_b)
     quanty_f = iv[BIGGER];
 
   // dim(left_y_) = internote
-  left_y_ = dir_ * quanty_f / internote_f;
+  left_y_ = get_direction () * quanty_f / internote_f;
 }
 
 void
 Beam::set_stemlens ()
 {
-  Real staffline_f = paper_l ()->rule_thickness ();
+  Real staffline_f = paper_l ()->get_var ("stafflinethickness");
   // enge floots
   Real epsilon_f = staffline_f / 8;
 
 
   // je bent zelf eng --hwn.
   Real dy_f = check_stemlengths_f (false);
-  for (int i = 0; i < 2; i++)
+  for (int i = 0; i < 2; i++)  // 2 ?
     { 
-      left_y_ += dy_f * dir_;
+      left_y_ += dy_f * get_direction ();
       quantise_left_y (dy_f);
       dy_f = check_stemlengths_f (true);
       if (abs (dy_f) <= epsilon_f)
@@ -687,9 +653,6 @@ Beam::set_stemlens ()
          break;
        }
     }
-
-  test_pos++;
-  test_pos %= 4;
 }
 
 void
@@ -730,6 +693,8 @@ Beam::do_add_processing ()
 
 /*
   beams to go with one stem.
+
+  clean  me up.
   */
 Molecule
 Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
@@ -738,16 +703,15 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
       (prev && !(prev->hpos_f () < here->hpos_f ())))
       programming_error ("Beams are not left-to-right");
 
-  Real staffline_f = paper_l ()->rule_thickness ();
+  Real staffline_f = paper_l ()->get_var ("stafflinethickness");
   Real interbeam_f = paper_l ()->interbeam_f (multiple_i_);
 
   Real internote_f = here->staff_line_leading_f ()/2;
-  Real beam_f = paper_l ()->beam_thickness_f ();
+  Real beam_f = paper_l ()->get_var ("beam_thickness");;
 
   Real dy = interbeam_f;
   Real stemdx = staffline_f;
   Real sl = slope_f_* internote_f;
-  lookup_l ()->beam (sl, 20 PT, 1 PT);
 
   Molecule leftbeams;
   Molecule rightbeams;
@@ -759,7 +723,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
   else if (here->type_i ()== 1)
     nw_f = paper_l ()->get_var ("wholewidth");
   else if (here->type_i () == 2)
-    nw_f = paper_l ()->note_width () * 0.8;
+    nw_f = paper_l ()->get_var ("notewidth") * 0.8;
   else
     nw_f = paper_l ()->get_var ("quartwidth");
 
@@ -781,7 +745,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
       for (int j = 0; j  < lhalfs; j++)
        {
          Molecule b (a);
-         b.translate_axis (-dir_ * dy * (lwholebeams+j), Y_AXIS);
+         b.translate_axis (-get_direction () * dy * (lwholebeams+j), Y_AXIS);
          leftbeams.add_molecule (b);
        }
     }
@@ -797,16 +761,16 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
       int j = 0;
       Real gap_f = 0;
 
-      SCM gap = get_elt_property (beam_gap_scm_sym);
-      if (gap != SCM_BOOL_F)
+      SCM gap = get_elt_property ("beam-gap");
+      if (gap != SCM_UNDEFINED)
        {
-         int gap_i = gh_scm2int (SCM_CDR (gap));
+         int gap_i = gh_scm2int ( (gap));
          int nogap = rwholebeams - gap_i;
          
          for (; j  < nogap; j++)
            {
              Molecule b (a);
-             b.translate_axis (-dir_ * dy * j, Y_AXIS);
+             b.translate_axis (-get_direction () * dy * j, Y_AXIS);
              rightbeams.add_molecule (b);
            }
          // TODO: notehead widths differ for different types
@@ -819,9 +783,9 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
        {
          Molecule b (a);
          if (!here->invisible_b ())
-           b.translate (Offset (gap_f, -dir_ * dy * j));
+           b.translate (Offset (gap_f, -get_direction () * dy * j));
          else
-           b.translate (Offset (0, -dir_ * dy * j));
+           b.translate (Offset (0, -get_direction () * dy * j));
          rightbeams.add_molecule (b);
        }
 
@@ -832,7 +796,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
       for (; j  < rwholebeams + rhalfs; j++)
        {
          Molecule b (a);
-         b.translate_axis (-dir_ * dy * j, Y_AXIS);
+         b.translate_axis (-get_direction () * dy * j, Y_AXIS);
          rightbeams.add_molecule (b);
        }
 
@@ -846,3 +810,4 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
   return leftbeams;
 }
 
+