]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-referencer.cc
patch::: 1.3.1.hwn1
[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_sym_l_ =0;
19 }
20
21 void
22 Staff_symbol_referencer::do_substitute_element_pointer (Score_element *o, Score_element*n)
23 {
24   if (staff_sym_l_ == o)
25     {
26       staff_sym_l_ = dynamic_cast<Staff_symbol*> (n);
27     }
28 }
29
30 int
31 Staff_symbol_referencer::lines_i () const
32 {
33   return (staff_sym_l_) ?  staff_sym_l_->no_lines_i_ : 5;
34 }
35
36 void
37 Staff_symbol_referencer::set_staff_symbol (Staff_symbol*s)
38 {
39   staff_sym_l_ =s;
40   add_dependency (s);
41 }
42
43 Staff_symbol*
44 Staff_symbol_referencer::staff_symbol_l () const
45 {
46   return staff_sym_l_;
47 }
48
49 Real
50 Staff_symbol_referencer::staff_line_leading_f () const
51 {
52   return (staff_sym_l_) ? staff_sym_l_->staff_line_leading_f_ : paper_l ()->get_var ("interline");
53 }
54
55 Real
56 Staff_symbol_referencer::position_f () const
57 {
58   if (!staff_sym_l_ )
59     return 0;
60
61   Graphical_element * c = common_refpoint (staff_sym_l_, Y_AXIS);
62   Real y = relative_coordinate (c, Y_AXIS) - staff_sym_l_->relative_coordinate (c, Y_AXIS);
63
64   return 2.0 * y / staff_line_leading_f ();
65 }
66