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::on_staffline (Score_element*me)
45 return on_staffline (me, (int) position_f (me));
49 Staff_symbol_referencer::on_staffline (Score_element*me, int pos)
51 int sz = line_count (me)-1;
52 return ((pos + sz) % 2) == 0;
56 Staff_symbol_referencer::staff_symbol_l (Score_element*me)
58 SCM st = me->get_elt_property ("staff-symbol");
59 return unsmob_element(st);
63 Staff_symbol_referencer::staff_space (Score_element*me)
65 Score_element * st = staff_symbol_l (me);
67 return Staff_symbol::staff_space (st);
68 else if (me->pscore_l_ && me->paper_l ())
69 return me->paper_l ()->get_var ("staffspace");
76 Staff_symbol_referencer::position_f (Score_element*me)
79 Score_element * st = staff_symbol_l (me);
80 Score_element * c = st ? me->common_refpoint (st, Y_AXIS) : 0;
83 Real y = me->relative_coordinate (c, Y_AXIS)
84 - st->relative_coordinate (c, Y_AXIS);
86 p += 2.0 * y / Staff_symbol::staff_space (st);
90 SCM pos = me->get_elt_property ("staff-position");
91 if (gh_number_p (pos))
92 return gh_scm2double (pos);
101 should use offset callback!
104 Staff_symbol_referencer::callback (Score_element * sc,Axis )
106 Score_element* me = (Score_element*)sc; // UGH.
108 SCM pos = sc->get_elt_property ("staff-position");
110 if (gh_number_p (pos))
112 Real space = Staff_symbol_referencer::staff_space (sc);
113 off = gh_scm2double (pos) * space/2.0;
116 me->set_elt_property ("staff-position", gh_double2scm (0.0));
123 This sets the position relative to the center of the staff symbol.
125 The function is hairy, because it can be callled in two situations:
127 1. There is no staff yet; we must set staff-position
129 2. There is a staff, and perhaps someone even applied a
130 translate_axis (). Then we must compensate for the translation
132 In either case, we set a callback to be sure that our new position
133 will be extracted from staff-position
137 Staff_symbol_referencer::set_position (Score_element*me,Real p)
139 Score_element * st = staff_symbol_l (me);
140 if (st && me->common_refpoint(st, Y_AXIS))
142 Real oldpos = position_f (me);
143 me->set_elt_property ("staff-position", gh_double2scm (p - oldpos));
147 me->set_elt_property ("staff-position",
152 if (me->has_offset_callback_b (callback, Y_AXIS))
155 me->add_offset_callback (callback, Y_AXIS);
159 half of the height, in staff space.
162 Staff_symbol_referencer::staff_radius (Score_element*me)
164 return (line_count (me) -1) / 2;
169 compare_position (Score_element *const &a, Score_element * const &b)
171 return sign (Staff_symbol_referencer::position_f((Score_element*)a) -
172 Staff_symbol_referencer::position_f((Score_element*)b));