]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-side.cc
release: 1.1.28
[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--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "interval.hh"
10 #include "paper-def.hh"
11 #include "staff-side.hh"
12 #include "staff-sym.hh"
13 #include "debug.hh"
14 #include "dimensions.hh"
15
16
17 Staff_side::Staff_side()
18 {
19   coordinate_offset_f_=0;
20   sym_int_ = Interval (0,0);
21   padding_f_ = 0.0;
22   dir_ = CENTER;
23   axis_ = Y_AXIS;
24 }
25
26
27 Interval
28 Staff_side::support_extent() const
29 {
30   Interval y_int;
31   for (int i=0; i < support_l_arr_.size(); i++) 
32     {
33       Dimension_cache *common = 
34         common_group (support_l_arr_[i], axis_);
35         
36       Real y = support_l_arr_[i]->relative_coordinate (common, axis_)  
37         -relative_coordinate (common,axis_);
38
39       y_int.unite (y + support_l_arr_[i]->extent(axis_));
40     }
41
42   if (y_int.empty_b())
43     {
44       y_int = Interval (0,0);
45     }
46   return Interval(y_int[LEFT] - padding_f_, y_int[RIGHT] + padding_f_);
47 }
48
49 void
50 Staff_side::add_support (Score_element*i)
51 {
52   support_l_arr_.push (i);
53   add_dependency (i);
54 }
55
56 Real
57 Staff_side::get_position_f () const
58 {
59   if (!dir_)
60     {
61       warning (_ ("Staff_side::get_position_f(): "
62                  "somebody forgot to set my direction, returning -20"));
63       return -20;
64     }
65
66
67   Real y = 0;
68   Real inter_f = paper()-> internote_f ();
69
70   Interval v = support_extent();
71
72   // ugh, dim[y] = PT over here
73   y = v[dir_] + 1 * dir_ * inter_f;
74
75   int coordinate_offset_f_i = (int)rint (y / inter_f);
76   // ugh: 5 -> staff_lines
77   if (axis_ == Y_AXIS && abs (coordinate_offset_f_i) < 5)
78     {
79       if (!(abs (coordinate_offset_f_i) % 2))
80         y += (Real)dir_ * inter_f;
81     }
82
83   return y;
84 }
85
86 Interval
87 Staff_side::symbol_height() const
88 {
89   return Interval (0,0);
90 }
91
92 void
93 Staff_side::do_pre_processing ()
94 {
95   if (axis_== X_AXIS)
96     do_side_processing ();
97 }
98
99 void
100 Staff_side::do_side_processing ()
101 {
102   sym_int_ = symbol_extent();
103   coordinate_offset_f_ = get_position_f();
104   if (dir_)
105     coordinate_offset_f_ += - sym_int_[-dir_];
106
107 }
108
109 /*
110   ugh should use do_width (), do_height (), get_extent ()
111  */
112 Interval
113 Staff_side::symbol_extent () const
114 {
115   if (axis_ == Y_AXIS)
116     return symbol_height ();
117   else
118     {
119       assert (false);
120     }
121 }
122
123
124 void
125 Staff_side::do_post_processing()
126 {
127   if (axis_ == Y_AXIS)
128     do_side_processing ();
129 }
130
131 void
132 Staff_side::do_substitute_dependency (Score_element*o, Score_element*n)
133 {
134   support_l_arr_.unordered_substitute (o,n);
135 }
136
137
138