]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 0.1.24
[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_ = CENTER;
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_)
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  = (staff_sym_l_) ? dir_ * (staff_sym_l_->steps_i()/2 + 2) : -2;
79       y *=inter_f;
80
81       Interval v= support_height();
82
83       if (dir_ > 0)
84         {
85           y = y >? (v.max() + 2*inter_f);
86         }
87       else if (dir_ < 0)
88         {
89           y = y <? (v.min() - 2*inter_f);
90         }
91     }
92   else
93     {
94       Interval v= support_height();
95       y = v[dir_]  + 2*dir_*inter_f;    // ugh
96     }
97   return int (rint (Real (y)/inter_f)); // should ret a float?
98 }
99
100 Interval
101 Staff_side::symbol_height() const
102 {
103   return Interval (0,0);
104 }
105
106 void
107 Staff_side::do_post_processing()
108 {
109   sym_int_ = symbol_height();
110   pos_i_ = get_position_i();
111   if (dir_)
112     pos_i_ += int (rint (- sym_int_[-dir_] / paper()->internote_f ()));
113 }
114
115 void
116 Staff_side::do_substitute_dependency (Score_elem*o, Score_elem*n)
117 {
118   support_l_arr_.unordered_substitute (o,n);
119   if (staff_sym_l_ == o)
120     staff_sym_l_ = n ? (Staff_symbol*) n->spanner():0;
121 }
122
123
124 IMPLEMENT_IS_TYPE_B1(Staff_side, Score_elem);