2 staff-symbol-referencer.cc -- implement Staff_symbol_referencer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "staff-symbol-referencer.hh"
12 #include "staff-symbol.hh"
13 #include "paper-def.hh"
14 #include "dimension-cache.hh"
16 Staff_symbol_referencer_interface::Staff_symbol_referencer_interface (Score_element
const *sc
)
18 elt_l_
= (Score_element
*)sc
;
22 Staff_symbol_referencer_interface::set_interface ()
24 if (!gh_number_p (elt_l_
->get_elt_property ("staff-position")))
25 elt_l_
->set_elt_property ("staff-position", gh_double2scm (0.0));
27 elt_l_
->add_offset_callback (callback
, Y_AXIS
);
31 Staff_symbol_referencer_interface::has_interface_b ()
33 return unsmob_element (elt_l_
->get_elt_pointer ("staff-symbol"))
34 || gh_number_p (elt_l_
->get_elt_property ("staff-position"));
39 Staff_symbol_referencer_interface::line_count () const
41 Staff_symbol
*st
= staff_symbol_l ();
42 return st
? st
->line_count () : 0;
46 Staff_symbol_referencer_interface::staff_symbol_l () const
48 SCM st
= elt_l_
->get_elt_pointer ("staff-symbol");
49 return dynamic_cast<Staff_symbol
* > (unsmob_element(st
));
53 Staff_symbol_referencer_interface::staff_space () const
55 Staff_symbol
* st
= staff_symbol_l ();
57 return st
->staff_space ();
58 else if (elt_l_
->pscore_l_
&& elt_l_
->paper_l ())
59 return elt_l_
->paper_l ()->get_var ("interline");
66 Staff_symbol_referencer_interface::position_f () const
69 Staff_symbol
* st
= staff_symbol_l ();
70 Score_element
* c
= st
? elt_l_
->common_refpoint (st
, Y_AXIS
) : 0;
73 Real y
= elt_l_
->relative_coordinate (c
, Y_AXIS
)
74 - st
->relative_coordinate (c
, Y_AXIS
);
76 p
+= 2.0 * y
/ st
->staff_space ();
80 SCM pos
= elt_l_
->get_elt_property ("staff-position");
81 if (gh_number_p (pos
))
82 return gh_scm2double (pos
);
91 should use offset callback!
94 Staff_symbol_referencer_interface::callback (Score_element
const* sc
,Axis
)
96 Score_element
* me
= (Score_element
*)sc
; // UGH.
98 SCM pos
= sc
->get_elt_property ("staff-position");
100 if (gh_number_p (pos
))
102 Real space
= staff_symbol_referencer (sc
).staff_space ();
103 off
= gh_scm2double (pos
) * space
/2.0;
106 me
->set_elt_property ("staff-position", gh_double2scm (0.0));
113 This sets the position relative to the center of the staff symbol.
115 The function is hairy, because it can be callled in two situations:
117 1. There is no staff yet; we must set staff-position
119 2. There is a staff, and perhaps someone even applied a
120 translate_axis (). Then we must compensate for the translation
122 In either case, we set a callback to be sure that our new position
123 will be extracted from staff-position
127 Staff_symbol_referencer_interface::set_position (Real p
)
129 Staff_symbol
* st
= staff_symbol_l ();
130 if (st
&& elt_l_
->common_refpoint(st
, Y_AXIS
))
132 Real oldpos
= position_f ();
133 elt_l_
->set_elt_property ("staff-position", gh_double2scm (p
- oldpos
));
137 elt_l_
->set_elt_property ("staff-position",
142 if (elt_l_
->has_offset_callback_b (callback
, Y_AXIS
))
145 elt_l_
->add_offset_callback (callback
, Y_AXIS
);
148 Staff_symbol_referencer_interface
149 staff_symbol_referencer (Score_element
const*e
)
151 return e
; // gee, I'm so smart!
155 compare_position (Score_element
*const &a
, Score_element
* const &b
)
157 Staff_symbol_referencer_interface
s1(a
);
158 Staff_symbol_referencer_interface
s2(b
);
160 return sign(s1
.position_f () - s2
.position_f ());