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 elt_l_->set_elt_property ("staff-position", gh_double2scm (0.0));
25 elt_l_->add_offset_callback (callback, Y_AXIS);
29 Staff_symbol_referencer_interface::has_interface_b ()
31 return unsmob_element (elt_l_->get_elt_pointer ("staff-symbol"))
32 || gh_number_p (elt_l_->get_elt_property ("staff-position"));
37 Staff_symbol_referencer_interface::line_count () const
39 Staff_symbol *st = staff_symbol_l ();
40 return st ? st->line_count () : 0;
44 Staff_symbol_referencer_interface::staff_symbol_l () const
46 SCM st = elt_l_->get_elt_pointer ("staff-symbol");
47 return dynamic_cast<Staff_symbol* > (unsmob_element(st));
51 Staff_symbol_referencer_interface::staff_space () const
53 Staff_symbol * st = staff_symbol_l ();
55 return st->staff_space ();
56 else if (elt_l_->pscore_l_ && elt_l_->paper_l ())
57 return elt_l_->paper_l ()->get_var ("interline");
64 Staff_symbol_referencer_interface::position_f () const
67 Staff_symbol * st = staff_symbol_l ();
68 Score_element * c = st ? elt_l_->common_refpoint (st, Y_AXIS) : 0;
71 Real y = elt_l_->relative_coordinate (c, Y_AXIS)
72 - st->relative_coordinate (c, Y_AXIS);
74 p += 2.0 * y / st->staff_space ();
78 SCM pos = elt_l_->get_elt_property ("staff-position");
79 if (gh_number_p (pos))
80 return gh_scm2double (pos);
89 should use offset callback!
92 Staff_symbol_referencer_interface::callback (Score_element const* sc,Axis )
94 SCM pos = sc->get_elt_property ("staff-position");
96 if (gh_number_p (pos))
98 Real space = staff_symbol_referencer (sc).staff_space ();
99 off = gh_scm2double (pos) * space/2.0;
101 Score_element* urg = (Score_element*)sc;
102 urg->set_elt_property ("staff-position", gh_double2scm (0.0));
109 This sets the position relative to the center of the staff symbol.
111 The function is hairy, because it can be callled in two situations:
113 1. There is no staff yet; we must set staff-position
115 2. There is a staff, and perhaps someone even applied a
116 translate_axis (). Then we must compensate for the translation
118 In either case, we set a callback to be sure that our new position
119 will be extracted from staff-position
123 Staff_symbol_referencer_interface::set_position (Real p)
125 Staff_symbol * st = staff_symbol_l ();
126 if (st && elt_l_->common_refpoint(st, Y_AXIS))
128 Real oldpos = position_f ();
129 elt_l_->set_elt_property ("staff-position", gh_double2scm (p - oldpos));
133 elt_l_->set_elt_property ("staff-position",
138 if (elt_l_->has_offset_callback_b (callback, Y_AXIS))
141 elt_l_->add_offset_callback (callback, Y_AXIS);
144 Staff_symbol_referencer_interface
145 staff_symbol_referencer (Score_element const*e)
147 return e; // gee, I'm so smart!
151 compare_position (Score_element *const &a, Score_element * const &b)
153 Staff_symbol_referencer_interface s1(a);
154 Staff_symbol_referencer_interface s2(b);
156 return sign(s1.position_f () - s2.position_f ());