]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/stem.cc
release: 1.3.3
[lilypond.git] / lily / stem.cc
index 7f5129763f78f6cd537736444c1aaec9977894cd..178166d73be50bd3c4f82f3501510c6f573980cc 100644 (file)
@@ -14,7 +14,7 @@
 #include "note-head.hh"
 #include "lookup.hh"
 #include "molecule.hh"
-#include "p-col.hh"
+#include "paper-column.hh"
 #include "misc.hh"
 #include "beam.hh"
 #include "rest.hh"
@@ -22,8 +22,8 @@
 void
 Stem::set_direction (Direction d)
 {
-  if  (!dir_)
-    warning ("Stem direction set already!");
+  if  (!get_direction ())
+    warning (_ ("stem direction set already!"));
 
   dir_ = d;
 
@@ -37,7 +37,7 @@ Stem::Stem ()
   beams_i_drul_[LEFT] = beams_i_drul_[RIGHT] = -1;
   yextent_drul_[DOWN] = yextent_drul_[UP] = 0;
   flag_i_ = 2;
-  dir_ = CENTER;
+  set_direction (CENTER);
   beam_l_ = 0;
 }
 
@@ -57,7 +57,7 @@ Stem::head_positions () const
   Interval_t<int> r;
   for (int i =0; i < head_l_arr_.size (); i++)
     {
-      int p = head_l_arr_[i]->position_i_;
+      int p = (int)head_l_arr_[i]->position_f ();
       r[BIGGER] = r[BIGGER] >? p;
       r[SMALLER] = r[SMALLER] <? p;
     }
@@ -68,9 +68,9 @@ void
 Stem::do_print () const
 {
 #ifndef NPRINT
-  DOUT << "flag "<< flag_i_;
+  DEBUG_OUT << "flag "<< flag_i_;
   if (beam_l_)
-    DOUT << "beamed";
+    DEBUG_OUT << "beamed";
 #endif
 }
 
@@ -83,31 +83,31 @@ Stem::stem_length_f () const
 Real
 Stem::stem_begin_f () const
 {
-  return yextent_drul_[Direction(-dir_)];
+  return yextent_drul_[Direction(-get_direction ())];
 }
 
 Real
 Stem::chord_start_f () const
 {
-  return head_positions()[dir_] * staff_line_leading_f ()/2.0;
+  return head_positions()[get_direction ()] * staff_line_leading_f ()/2.0;
 }
 
 Real
 Stem::stem_end_f () const
 {
-  return yextent_drul_[dir_];
+  return yextent_drul_[get_direction ()];
 }
 
 void
 Stem::set_stemend (Real se)
 {
   // todo: margins
-  if (dir_ && dir_ * head_positions()[dir_] >= se*dir_)
-    warning (_ ("weird stem size; check for narrow beams"));
+  if (get_direction () && get_direction () * head_positions()[get_direction ()] >= se*get_direction ())
+    warning (_ ("Weird stem size; check for narrow beams"));
 
   
-  yextent_drul_[dir_]  =  se;
-  yextent_drul_[Direction(-dir_)] = head_positions()[-dir_];
+  yextent_drul_[get_direction ()]  =  se;
+  yextent_drul_[Direction(-get_direction ())] = head_positions()[-get_direction ()];
 }
 
 int
@@ -149,45 +149,43 @@ Stem::get_center_distance (Direction d) const
 Direction
 Stem::get_default_dir () const
 {
-  return (get_center_distance (UP) >
-         get_center_distance (DOWN)) 
-    ? DOWN 
-    : UP;
-}
+  int du = get_center_distance (UP);
+  int dd = get_center_distance (DOWN);
 
-Direction
-Stem::get_dir () const
-{
-  return dir_;
+  if (sign (dd - du))
+    return Direction (sign (dd -du));
+
+  return Direction (int(paper_l ()->get_var ("stem_default_neutral_direction")));
 }
 
 
+
 void
 Stem::set_default_stemlen ()
 {
   Real length_f = 0.;
-  SCM scm_len = get_elt_property(length_scm_sym);
-  if (scm_len != SCM_BOOL_F)
+  SCM scm_len = get_elt_property("length");
+  if (scm_len != SCM_UNDEFINED)
     {
-      length_f = gh_scm2double (SCM_CDR(scm_len));
+      length_f = gh_scm2double (scm_len);
     }
   else
     length_f = paper_l ()->get_var ("stem_length0");
 
-  bool grace_b = get_elt_property (grace_scm_sym) != SCM_BOOL_F;
+  bool grace_b = get_elt_property ("grace") != SCM_UNDEFINED;
   String type_str = grace_b ? "grace_" : "";
 
   Real shorten_f = paper_l ()->get_var (type_str + "forced_stem_shorten0");
 
-  if (!dir_)
-    dir_ = get_default_dir ();
+  if (!get_direction ())
+    set_direction (get_default_dir ());
 
   /* 
     stems in unnatural (forced) direction should be shortened, 
     according to [Roush & Gourlay]
    */
   if (((int)chord_start_f ())
-      && (dir_ != get_default_dir ()))
+      && (get_direction () != get_default_dir ()))
     length_f -= shorten_f;
 
   if (flag_i_ >= 5)
@@ -195,10 +193,11 @@ Stem::set_default_stemlen ()
   if (flag_i_ >= 6)
     length_f += 1.0;
   
-  set_stemend ((dir_ > 0) ? head_positions()[BIGGER] + length_f:
+  set_stemend ((get_direction () > 0) ? head_positions()[BIGGER] + length_f:
               head_positions()[SMALLER] - length_f);
 
-  if (!grace_b && (dir_ * stem_end_f () < 0))
+  bool no_extend_b = get_elt_property ("no-stem-extend") != SCM_UNDEFINED;
+  if (!grace_b && !no_extend_b && (get_direction () * stem_end_f () < 0))
     set_stemend (0);
 }
 
@@ -217,29 +216,29 @@ Stem::set_noteheads ()
   if (!head_l_arr_.size ())
     return;
   head_l_arr_.sort (Note_head::compare);
-  if (dir_ < 0)
+  if (get_direction () < 0)
     head_l_arr_.reverse ();
 
   Note_head * beginhead =   head_l_arr_[0];
-  beginhead->set_elt_property (extremal_scm_sym, SCM_BOOL_T);
+  beginhead->set_elt_property ("extremal", SCM_BOOL_T);
   if  (beginhead !=   head_l_arr_.top ())
-    head_l_arr_.top ()->set_elt_property (extremal_scm_sym, SCM_BOOL_T);
+    head_l_arr_.top ()->set_elt_property ("extremal", SCM_BOOL_T);
   
   int parity=1;
-  int lastpos = beginhead->position_i_;
+  int lastpos = int (beginhead->position_f ());
   for (int i=1; i < head_l_arr_.size (); i ++)
     {
-      int dy =abs (lastpos- head_l_arr_[i]->position_i_);
+      int dy =abs (lastpos- (int)head_l_arr_[i]->position_f ());
 
       if (dy <= 1)
        {
          if (parity)
-           head_l_arr_[i]->flip_around_stem (dir_);
+           head_l_arr_[i]->flip_around_stem (get_direction ());
          parity = !parity;
        }
       else
        parity = 1;
-      lastpos = head_l_arr_[i]->position_i_;
+      lastpos = int (head_l_arr_[i]->position_f ());
     }
 }
 
@@ -252,9 +251,9 @@ Stem::do_pre_processing ()
 
   if (invisible_b ())
     {
-      set_elt_property (transparent_scm_sym, SCM_BOOL_T);
+      set_elt_property ("transparent", SCM_BOOL_T);
     }
-  set_empty (invisible_b ());
+  set_empty (invisible_b (), X_AXIS, Y_AXIS);
   set_spacing_hints ();
 }
 
@@ -267,22 +266,21 @@ Stem::do_pre_processing ()
 
    TODO: more advanced: supply height of noteheads as well, for more advanced spacing possibilities
  */
+
 void
 Stem::set_spacing_hints () 
 {
   if (!invisible_b ())
     {
-      SCM scmdir  = gh_int2scm (dir_);
-      SCM dirlist = column_l ()->get_elt_property (dir_list_scm_sym);
-      if (dirlist == SCM_BOOL_F)
+      SCM scmdir  = gh_int2scm (get_direction ());
+      SCM dirlist = column_l ()->get_elt_property ("dir-list");
+      if (dirlist == SCM_UNDEFINED)
        dirlist = SCM_EOL;
-      else
-       dirlist = SCM_CDR (dirlist);
 
       if (scm_sloppy_memq (scmdir, dirlist) == SCM_EOL)
        {
          dirlist = gh_cons (scmdir, dirlist);
-         column_l ()->set_elt_property (dir_list_scm_sym, dirlist);
+         column_l ()->set_elt_property ("dir-list", dirlist);
        }
     }
 }
@@ -291,15 +289,18 @@ Molecule
 Stem::flag () const
 {
   String style;
-  SCM st = get_elt_property (style_scm_sym);
-  if ( st != SCM_BOOL_F)
+  SCM st = get_elt_property ("style");
+  if ( st != SCM_UNDEFINED)
     {
-      st = SCM_CDR(st);
       style = ly_scm2string (st);
     }
 
-  char c = (dir_ == UP) ? 'u' : 'd';
-  return lookup_l ()->afm_find (String ("flags-") + to_str (c) + to_str (flag_i_) + style);
+  char c = (get_direction () == UP) ? 'u' : 'd';
+  Molecule m = lookup_l ()->afm_find (String ("flags-") + to_str (c) + 
+                                     to_str (flag_i_));
+  if (!style.empty_b ())
+    m.add_molecule(lookup_l ()->afm_find (String ("flags-") + to_str (c) + style));
+  return m;
 }
 
 Interval
@@ -331,7 +332,7 @@ Stem::do_brew_molecule_p () const
   Real head_wid = 0;
   if (head_l_arr_.size ())
     head_wid = head_l_arr_[0]->extent (X_AXIS).length ();
-  stem_y[Direction(-dir_)] += dir_ * head_wid * tan(ANGLE)/(2*dy);
+  stem_y[Direction(-get_direction ())] += get_direction () * head_wid * tan(ANGLE)/(2*dy);
   
   if (!invisible_b ())
     {
@@ -344,7 +345,7 @@ Stem::do_brew_molecule_p () const
   if (!beam_l_ && abs (flag_i_) > 2)
     {
       Molecule fl = flag ();
-      fl.translate_axis(stem_y[dir_]*dy, Y_AXIS);
+      fl.translate_axis(stem_y[get_direction ()]*dy, Y_AXIS);
       mol_p->add_molecule (fl);
     }
 
@@ -362,12 +363,13 @@ Stem::note_delta_f () const
   if (head_l_arr_.size())
     {
       Interval head_wid(0,  head_l_arr_[0]->extent (X_AXIS).length ());
-      Real rule_thick(paper_l ()->rule_thickness ());
+         Real rule_thick = paper_l ()->get_var ("stemthickness");
+
       Interval stem_wid(-rule_thick/2, rule_thick/2);
-      if (dir_ == CENTER)
+      if (get_direction () == CENTER)
        r = head_wid.center ();
       else
-       r = head_wid[dir_] - stem_wid[dir_];
+       r = head_wid[get_direction ()] - stem_wid[get_direction ()];
     }
   return r;
 }
@@ -392,3 +394,4 @@ Stem::do_substitute_element_pointer (Score_element*o,Score_element*n)
     }
   Staff_symbol_referencer::do_substitute_element_pointer (o,n);
 }
+