]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 0.0.68pre
[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 "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"
15
16 void
17 Staff_side::set_staffsym(Staff_symbol* s_l)
18 {
19     staff_sym_l_ = s_l;
20 }
21
22 Staff_side::Staff_side()
23 {
24     staff_size_i_ = 0;
25     staff_sym_l_=0;
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     staff_size_i_ = staff_sym_l_->steps_i();
36 }
37
38
39 Interval
40 Staff_side::support_height() const
41 {
42     Interval r;
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     return r;
50 }
51
52 void
53 Staff_side::add_support(Score_elem*i)
54 {
55     support_l_arr_.push(i);
56     add_dependency(i);
57 }
58
59 int
60 Staff_side::get_position_i()const
61 {
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     Real inter_f = paper()-> internote_f();
71     if (!inside_staff_b_) {
72         y  = (dir_i_ > 0 && staff_sym_l_) ? staff_sym_l_->steps_i() + 2: -2; 
73         y *=inter_f;
74         Interval v= support_height();
75
76         if (dir_i_ > 0) {
77             y = y >? (v.max() + 2*inter_f);
78         } else if (dir_i_ < 0) {
79             y = y <? (v.min() - 2*inter_f);
80         }
81     } else {
82         Interval v= support_height();
83         y = v[dir_i_]  + 2*dir_i_*inter_f;      // ugh
84     }
85     return int(rint(Real(y)/inter_f)); // should ret a float?
86 }
87
88 int
89 Staff_side::get_position_i(Interval sym_dim) const
90
91     int i= get_position_i();
92     return i+ int(rint(- sym_dim[-dir_i_] / paper()->internote_f()));
93 }
94
95
96 void
97 Staff_side::do_substitute_dependency(Score_elem*o, Score_elem*n )
98
99     int i;
100     while ((i=support_l_arr_.find_i(o) ) >=0)
101         if (n) 
102             support_l_arr_[i] = n;
103         else
104             support_l_arr_.del(i);
105
106     if (staff_sym_l_ == o)
107         staff_sym_l_ = n ? (Staff_symbol*) n->spanner():0;
108 }
109
110 IMPLEMENT_STATIC_NAME(Staff_side);
111 IMPLEMENT_IS_TYPE_B1(Staff_side, Score_elem);