]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 0.1.7
[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     add_dependency( s_l );
21 }
22
23 Staff_side::Staff_side()
24 {
25     pos_i_ =0;
26     sym_int_ = Interval(0,0);
27     staff_size_i_ = 0;
28     staff_sym_l_=0;
29     dir_i_ =0;
30     inside_staff_b_ =false;
31 }
32
33 void
34 Staff_side::read_staff_sym()
35 {
36     if (! staff_sym_l_)
37         return ;
38     staff_size_i_ = staff_sym_l_->steps_i();
39 }
40
41
42 Interval
43 Staff_side::support_height() const
44 {
45     Interval r;
46     
47     for (int i=0; i < support_l_arr_.size(); i++)
48         r.unite(support_l_arr_[i]->height());
49     if (r.empty_b()) {
50         r = Interval(0,0);
51     }
52     return r;
53 }
54
55 void
56 Staff_side::add_support(Score_elem*i)
57 {
58     support_l_arr_.push(i);
59     add_dependency(i);
60 }
61
62 int
63 Staff_side::get_position_i()const
64 {
65     if (!dir_i_) {
66         warning("Staff_side::get_position_i(): " 
67                 "somebody forgot to set my vertical direction, returning -20");
68         return -20;
69     }
70     
71
72     Real y=0;
73     Real inter_f = paper()-> internote_f();
74     if (!inside_staff_b_) {
75         y  = (dir_i_ > 0 && staff_sym_l_) ? staff_sym_l_->steps_i() + 2: -2; 
76         y *=inter_f;
77         Interval v= support_height();
78
79         if (dir_i_ > 0) {
80             y = y >? (v.max() + 2*inter_f);
81         } else if (dir_i_ < 0) {
82             y = y <? (v.min() - 2*inter_f);
83         }
84     } else {
85         Interval v= support_height();
86         y = v[dir_i_]  + 2*dir_i_*inter_f;      // ugh
87     }
88     return int(rint(Real(y)/inter_f)); // should ret a float?
89 }
90
91 Interval
92 Staff_side::symbol_height() const
93 {
94     return Interval(0,0);
95 }
96
97 void
98 Staff_side::do_post_processing()
99 {
100     sym_int_ = symbol_height();
101     pos_i_ = get_position_i( );
102     if (dir_i_)
103         pos_i_ += int(rint(- sym_int_[-dir_i_] / paper()->internote_f()));
104 }
105
106 void
107 Staff_side::do_substitute_dependency(Score_elem*o, Score_elem*n)
108
109     support_l_arr_.unordered_substitute(o,n);
110     if (staff_sym_l_ == o)
111         staff_sym_l_ = n ? (Staff_symbol*) n->spanner():0;
112 }
113
114
115 IMPLEMENT_IS_TYPE_B1(Staff_side, Score_elem);