]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/beam.cc
release: 1.1.65
[lilypond.git] / lily / beam.cc
index c6ae9c7f896ec8964d66385df1b065e17f0a12b2..64448f2450ab50c96b7dd5e2a1f3cea71212b8a2 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999, 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
     Jan Nieuwenhuizen <janneke@gnu.org>
 
 */
@@ -24,6 +24,7 @@ needs what, and what information should be available when.
 
 #include <math.h>
 
+#include "new-beaming.hh"
 #include "proto.hh"
 #include "dimensions.hh"
 #include "beam.hh"
@@ -34,7 +35,6 @@ needs what, and what information should be available when.
 #include "stem.hh"
 #include "paper-def.hh"
 #include "lookup.hh"
-#include "rhythmic-grouping.hh"
 
 Beam::Beam ()
 {
@@ -170,7 +170,6 @@ Beam::get_default_dir () const
   count[UP]  = count[DOWN] = 0;
   Direction d = DOWN;
 
-  Direction beamdir;
   for (int i=0; i <stems_.size (); i++)
     do {
       Stem *s = stems_[i];
@@ -194,30 +193,42 @@ Beam::get_default_dir () const
      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 ())
   */
 
+  Direction beam_dir;
+  Direction neutral_dir = (int)paper_l ()->get_var ("stem_default_neutral_direction");
+
   Dir_algorithm a = (Dir_algorithm)rint(paper_l ()->get_var ("beam_dir_algorithm"));
   switch (a)
     {
     case MAJORITY:
-      beamdir = (count[UP] > count[DOWN]) ? UP : DOWN;
+      beam_dir = (count[UP] == count[DOWN]) ? neutral_dir 
+        : (count[UP] > count[DOWN]) ? UP : DOWN;
       break;
     case MEAN:
       // mean center distance
-      beamdir = (total[UP] > total[DOWN]) ? UP : DOWN;
+      beam_dir = (total[UP] == total[DOWN]) ? neutral_dir
+        : (total[UP] > total[DOWN]) ? UP : DOWN;
       break;
     default:
     case MEDIAN:
       // median center distance
-      if (!count[UP])
-       beamdir = DOWN;
-      else if (!count[DOWN])
-       beamdir = UP;
+      if (!count[DOWN] || !count[UP])
+        {
+         beam_dir = (count[UP] == count[DOWN]) ? neutral_dir 
+           : (count[UP] > count[DOWN]) ? UP : DOWN;
+       }
       else
-       beamdir = (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+        {
+         beam_dir = (total[UP] / count[UP] == total[DOWN] / count[DOWN]) 
+           ? neutral_dir 
+             : (total[UP] / count[UP] > total[DOWN] / count[DOWN]) ? UP : DOWN;
+       }
       break;
     }
-  return beamdir;
+  return beam_dir;
 }
 
 void
@@ -330,8 +341,11 @@ Beam::set_steminfo ()
   for (int i=0; i < stems_.size (); i++)
     {
       Stem *s = stems_[i];
+#if 0
+      // abbreviation beam needs to beam over invisible stems of wholes
       if (s->invisible_b ())
        continue;
+#endif
 
       Stem_info info (s, multiple_i_);
       if (leftx == 0)
@@ -573,6 +587,8 @@ Beam::set_stemlens ()
   // 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++)
     { 
@@ -589,52 +605,42 @@ Beam::set_stemlens ()
   test_pos %= 4;
 }
 
-/*
- FIXME
- ugh.  this is broken and should be rewritten.
-  - [c8. c32 c32]
- */
 void
-Beam::set_grouping (Rhythmic_grouping def, Rhythmic_grouping cur)
+Beam::set_beaming (Beaming_info_list *beaming)
 {
-  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 (); j++)
+  Direction d = LEFT;
+  for (int i=0; i  < stems_.size (); i++)
+    {
+      do
+       {
+         if (stems_[i]->beams_i_drul_[d] < 0)
+           stems_[i]->beams_i_drul_[d] = beaming->infos_.elem (i).beams_i_drul_[d];
+       }
+      while (flip (&d) != LEFT);
+    }
+}
+
+
+void
+Beam::do_add_processing ()
+{
+  for (int i=0; i < stems_.size () ; i++) 
     {
-      Stem *s = stems_[j];
       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++;
+       multiple_i_ = multiple_i_ >? stems_[i]->beams_i_drul_[d];
       } while ((flip (&d)) != LEFT);
     }
+
+  if (stems_.size ())
+    {
+      stems_[0]->beams_i_drul_[LEFT] =0;
+      stems_.top()->beams_i_drul_[RIGHT] =0;
+    }
 }
 
+
+
 /*
   beams to go with one stem.
   */
@@ -660,7 +666,13 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
   Molecule rightbeams;
 
   // UGH
-  Real nw_f = paper_l ()->note_width () * 0.8;
+  Real nw_f;
+  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;
+  else
+    nw_f = paper_l ()->get_var ("quartwidth");
 
   /* half beams extending to the left. */
   if (prev)
@@ -699,7 +711,7 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
       SCM gap = get_elt_property (beam_gap_scm_sym);
       if (gap != SCM_BOOL_F)
        {
-         int gap_i = gh_scm2int (gap);
+         int gap_i = gh_scm2int (SCM_CDR (gap));
          int nogap = rwholebeams - gap_i;
          
          for (; j  < nogap; j++)
@@ -717,7 +729,10 @@ Beam::stem_beams (Stem *here, Stem *next, Stem *prev) const
       for (; j  < rwholebeams; j++)
        {
          Molecule b (a);
-         b.translate (Offset (gap_f, -dir_ * dy * j));
+         if (!here->invisible_b ())
+           b.translate (Offset (gap_f, -dir_ * dy * j));
+         else
+           b.translate (Offset (0, -dir_ * dy * j));
          rightbeams.add_molecule (b);
        }