]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-referencer.cc
release: 1.3.9
[lilypond.git] / lily / staff-symbol-referencer.cc
1 /*   
2   staff-symbol-referencer.cc -- implement Staff_symbol_referencer
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7  */
8
9 #include <math.h>
10
11 #include "staff-symbol-referencer.hh"
12 #include "staff-symbol.hh"
13 #include "paper-def.hh"
14 #include "dimension-cache.hh"
15
16 Staff_symbol_referencer::Staff_symbol_referencer ()
17 {
18   staff_symbol_l_ =0;
19   position_f_ =0;
20 }
21
22 void
23 Staff_symbol_referencer::do_substitute_element_pointer (Score_element *o,
24                                                         Score_element*n)
25 {
26   if (staff_symbol_l_ == o)
27     {
28       staff_symbol_l_ = dynamic_cast<Staff_symbol*> (n);
29     }
30 }
31
32 int
33 Staff_symbol_referencer::lines_i () const
34 {
35   return (staff_symbol_l_) ?  staff_symbol_l_->no_lines_i_ : 5;
36 }
37
38 void
39 Staff_symbol_referencer::set_staff_symbol (Staff_symbol*s)
40 {
41   staff_symbol_l_ =s;
42   add_dependency (s);
43 }
44
45 Staff_symbol*
46 Staff_symbol_referencer::staff_symbol_l () const
47 {
48   return staff_symbol_l_;
49 }
50
51 Real
52 Staff_symbol_referencer::staff_line_leading_f () const
53 {
54   if (staff_symbol_l_)
55     return  staff_symbol_l_->staff_line_leading_f_;
56   else if (pscore_l_ && paper_l ())
57     paper_l ()->get_var ("interline");
58  
59   return 0.0;
60 }
61
62 Real
63 Staff_symbol_referencer::position_f () const
64 {
65   Real p = position_f_;
66   if (staff_symbol_l_ )
67     {
68       Graphical_element * c = common_refpoint (staff_symbol_l_, Y_AXIS);
69       Real y = relative_coordinate (c, Y_AXIS) - staff_symbol_l_->relative_coordinate (c, Y_AXIS);
70
71       p += 2.0 * y / staff_line_leading_f ();
72     }
73   return  p;
74 }
75
76
77
78 /*
79   should use offset callback!
80  */
81 void
82 Staff_symbol_referencer::do_pre_processing ()
83 {
84   translate_axis (position_f_ * staff_line_leading_f () /2.0, Y_AXIS);
85   position_f_ =0;
86 }
87
88
89 void
90 Staff_symbol_referencer::set_position (Real p)
91 {
92   Real halfspace =  staff_line_leading_f ()* 0.5;
93   
94   translate_axis (- halfspace * position_f (), Y_AXIS);
95   if (staff_symbol_l_)
96     translate_axis (halfspace * p, Y_AXIS);
97   else
98     position_f_ =   p;
99 }
100