]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/staff-side.cc
release: 0.1.53
[lilypond.git] / lily / staff-side.cc
index 92b7917acb3a533797cd521324631f517967512c..35af4fff2d3fa456dc8f0548467bffa71e9292d1 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>
 */
 
+#include "interval.hh"
+#include "paper-def.hh"
+#include "dimen.hh"
 #include "staff-side.hh"
 #include "staff-sym.hh"
+#include "debug.hh"
 
-void
-Staff_side::set_staffsym(Staff_symbol* s_l)
+
+Staff_side::Staff_side()
+{
+  y_=0;
+  sym_int_ = Interval (0,0);
+  dir_ = CENTER;
+  inside_staff_b_ = false;
+}
+
+
+Interval
+Staff_side::support_height() const
 {
-    staff_sym_l_ = s_l;
+  Interval y_int;
+  for (int i=0; i < support_l_arr_.size(); i++) 
+    {
+      Axis_group_element *common = 
+       common_group (support_l_arr_[i], Y_AXIS);
+       
+      Real y = support_l_arr_[i]->relative_coordinate (common, Y_AXIS)  
+       -relative_coordinate (common,Y_AXIS);
+
+      y_int.unite (y + support_l_arr_[i]->height());
+    }
+
+
+  if (y_int.empty_b())
+    {
+      y_int = Interval (0,0);
+    }
+  return y_int;
 }
 
-Staff_side::Staff_side(Staff_elem * elem_l)
+void
+Staff_side::add_support (Score_elem*i)
 {
-    elem_l_ = elem_l;
-    dir_i_ =0;
-    staff_sym_l_ =0;
-    inside_staff_b_ =false;
+  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 vertical direction, returning -20"));
+      return -20;
+    }
+
+
+  Real y=0;
+  Real inter_f = paper()-> internote_f ();
+
+  Interval v= support_height();
+  if (inside_staff_b_)
+    // ugh: i don't know why, but this is needed for inside-staff
+    y = v[dir_] + 2 * dir_ * inter_f;  // ugh
+  else
+    // get accents just above staff; (fermata etc.: ugh)
+    y = v[dir_] - 3 * dir_ * inter_f;
+
+  return y;
+}
 
 Interval
-Staff_side::support_height() const return r;
+Staff_side::symbol_height() const
 {
-    for (int i=0; i < support_l_arr_.size(); i++)
-       r.unite(support_l_arr_[i]->height());
+  return Interval (0,0);
 }
 
 void
-Staff_side::add_support(Staff_elem*i)
+Staff_side::do_post_processing()
 {
-    support_l_arr_.push(i);
-    elem_l_->add_dependency(i);
+  sym_int_ = symbol_height();
+  y_ = get_position_f();
+  if (dir_)
+    y_ += - sym_int_[-dir_];
 }
 
-int
-Staff_side::get_position_i()const
+void
+Staff_side::do_substitute_dependency (Score_elem*o, Score_elem*n)
 {
-    if (!staff_sym_l_)
-       return 0;
-    
-    Real inter_f = staff_sym_l_->inter_note_f();
-    int staff_size_i = staff_sym_l_->steps_i();
-    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));
+  support_l_arr_.unordered_substitute (o,n);
 }
+
+
+IMPLEMENT_IS_TYPE_B1(Staff_side, Score_elem);