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"
19 Staff_symbol_referencer::set_interface (Score_element
* e
)
21 if (!gh_number_p (e
->get_elt_property ("staff-position")))
22 e
->set_elt_property ("staff-position", gh_double2scm (0.0));
24 e
->add_offset_callback (callback
, Y_AXIS
);
28 Staff_symbol_referencer::has_interface (Score_element
*e
)
30 return unsmob_element (e
->get_elt_property ("staff-symbol"))
31 || gh_number_p (e
->get_elt_property ("staff-position"));
36 Staff_symbol_referencer::line_count (Score_element
*me
)
38 Score_element
*st
= staff_symbol_l (me
);
39 return st
? Staff_symbol::line_count (st
) : 0;
43 Staff_symbol_referencer::staff_symbol_l (Score_element
*me
)
45 SCM st
= me
->get_elt_property ("staff-symbol");
46 return unsmob_element(st
);
50 Staff_symbol_referencer::staff_space (Score_element
*me
)
52 Score_element
* st
= staff_symbol_l (me
);
54 return Staff_symbol::staff_space (st
);
55 else if (me
->pscore_l_
&& me
->paper_l ())
56 return me
->paper_l ()->get_var ("interline");
63 Staff_symbol_referencer::position_f (Score_element
*me
)
66 Score_element
* st
= staff_symbol_l (me
);
67 Score_element
* c
= st
? me
->common_refpoint (st
, Y_AXIS
) : 0;
70 Real y
= me
->relative_coordinate (c
, Y_AXIS
)
71 - st
->relative_coordinate (c
, Y_AXIS
);
73 p
+= 2.0 * y
/ Staff_symbol::staff_space (st
);
77 SCM pos
= me
->get_elt_property ("staff-position");
78 if (gh_number_p (pos
))
79 return gh_scm2double (pos
);
88 should use offset callback!
91 Staff_symbol_referencer::callback (Score_element
* sc
,Axis
)
93 Score_element
* me
= (Score_element
*)sc
; // UGH.
95 SCM pos
= sc
->get_elt_property ("staff-position");
97 if (gh_number_p (pos
))
99 Real space
= Staff_symbol_referencer::staff_space (sc
);
100 off
= gh_scm2double (pos
) * space
/2.0;
103 me
->set_elt_property ("staff-position", gh_double2scm (0.0));
110 This sets the position relative to the center of the staff symbol.
112 The function is hairy, because it can be callled in two situations:
114 1. There is no staff yet; we must set staff-position
116 2. There is a staff, and perhaps someone even applied a
117 translate_axis (). Then we must compensate for the translation
119 In either case, we set a callback to be sure that our new position
120 will be extracted from staff-position
124 Staff_symbol_referencer::set_position (Score_element
*me
,Real p
)
126 Score_element
* st
= staff_symbol_l (me
);
127 if (st
&& me
->common_refpoint(st
, Y_AXIS
))
129 Real oldpos
= position_f (me
);
130 me
->set_elt_property ("staff-position", gh_double2scm (p
- oldpos
));
134 me
->set_elt_property ("staff-position",
139 if (me
->has_offset_callback_b (callback
, Y_AXIS
))
142 me
->add_offset_callback (callback
, Y_AXIS
);
146 half of the height, in staff space.
149 Staff_symbol_referencer::staff_radius (Score_element
*me
)
151 return (line_count (me
) -1) / 2;
156 compare_position (Score_element
*const &a
, Score_element
* const &b
)
158 return sign (Staff_symbol_referencer::position_f((Score_element
*)a
) -
159 Staff_symbol_referencer::position_f((Score_element
*)b
));