]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem-info.cc
release: 1.2.4
[lilypond.git] / lily / stem-info.cc
index 34aadfc976d97f32723a55776f5e433f20e33d31..930130da2bb0f96ec120d147d5088e5dab5886fc 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+  (c)  1997--1999 Jan Nieuwenhuizen <janneke@gnu.org>
 
 */
 
 #include "proto.hh"
-#include "dimen.hh"
 #include "misc.hh"
 #include "debug.hh"
-#include "atom.hh"
+#include "dimension-cache.hh"
+
+#include "align-element.hh"
 #include "stem.hh"
 #include "paper-def.hh"
 #include "lookup.hh"
 #include "stem-info.hh"
+#include "beam.hh"
+#include "staff-symbol.hh"
 
 Stem_info::Stem_info ()
 {
 }
+/*
+  FIXME: y dims should not be in internote.
+ */
 
-Stem_info::Stem_info (Stem const *s)
+Stem_info::Stem_info (Stem*s, int mult)
 {
-  x = s->hpos_f ();
-  dir_ = s->dir_;
-  beams_i_ =  0 >? (abs (s->flag_i_) - 2);
-
-  /*
-    [todo] 
-    * get algorithm
-    * runtime
-
-    Breitkopf + H\"artel:
-    miny_f_ = interline + #beams * interbeam
-    ideal8 = 2 * interline + interbeam
-    ideal16,32,64,128 = 1.5 * interline + #beams * interbeam
-
-    * B\"arenreiter:
-    miny_f_ = interline + #beams * interbeam
-    ideal8,16 = 2 interline + #beams * interbeam
-    ideal32,64,128 = 1.5 interline + #beams * interbeam
-       
-    */
-
-  Real internote_f = s->paper ()->internote_f ();
-  Real interline_f = 2 * internote_f;
-  Real notehead_y = interline_f;
-  // huh? why do i seem to need the / 2 ?
-  Real interbeam_f = s->paper ()->interbeam_f ();
-  // Real interbeam_f = s->paper ()->interbeam_f () / 2;
-  // perhaps bo dim (y) = internote?
+  mult_i_ =mult;
+  stem_l_ = s;
+  x_ = stem_l_->hpos_f ();
+  dir_ = stem_l_->dir_;
+  SCM bd = stem_l_->remove_elt_property (beam_dir_scm_sym);
+  
+  beam_dir_ = gh_scm2int (SCM_CDR(bd));
+  interstaff_f_ = 0;
+
+  Paper_def* paper_l = stem_l_->paper_l ();
+  Real internote_f = stem_l_->staff_line_leading_f ()/2;
+  Real interbeam_f = paper_l->interbeam_f (mult_i_);
+  Real beam_f = paper_l->beam_thickness_f ();
          
-   idealy_f_  = dir_ * s->stem_begin_f () + beams_i_ * interbeam_f; 
-   if (beams_i_ < 3)
-     idealy_f_ += 2 * interline_f;
-   else
-     idealy_f_ += 1.5 * interline_f;
-   idealy_f_ /= internote_f;
-  miny_f_ = dir_ * s->stem_begin_f () + 2 + beams_i_ * interbeam_f / internote_f;
-
-  idealy_f_ =  miny_f_ >? idealy_f_;
-  //    assert (miny_f_ <= idealy_f_);
+  {
+      static int i = 1;
+      DOUT << "******" << i++ << "******\n" 
+          << "begin_f: " << stem_l_->stem_begin_f () * dir_ 
+          << "\nchord_f/i: " << stem_l_->chord_start_f () * dir_ / internote_f << '\n';
+  }
+
+  // strangely enough, dim(chord_start_f) == pt (and not internote!)
+  idealy_f_ = stem_l_->chord_start_f () / internote_f;
+
+  // calculate using dim(y) == pt
+  idealy_f_ *= internote_f;
+
+  // for simplicity, we calculate as if dir == UP
+  idealy_f_ *= beam_dir_;
+
+  bool grace_b = stem_l_->get_elt_property (grace_scm_sym) != SCM_BOOL_F;
+
+  int stem_max = (int)rint(paper_l->get_var ("stem_max"));
+  String type_str = grace_b ? "grace_" : "";
+  Real min_stem_f = paper_l->get_var (type_str + "minimum_stem_length"
+                                     + to_str (mult_i_ <? stem_max)) * internote_f;
+  Real stem_f = paper_l->get_var (type_str + "stem_length"
+                                 + to_str (mult_i_ <? stem_max))* internote_f;
+
+  if (!beam_dir_ || (beam_dir_ == dir_))
+    /* normal beamed stem */
+    {
+      if (mult_i_)
+       {
+         idealy_f_ += beam_f;
+         idealy_f_ += (mult_i_ - 1) * interbeam_f;
+       }
+      miny_f_ = idealy_f_;
+      maxy_f_ = INT_MAX;
+
+      idealy_f_ += stem_f;
+      miny_f_ += min_stem_f;
+
+      /*
+       lowest beam of (UP) beam must never be lower than second staffline
+
+       Hmm, reference (Wanske?)
+
+       Although this (additional) rule is probably correct,
+       I expect that highest beam (UP) should also never be lower
+       than middle staffline, just as normal stems.
+       
+      */
+      if (!grace_b)
+       {
+         //highest beam of (UP) beam must never be lower than middle staffline
+         miny_f_ = miny_f_ >? 0;
+         //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
+    /* knee */
+    {
+      idealy_f_ -= beam_f;
+      // idealy_f_ -= (mult_i_ - 1) * interbeam_f;
+      // idealy_f_ += (mult_i_ - stem_l_->flag_i_ >? 0) * interbeam_f;
+      maxy_f_ = idealy_f_;
+      miny_f_ = -INT_MAX;
+
+      idealy_f_ -= stem_f;
+      maxy_f_ -= min_stem_f;
+    }
+
+  // set dim(y) == internote
+  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_ = maxy_f_ <? idealy_f_;
+  idealy_f_ = miny_f_ >? idealy_f_;
+
+  // interstaff beam
+  Beam* beam_l = stem_l_->beam_l_;
+  
+  Graphical_element *common = stem_l_->common_refpoint (beam_l, Y_AXIS);
+  Align_element * align = dynamic_cast<Align_element*> (common);
+  if (align && align->axis() == Y_AXIS)
+    {
+      if (align->threshold_interval_[MIN] != 
+         align->threshold_interval_[MAX])
+       warning (_ ("minVerticalAlign != maxVerticalAlign: interstaff beams/slurs may be broken"));
+
+      interstaff_f_ = align->threshold_interval_[MIN] / internote_f;
+
+      Graphical_element * beam_refpoint = beam_l;
+      Graphical_element * stem_refpoint = stem_l_;
+
+      while (beam_refpoint->parent_l (Y_AXIS) != common)
+       beam_refpoint = beam_refpoint->parent_l (Y_AXIS);
+      while (stem_refpoint->parent_l (Y_AXIS) != common)
+       stem_refpoint = stem_refpoint->parent_l (Y_AXIS);
+
+
+      int beam_prio =
+       align->get_priority (dynamic_cast<Score_element*> (beam_refpoint));
+      int stem_prio =
+       align->get_priority (dynamic_cast<Score_element*> (stem_refpoint));
+
+      /*
+       our staff is lower -> interstaff_f_ *= -1
+       */
+      if (beam_prio < stem_prio)
+       interstaff_f_ *= -1;
+      
+      idealy_f_ += interstaff_f_ * beam_dir_;
+      miny_f_ += interstaff_f_ * beam_dir_;
+      maxy_f_ += interstaff_f_ * beam_dir_;
+    }
 }