]> git.donarmstrong.com Git - lilypond.git/commitdiff
patch::: 1.3.10.jcn2
authorJan Nieuwenhuizen <janneke@gnu.org>
Thu, 9 Dec 1999 16:08:28 +0000 (17:08 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Thu, 9 Dec 1999 16:08:28 +0000 (17:08 +0100)
pl 10.jcn2
- fixes for invisible beamed stems
- removed steminfo from properties, don't cache Stem_info

CHANGES
VERSION
lily/beam.cc
lily/include/beam.hh
lily/include/stem-info.hh
lily/include/stem.hh
lily/stem.cc

diff --git a/CHANGES b/CHANGES
index 9e4c61e8a05540db08a37b090631d1a512b20989..972c92ac2d25ce1dc2e4f4a3f4f56c27181fcb4a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+pl 10.jcn2
+       - fixes for invisible beamed stems
+       - removed steminfo from properties, don't cache Stem_info
+
 pl 10.jcn1
        - steminfo to properties
        - dropped internote dim for stem-beams
diff --git a/VERSION b/VERSION
index 48ade71e1d508f3697654a119152bd83b4b02194..130506112a7a310539b8431659977c6952242b08 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond
 MAJOR_VERSION=1
 MINOR_VERSION=3
 PATCH_LEVEL=10
-MY_PATCH_LEVEL=jcn1
+MY_PATCH_LEVEL=jcn2
 
 # use the above to send patches: MY_PATCH_LEVEL is always empty for a
 # released version.
index c8c1dd022948e942dc795c0dae17ff46206d0062..146a47218d5f8c28c1fde6170aec58d21b95456a 100644 (file)
   [TODO]
     * center beam symbol
     * less hairy code
-    * redo grouping 
-
-TODO:
-
-The relationship Stem <-> Beam is way too hairy.  Let's figure who
-needs what, and what information should be available when.
 
     */
 
@@ -36,6 +30,7 @@ needs what, and what information should be available when.
 #include "paper-def.hh"
 #include "lookup.hh"
 #include "group-interface.hh"
+#include "cross-staff.hh"
 
 Beam::Beam ()
 {
@@ -69,6 +64,48 @@ Beam::stem_top ()const
   return Group_interface__extract_elements ((Beam*) this, (Stem*) 0, "stems")[stem_count () - 1];
 }
 
+/* burp */
+int
+Beam::visible_stem_count () const
+{
+  int c = 0;
+  for (int i = 0; i < stem_count (); i++)
+    {
+      if (!stem (i)->invisible_b ())
+        c++;
+    }
+  return c;
+}
+
+Stem*
+Beam::first_visible_stem () const
+{
+  for (int i = 0; i < stem_count (); i++)
+    {
+      Stem* s = stem (i);
+      if (!s->invisible_b ())
+        return s;
+    }
+
+  assert (0);
+  // sigh
+  return 0;
+}
+
+Stem*
+Beam::last_visible_stem () const
+{
+  for (int i = stem_count (); i > 0; i--)
+    {
+      Stem* s = stem (i - 1);
+      if (!s->invisible_b ())
+        return s;
+    }
+
+  assert (0);
+  // sigh
+  return 0;
+}
 
 void
 Beam::add_stem (Stem*s)
@@ -94,7 +131,7 @@ Beam::do_brew_molecule_p () const
   if (!stem_count ())
     return mol_p;
   
-  Real x0 = stem (0)->hpos_f ();
+  Real x0 = first_visible_stem ()->hpos_f ();
   for (int j=0; j <stem_count (); j++)
     {
       Stem *i = stem (j);
@@ -115,7 +152,7 @@ Beam::do_brew_molecule_p () const
 Offset
 Beam::center () const
 {
-  Real w = (stem (0)->note_delta_f () + extent (X_AXIS).length ())/2.0;
+  Real w = (first_visible_stem ()->note_delta_f () + extent (X_AXIS).length ())/2.0;
   return Offset (w, w * slope_f_);
 }
 
@@ -133,11 +170,12 @@ Beam::auto_knee (SCM gap, bool interstaff_b)
       int auto_gap_i = gh_scm2int (gap);
       for (int i=1; i < stem_count (); i++)
         {
-         bool is_b = (bool)(stem (i)->get_real ("interstaff-f") - stem (i-1)->get_real ("interstaff-f"));
+         bool is_b = (bool)(calc_interstaff_dist (stem (i), this) 
+           - calc_interstaff_dist (stem (i-1), this));
          int l_y = (int)(stem (i-1)->chord_start_f ())
-           + (int)stem (i-1)->get_real ("interstaff-f");
+           + (int)calc_interstaff_dist (stem (i-1), this);
          int r_y = (int)(stem (i)->chord_start_f ())
-           + (int)stem (i)->get_real ("interstaff-f");
+           + (int)calc_interstaff_dist (stem (i), this);
          int gap_i = r_y - l_y;
 
          /*
@@ -157,7 +195,7 @@ Beam::auto_knee (SCM gap, bool interstaff_b)
       for (int i=0; i < stem_count (); i++)
         {
          int y = (int)(stem (i)->chord_start_f ())
-           + (int)stem (i)->get_real ("interstaff-f");
+           + (int)calc_interstaff_dist (stem (i), this);
          stem (i)->set_direction ( y < knee_y ? UP : DOWN);
          stem (i)->set_elt_property ("dir-forced", SCM_BOOL_T);
        }
@@ -200,13 +238,13 @@ Beam::do_print () const
 void
 Beam::do_post_processing ()
 {
-  if (stem_count () < 2)
+  if (visible_stem_count () < 2)
     {
       warning (_ ("beam with less than two stems"));
       set_elt_property ("transparent", SCM_BOOL_T);
       return;
     }
-  beamify_stems ();
+  set_stem_shorten ();
   if (auto_knees ())
     {
       /*
@@ -221,7 +259,7 @@ Beam::do_post_processing ()
          set_elt_property ("damping", gh_int2scm(1000));
       */
 
-      beamify_stems ();
+      set_stem_shorten ();
     }
   calculate_slope ();
   set_stemlens ();
@@ -325,14 +363,16 @@ Beam::set_direction (Direction d)
 void
 Beam::solve_slope ()
 {
-  assert (stem_count () > 1);
+  assert (visible_stem_count () > 1);
 
   Least_squares l;
-  Real x0 = stem (0)->hpos_f ();
+  Real x0 = first_visible_stem ()->hpos_f ();
   for (int i=0; i < stem_count (); i++)
     {
-      l.input.push (Offset (stem (i)->hpos_f () - x0, 
-        stem (i)->get_real ("idealy-f")));
+      Stem* s = stem (i);
+      if (s->invisible_b ())
+        continue;
+      l.input.push (Offset (s->hpos_f () - x0, s->get_info ().idealy_f_));
     }
   l.minimise (slope_f_, left_y_);
 }
@@ -340,7 +380,6 @@ Beam::solve_slope ()
 /*
   ugh. Naming: this doesn't check, but sets as well.
  */
-  
 Real
 Beam::check_stemlengths_f (bool set_b)
 {
@@ -350,44 +389,48 @@ Beam::check_stemlengths_f (bool set_b)
   Real staffline_f = paper_l ()-> get_var ("stafflinethickness");
   Real epsilon_f = staffline_f / 8;
   Real dy_f = 0.0;
-  Real x0 = stem (0)->hpos_f ();
+  Real x0 = first_visible_stem ()->hpos_f ();
   Real internote_f = paper_l ()->get_var ("interline");
   for (int i=0; i < stem_count (); i++)
     {
-      Real y = (stem (i)->hpos_f () - x0) * slope_f_ + left_y_;
+      Stem* s = stem (i);
+      if (s->invisible_b ())
+       continue;
+      Real y = (s->hpos_f () - x0) * slope_f_ + left_y_;
+      Stem_info info = s->get_info ();
 
       // correct for knee
-      if (get_direction () != stem (i)->get_direction ())
+      if (get_direction () != s->get_direction ())
        {
          y -= get_direction () * (beam_f / 2
            + (multiplicity_i_ - 1) * interbeam_f);
          if (!i
-           && stem (i)->staff_symbol_l () != stem_top ()->staff_symbol_l ())
-           y += get_direction () * (multiplicity_i_ - (stem (i)->flag_i_ - 2) >? 0)
+           && s->staff_symbol_l () != stem_top ()->staff_symbol_l ())
+           y += get_direction () * (multiplicity_i_ - (s->flag_i_ - 2) >? 0)
              * interbeam_f;
        }
 
       /* caution: stem measures in staff-positions */
       if (set_b)
-       stem (i)->set_stemend ((y - stem (i)->get_real ("interstaff-f"))
+       s->set_stemend ((y - calc_interstaff_dist (s, this))
                               / internote_f);
        
       y *= get_direction ();
-      if (y > stem (i)->get_real ("maxy-f"))
-       dy_f = dy_f <? stem (i)->get_real ("maxy-f") - y;
-      if (y < stem (i)->get_real ("miny-f"))
+      if (y > info.maxy_f_)
+       dy_f = dy_f <? info.maxy_f_ - y;
+      if (y < info.miny_f_)
        { 
          // when all too short, normal stems win..
          if (dy_f < -epsilon_f)
            warning (_ ("weird beam vertical offset"));
-         dy_f = dy_f >? stem (i)->get_real ("miny-f") - y; 
+         dy_f = dy_f >? info.miny_f_ - y; 
        }
     }
   return dy_f;
 }
 
 void
-Beam::beamify_stems ()
+Beam::set_stem_shorten ()
 {
   if(!stem_count ())
     return;
@@ -428,13 +471,12 @@ Beam::beamify_stems ()
            continue;
        }
 
-      s->beamify ();
       if (s->get_direction () == get_direction ())
         {
          if (forced_count_i == total_count_i)
-           s->set_real ("idealy-f", s->get_real ("idealy-f") - shorten_f);
+           s->set_real ("shorten", shorten_f);
          else if (forced_count_i > total_count_i / 2)
-           s->set_real ("idealy-f", s->get_real ("idealy-f") - shorten_f/2);
+           s->set_real ("shorten", shorten_f/2);
        }
     }
 }
@@ -444,10 +486,10 @@ Beam::calculate_slope ()
 {
   if (!stem_count ())
     slope_f_ = left_y_ = 0;
-  else if (stem (0)->get_real ("idealy-f") == stem_top ()->get_real ("idealy-f"))
+  else if (first_visible_stem ()->get_info ().idealy_f_ == last_visible_stem ()->get_info ().idealy_f_)
     {
       slope_f_ = 0;
-      left_y_ = stem (0)->get_real ("idealy-f");
+      left_y_ = first_visible_stem ()->get_info ().idealy_f_;
       left_y_ *= get_direction ();
     }
   else
@@ -458,13 +500,13 @@ Beam::calculate_slope ()
       /*
        steep slope running against lengthened stem is suspect
       */
-      Real dx_f = stem (stem_count () -1)->hpos_f () - stem (0)->hpos_f ();
+      Real dx_f = stem (stem_count () -1)->hpos_f () - first_visible_stem ()->hpos_f ();
 
       Real lengthened = paper_l ()->get_var ("beam_lengthened");
       Real steep = paper_l ()->get_var ("beam_steep_slope");
-      if (((left_y_ - stem (0)->get_real ("idealy-f") > lengthened)
+      if (((left_y_ - first_visible_stem ()->get_info ().idealy_f_ > lengthened)
           && (slope_f_ > steep))
-         || ((left_y_ + slope_f_ * dx_f - stem_top ()->get_real ("idealy-f") > lengthened)
+         || ((left_y_ + slope_f_ * dx_f - last_visible_stem ()->get_info ().idealy_f_ > lengthened)
              && (slope_f_ < -steep)))
        {
          slope_f_ = 0;
@@ -514,7 +556,7 @@ Beam::quantise_dy ()
   Real staffline_f = paper_l ()->get_var ("stafflinethickness");
   Real beam_f = gh_scm2double (get_elt_property ("beam-thickness"));;
 
-  Real dx_f = stem (stem_count () -1 )->hpos_f () - stem (0)->hpos_f ();
+  Real dx_f = stem (stem_count () -1 )->hpos_f () - first_visible_stem ()->hpos_f ();
 
   Real dy_f = dx_f * abs (slope_f_);
   
@@ -585,7 +627,7 @@ Beam::quantise_left_y (bool extend_b)
   
   Real dy_f = get_direction () * left_y_;
 
-  Real beamdx_f = stem (stem_count () -1)->hpos_f () - stem (0)->hpos_f ();
+  Real beamdx_f = stem (stem_count () -1)->hpos_f () - first_visible_stem ()->hpos_f ();
   Real beamdy_f = beamdx_f * slope_f_;
 
   Array<Real> allowed_position;
@@ -667,6 +709,7 @@ Beam::do_add_processing ()
       } while ((flip (&d)) != LEFT);
     }
 
+#if 0
   /*
     Why?
    */
@@ -675,6 +718,7 @@ Beam::do_add_processing ()
       stem (0)->beams_i_drul_[LEFT] =0;
       stem (stem_count () -1)->beams_i_drul_[RIGHT] =0;
     }
+#endif
 }
 
 
index 67c443eee616eebe9409382fcfda9504309484ec..d3d3c71afd089c50f6567e5a5270393a4226f70c 100644 (file)
@@ -28,9 +28,12 @@ slope_quantisation: 'none, 'normal or 'traditional
 class Beam : public Directional_spanner  {
 public:
 
-  int stem_count ()const;
-  Stem * stem (int )const;
-  Stem* Beam::stem_top ()const;
+  int stem_count () const;
+  Stem* stem (int) const;
+  Stem* stem_top () const;
+  int visible_stem_count () const;
+  Stem* first_visible_stem () const;
+  Stem* last_visible_stem () const;
 
   /**
      the slope of the beam in (staffpositions) per (X-dimension, in PT).
@@ -59,7 +62,7 @@ protected:
   Offset center () const;
   Direction get_default_dir () const;
   void set_direction (Direction);
-  void beamify_stems ();
+  void set_stem_shorten ();
   bool auto_knee (SCM gap, bool interstaff_b);
   bool auto_knees ();
   
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..096671a6d5faacaeba3aa88ab9e8f772c90bf16b 100644 (file)
@@ -0,0 +1,22 @@
+/*
+  stem-info.hh -- declare Stem_info
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--1999 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+
+#ifndef STEM_INFO_HH
+#define STEM_INFO_HH
+
+#include "real.hh"
+
+struct Stem_info 
+{
+  Real idealy_f_;
+  Real miny_f_;
+  Real maxy_f_;
+};
+
+#endif // STEM_INFO_HH
index 6f6fd757829d57aa57de0ef0a928939e5c61318f..3f4a19197b96bbd166a5da255cbbbaafd006ddd8 100644 (file)
@@ -12,6 +12,7 @@
 #include "molecule.hh"
 #include "staff-symbol-referencer.hh"
 #include "directional-element.hh"
+#include "stem-info.hh"
 
 /**the rule attached to the ball.
   takes care of:
@@ -69,7 +70,7 @@ public:
     
   /// ensure that this Stem also encompasses the Notehead #n#
   void add_head (Rhythmic_head*n);
-  void beamify ();
+  Stem_info get_info () const;
 
   Real hpos_f () const;
   Real chord_start_f () const;
index 74b92dd89d2f7c7fd16594571617e25b09e6bb36..9f9ab098e9bc3f9d0975fb2c826b2dfcad13f320 100644 (file)
@@ -402,23 +402,16 @@ Stem::beam_l ()const
 }
 
 
-/*
-  stupid name: we're calculating and setting (caching??)
-  some stem length parameters for beamed stem
-*/
-void
-Stem::beamify ()
+Stem_info
+Stem::get_info () const
 {
   assert (beam_l ());
 
-  SCM bd = remove_elt_property ("beam-dir");
+  SCM bd = get_elt_property ("beam-dir");
   Real internote_f = staff_line_leading_f ()/2;
   
   Direction beam_dir;
-  Real idealy_f;
-  Real interstaff_f;
-  Real maxy_f;
-  Real miny_f;
+  Stem_info info; 
 
   if (gh_number_p (bd))
     {
@@ -433,10 +426,10 @@ Stem::beamify ()
   Real interbeam_f = paper_l ()->interbeam_f (beam_l ()->multiplicity_i_);
   Real beam_f = gh_scm2double (beam_l ()->get_elt_property ("beam-thickness"));
          
-  idealy_f = chord_start_f ();
+  info.idealy_f_ = chord_start_f ();
 
   // for simplicity, we calculate as if dir == UP
-  idealy_f *= beam_dir;
+  info.idealy_f_ *= beam_dir;
 
   bool grace_b = get_elt_property ("grace") != SCM_UNDEFINED;
   bool no_extend_b = get_elt_property ("no-stem-extend") != SCM_UNDEFINED;
@@ -453,14 +446,14 @@ Stem::beamify ()
     {
       if (beam_l ()->multiplicity_i_)
        {
-         idealy_f += beam_f;
-         idealy_f += (beam_l ()->multiplicity_i_ - 1) * interbeam_f;
+         info.idealy_f_ += beam_f;
+         info.idealy_f_ += (beam_l ()->multiplicity_i_ - 1) * interbeam_f;
        }
-      miny_f = idealy_f;
-      maxy_f = INT_MAX;
+      info.miny_f_ = info.idealy_f_;
+      info.maxy_f_ = INT_MAX;
 
-      idealy_f += stem_f;
-      miny_f += min_stem_f;
+      info.idealy_f_ += stem_f;
+      info.miny_f_ += min_stem_f;
 
       /*
        lowest beam of (UP) beam must never be lower than second staffline
@@ -475,34 +468,35 @@ Stem::beamify ()
       if (!grace_b && !no_extend_b)
        {
          //highest beam of (UP) beam must never be lower than middle staffline
-         miny_f = miny_f >? 0;
+         info.miny_f_ = info.miny_f_ >? 0;
          //lowest beam of (UP) beam must never be lower than second staffline
-         miny_f = miny_f >? (- 2 * internote_f - beam_f
+         info.miny_f_ = info.miny_f_ >? (- 2 * internote_f - beam_f
                                + (beam_l ()->multiplicity_i_ > 0) * beam_f + interbeam_f * (beam_l ()->multiplicity_i_ - 1));
        }
     }
   else
     /* knee */
     {
-      idealy_f -= beam_f;
-      maxy_f = idealy_f;
-      miny_f = -INT_MAX;
+      info.idealy_f_ -= beam_f;
+      info.maxy_f_ = info.idealy_f_;
+      info.miny_f_ = -INT_MAX;
 
-      idealy_f -= stem_f;
-      maxy_f -= min_stem_f;
+      info.idealy_f_ -= stem_f;
+      info.maxy_f_ -= min_stem_f;
     }
 
-  idealy_f = maxy_f <? idealy_f;
-  idealy_f = miny_f >? idealy_f;
+  info.idealy_f_ = info.maxy_f_ <? info.idealy_f_;
+  info.idealy_f_ = info.miny_f_ >? info.idealy_f_;
+
+  Real interstaff_f = calc_interstaff_dist (this, beam_l ());
+  info.idealy_f_ += interstaff_f * beam_dir;
 
-  interstaff_f = calc_interstaff_dist (this, beam_l ());
-  idealy_f += interstaff_f * beam_dir;
-  miny_f += interstaff_f * beam_dir;
-  maxy_f += interstaff_f * beam_dir;
+  SCM s = get_elt_property ("shorten");
+  if (s != SCM_UNDEFINED)
+    info.idealy_f_ -= gh_double2scm (s);
+  info.miny_f_ += interstaff_f * beam_dir;
+  info.maxy_f_ += interstaff_f * beam_dir;
 
-  set_elt_property ("interstaff-f", gh_double2scm (interstaff_f));
-  set_elt_property ("idealy-f", gh_double2scm (idealy_f));
-  set_elt_property ("miny-f", gh_double2scm (miny_f));
-  set_real ("maxy-f", gh_double2scm (maxy_f));
+  return info;
 }