]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
release: 0.1.48
[lilypond.git] / lily / beam.cc
index 389226fa7158a8e09e97923ad3e4f9918c16b1d5..cb6159ae09a108f8856bccb66ef86ddb52418f8b 100644 (file)
-#include "varray.hh"
+/*
+  beam.cc -- implement Beam
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+
+  TODO
+
+  Less hairy code.  knee: ([\stem 1; c8 \stem -1; c8]
 
+*/
+
+#include <math.h>
+
+#include "p-col.hh"
+#include "varray.hh"
 #include "proto.hh"
 #include "dimen.hh"
 #include "beam.hh"
+#include "abbreviation-beam.hh"
 #include "misc.hh"
 #include "debug.hh"
-#include "symbol.hh"
+#include "atom.hh"
 #include "molecule.hh"
 #include "leastsquares.hh"
-#include "p-col.hh"
 #include "stem.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);
 
-struct Stem_info {
-    Real x;
-    Real idealy;
-    Real miny;
-    int no_beams;
-
-    
-    Stem_info(){}
-    Stem_info(Stem const *);
+// ugh, hardcoded
+const Real MINIMUM_STEMLEN[] = {
+  0, // just in case
+  5, 
+  4,
+  3,
+  2,
+  2,
 };
 
-Stem_info::Stem_info(Stem const *s)
+Beam::Beam ()
 {
-    x = s->hindex();
-    int dir = s->dir_i_;
-    idealy  = max(dir*s->top, dir*s->bot);
-    miny = max(dir*s->minnote, dir*s-> maxnote);
-    assert(miny <= idealy);
+  slope_f_ = 0;
+  left_y_ = 0.0;
+  damping_i_ = 1;
+  quantisation_ = NORMAL;
+  multiple_i_ = 0;
+}
 
+void
+Beam::add (Stem*s)
+{
+  stems_.push (s);
+  s->add_dependency (this);
+  s->beam_l_ = this;
+
+  if (!spanned_drul_[LEFT])
+    set_bounds (LEFT,s);
+  else
+    set_bounds (RIGHT,s);
 }
 
-/* *************** */
+Molecule*
+Beam::brew_molecule_p () const
+{
+  Molecule *mol_p = new Molecule;
+  Real inter_f = paper ()->internote_f ();
+  Real x0 = stems_[0]->hpos_f ();
+  for (int j=0; j <stems_.size (); j++)
+    {
+      Stem *i = stems_[j];
+      Stem * prev = (j > 0)? stems_[j-1] : 0;
+      Stem * next = (j < stems_.size ()-1) ? stems_[j+1] :0;
+
+      Molecule sb = stem_beams (i, next, prev);
+      Real  x = i->hpos_f ()-x0;
+      sb.translate (Offset (x, (x * slope_f_  + left_y_)* inter_f));
+      mol_p->add (sb);
+    }
+  mol_p->translate_axis (x0 - spanned_drul_[LEFT]->absolute_coordinate (X_AXIS), X_AXIS);
+  return mol_p;
+}
 
 Offset
-Beam::center()const
+Beam::center () const
 {
-    assert(status >= POSTCALCED);
+  Real w= (paper ()->note_width () + width ().length ())/2.0;
+  return Offset (w, (left_y_ + w* slope_f_)*paper ()->internote_f ());
+}
 
-    Real w=(paper()->note_width() + width().length())/2.0;
-    return Offset(w, (left_pos + w* slope)*paper()->internote());
+void
+Beam::do_pre_processing ()
+{
+  if (!dir_)
+    set_default_dir ();
 }
 
+void
+Beam::do_print () const
+{
+#ifndef NPRINT
+  DOUT << "slope_f_ " <<slope_f_ << "left ypos " << left_y_;
+  Spanner::do_print ();
+#endif
+}
 
-Beam::Beam()
+void
+Beam::do_post_processing ()
 {
-    slope = 0;
-    left_pos = 0.0;
+  if (stems_.size () < 2)
+    {
+      warning (_ ("Beam with less than 2 stems"));
+      transparent_b_ = true;
+      return ;
+    }
+  solve_slope ();
+  set_stemlens ();
 }
 
 void
-Beam::add(Stem*s)
+Beam::do_substitute_dependent (Score_elem*o,Score_elem*n)
+{
+  if (o->is_type_b (Stem::static_name ()))
+      stems_.substitute ((Stem*)o->item (),  n? (Stem*) n->item ():0);
+}
+
+Interval
+Beam::do_width () const
 {
-    stems.bottom().add(s);
-    s->add_dependency(this);
-    s->print_flag = false;
+  return Interval (stems_[0]->hpos_f (),
+                  stems_.top ()->hpos_f ());
 }
 
 void
-Beam::set_default_dir()
+Beam::set_default_dir ()
 {
-    int dirs[2];
-    dirs[0]=0; dirs[1] =0;
-    for (iter_top(stems,i); i.ok(); i++) {
-       int d = i->get_default_dir();
-       dirs[(d+1)/2] ++;
-    }
-    dir_i_ =  (dirs[0] > dirs[1]) ? -1 : 1;
-    for (iter_top(stems,i); i.ok(); i++) {
-       i->dir_i_ = dir_i_;
+  Drul_array<int> total;
+  total[UP]  = total[DOWN] = 0;
+  Drul_array<int> count; 
+  count[UP]  = count[DOWN] = 0;
+  Direction d = DOWN;
+  
+  for (int i=0; i <stems_.size (); i++)
+    do {
+      Stem *s = stems_[i];
+      int current = s->dir_ 
+       ? (1 + d * s->dir_)/2
+       : s->get_center_distance (Direction (-d));
+
+      if (current)
+       {
+         total[d] += current;
+         count[d] ++;
+       }
+
+    } while ((d *= -1) != DOWN);
+  
+   do {
+    if (!total[d])
+      count[d] = 1;
+  } while ((d *= -1) != DOWN);
+  
+  /* 
+
+     [Ross] states that the majority of the notes dictates the
+     direction (and not the mean of "center distance")
+  */
+  dir_ = (total[UP] > total[DOWN]) ? UP : DOWN;
+
+  for (int i=0; i <stems_.size (); i++)
+    {
+      Stem *sl = stems_[i];
+      sl->dir_ = dir_;
     }
 }
 
 /*
   should use minimum energy formulation (cf linespacing)
-  */
+*/
 void
-Beam::solve_slope()
+Beam::solve_slope ()
 {
-    Array<Stem_info> sinfo;
-    for (iter_top(stems,i); i.ok(); i++) {
-       i->set_default_extents();
-       Stem_info info(i);
-       sinfo.push(info);
+  Array<Stem_info> sinfo;
+  for (int j=0; j <stems_.size (); j++)
+    {
+      Stem *i = stems_[j];
+
+      i->set_default_extents ();
+      if (i->invisible_b ())
+       continue;
+
+      Stem_info info (i);
+      sinfo.push (info);
     }
-    Real leftx = sinfo[0].x;
-    Least_squares l;
-    for (int i=0; i < sinfo.size(); i++) {
-       sinfo[i].x -= leftx;
-       l.input.push(Offset(sinfo[i].x, sinfo[i].idealy));
+  if (! sinfo.size ())
+    slope_f_ = left_y_ = 0;
+  else if (sinfo.size () == 1)
+    {
+      slope_f_ = 0;
+      left_y_ = sinfo[0].idealy_f_;
     }
+  else
+    {
 
-    l.minimise(slope, left_pos);
-    Real dy = 0.0;
-    for (int i=0; i < sinfo.size(); i++) {
-       Real y = sinfo[i].x * slope + left_pos;
-       Real my = sinfo[i].miny;
+      Real leftx = sinfo[0].x;
+      Least_squares l;
+      for (int i=0; i < sinfo.size (); i++)
+       {
+         sinfo[i].x -= leftx;
+         l.input.push (Offset (sinfo[i].x, sinfo[i].idealy_f_));
+       }
 
-       if (my - y > dy)
-           dy = my -y; 
+      l.minimise (slope_f_, left_y_);
     }
-    left_pos += dy;
-    left_pos *= dir_i_;    
-    slope *= dir_i_;
-
-                               // URG
-    Real sl = slope*paper()->internote();
-    paper()->lookup_l()->beam(sl, 20 PT);
-    slope = sl /paper()->internote();
-}
 
-void
-Beam::set_stemlens()
-{
-    iter_top(stems,s);
-    Real x0 = s->hindex();    
-    for (; s.ok() ; s++) {
-       Real x =  s->hindex()-x0;
-       s->set_stemend(left_pos + slope * x);   
+  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_yspan ();
+
+  // y-values traditionally use internote dimension: therefore slope = (y/in)/x
+  // but mf and beam-lookup use PT dimension for y (as used for x-values)
+  // ugh --- there goes our simplified but careful quantisation
+  Real sl = slope_f_ * paper ()->internote_f ();
+  paper ()->lookup_l ()->beam (sl, 20 PT, 1 PT);
+  slope_f_ = sl / paper ()->internote_f ();
 }
 
-
 void
-Beam::do_post_processing()
+Beam::quantise_yspan ()
 {
-    solve_slope();    
-    set_stemlens();
+  /*
+    [Ross] (simplification of)
+    Try to set slope_f_ complying with y-span of:
+      - zero
+      - beam_thickness / 2 + staffline_thickness / 2
+      - beam_thickness + staffline_thickness
+    + n * interline
+    */
+
+  if (!quantisation_)
+    return;
+
+  Real interline_f = paper ()->interline_f ();
+  Real internote_f = interline_f / 2;
+  Real staffline_thickness = paper ()->rule_thickness ();
+  Real beam_thickness = 0.48 * (interline_f - staffline_thickness);
+
+  const int QUANTS = 3;
+  Real qdy[QUANTS] = {
+    0,
+    beam_thickness / 2 + staffline_thickness / 2,
+    beam_thickness + staffline_thickness
+  };
+
+  Real xspan_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
+  // y-values traditionally use internote dimension: therefore slope = (y/in)/x
+  Real yspan_f = xspan_f * abs (slope_f_ * internote_f);
+  int yspan_i = (int)(yspan_f / interline_f);
+  Real q = (yspan_f / interline_f - yspan_i) * interline_f;
+  int i = 0;
+  for (; i < QUANTS - 1; i++)
+    if ((q >= qdy[i]) && (q <= qdy[i + 1]))
+      {
+       if (q - qdy[i] < qdy[i + 1] - q)
+         break;
+       else
+       { 
+         i++;
+         break;
+       }
+      }
+  q = qdy[i];
+
+  yspan_f = (Real)yspan_i * interline_f + q;
+  // y-values traditionally use internote dimension: therefore slope = (y/in)/x
+  slope_f_ = yspan_f / xspan_f / internote_f * sign (slope_f_);
 }
 
 void
-Beam::set_grouping(Rhythmic_grouping def, Rhythmic_grouping cur)
+Beam::quantise_left_y (Beam::Pos pos, bool extend_b)
 {
-    def.OK();
-    cur.OK();
-    assert(cur.children.size() == stems.size());
-    
-    cur.split(def);
-
-    Array<int> b;
+  /*
+   quantising left y should suffice, as slope is quantised too
+   if extend then stems must not get shorter
+   */
+
+  if (!quantisation_)
+    return;
+
+  Real interline_f = paper ()->interline_f ();
+  Real internote_f = interline_f / 2;
+  Real staffline_thickness = paper ()->rule_thickness ();
+  Real beam_thickness = 0.48 * (interline_f - staffline_thickness);
+
+  const int QUANTS = 7;
+  Real qy[QUANTS] = 
+  {
+    0,
+    beam_thickness / 2,
+    beam_thickness,
+    interline_f / 2 + beam_thickness / 2 + staffline_thickness / 2,
+    interline_f,
+    interline_f + beam_thickness / 2,
+    interline_f + beam_thickness
+  };
+  /* 
+   ugh, using i triggers gcc 2.7.2.1 internal compiler error (far down):
+   for (int i = 0; i < QUANTS; i++)
+   */
+  
+  // fixme!
+  for (int ii = 0; ii < QUANTS; ii++)
+    qy[ii] -= 0.5 *beam_thickness;
+  Pos qpos[QUANTS] = 
+  {
+    HANG,
+    STRADDLE,
+    SIT,
+    INTER,
+    HANG,
+    STRADDLE,
+    SIT
+  };
+
+  // y-values traditionally use internote dimension
+  Real y = left_y_ * internote_f;
+  int y_i = (int)floor(y / interline_f);
+  y = (y / interline_f - y_i) * interline_f;
+
+  if (y < 0)
+    for (int ii = 0; ii < QUANTS; ii++)
+      qy[ii] -= interline_f;
+
+  int lower_i = 0;
+  int i = 0;
+  for (; i < QUANTS; i++)
     {
-       iter_top(stems,s);
-       Array<int> flags;
-       for (; s.ok(); s++) {
-           int f = intlog2(abs(s->flag))-2;
-           assert(f>0);
-           flags.push(f);
-       }
-       int fi =0;
-       b= cur.generate_beams(flags, fi);
-       b.insert(0,0);
-       b.push(0);
-       assert(stems.size() == b.size()/2);
+      if (qy[i] > y)
+       break;
+      // found if lower_i is allowed, and nearer (from below) y than new pos
+      if ((pos & qpos[lower_i]) && (y - qy[lower_i] < y - qy[i]))
+        break;
+      // if new pos is allowed or old pos isn't: assign new pos
+      if ((pos & qpos[i]) || !(pos & qpos[lower_i]))
+       lower_i = i;
     }
 
-    iter_top(stems,s);
-    for (int i=0; i < b.size() && s.ok(); i+=2, s++) {
-       s->beams_left = b[i];
-       s->beams_right = b[i+1];
+  int upper_i = QUANTS - 1;
+  for (i = QUANTS - 1; i >= 0; i--)
+    {
+      if (qy[i] < y)
+       break;
+      // found if upper_i is allowed, and nearer (from above) y than new pos
+      if ((pos & qpos[upper_i]) && (qy[upper_i] - y < qy[i] - y))
+        break;
+      // if new pos is allowed or old pos isn't: assign new pos
+      if ((pos & qpos[i]) || !(pos & qpos[upper_i]))
+       upper_i = i;
     }
-}
 
+  // y-values traditionally use internote dimension
+  Real upper_y = (qy[upper_i] + interline_f * y_i) / internote_f;
+  Real lower_y = (qy[lower_i] + interline_f * y_i) / internote_f;
 
-// todo.
-Spanner *
-Beam::do_break_at( PCol *, PCol *) const
-{
-    Beam *beam_p= new Beam(*this);
-    
-    return beam_p;
+  if (extend_b)
+    left_y_ = (dir_ > 0 ? upper_y : lower_y);
+  else
+    left_y_ = (upper_y - y < y - lower_y ? upper_y : lower_y);
 }
 
 void
-Beam::do_pre_processing()
+Beam::set_stemlens ()
 {
-    left_col_l_ = (*stems.top())   ->pcol_l_;
-    right_col_l_ = (*stems.bottom())->pcol_l_;    
-    assert(stems.size()>1);
-    if (!dir_i_)
-       set_default_dir();
-
+  Real x0 = stems_[0]->hpos_f ();
+  Real dy = 0;
+
+  Real interline_f = paper ()->interline_f ();
+  Real internote_f = interline_f / 2;
+  Real staffline_thickness = paper ()->rule_thickness ();
+  Real beam_thickness = 0.48 * (interline_f - staffline_thickness);
+  Real interbeam_f = paper ()->interbeam_f ();
+  if (multiple_i_ > 3)
+    interbeam_f += 2.0 * staffline_thickness / 4;
+  Real xspan_f = stems_.top ()->hpos_f () - stems_[0]->hpos_f ();
+  /*
+   ugh, y values are in "internote" dimension
+   */
+  Real yspan_f = xspan_f * abs (slope_f_ * internote_f);
+  int yspan_i = (int)(yspan_f / interline_f);
+
+  Pos left_pos = NONE;
+
+  if ((yspan_f < staffline_thickness / 2) || (quantisation_ == NORMAL))
+    left_pos = (Pos)(STRADDLE | SIT | HANG);
+  else
+    left_pos = (Pos) (sign (slope_f_) > 0 ? STRADDLE | HANG 
+      : SIT | STRADDLE);
+
+  /* 
+   ugh, slope currently mangled by availability mf chars...
+   be more generous regarding beam position between stafflines
+   */
+  Real q = (yspan_f / interline_f - yspan_i) * interline_f;
+  if (q < interline_f / 3 - beam_thickness / 2)
+    left_pos = (Pos) (left_pos | INTER);
+
+  if (multiple_i_ > 1)
+    left_pos = (Pos) (dir_ > 0 ? HANG : SIT);
+
+  // ugh, rounding problems!
+  const Real EPSILON = interline_f / 10;
+  do
+    { 
+      left_y_ += dy * dir_;
+      quantise_left_y (left_pos, dy);
+      dy = 0;
+      for (int j=0; j < stems_.size (); j++)
+       {
+         Stem *s = stems_[j];
+         if (s->transparent_b_)
+           continue;
+
+         Real x = s->hpos_f () - x0;
+         s->set_stemend (left_y_ + slope_f_ * x);
+         Real y = s->stem_length_f ();
+         int mult = max (stems_[j]->beams_left_i_, stems_[j]->beams_right_i_);
+         if (mult > 1)
+             // dim(y) = internote
+             y -= (Real)(mult - 1) * interbeam_f / internote_f;
+         if (y < MINIMUM_STEMLEN[mult])
+           dy = dy >? (MINIMUM_STEMLEN[mult] - y);
+       }
+    } while (abs (dy) > EPSILON);
 }
 
-
-Interval
-Beam::do_width() const
+void
+Beam::set_grouping (Rhythmic_grouping def, Rhythmic_grouping cur)
 {
-    Beam * me = (Beam*) this;  // ugh
-    return Interval( (*me->stems.top()) ->hindex(),
-                    (*me->stems.bottom()) ->hindex() );
+  def.OK ();
+  cur.OK ();
+  assert (cur.children.size () == stems_.size ());
+
+  cur.split (def);
+
+  Array<int> b;
+  {
+    Array<int> flags;
+    for (int j=0; j <stems_.size (); j++)
+      {
+       Stem *s = stems_[j];
+
+       int f = s->flag_i_ - 2;
+       assert (f>0);
+       flags.push (f);
+      }
+    int fi =0;
+    b= cur.generate_beams (flags, fi);
+    b.insert (0,0);
+    b.push (0);
+    assert (stems_.size () == b.size ()/2);
+  }
+
+  for (int j=0, i=0; i < b.size () && j <stems_.size (); i+= 2, 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]);
+    }
 }
 
 /*
   beams to go with one stem.
   */
 Molecule
-Beam::stem_beams(Stem *here, Stem *next, Stem *prev)const
+Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
 {
-    assert( !next || next->hindex() > here->hindex()  );
-    assert( !prev || prev->hindex() < here->hindex()  );
-    Real dy=paper()->internote()*2;
-    Real stemdx = paper()->rule_thickness();
-    Real sl = slope*paper()->internote();
-    paper()->lookup_l()->beam(sl, 20 PT);
-
-    Molecule leftbeams;
-    Molecule rightbeams;
-
-    /* half beams extending to the left. */
-    if (prev) {
-       int lhalfs= lhalfs = here->beams_left - prev->beams_right ;
-       int lwholebeams= here->beams_left <? prev->beams_right ;
-       Real w = (here->hindex() - prev->hindex())/4;
-       Symbol dummy;
-       Atom a(dummy);
-       if (lhalfs)             // generates warnings if not
-           a =  paper()->lookup_l()->beam(sl, w);
-       a.translate(Offset (-w, -w * sl));
-       for (int j = 0; j  < lhalfs; j++) {
-           Atom b(a);
-           b.translate(Offset(0, -dir_i_ * dy * (lwholebeams+j)));
-           leftbeams.add( b );
+  assert (!next || next->hpos_f () > here->hpos_f ());
+  assert (!prev || prev->hpos_f () < here->hpos_f ());
+
+  Real staffline_thickness = 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_thickness);
+  if (multiple_i_ > 3)
+    interbeam_f += 2.0 * staffline_thickness / 4;
+  Real dy = interbeam_f;
+  Real stemdx = staffline_thickness;
+  Real sl = slope_f_* internote_f;
+  paper ()->lookup_l ()->beam (sl, 20 PT, 1 PT);
+
+  Molecule leftbeams;
+  Molecule rightbeams;
+
+  /* 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 ();;
+      Atom a;
+      if (lhalfs)              // generates warnings if not
+       a =  paper ()->lookup_l ()->beam (sl, w, beamheight_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);
        }
     }
-       
-    if (next){
-       int rhalfs = here->beams_right - next->beams_left;
-       int rwholebeams = here->beams_right <? next->beams_left; 
-
-       Real w = next->hindex() - here->hindex();
-       Atom a = paper()->lookup_l()->beam(sl, w + stemdx);
-       
-       int j = 0;
-       for (; j  < rwholebeams; j++) {
-           Atom b(a);
-           b.translate(Offset(0, -dir_i_ * dy * j));
-           rightbeams.add( b ); 
-       }
 
-       w /= 4;
-       if (rhalfs)
-           a = paper()->lookup_l()->beam(sl, w);
-       
-       for (; j  < rwholebeams + rhalfs; j++) {
-           Atom b(a);
-           b.translate(Offset(0, -dir_i_ * dy * j));
-           rightbeams.add(b ); 
+  if (next)
+    {
+      int rhalfs = here->beams_right_i_ - next->beams_left_i_;
+      int rwholebeams = here->beams_right_i_ <? next->beams_left_i_;
+
+      Real w = next->hpos_f () - here->hpos_f ();
+      Atom a = paper ()->lookup_l ()->beam (sl, w + stemdx, beamheight_f);
+      a.translate_axis( - stemdx/2, X_AXIS);
+      int j = 0;
+      Real gap_f = 0;
+      if (here->beam_gap_i_)
+       {
+         int nogap = rwholebeams - here->beam_gap_i_;
+         for (; j  < nogap; j++)
+           {
+             Atom b (a);
+             b.translate_axis (-dir_ * dy * j, Y_AXIS);
+             rightbeams.add (b);
+           }
+         // TODO: notehead widths differ for different types
+         gap_f = paper ()->note_width () / 2;
+         w -= 2 * gap_f;
+         a = paper ()->lookup_l ()->beam (sl, w + stemdx, beamheight_f);
        }
-       
-    }
-    leftbeams.add(rightbeams);
-    return leftbeams;
-}
-
-
-Molecule*
-Beam::brew_molecule_p() const return out;
-{
-    Real inter=paper()->internote();
-    out = new Molecule;
-    Real x0 = stems.top()->hindex();
-    
-    for (iter_top(stems,i); i.ok(); i++) {
-       PCursor<Stem*> p(i-1);
-       PCursor<Stem*> n(i+1);
-       Stem * prev = p.ok() ? p.ptr() : 0;
-       Stem * next = n.ok() ? n.ptr() : 0;
-
-       Molecule sb = stem_beams(i, next, prev);
-       Real  x = i->hindex()-x0;
-       sb.translate(Offset(x, (x * slope  + left_pos)* inter));
-       out->add(sb);
-    }
-    out->translate(Offset(x0 - left_col_l_->hpos,0));
-}
 
-IMPLEMENT_STATIC_NAME(Beam);
+      for (; j  < rwholebeams; j++)
+       {
+         Atom b (a);
+         b.translate (Offset (gap_f, -dir_ * dy * j));
+         rightbeams.add (b);
+       }
 
-void
-Beam::do_print()const
-{
-#ifndef NPRINT
-    mtor << "slope " <<slope << "left ypos " << left_pos;
-    Spanner::print();
-#endif
-}
+      w = w/4 <? paper ()->note_width ();
+      if (rhalfs)
+       a = paper ()->lookup_l ()->beam (sl, w, beamheight_f);
 
-Beam::~Beam()
-{
+      for (; j  < rwholebeams + rhalfs; j++)
+       {
+         Atom b (a);
+         b.translate_axis (-dir_ * dy * j, Y_AXIS);
+         rightbeams.add (b);
+       }
 
+    }
+  leftbeams.add (rightbeams);
+
+  /*
+    Does beam quanting think  of the asymetry of beams? 
+    Refpoint is on bottom of symbol. (FIXTHAT) --hwn.
+   */
+  if (experimental_features_global_b && dir_ < 0)
+    leftbeams.translate_axis (-beamheight_f, Y_AXIS);
+  return leftbeams;
 }