]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
patch::: 1.1.19.jcn5: isb
[lilypond.git] / lily / beam.cc
index fef050e58ba962cf11604b351afe9e8b3df58c42..af118cb5dddc8ee3b339b4cb628278f42ab76822 100644 (file)
@@ -3,27 +3,25 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998, 1998 Han-Wen Nienhuys <hanwen@stack.nl>
-    Jan Nieuwenhuizen <jan@digicash.com>
+  (c)  1997--1998, 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+    Jan Nieuwenhuizen <janneke@gnu.org>
 
 */
 
 
 /*
   [TODO]
-    * lowest beam of (UP) beam must never be lower than second staffline
     * centre beam symbol
     * less hairy code
     * redo grouping 
-    * (future) knee: ([\stem 1; c8 \stem -1; c8]
  */
 
 #include <math.h>
 
 #include "p-col.hh"
-#include "varray.hh"
+#include "array.hh"
 #include "proto.hh"
-#include "dimen.hh"
+#include "dimensions.hh"
 #include "beam.hh"
 #include "abbreviation-beam.hh"
 #include "misc.hh"
 #include "paper-def.hh"
 #include "lookup.hh"
 #include "grouping.hh"
-#include "stem-info.hh"
-#include "main.hh"  // experimental features
-
-
-IMPLEMENT_IS_TYPE_B1 (Beam, Spanner);
 
 Beam::Beam ()
 {
@@ -51,7 +44,7 @@ Beam::Beam ()
 }
 
 void
-Beam::add (Stem*s)
+Beam::add_stem (Stem*s)
 {
   stems_.push (s);
   s->add_dependency (this);
@@ -64,14 +57,10 @@ Beam::add (Stem*s)
 }
 
 Molecule*
-Beam::brew_molecule_p () const
+Beam::do_brew_molecule_p () const
 {
   Molecule *mol_p = new Molecule;
-
-  Real interline_f = paper ()->interline_f ();
-  Real internote_f = interline_f / 2;
-  Real staffline_f = paper ()->rule_thickness ();
-  Real beam_f = 0.48 * (interline_f - staffline_f);
+  Real internote_f = paper ()->internote_f ();
 
   Real x0 = stems_[0]->hpos_f ();
   for (int j=0; j <stems_.size (); j++)
@@ -83,18 +72,22 @@ Beam::brew_molecule_p () const
       Molecule sb = stem_beams (i, next, prev);
       Real  x = i->hpos_f ()-x0;
       sb.translate (Offset (x, (x * slope_f_ + left_y_) * internote_f));
-      mol_p->add (sb);
+      mol_p->add_molecule (sb);
     }
   mol_p->translate_axis (x0 
     - spanned_drul_[LEFT]->absolute_coordinate (X_AXIS), X_AXIS);
 
+  // correct if last note (and therefore reference point of beam)
+  // is on different staff
+  mol_p->translate_axis (- sinfo_.top ().interstaff_f_ * internote_f, Y_AXIS);
+
   return mol_p;
 }
 
 Offset
 Beam::center () const
 {
-  Real w= (paper ()->note_width () + width ().length ())/2.0;
+  Real w= (paper ()->note_width () + extent (X_AXIS).length ())/2.0;
   return Offset (w, (left_y_ + w* slope_f_)*paper ()->internote_f ());
 }
 
@@ -109,7 +102,7 @@ void
 Beam::do_print () const
 {
 #ifndef NPRINT
-  DOUT << "slope_f_ " <<slope_f_ << "left ypos " << left_y_;
+  DOUT << "slope_f_ " << slope_f_ << "left ypos " << left_y_;
   Spanner::do_print ();
 #endif
 }
@@ -119,19 +112,20 @@ Beam::do_post_processing ()
 {
   if (stems_.size () < 2)
     {
-      warning (_ ("Beam with less than 2 stems"));
+      warning (_ ("beam with less than two stems"));
       transparent_b_ = true;
       return ;
     }
-  solve_slope ();
+  calculate_slope ();
   set_stemlens ();
 }
 
 void
-Beam::do_substitute_dependent (Score_elem*o,Score_elem*n)
+Beam::do_substitute_dependent (Score_element*o,Score_element*n)
 {
-  if (o->is_type_b (Stem::static_name ()))
-      stems_.substitute ((Stem*)o->item (),  n? (Stem*) n->item ():0);
+  if (Stem * os = dynamic_cast<Stem*> (o))
+    stems_.substitute (os,
+                      dynamic_cast<Stem *> (n));
 }
 
 Interval
@@ -165,96 +159,205 @@ Beam::set_default_dir ()
 
     } while (flip(&d) != DOWN);
   
-   do {
-    if (!total[d])
-      count[d] = 1;
-  } while (flip(&d) != DOWN);
-  
   /* 
-
      [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.
+     
+     We have our doubts, so we simply provide all sensible alternatives.
   */
-  dir_ = (total[UP] > total[DOWN]) ? UP : DOWN;
+
+  Dir_algorithm a = (Dir_algorithm)rint(paper ()->get_var ("beam_dir_algorithm"));
+  switch (a)
+    {
+    case MAJORITY:
+      dir_ = (count[UP] > count[DOWN]) ? UP : DOWN;
+      break;
+    case MEAN:
+      // mean centre distance
+      dir_ = (total[UP] > total[DOWN]) ? UP : DOWN;
+      break;
+    default:
+    case MEDIAN:
+      // median centre distance
+      if (!count[UP])
+       dir_ = DOWN;
+      else if (!count[DOWN])
+       dir_ = UP;
+      else
+       dir_ = (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+      break;
+    }
 
   for (int i=0; i <stems_.size (); i++)
     {
-      Stem *sl = stems_[i];
-      sl->dir_ = dir_;
+      Stem *s = stems_[i];
+      s->beam_dir_ = dir_;
+      if (!s->dir_forced_b_)
+       s->dir_ = dir_;
     }
 }
 
 /*
   See Documentation/tex/fonts.doc
  */
+
 void
 Beam::solve_slope ()
 {
   /*
     should use minimum energy formulation (cf linespacing)
   */
+  assert (sinfo_.size () > 1);
+  DOUT << "Beam::solve_slope: \n";
+
+  Least_squares l;
+  for (int i=0; i < sinfo_.size (); i++)
+    {
+      l.input.push (Offset (sinfo_[i].x_, sinfo_[i].idealy_f_));
+    }
+  l.minimise (slope_f_, left_y_);
+}
+
+Real
+Beam::check_stemlengths_f (bool set_b)
+{
+  Real interbeam_f = paper ()->interbeam_f (multiple_i_);
+  Real internote_f = paper ()->internote_f (); 
+  Real beam_f = paper ()->beam_thickness_f ();
+  Real staffline_f = paper ()->rule_thickness ();
+  Real epsilon_f = staffline_f / 8;
+  Real dy_f = 0.0;
+  for (int i=0; i < sinfo_.size (); i++)
+    {
+      Real y = sinfo_[i].x_ * slope_f_ + left_y_;
 
+      // correct for knee
+      if (dir_ != sinfo_[i].dir_)
+       {
+         y -= dir_ * (beam_f / 2
+                      + (sinfo_[i].mult_i_ - 1) * interbeam_f) / internote_f;
+         if (!i && sinfo_[i].stem_l_->staff_sym_l_ !=
+             sinfo_.top ().stem_l_->staff_sym_l_)
+           y += dir_ * (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_;
+      if (y > sinfo_[i].maxy_f_)
+       dy_f = dy_f <? sinfo_[i].maxy_f_ - y;
+      if (y < sinfo_[i].miny_f_)
+       { 
+         // when all too short, normal stems win..
+         if (dy_f < -epsilon_f)
+           warning (_ ("weird beam shift, check your knees"));
+         dy_f = dy_f >? sinfo_[i].miny_f_ - y;
+       }
+    }
+  return dy_f;
+}
+
+void
+Beam::set_steminfo ()
+{
   assert (multiple_i_);
-  Array<Stem_info> sinfo;
-  for (int j=0; j <stems_.size (); j++)
+  int total_count_i = 0;
+  int forced_count_i = 0;
+  for (int i=0; i < stems_.size (); i++)
     {
-      Stem *i = stems_[j];
+      Stem *s = stems_[i];
+      s->mult_i_ = multiple_i_;
+      s->set_default_extents ();
+      if (s->invisible_b ())
+       continue;
+      if (((int)s->chord_start_f ()) && (s->dir_ != s->get_default_dir ()))
+        forced_count_i++;
+      total_count_i++;
+    }
 
-      i->mult_i_ = multiple_i_;
-      i->set_default_extents ();
-      if (i->invisible_b ())
+  Real internote_f = paper ()->internote_f ();
+  int stem_max = (int)rint(paper ()->get_var ("stem_max"));
+  Real shorten_f = paper ()->get_var (String ("forced_stem_shorten"
+                                             + to_str (multiple_i_ <? stem_max)))
+    / internote_f;
+    
+  Real leftx = 0;
+  for (int i=0; i < stems_.size (); i++)
+    {
+      Stem *s = stems_[i];
+      if (s->invisible_b ())
        continue;
 
-      Stem_info info (i);
-      sinfo.push (info);
+      Stem_info info (s);
+      if (leftx == 0)
+       leftx = info.x_;
+      info.x_ -= leftx;
+      if (info.dir_ == dir_)
+        {
+         if (forced_count_i == total_count_i)
+           info.idealy_f_ -= shorten_f;
+         else if (forced_count_i > total_count_i / 2)
+           info.idealy_f_ -= shorten_f / 2;
+       }
+      sinfo_.push (info);
     }
-  if (! sinfo.size ())
+}
+
+void
+Beam::calculate_slope ()
+{
+  set_steminfo ();
+  if (!sinfo_.size ())
     slope_f_ = left_y_ = 0;
-  else if (sinfo.size () == 1)
+  else if (sinfo_[0].idealy_f_ == sinfo_.top ().idealy_f_)
     {
       slope_f_ = 0;
-      left_y_ = sinfo[0].idealy_f_;
+      left_y_ = sinfo_[0].idealy_f_;
+      left_y_ *= dir_;
     }
   else
     {
-
-      Real leftx = sinfo[0].x_;
-      Least_squares l;
-      for (int i=0; i < sinfo.size (); i++)
+      solve_slope ();
+      Real solved_slope_f = slope_f_;
+
+      /*
+       steep slope running against lengthened stem is suspect
+      */
+      Real dx_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
+
+      // urg, these y internote-y-dimensions
+      Real internote_f = paper ()->internote_f ();
+      Real lengthened = paper ()->get_var ("beam_lengthened") / internote_f;
+      Real steep = paper ()->get_var ("beam_steep_slope") / internote_f;
+      if (((left_y_ - sinfo_[0].idealy_f_ > lengthened)
+          && (slope_f_ > steep))
+         || ((left_y_ + slope_f_ * dx_f - sinfo_.top ().idealy_f_ > lengthened)
+             && (slope_f_ < -steep)))
        {
-         sinfo[i].x_ -= leftx;
-         l.input.push (Offset (sinfo[i].x_, sinfo[i].idealy_f_));
+         slope_f_ = 0;
        }
 
-      l.minimise (slope_f_, left_y_);
+      /*
+       This neat trick is by Werner Lemberg,
+       damped = tanh (slope_f_)
+       corresponds with some tables in [Wanske]
+      */
+      if (damping_i_)
+       slope_f_ = 0.6 * tanh (slope_f_) / damping_i_;
+      
+      quantise_dy ();
+
+      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_;
     }
-
-  Real dy = 0.0;
-  for (int i=0; i < sinfo.size (); i++)
-    {
-      Real y = sinfo[i].x_ * slope_f_ + left_y_;
-      Real my = sinfo[i].miny_f_;
-
-      if (my - y > dy)
-       dy = my -y;
-    }
-  left_y_ += dy;
-  left_y_ *= dir_;
-
-  slope_f_ *= dir_;
-
-  /*
-    This neat trick is by Werner Lemberg, damped = tanh (slope_f_) corresponds
-    with some tables in [Wanske]
-    */
-  if (damping_i_)
-    slope_f_ = 0.6 * tanh (slope_f_) / damping_i_;
-
-  quantise_dy ();
-
-  Real sl = slope_f_ * paper ()->internote_f ();
-  paper ()->lookup_l ()->beam (sl, 20 PT, 1 PT);
-  slope_f_ = sl / paper ()->internote_f ();
 }
 
 void
@@ -275,7 +378,7 @@ Beam::quantise_dy ()
   Real interline_f = paper ()->interline_f ();
   Real internote_f = interline_f / 2;
   Real staffline_f = paper ()->rule_thickness ();
-  Real beam_f = 0.48 * (interline_f - staffline_f);
+  Real beam_f = paper ()->beam_thickness_f ();
 
   Real dx_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
 
@@ -291,10 +394,10 @@ Beam::quantise_dy ()
   allowed_fraction[2] = (beam_f + staffline_f);
 
 
-    Interval iv = quantise_iv (allowed_fraction, interline_f, dy_f);
-    quanty_f = (dy_f - iv.min () <= iv.max () - dy_f)
-      ? iv.min ()
-      : iv.max ();
+  Interval iv = quantise_iv (allowed_fraction, interline_f, dy_f);
+  quanty_f = (dy_f - iv.min () <= iv.max () - dy_f)
+    ? iv.min ()
+    : iv.max ();
 
 
   slope_f_ = (quanty_f / dx_f) / internote_f * sign (slope_f_);
@@ -330,12 +433,16 @@ Beam::quantise_left_y (bool extend_b)
        hang       straddle   sit        inter      hang
    */
 
-  Real interbeam_f = paper ()->interbeam_f ();
   Real interline_f = paper ()->interline_f ();
-  Real internote_f = interline_f / 2;
+  Real internote_f = paper ()->internote_f ();
   Real staffline_f = paper ()->rule_thickness ();
-  Real beam_f = 0.48 * (interline_f - staffline_f);
-  Real symbol_f = beam_f + interbeam_f * (multiple_i_ - 1);
+  Real beam_f = paper ()->beam_thickness_f ();
+
+  /*
+    [TODO]
+    it would be nice to have all allowed positions in a runtime matrix:
+    (multiplicity, minimum_beam_dy, maximum_beam_dy)
+   */
 
   Real straddle = 0;
   Real sit = beam_f / 2 - staffline_f / 2;
@@ -354,25 +461,28 @@ Beam::quantise_left_y (bool extend_b)
   // dim(left_y_) = internote
   Real dy_f = dir_ * 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 (quantisation_ <= NORMAL) 
        {
-         if ((multiple_i_ <= 2) || (abs (dy_f) >= staffline_f / 2))
+         if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
            allowed_position.push (straddle);
-         if ((multiple_i_ <= 1) || (abs (dy_f) >= staffline_f / 2))
+         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 (dy_f) >= staffline_f / 2))
+         if ((multiple_i_ <= 2) || (abs (beamdy_f) >= staffline_f / 2))
            allowed_position.push (straddle);
-         if ((multiple_i_ <= 1) && (dy_f <= staffline_f / 2))
+         if ((multiple_i_ <= 1) && (beamdy_f <= staffline_f / 2))
            allowed_position.push (sit);
-         if (dy_f >= -staffline_f / 2)
+         if (beamdy_f >= -staffline_f / 2)
            allowed_position.push (hang);
        }
     }
@@ -381,7 +491,7 @@ Beam::quantise_left_y (bool extend_b)
       if (test_pos == 0)
         {
        allowed_position.push (hang);
-       cout << "hang" << hang << endl;
+       cout << "hang" << hang << "\n";
        }
       else if (test_pos==1)
         {
@@ -400,13 +510,6 @@ Beam::quantise_left_y (bool extend_b)
        }
     }
 
-#if 0
-  // this currently never happens
-  Real q = (dy_f / interline_f - dy_i) * interline_f;
-  if ((quantisation_ < NORMAL) && (q < interline_f / 3 - beam_f / 2))
-    allowed_position.push (inter);
-#endif
-
   Interval iv = quantise_iv (allowed_position, interline_f, dy_f);
 
   Real quanty_f = dy_f - iv.min () <= iv.max () - dy_f ? iv.min () : iv.max ();
@@ -420,49 +523,23 @@ Beam::quantise_left_y (bool extend_b)
 void
 Beam::set_stemlens ()
 {
-  Real interbeam_f = paper ()->interbeam_f ();
-  Real interline_f = paper ()->interline_f ();
-  Real internote_f = interline_f / 2;
   Real staffline_f = paper ()->rule_thickness ();
-  Real beam_f = 0.48 * (interline_f - staffline_f);
+  // enge floots
+  Real epsilon_f = staffline_f / 8;
 
-  /*
-    if we have more than three beams they must open-up
-    in order to not collide with staff lines
-   */
-  if (multiple_i_ > 3)
-    interbeam_f += 2.0 * staffline_f / 4;
-
-  Real x0 = stems_[0]->hpos_f ();
-  Real dy = 0;
-  // ugh, rounding problems! (enge floots)
-  Real epsilon = staffline_f / 8;
-  do
+  DOUT << "Beam::set_stemlens: \n";
+  Real dy_f = check_stemlengths_f (false);
+  for (int i = 0; i < 2; i++)
     { 
-      left_y_ += dy * dir_;
-      quantise_left_y (dy);
-      dy = 0;
-      for (int i=0; i < stems_.size (); i++)
-       {
-         Stem *s = stems_[i];
-         if (s->transparent_b_)
-           continue;
-
-         Real x = s->hpos_f () - x0;
-         s->set_stemend (left_y_ + slope_f_ * x);
-         Real y = s->stem_end_f () * dir_;
-         Stem_info info (s);
-         if (y < info.miny_f_)
-           dy = dy >? info.miny_f_ - y;
+      left_y_ += dy_f * dir_;
+      quantise_left_y (dy_f);
+      dy_f = check_stemlengths_f (true);
+      if (abs (dy_f) <= epsilon_f)
+        {
+         DOUT << "Beam::set_stemlens: " << i << " iterations\n";
+         break;
        }
-    } while (abs (dy) > epsilon);
-
-  // ugh asymmetric symbol ?
-  if (dir_ == UP)
-    left_y_ -= dir_ * staffline_f / 4;
-
-  if ((multiple_i_ >= 3) && (dir_ == UP))
-    left_y_ -= dir_ * staffline_f / 4;
+    }
 
   test_pos++;
   test_pos %= 4;
@@ -500,12 +577,17 @@ Beam::set_grouping (Rhythmic_grouping def, Rhythmic_grouping cur)
     assert (stems_.size () == b.size ()/2);
   }
 
-  for (int j=0, i=0; i < b.size () && j <stems_.size (); i+= 2, j++)
+  for (int j=0, i=0; i < b.size () && j <stems_.size (); j++)
     {
       Stem *s = stems_[j];
-      s->beams_left_i_ = b[i];
-      s->beams_right_i_ = b[i+1];
-      multiple_i_ = multiple_i_ >? (b[i] >? b[i+1]);
+      Direction d = LEFT;
+      do {
+       if (s->beams_i_drul_[d] < 0)
+         s->beams_i_drul_[d] = b[i];
+
+       multiple_i_ = multiple_i_ >? s->beams_i_drul_[d];
+       i++;
+      } while ((flip (&d)) != LEFT);
     }
 }
 
@@ -519,46 +601,51 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
   assert (!prev || prev->hpos_f () < here->hpos_f ());
 
   Real staffline_f = paper ()->rule_thickness ();
-  Real interbeam_f = paper ()->interbeam_f ();
-  Real internote_f =paper ()->internote_f (); 
-  Real interline_f = 2 * internote_f;
-  Real beamheight_f = 0.48 * (interline_f - staffline_f);
+  Real interbeam_f = paper ()->interbeam_f (multiple_i_);
+  Real internote_f = paper ()->internote_f (); 
+  Real beam_f = paper ()->beam_thickness_f ();
 
-  if (multiple_i_ > 3)
-    interbeam_f += 2.0 * staffline_f / 4;
   Real dy = interbeam_f;
   Real stemdx = staffline_f;
   Real sl = slope_f_* internote_f;
-  paper ()->lookup_l ()->beam (sl, 20 PT, 1 PT);
+  lookup_l ()->beam (sl, 20 PT, 1 PT);
 
   Molecule leftbeams;
   Molecule rightbeams;
 
+  // UGH
+  Real nw_f = paper ()->note_width () * 0.8;
+
   /* half beams extending to the left. */
   if (prev)
     {
-      int lhalfs= lhalfs = here->beams_left_i_ - prev->beams_right_i_ ;
-      int lwholebeams= here->beams_left_i_ <? prev->beams_right_i_ ;
-      Real w = (here->hpos_f () - prev->hpos_f ())/4 <? paper ()->note_width ();;
+      int lhalfs= lhalfs = here->beams_i_drul_[LEFT] - prev->beams_i_drul_[RIGHT] ;
+      int lwholebeams= here->beams_i_drul_[LEFT] <? prev->beams_i_drul_[RIGHT] ;
+      /*
+       Half beam should be one note-width, 
+       but let's make sure two half-beams never touch
+       */
+      Real w = here->hpos_f () - prev->hpos_f ();
+      w = w/2 <? nw_f;
       Atom a;
       if (lhalfs)              // generates warnings if not
-       a =  paper ()->lookup_l ()->beam (sl, w, beamheight_f);
+       a =  lookup_l ()->beam (sl, w, beam_f);
       a.translate (Offset (-w, -w * sl));
       for (int j = 0; j  < lhalfs; j++)
        {
          Atom b (a);
          b.translate_axis (-dir_ * dy * (lwholebeams+j), Y_AXIS);
-         leftbeams.add (b);
+         leftbeams.add_atom (b);
        }
     }
 
   if (next)
     {
-      int rhalfs = here->beams_right_i_ - next->beams_left_i_;
-      int rwholebeams = here->beams_right_i_ <? next->beams_left_i_;
+      int rhalfs = here->beams_i_drul_[RIGHT] - next->beams_i_drul_[LEFT];
+      int rwholebeams = here->beams_i_drul_[RIGHT] <? next->beams_i_drul_[LEFT];
 
       Real w = next->hpos_f () - here->hpos_f ();
-      Atom a = paper ()->lookup_l ()->beam (sl, w + stemdx, beamheight_f);
+      Atom a = lookup_l ()->beam (sl, w + stemdx, beam_f);
       a.translate_axis( - stemdx/2, X_AXIS);
       int j = 0;
       Real gap_f = 0;
@@ -569,34 +656,34 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
            {
              Atom b (a);
              b.translate_axis (-dir_ * dy * j, Y_AXIS);
-             rightbeams.add (b);
+             rightbeams.add_atom (b);
            }
          // TODO: notehead widths differ for different types
-         gap_f = paper ()->note_width () / 2;
+         gap_f = nw_f / 2;
          w -= 2 * gap_f;
-         a = paper ()->lookup_l ()->beam (sl, w + stemdx, beamheight_f);
+         a = lookup_l ()->beam (sl, w + stemdx, beam_f);
        }
 
       for (; j  < rwholebeams; j++)
        {
          Atom b (a);
          b.translate (Offset (gap_f, -dir_ * dy * j));
-         rightbeams.add (b);
+         rightbeams.add_atom (b);
        }
 
-      w = w/4 <? paper ()->note_width ();
+      w = w/2 <? nw_f;
       if (rhalfs)
-       a = paper ()->lookup_l ()->beam (sl, w, beamheight_f);
+       a = lookup_l ()->beam (sl, w, beam_f);
 
       for (; j  < rwholebeams + rhalfs; j++)
        {
          Atom b (a);
          b.translate_axis (-dir_ * dy * j, Y_AXIS);
-         rightbeams.add (b);
+         rightbeams.add_atom (b);
        }
 
     }
-  leftbeams.add (rightbeams);
+  leftbeams.add_molecule (rightbeams);
 
   /*
     Does beam quanting think  of the asymetry of beams?