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