]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-symbol-referencer.cc
patch::: 1.3.9.hwn2
[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   set_elt_property ("staff-position", gh_double2scm (0.0));
19   dim_cache_[Y_AXIS]->off_callbacks_.push (callback);
20 }
21
22
23 int
24 Staff_symbol_referencer::lines_i () const
25 {
26   Staff_symbol *st = staff_symbol_l ();
27   return st  ?  st->no_lines_i_ : 5;
28 }
29
30 Staff_symbol*
31 Staff_symbol_referencer::staff_symbol_l () const
32 {
33   SCM st = get_elt_property ("staff-symbol");
34   if (SMOB_IS_TYPE_B (Score_element, st))
35     return dynamic_cast<Staff_symbol* > (SMOB_TO_TYPE (Score_element,st));
36   else
37     return 0;
38 }
39
40 Real
41 Staff_symbol_referencer::staff_line_leading_f () const
42 {
43   Staff_symbol * st = staff_symbol_l ();
44   if (st)
45     return st->staff_line_leading_f_;
46   else if (pscore_l_ && paper_l ())
47     paper_l ()->get_var ("interline");
48  
49   return 0.0;
50 }
51
52
53 Real
54 Staff_symbol_referencer::position_f () const
55 {
56   Real p =0.0;
57   SCM pos = get_elt_property ("staff-position");
58   if (gh_number_p (pos))
59     p = gh_scm2double (pos);
60
61   Staff_symbol * st = staff_symbol_l ();
62   if (st)
63     {
64       Score_element * c = common_refpoint (st, Y_AXIS);
65       Real y = relative_coordinate (c, Y_AXIS)
66         - st->relative_coordinate (c, Y_AXIS);
67
68       p += 2.0 * y / staff_line_leading_f ();
69     }
70   return  p;
71 }
72
73
74
75 /*
76   should use offset callback!
77  */
78 Real
79 Staff_symbol_referencer::callback (Dimension_cache const * c)
80 {
81   Score_element * sc = dynamic_cast<Score_element*> (c->element_l ());
82   Staff_symbol_referencer * ref = dynamic_cast<Staff_symbol_referencer*> (sc);
83   SCM pos = sc->get_elt_property ("staff-position");
84   Real off =0.0;
85   if (gh_number_p (pos))
86     {
87       off = gh_scm2double (pos) * ref->staff_line_leading_f () /2.0;
88     }
89   sc->set_elt_property ("staff-position", gh_double2scm (0.0));
90
91   return off;
92 }
93
94
95 void
96 Staff_symbol_referencer::set_position (Real p)
97 {
98   Real halfspace = staff_line_leading_f ()* 0.5;
99   
100   translate_axis (- halfspace * position_f (), Y_AXIS);
101   Staff_symbol *st = staff_symbol_l ();
102   if (st)
103     translate_axis (halfspace * p, Y_AXIS);
104   else
105     {
106       //      SCM pos = get_elt_property ("staff-position");
107       set_elt_property ("staff-position",
108                         gh_double2scm (p));
109                         //                      gh_double2scm (p + gh_scm2double (pos)));
110     }
111 }
112