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"
16 Staff_symbol_referencer::has_interface (Score_element*e)
18 return unsmob_element (e->get_elt_property ("staff-symbol"))
19 || gh_number_p (e->get_elt_property ("staff-position"));
23 Staff_symbol_referencer::line_count (Score_element*me)
25 Score_element *st = staff_symbol_l (me);
26 return st ? Staff_symbol::line_count (st) : 0;
30 Staff_symbol_referencer::on_staffline (Score_element*me)
32 return on_staffline (me, (int) position_f (me));
36 Staff_symbol_referencer::on_staffline (Score_element*me, int pos)
38 int sz = line_count (me)-1;
39 return ((pos + sz) % 2) == 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 ("staffspace");
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!
90 MAKE_SCHEME_CALLBACK(Staff_symbol_referencer,callback,2);
92 Staff_symbol_referencer::callback (SCM element_smob, SCM )
94 Score_element *me = unsmob_element (element_smob);
97 SCM pos = me->get_elt_property ("staff-position");
99 if (gh_number_p (pos))
101 Real space = Staff_symbol_referencer::staff_space (me);
102 off = gh_scm2double (pos) * space/2.0;
105 me->set_elt_property ("staff-position", gh_double2scm (0.0));
107 return gh_double2scm (off);
112 This sets the position relative to the center of the staff symbol.
114 The function is hairy, because it can be callled in two situations:
116 1. There is no staff yet; we must set staff-position
118 2. There is a staff, and perhaps someone even applied a
119 translate_axis (). Then we must compensate for the translation
121 In either case, we set a callback to be sure that our new position
122 will be extracted from staff-position
126 Staff_symbol_referencer::set_position (Score_element*me,Real p)
128 Score_element * st = staff_symbol_l (me);
129 if (st && me->common_refpoint(st, Y_AXIS))
131 Real oldpos = position_f (me);
132 me->set_elt_property ("staff-position", gh_double2scm (p - oldpos));
136 me->set_elt_property ("staff-position",
141 if (me->has_offset_callback_b (Staff_symbol_referencer::callback_proc, Y_AXIS))
144 me->add_offset_callback (Staff_symbol_referencer::callback_proc, Y_AXIS);
148 half of the height, in staff space.
151 Staff_symbol_referencer::staff_radius (Score_element*me)
153 return (line_count (me) -1) / 2;
158 compare_position (Score_element *const &a, Score_element * const &b)
160 return sign (Staff_symbol_referencer::position_f((Score_element*)a) -
161 Staff_symbol_referencer::position_f((Score_element*)b));
166 Staff_symbol_referencer::set_interface (Score_element * e)
168 if (!gh_number_p (e->get_elt_property ("staff-position")))
169 e->set_elt_property ("staff-position", gh_double2scm (0.0));
171 e->add_offset_callback (Staff_symbol_referencer::callback_proc, Y_AXIS);