]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 0.0.65
[lilypond.git] / lily / staff-side.cc
1 /*
2   staff-side.cc -- implement Staff_side
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "paper-def.hh"
10 #include "dimen.hh"
11 #include "staff-side.hh"
12 #include "staff-sym.hh"
13 #include "debug.hh"
14
15 void
16 Staff_side::set_staffsym(Staff_symbol* s_l)
17 {
18     staff_sym_l_ = s_l;
19 }
20
21 Staff_side::Staff_side()
22 {
23     staff_size_i_ = 0;
24     staff_sym_l_=0;
25     dir_i_ =0;
26     inside_staff_b_ =false;
27 }
28
29 void
30 Staff_side::read_staff_sym()
31 {
32     if (! staff_sym_l_)
33         return ;
34     staff_size_i_ = staff_sym_l_->steps_i();
35 }
36
37
38 Interval
39 Staff_side::support_height() const
40 {
41     Interval r;
42     
43     for (int i=0; i < support_l_arr_.size(); i++)
44         r.unite(support_l_arr_[i]->height());
45     if (r.empty_b()) {
46         r = Interval(0,0);
47     }
48     return r;
49 }
50
51 void
52 Staff_side::add_support(Score_elem*i)
53 {
54     support_l_arr_.push(i);
55     add_dependency(i);
56 }
57
58 int
59 Staff_side::get_position_i()const
60 {
61     if (!dir_i_) {
62         warning("Staff_side::get_position_i(): " 
63                 "somebody forgot to set my vertical direction, returning -20");
64         return -20;
65     }
66     
67
68     Real y=0;
69     Real inter_f = paper()-> internote_f();
70     if (!inside_staff_b_) {
71         y  = (dir_i_ > 0 && staff_sym_l_) ? staff_sym_l_->steps_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_] / paper()->internote_f()));
92 }
93
94
95 void
96 Staff_side::do_substitute_dependency(Score_elem*o, Score_elem*n )
97
98     int i;
99     while ((i=support_l_arr_.find_i(o) ) >=0)
100         if (n) 
101             support_l_arr_[i] = n;
102         else
103             support_l_arr_.del(i);
104
105     if (staff_sym_l_ == o)
106         staff_sym_l_ = n ? (Staff_symbol*) n->spanner():0;
107 }