]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem-info.cc
release: 1.0.1
[lilypond.git] / lily / stem-info.cc
index 89cd395c0b66001f3bcff05ea20b8e4fc4012d2c..535cc6f7d771bbbf7a526fa20a68c80cdd6f65d0 100644 (file)
@@ -3,12 +3,12 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+  (c)  1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
 
 */
 
 #include "proto.hh"
-#include "dimen.hh"
+#include "dimension.hh"
 #include "misc.hh"
 #include "debug.hh"
 #include "atom.hh"
@@ -23,14 +23,14 @@ Stem_info::Stem_info ()
 
 Stem_info::Stem_info (Stem const *s)
 {
-  x = s->hpos_f();
+  x_ = s->hpos_f ();
   dir_ = s->dir_;
-  beams_i_ =  0 >? (abs (s->flag_i_) - 2);
+  beam_dir_ = s->beam_dir_;
+  mult_i_ = s->mult_i_;
 
   /*
-    [todo] 
-    * get algorithm
-    * runtime
+    [TODO]
+    make this runtime
 
     Breitkopf + H\"artel:
     miny_f_ = interline + #beams * interbeam
@@ -44,24 +44,87 @@ Stem_info::Stem_info (Stem const *s)
        
     */
 
-  Real notehead_y = s->paper()->interline_f ();
-  // huh? why do i need the / 2
-  //    Real interbeam_f = s->paper()->interbeam_f ();
-  Real interbeam_f = s->paper()->interbeam_f () / 2;
+  Real internote_f = s->paper ()->internote_f ();
+  Real interbeam_f = s->paper ()->interbeam_f (mult_i_);
+  Real beam_f = s->paper ()->beam_thickness_f ();
          
-  /* well eh, huh?
-     idealy_f_  = dir_ * s->stem_start_f() + beams_i_ * interbeam_f; 
-     if (beams_i_ < 3)
-     idealy_f_ += 2 * interline_f;
-     else
-     idealy_f_ += 1.5 * interline_f;
-     */
 
-  idealy_f_  = dir_ * s->stem_end_f();
+  {
+      static int i = 1;
+      DOUT << "******" << i++ << "******\n" 
+          << "begin_f: " << s->stem_begin_f () * dir_ 
+          << "\nchord_f/i: " << s->chord_start_f () * dir_ / internote_f << '\n';
+  }
 
-  miny_f_ = dir_ * s->stem_start_f() + notehead_y + beams_i_ * interbeam_f;
+  /*
+    For simplicity, we'll assume dir = UP and correct if 
+    dir = DOWN afterwards.
+   */
+  idealy_f_ = s->chord_start_f () * beam_dir_ / internote_f;
+  idealy_f_ *= internote_f;
+
+  Real break_i = (int)rint (s->paper ()->get_var ("beam_multiple_break"));
+  Real min_stem1_f = s->paper ()->get_var ("beam_minimum_stem1");
+  Real min_stem2_f = s->paper ()->get_var ("beam_minimum_stem2");
+  Real ideal_stem1_f = s->paper ()->get_var ("beam_ideal_stem1");
+  Real ideal_stem2_f = s->paper ()->get_var ("beam_ideal_stem2");
+  Real shorten_f = s->paper ()->get_var ("forced_stem_shorten");
+
+  if (!beam_dir_ || (beam_dir_ == dir_))
+    {
+      idealy_f_ += interbeam_f * mult_i_;
+      miny_f_ = idealy_f_;
+      maxy_f_ = INT_MAX;
+
+      if (mult_i_ < break_i)
+        {
+         idealy_f_ += ideal_stem1_f;
+         miny_f_ += min_stem1_f;
+       }
+      else
+        {
+         idealy_f_ += ideal_stem2_f;
+         miny_f_ += min_stem2_f;
+       }
+
+      // stems in unnatural (forced) direction are shortened
+      if (s->dir_ != s->get_default_dir ())
+       idealy_f_ -= shorten_f;
+
+      // lowest beam of (UP) beam must never be lower than second staffline
+      miny_f_ = miny_f_ >? (- 2 * internote_f - beam_f
+       + (mult_i_ > 0) * beam_f + interbeam_f * (mult_i_ - 1));
+    }
+  else
+    {
+      idealy_f_ -= beam_f;
+      maxy_f_ = idealy_f_;
+      miny_f_ = -INT_MAX;
+
+      // B"arenreiter
+      if (mult_i_ < break_i)
+        {
+         idealy_f_ -= ideal_stem1_f;
+         maxy_f_ -= min_stem1_f;
+       }
+      else
+        {
+         idealy_f_ -= ideal_stem2_f;
+         maxy_f_ -= min_stem2_f;
+       }
+    }
+
+  idealy_f_ /= internote_f;
+  miny_f_ /= internote_f;
+  maxy_f_ /= internote_f;
+
+  DOUT << "dir_: " << dir_ << '\n';
+  DOUT << "mult_i_: " << mult_i_ << '\n';
+  DOUT << "idealy_f_: " << idealy_f_ << '\n';
+  DOUT << "miny_f_: " << miny_f_ << '\n';
+  DOUT << "maxy_f_: " << maxy_f_ << '\n';
 
-  idealy_f_ =  miny_f_ >? idealy_f_;
-  //    assert (miny_f_ <= idealy_f_);
+  idealy_f_ = maxy_f_ <? idealy_f_;
+  idealy_f_ = miny_f_ >? idealy_f_;
 }