]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-referencer.cc
release: 1.3.6
[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   position_i_ =0;
20 }
21
22 void
23 Staff_symbol_referencer::do_substitute_element_pointer (Score_element *o, Score_element*n)
24 {
25   if (staff_sym_l_ == o)
26     {
27       staff_sym_l_ = dynamic_cast<Staff_symbol*> (n);
28     }
29 }
30
31 int
32 Staff_symbol_referencer::lines_i () const
33 {
34   return (staff_sym_l_) ?  staff_sym_l_->no_lines_i_ : 5;
35 }
36
37 void
38 Staff_symbol_referencer::set_staff_symbol (Staff_symbol*s)
39 {
40   staff_sym_l_ =s;
41   add_dependency (s);
42 }
43
44 Staff_symbol*
45 Staff_symbol_referencer::staff_symbol_l () const
46 {
47   return staff_sym_l_;
48 }
49
50 Real
51 Staff_symbol_referencer::staff_line_leading_f () const
52 {
53   if (staff_sym_l_)
54     return  staff_sym_l_->staff_line_leading_f_;
55   else if (pscore_l_ && paper_l ())
56     paper_l ()->get_var ("interline");
57  
58   return 0.0;
59 }
60
61 Real
62 Staff_symbol_referencer::position_f () const
63 {
64   Real p = position_i_;
65   if (staff_sym_l_ )
66     {
67       Graphical_element * c = common_refpoint (staff_sym_l_, Y_AXIS);
68       Real y = relative_coordinate (c, Y_AXIS) - staff_sym_l_->relative_coordinate (c, Y_AXIS);
69
70       p += 2.0 * y / staff_line_leading_f ();
71     }
72   return  p;
73 }
74
75
76
77 void
78 Staff_symbol_referencer::do_pre_processing ()
79 {
80   translate_axis (position_i_ * staff_line_leading_f () /2.0, Y_AXIS);
81   position_i_ =0;
82 }
83
84
85 void
86 Staff_symbol_referencer::set_position (int p)
87 {
88   Real halfspace =  staff_line_leading_f ()* 0.5;
89   
90   translate_axis (- halfspace * position_f (), Y_AXIS);
91   if (staff_sym_l_)
92     translate_axis (halfspace * p, Y_AXIS);
93   else
94     position_i_ =   p;
95 }