]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-column.cc
release: 1.3.29
[lilypond.git] / lily / note-column.cc
index 21740f4513ccd9a02707d047e05ad84760a362bc..8dca8fc0610632b10737a4d088423cf70256438c 100644 (file)
@@ -3,8 +3,11 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
+#include <math.h>              // ceil
+
+
 #include "dot-column.hh"
 #include "note-column.hh"
 #include "beam.hh"
@@ -14,6 +17,7 @@
 #include "debug.hh"
 #include "paper-def.hh"
 #include "group-interface.hh"
+#include "staff-symbol-referencer.hh"
 
 bool
 Note_column::rest_b () const
@@ -29,8 +33,8 @@ Note_column::shift_compare (Note_column *const &p1, Note_column*const&p2)
   SCM s1 = p1->get_elt_property ("horizontal-shift");
   SCM s2 = p2->get_elt_property ("horizontal-shift");
 
-  int h1 = (s1 == SCM_UNDEFINED) ? 0 : gh_scm2int (s1);
-  int h2 = (s2 == SCM_UNDEFINED) ? 0 : gh_scm2int (s2);
+  int h1 = (gh_number_p (s1))?  gh_scm2int (s1) :0;
+  int h2 = (gh_number_p (s2)) ? gh_scm2int (s2):0;
   return h1 - h2;
 }
 
@@ -61,8 +65,9 @@ Note_column::head_positions_interval() const
   for (; gh_pair_p (h); h = gh_cdr (h))
     {
       Score_element *se = unsmob_element (gh_car (h));
+      Staff_symbol_referencer_interface si (se); 
       
-      int j = int (dynamic_cast<Staff_symbol_referencer*> (se)->position_f ());
+      int j = int (si.position_f ());
       iv.unite (Slice (j,j));
     }
   return iv;
@@ -114,14 +119,13 @@ Note_column::add_head (Rhythmic_head *h)
 void
 Note_column::translate_rests (int dy_i)
 {
-  invalidate_cache (Y_AXIS);
-
   SCM s = get_elt_property ("rests");
   for (; gh_pair_p (s); s = gh_cdr (s))
     {
-      Score_element * se = unsmob_element ( gh_car (s));
-      Staff_symbol_referencer *str = dynamic_cast<Staff_symbol_referencer*> (se);
-      se->translate_axis (dy_i * str->staff_line_leading_f ()/2.0, Y_AXIS);
+      Score_element * se = unsmob_element (gh_car (s));
+      Staff_symbol_referencer_interface si (se);
+
+      se->translate_axis (dy_i * si.staff_space ()/2.0, Y_AXIS);
     }
 }
 
@@ -140,7 +144,6 @@ Note_column::set_dotcol (Dot_column *d)
   Should lookup
     
     rest -> stem -> beam -> interpolate_y_position ()
-    
 */
 
 void
@@ -150,18 +153,37 @@ Note_column::do_post_processing ()
     return;
 
   Beam * b = stem_l ()->beam_l ();
-  if (!b || !b->stem_count ())
+  if (!b || !b->visible_stem_count ())
     return;
   
-  /* ugh. Should be done by beam. */
+  /* ugh. Should be done by beam.
+     (what? should be done --jcn)
+    scary too?: height is calculated during post_processing
+   */
+  Real beam_dy = 0;
+  Real beam_y = 0;
+
+  SCM s = b->get_elt_property ("height");
+  if (gh_number_p (s))
+    beam_dy = gh_scm2double (s);
+  
+  s = b->get_elt_property ("y-position");
+  if (gh_number_p (s))
+    beam_y = gh_scm2double (s);
+
+  
+  Real x0 = b->first_visible_stem ()->hpos_f ();
+  Real dx = b->last_visible_stem ()->hpos_f () - x0;
+  Real dydx = beam_dy && dx ? beam_dy/dx : 0;
+
   Direction d = stem_l ()->get_direction ();
-  Real beamy = (stem_l ()->hpos_f () - b->stem(0)->hpos_f ()) * b->slope_f_ + b->left_y_;
+  Real beamy = (stem_l ()->hpos_f () - x0) * dydx + beam_y;
 
-  SCM s = get_elt_property ("rests");
+  s = get_elt_property ("rests");
   Score_element * se = unsmob_element (gh_car (s));
-  Staff_symbol_referencer *str = dynamic_cast<Staff_symbol_referencer*> (se);
+  Staff_symbol_referencer_interface si (se);
 
-  Real staff_space = str->staff_line_leading_f ();      
+  Real staff_space = si.staff_space ();      
   Real rest_dim = extent (Y_AXIS)[d]*2.0  /staff_space ;
 
   Real minimum_dist
@@ -169,7 +191,7 @@ Note_column::do_post_processing ()
   Real dist =
     minimum_dist +  -d  * (beamy - rest_dim) >? 0;
 
-  int stafflines = str->lines_i ();
+  int stafflines = si.line_count ();
 
   // move discretely by half spaces.
   int discrete_dist = int (ceil (dist ));
@@ -201,5 +223,4 @@ Note_column::first_head () const
 {
   Stem * st = stem_l ();
   return st?  st->first_head (): 0; 
-
 }