2 staff-symbol-referencer.cc -- implement Staff_symbol_referencer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "staff-symbol-referencer.hh"
12 #include "staff-symbol.hh"
13 #include "paper-def.hh"
16 Staff_symbol_referencer::has_interface (Grob
*e
)
18 return unsmob_grob (e
->get_grob_property ("staff-symbol"))
19 || gh_number_p (e
->get_grob_property ("staff-position"));
23 Staff_symbol_referencer::line_count (Grob
*me
)
25 Grob
*st
= staff_symbol_l (me
);
26 return st
? Staff_symbol::line_count (st
) : 0;
30 Staff_symbol_referencer::on_staffline (Grob
*me
)
32 return on_staffline (me
, (int) rint (position_f (me
)));
36 Staff_symbol_referencer::on_staffline (Grob
*me
, int pos
)
38 int sz
= line_count (me
)-1;
39 return ((pos
+ sz
) % 2) == 0;
43 Staff_symbol_referencer::staff_symbol_l (Grob
*me
)
45 SCM st
= me
->get_grob_property ("staff-symbol");
46 return unsmob_grob (st
);
50 Staff_symbol_referencer::staff_space (Grob
*me
)
52 Grob
* st
= staff_symbol_l (me
);
54 return Staff_symbol::staff_space (st
);
62 Staff_symbol_referencer::position_f (Grob
*me
)
65 Grob
* st
= staff_symbol_l (me
);
66 Grob
* c
= st
? me
->common_refpoint (st
, Y_AXIS
) : 0;
69 Real y
= me
->relative_coordinate (c
, Y_AXIS
)
70 - st
->relative_coordinate (c
, Y_AXIS
);
72 p
+= 2.0 * y
/ Staff_symbol::staff_space (st
);
76 SCM pos
= me
->get_grob_property ("staff-position");
77 if (gh_number_p (pos
))
78 return gh_scm2double (pos
);
87 should use offset callback!
89 MAKE_SCHEME_CALLBACK (Staff_symbol_referencer
,callback
,2);
91 Staff_symbol_referencer::callback (SCM element_smob
, SCM
)
93 Grob
*me
= unsmob_grob (element_smob
);
96 SCM pos
= me
->get_grob_property ("staff-position");
98 if (gh_number_p (pos
))
100 Real space
= Staff_symbol_referencer::staff_space (me
);
101 off
= gh_scm2double (pos
) * space
/2.0;
104 me
->set_grob_property ("staff-position", gh_double2scm (0.0));
106 return gh_double2scm (off
);
111 This sets the position relative to the center of the staff symbol.
113 The function is hairy, because it can be callled in two situations:
115 1. There is no staff yet; we must set staff-position
117 2. There is a staff, and perhaps someone even applied a
118 translate_axis (). Then we must compensate for the translation
120 In either case, we set a callback to be sure that our new position
121 will be extracted from staff-position
125 Staff_symbol_referencer::set_position (Grob
*me
,Real p
)
127 Grob
* st
= staff_symbol_l (me
);
128 if (st
&& me
->common_refpoint (st
, Y_AXIS
))
130 Real oldpos
= position_f (me
);
131 me
->set_grob_property ("staff-position", gh_double2scm (p
- oldpos
));
135 me
->set_grob_property ("staff-position",
140 if (me
->has_offset_callback_b (Staff_symbol_referencer::callback_proc
, Y_AXIS
))
143 me
->add_offset_callback (Staff_symbol_referencer::callback_proc
, Y_AXIS
);
147 half of the height, in staff space.
150 Staff_symbol_referencer::staff_radius (Grob
*me
)
152 return (line_count (me
) -1) / 2;
157 compare_position (Grob
*const &a
, Grob
* const &b
)
159 return sign (Staff_symbol_referencer::position_f ((Grob
*)a
) -
160 Staff_symbol_referencer::position_f ((Grob
*)b
));
165 Staff_symbol_referencer::set_interface (Grob
* e
)
167 if (!gh_number_p (e
->get_grob_property ("staff-position")))
168 e
->set_grob_property ("staff-position", gh_double2scm (0.0));
170 e
->add_offset_callback (Staff_symbol_referencer::callback_proc
, Y_AXIS
);