]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 0.0.55
[lilypond.git] / lily / staff-side.cc
1 /*
2   staff-side.cc -- implement Staff_side
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "dimen.hh"
10 #include "staff-side.hh"
11 #include "staff-sym.hh"
12 #include "debug.hh"
13
14 void
15 Staff_side::set_staffsym(Staff_symbol* s_l)
16 {
17     staff_sym_l_ = s_l;
18 }
19
20 Staff_side::Staff_side(Staff_elem * elem_l)
21 {
22     inter_f_ = 2 PT;
23     staff_size_i_ = 0;
24     staff_sym_l_=0;
25     elem_l_ = elem_l;
26     dir_i_ =0;
27     inside_staff_b_ =false;
28 }
29
30 void
31 Staff_side::read_staff_sym()
32 {
33     if (! staff_sym_l_)
34         return ;
35     inter_f_ = staff_sym_l_->inter_note_f();
36     staff_size_i_ = staff_sym_l_->steps_i();
37 }
38
39
40 Interval
41 Staff_side::support_height() const return r;
42 {
43     
44     for (int i=0; i < support_l_arr_.size(); i++)
45         r.unite(support_l_arr_[i]->height());
46     if (r.empty_b()) {
47         r = Interval(0,0);
48     }
49 }
50
51 void
52 Staff_side::add_support(Staff_elem*i)
53 {
54     support_l_arr_.push(i);
55     elem_l_->add_dependency(i);
56 }
57
58 int
59 Staff_side::get_position_i()const
60 {
61     ((Staff_side*)this)->read_staff_sym();
62     if (!dir_i_) {
63         warning("Staff_side::get_position_i(): " 
64                 "somebody forgot to set my vertical direction, returning -20");
65         return -20;
66     }
67     
68
69     Real y=0;
70     if (!inside_staff_b_) {
71         y  = (dir_i_ > 0) ? staff_size_i_ + 2: -2; 
72         y *=inter_f_;
73         Interval v= support_height();
74
75         if (dir_i_ > 0) {
76             y = y >? (v.max() + 2*inter_f_);
77         } else if (dir_i_ < 0) {
78             y = y <? (v.min() - 2*inter_f_);
79         }
80     } else {
81         Interval v= support_height();
82         y = v[dir_i_]  + 2*dir_i_*inter_f_;     // ugh
83     }
84     return int(rint(Real(y)/inter_f_)); // should ret a float?
85 }
86
87 int
88 Staff_side::get_position_i(Interval sym_dim) const
89
90     int i= get_position_i();
91     return i+ int(rint(- sym_dim[dir_i_] / inter_f_));
92 }