]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/staff-side.cc
release: 1.1.18
[lilypond.git] / lily / staff-side.cc
index 29c584822f1b6079aef7697bd855cb1661bf1010..31180f0f6e9b2992cf774c65d5cae66f1e3b1d31 100644 (file)
 /*
   staff-side.cc -- implement Staff_side
 
-  source file of the LilyPond music typesetter
+  source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "dimen.hh"
+#include "interval.hh"
+#include "paper-def.hh"
 #include "staff-side.hh"
 #include "staff-sym.hh"
 #include "debug.hh"
+#include "dimensions.hh"
 
-void
-Staff_side::set_staffsym(Staff_symbol* s_l)
+
+Staff_side::Staff_side()
 {
-    staff_sym_l_ = s_l;
+  coordinate_offset_f_=0;
+  sym_int_ = Interval (0,0);
+  padding_f_ = 0.0;
+  dir_ = CENTER;
+  axis_ = Y_AXIS;
 }
 
-Staff_side::Staff_side(Staff_elem * elem_l)
+
+Interval
+Staff_side::support_extent() const
 {
-    inter_f_ = 2 PT;
-    staff_size_i_ = 0;
-    staff_sym_l_=0;
-    elem_l_ = elem_l;
-    dir_i_ =0;
-    inside_staff_b_ =false;
+  Interval y_int;
+  for (int i=0; i < support_l_arr_.size(); i++) 
+    {
+      Dimension_cache *common = 
+       common_group (support_l_arr_[i], axis_);
+       
+      Real y = support_l_arr_[i]->relative_coordinate (common, axis_)  
+       -relative_coordinate (common,axis_);
+
+      y_int.unite (y + support_l_arr_[i]->extent(axis_));
+    }
+
+  if (y_int.empty_b())
+    {
+      y_int = Interval (0,0);
+    }
+  return Interval(y_int[LEFT] - padding_f_, y_int[RIGHT] + padding_f_);
 }
 
 void
-Staff_side::read_staff_sym()
+Staff_side::add_support (Score_element*i)
 {
-    if (! staff_sym_l_)
-       return ;
-    inter_f_ = staff_sym_l_->inter_note_f();
-    staff_size_i_ = staff_sym_l_->steps_i();
+  support_l_arr_.push (i);
+  add_dependency (i);
 }
 
+Real
+Staff_side::get_position_f () const
+{
+  if (!dir_)
+    {
+      warning (_ ("Staff_side::get_position_f(): "
+                "somebody forgot to set my direction, returning -20"));
+      return -20;
+    }
+
+
+  Real y = 0;
+  Real inter_f = paper()-> internote_f ();
+
+  Interval v = support_extent();
+
+  // ugh, dim[y] = PT over here
+  y = v[dir_] + 1 * dir_ * inter_f;
+
+  int coordinate_offset_f_i = (int)rint (y / inter_f);
+  // ugh: 5 -> staff_lines
+  if (axis_ == Y_AXIS && abs (coordinate_offset_f_i) < 5)
+    {
+      if (!(abs (coordinate_offset_f_i) % 2))
+       y += (Real)dir_ * inter_f;
+    }
+//  else
+//    y = v[dir_] + 1 * dir_ * inter_f;
+
+  return y;
+}
 
 Interval
-Staff_side::support_height() const
+Staff_side::symbol_height() const
 {
-    Interval r;
-    
-    for (int i=0; i < support_l_arr_.size(); i++)
-       r.unite(support_l_arr_[i]->height());
-    if (r.empty_b()) {
-       r = Interval(0,0);
-    }
-    return r;
+  return Interval (0,0);
+}
+
+Interval
+Staff_side::symbol_width () const
+{
+  return Interval (0,0);
 }
 
 void
-Staff_side::add_support(Staff_elem*i)
+Staff_side::do_pre_processing ()
 {
-    support_l_arr_.push(i);
-    elem_l_->add_dependency(i);
+  if (axis_== X_AXIS)
+    do_side_processing ();
 }
 
-int
-Staff_side::get_position_i()const
+void
+Staff_side::do_side_processing ()
 {
-    ((Staff_side*)this)->read_staff_sym();
-    if (!dir_i_) {
-       warning("Staff_side::get_position_i(): " 
-               "somebody forgot to set my vertical direction, returning -20");
-       return -20;
-    }
-    
-
-    Real y=0;
-    if (!inside_staff_b_) {
-       y  = (dir_i_ > 0) ? staff_size_i_ + 2: -2; 
-       y *=inter_f_;
-       Interval v= support_height();
-
-       if (dir_i_ > 0) {
-           y = y >? (v.max() + 2*inter_f_);
-       } else if (dir_i_ < 0) {
-           y = y <? (v.min() - 2*inter_f_);
-       }
-    } else {
-       Interval v= support_height();
-       y = v[dir_i_]  + 2*dir_i_*inter_f_;     // ugh
-    }
-    return int(rint(Real(y)/inter_f_)); // should ret a float?
+  sym_int_ = symbol_extent();
+  coordinate_offset_f_ = get_position_f();
+  if (dir_)
+    coordinate_offset_f_ += - sym_int_[-dir_];
+
 }
 
-int
-Staff_side::get_position_i(Interval sym_dim) const
-{ 
-    int i= get_position_i();
-    return i+ int(rint(- sym_dim[-dir_i_] / inter_f_));
+/*
+  ugh should use do_width (), do_height (), get_extent ()
+ */
+Interval
+Staff_side::symbol_extent () const
+{
+  if (axis_ == Y_AXIS)
+    return symbol_height ();
+  else
+    return symbol_width ();
 }
+
+
+void
+Staff_side::do_post_processing()
+{
+  if (axis_ == Y_AXIS)
+    do_side_processing ();
+}
+
+void
+Staff_side::do_substitute_dependency (Score_element*o, Score_element*n)
+{
+  support_l_arr_.unordered_substitute (o,n);
+}
+
+
+