]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 0.1.9
[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     {
51         r = Interval (0,0);
52     }
53   return r;
54 }
55
56 void
57 Staff_side::add_support (Score_elem*i)
58 {
59   support_l_arr_.push (i);
60   add_dependency (i);
61 }
62
63 int
64 Staff_side::get_position_i()const
65 {
66   if (!dir_i_) 
67     {
68         warning ("Staff_side::get_position_i(): " 
69                 "somebody forgot to set my vertical direction, returning -20");
70         return -20;
71     }
72   
73
74   Real y=0;
75   Real inter_f = paper()-> internote_f ();
76   if (!inside_staff_b_) 
77     {
78         y  = (dir_i_ > 0 && staff_sym_l_) ? staff_sym_l_->steps_i() + 2: -2; 
79         y *=inter_f;
80         Interval v= support_height();
81
82         if (dir_i_ > 0) 
83           {
84             y = y >? (v.max() + 2*inter_f);
85           }
86         else if (dir_i_ < 0) 
87           {
88             y = y <? (v.min() - 2*inter_f);
89           }
90     }
91   else 
92     {
93         Interval v= support_height();
94         y = v[dir_i_]  + 2*dir_i_*inter_f;      // ugh
95     }
96   return int (rint (Real (y)/inter_f)); // should ret a float?
97 }
98
99 Interval
100 Staff_side::symbol_height() const
101 {
102   return Interval (0,0);
103 }
104
105 void
106 Staff_side::do_post_processing()
107 {
108   sym_int_ = symbol_height();
109   pos_i_ = get_position_i();
110   if (dir_i_)
111         pos_i_ += int (rint (- sym_int_[-dir_i_] / paper()->internote_f ()));
112 }
113
114 void
115 Staff_side::do_substitute_dependency (Score_elem*o, Score_elem*n)
116
117   support_l_arr_.unordered_substitute (o,n);
118   if (staff_sym_l_ == o)
119         staff_sym_l_ = n ? (Staff_symbol*) n->spanner():0;
120 }
121
122
123 IMPLEMENT_IS_TYPE_B1(Staff_side, Score_elem);