lilypond-0.1.27
[lilypond.git] / lily / staff-side.cc
blob7f9abeeb8316d55e7c27db8e4c61a81fad0bdc9a
1 /*
2 staff-side.cc -- implement Staff_side
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "interval.hh"
10 #include "paper-def.hh"
11 #include "dimen.hh"
12 #include "staff-side.hh"
13 #include "staff-sym.hh"
14 #include "debug.hh"
16 void
17 Staff_side::set_staffsym (Staff_symbol* s_l)
19 staff_sym_l_ = s_l;
20 add_dependency (s_l);
23 Staff_side::Staff_side()
25 pos_i_ =0;
26 sym_int_ = Interval (0,0);
27 staff_size_i_ = 0;
28 staff_sym_l_ = 0;
29 dir_ = CENTER;
30 inside_staff_b_ = false;
33 void
34 Staff_side::read_staff_sym()
36 if (! staff_sym_l_)
37 return ;
38 staff_size_i_ = staff_sym_l_->steps_i();
42 Interval
43 Staff_side::support_height() const
45 Interval r;
47 for (int i=0; i < support_l_arr_.size(); i++)
48 r.unite (support_l_arr_[i]->height());
49 if (r.empty_b())
51 r = Interval (0,0);
53 return r;
56 void
57 Staff_side::add_support (Score_elem*i)
59 support_l_arr_.push (i);
60 add_dependency (i);
63 int
64 Staff_side::get_position_i() const
66 if (!dir_)
68 warning (_("Staff_side::get_position_i(): "
69 "somebody forgot to set my vertical direction, returning -20"));
70 return -20;
74 Real y=0;
75 Real inter_f = paper()-> internote_f ();
76 if (!inside_staff_b_)
78 y = (staff_sym_l_) ? dir_ * (staff_sym_l_->steps_i()/2 + 2) : -2;
79 y *=inter_f;
81 Interval v= support_height();
83 if (dir_ > 0)
85 y = y >? (v.max() + 2*inter_f);
87 else if (dir_ < 0)
89 y = y <? (v.min() - 2*inter_f);
92 else
94 Interval v= support_height();
95 y = v[dir_] + 2*dir_*inter_f; // ugh
97 return int (rint (Real (y)/inter_f)); // should ret a float?
100 Interval
101 Staff_side::symbol_height() const
103 return Interval (0,0);
106 void
107 Staff_side::do_post_processing()
109 sym_int_ = symbol_height();
110 pos_i_ = get_position_i();
111 if (dir_)
112 pos_i_ += int (rint (- sym_int_[-dir_] / paper()->internote_f ()));
115 void
116 Staff_side::do_substitute_dependency (Score_elem*o, Score_elem*n)
118 support_l_arr_.unordered_substitute (o,n);
119 if (staff_sym_l_ == o)
120 staff_sym_l_ = n ? (Staff_symbol*) n->spanner():0;
124 IMPLEMENT_IS_TYPE_B1(Staff_side, Score_elem);